IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NSProvider.h
Go to the documentation of this file.
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 
27 #ifndef _NS_PROVIDER_H_
28 #define _NS_PROVIDER_H_
29 
30 
31 #include <string>
32 #include "NSSyncInfo.h"
33 #include "NSMessage.h"
34 #include "NSUtils.h"
35 #include "NSTopicsList.h"
36 #include "NSException.h"
37 
38 namespace OIC
39 {
40  namespace Service
41  {
46  class NSProvider
47  {
48  public:
49 
55 
62 
69 
73  NSProvider(): m_topicList(std::make_shared<NSTopicsList>()), m_state(NSProviderState::DENY),
74  m_subscribedState(NSProviderSubscribedState::DENY),
75  m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
76  {
77  }
78 
84  NSProvider(const std::string &providerId) : m_providerId(providerId),
85  m_topicList(std::make_shared<NSTopicsList>()), m_state(NSProviderState::DENY),
86  m_subscribedState(NSProviderSubscribedState::DENY),
87  m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
88  {
89  }
90 
97  NSProvider(const std::string &providerId, std::shared_ptr<NSTopicsList> topicList) : m_providerId(
98  providerId), m_topicList(topicList), m_state(NSProviderState::DENY),
99  m_subscribedState(NSProviderSubscribedState::DENY),
100  m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
101  {
102  }
103 
109  NSProvider(::NSProvider *provider);
110 
116  NSProvider(const NSProvider &provider);
117 
124  NSProvider &operator=(const NSProvider &provider);
125 
129  ~NSProvider() = default;
130 
136  std::string getProviderId() const;
137 
143  std::shared_ptr<NSTopicsList> getTopicList() const throw (NSException);
144 
151  NSResult updateTopicList(std::shared_ptr<NSTopicsList> topicList) throw (NSException);
152 
159 
165  NSProviderSubscribedState getProviderSubscribedState() const throw (NSException);
166 
178  NSResult subscribe() throw (NSException);
179 
188  NSResult unsubscribe() throw (NSException);
189 
194  bool isSubscribed() throw (NSException);
195 
203  NSResult sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type) throw (NSException);
204 
212  void setListener(ProviderStateCallback stateHandle,
213  MessageReceivedCallback messageHandle,
214  SyncInfoReceivedCallback syncHandle);
215 
222 
229 
236 
242  void setTopicList(std::shared_ptr<NSTopicsList> topicsList);
243 
249  void setProviderState(const NSProviderState &providerState);
250 
256  void setProviderSubscribedState(const NSProviderSubscribedState &subscribedState);
257 
258  private:
259  ::NSProvider *getNSProvider();
260  bool isValid() const;
261 
262  private:
263  std::string m_providerId;
264  std::shared_ptr<NSTopicsList> m_topicList;
265  NSProviderState m_state;
266  NSProviderSubscribedState m_subscribedState;
267 
268  ProviderStateCallback m_stateCb;
269  MessageReceivedCallback m_messageCb;
270  SyncInfoReceivedCallback m_syncInfoCb;
271  };
272  }
273 }
274 #endif /* _NS_PROVIDER_H_ */
~NSProvider()=default
Destructor of NSProvider.
This file contains Notification service Utils.
This class provides a set of APIs for Notification service Topics Linked list.
Definition: NSTopicsList.h:43
ProviderStateCallback getProviderStateReceivedCb() const
This method is for getting the registered cb of Provider State received.
This class provides a set of Notification service Provider representation APIs.
Definition: NSProvider.h:46
NSProvider()
Constructor of NSProvider.
Definition: NSProvider.h:73
void setProviderSubscribedState(const NSProviderSubscribedState &subscribedState)
This method is for setting subscribedState for the Notification service provider. ...
bool isSubscribed()
This method is for requesting subscription status from Provider of Notification service.
NSProvider(const std::string &providerId, std::shared_ptr< NSTopicsList > topicList)
Constructor of NSProvider.
Definition: NSProvider.h:97
SyncInfoReceivedCallback getSyncInfoReceivedCb() const
This method is for getting the registered cb of Notification SyncInfo received.
std::string getProviderId() const
This method is for getting ProviderId from the Notification service provider.
std::shared_ptr< NSTopicsList > getTopicList() const
This method is for getting NSTopic List from the Notification service provider.
This file contains Notification service SyncInfo representation.
NSResult
NSResult - enumeration for NS service Result.
Definition: NSUtils.h:38
void(* ProviderStateCallback)(NSProviderState)
Invoked when the provider state is changed.
Definition: NSProvider.h:54
This class provides a set of APIs for Notification service Message .
Definition: NSMessage.h:42
void(* SyncInfoReceivedCallback)(NSSyncInfo)
Provider and consumer use this callback function to receive the status of the message synchronization...
Definition: NSProvider.h:68
NSResult updateTopicList(std::shared_ptr< NSTopicsList > topicList)
Update Topic list that is wanted to be subscribed from provider.
This file contains Notification service topics linked list representation.
MessageReceivedCallback getMessageReceivedCb() const
This method is for getting the registered cb of Notification message received.
NSProviderState
NSProviderState of notification service.
Definition: NSUtils.h:49
This class provides a set of APIs for Notification service SyncInfo .
Definition: NSSyncInfo.h:41
void(* MessageReceivedCallback)(NSMessage)
Consumer use this callback function to receive notification message from provider synchronization...
Definition: NSProvider.h:61
NSProviderSubscribedState
NSProviderSubscribedState of notification service.
Definition: NSUtils.h:60
NSProviderSubscribedState getProviderSubscribedState() const
This method is for getting SubscribedState from the Notification service provider.
NSSyncType
Notification message status to synchronize.
Definition: NSCommon.h:63
NSProviderState getProviderState() const
This method is for getting ProviderState from the Notification service provider.
NSProvider & operator=(const NSProvider &provider)
Copy assignment operator of NSProvider.
NSResult sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type)
This method is for Sending SyncInfo of Notification service.
NSResult subscribe()
This method is for requesting subscription of Notification service.
void setProviderState(const NSProviderState &providerState)
This method is for setting ProviderState for the Notification service provider.
NSProvider(const std::string &providerId)
Constructor of NSProvider.
Definition: NSProvider.h:84
This file contains Notification service Message representation.
void setListener(ProviderStateCallback stateHandle, MessageReceivedCallback messageHandle, SyncInfoReceivedCallback syncHandle)
This method is for registering for listeners of Notification .
NSResult unsubscribe()
Request to unsubscribe in order not to receive notification message from provider.
void setTopicList(std::shared_ptr< NSTopicsList > topicsList)
This method is for setting NSTopic List for the Notification service provider.