1 //******************************************************************
\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
7 // Licensed under the Apache License, Version 2.0 (the "License");
\r
8 // you may not use this file except in compliance with the License.
\r
9 // You may obtain a copy of the License at
\r
11 // http://www.apache.org/licenses/LICENSE-2.0
\r
13 // Unless required by applicable law or agreed to in writing, software
\r
14 // distributed under the License is distributed on an "AS IS" BASIS,
\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 // See the License for the specific language governing permissions and
\r
17 // limitations under the License.
\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
24 * This file provides C++ Wrapper APIs of Notification Service for Provider.
\r
27 #ifndef _NS_PROVIDER_SERVICE_H_
\r
28 #define _NS_PROVIDER_SERVICE_H_
\r
31 #include "NSConsumer.h"
\r
32 #include "NSSyncInfo.h"
\r
33 #include "NSMessage.h"
\r
34 #include "NSUtils.h"
\r
35 #include "NSTopicsList.h"
\r
42 * @class NSProviderService
\r
43 * @brief This class provides a set of C++APIs for Notification Provider.
\r
45 class NSProviderService
\r
50 * Provider uses this callback function to receive subscription request of consumer
\r
51 * @param[in] consumer Consumer who subscribes the notification message resource
\r
53 typedef void (*ConsumerSubscribedCallback)(NSConsumer *);
\r
56 * Provider use this callback function to receive the status of the message
\r
58 * @param[in] sync Synchronization information of the notification message
\r
60 typedef void (*MessageSynchronizedCallback)(NSSyncInfo *);
\r
64 * @struct ProviderConfig
\r
65 * @brief Provider sets this following configuration for registering callbacks and configs
\r
66 * Set the subControllability, for notification servcie refering to following
\r
67 * if subControllability, is true, provider decides to allow or deny for all the subscribing consumers.
\r
68 * Otherwise(subControllability, is false) consumer decides to request subscription to discovered providers.
\r
72 /** m_subscribeRequestCb - ConsumerSubscribedCallback callback listener.*/
\r
73 ConsumerSubscribedCallback m_subscribeRequestCb;
\r
74 /** m_syncInfoCb - MessageSynchronizedCallback callback listener.*/
\r
75 MessageSynchronizedCallback m_syncInfoCb;
\r
77 /** subControllability - for setting the subscription controllability for Consumer */
\r
78 bool subControllability;
\r
79 /** userInfo - user defined information such as device friendly name */
\r
80 std::string userInfo;
\r
81 /* Set on/off for secure resource channel setting */
\r
82 bool resourceSecurity;
\r
86 * API for starting the NS Provider
\r
88 * @return NSProviderService Pointer to singleton instance created
\r
90 static NSProviderService *getInstance();
\r
93 * Initialize notification service for provider
\r
94 * @param[in] config ProviderConfig Callback function pointers to onConsumerSubscribed,
\r
95 * and onMessageSynchronized function listeners
\r
96 * @return :: result code of Provider Service
\r
98 NSResult start(ProviderConfig config);
\r
101 * Terminate notification service for provider
\r
102 * @return :: result code of Provider Service
\r
107 * Request to publish resource to cloud server
\r
108 * @param[in] serverAddress combined with IP address and port number using delimiter :
\r
109 * @return result code of Provider Service
\r
111 NSResult enableRemoteService(const std::string &serverAddress);
\r
114 * Request to cancel remote service using cloud server
\r
115 * @param[in] serverAddress combined with IP address and port number using delimiter :
\r
116 * @return result code of Provider Service
\r
118 NSResult disableRemoteService(const std::string &serverAddress);
\r
121 * Send notification message to all subscribers
\r
122 * @param[in] msg Notification message including id, title, contentText
\r
123 * @return :: result code of Provider Service
\r
125 NSResult sendMessage(NSMessage *msg);
\r
129 * Send read-check to provider in order to synchronize notification status with other consumers
\r
130 * @param[in] messageId ID of Notification message to synchronize the status
\r
131 * @param[in] type NotificationSyncType of the SyncInfo message
\r
133 void sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);
\r
136 * Initialize NSMessage class, This function is valid only when subControllability is set true.
\r
137 * @return NSMessage *
\r
139 NSMessage *createMessage();
\r
142 * Add topic to topic list which is located in provider service storage
\r
143 * @param[in] topicName Topic name to add
\r
144 * @return :: OK or result code of NSResult
\r
146 NSResult registerTopic(const std::string &topicName);
\r
149 * Delete topic from topic list
\r
150 * @param[in] topicName Topic name to delete
\r
151 * @return :: OK or result code of NSResult
\r
153 NSResult unregisterTopic(const std::string &topicName);
\r
156 * Request topics list already registered by provider user
\r
157 * @return :: Topic list
\r
159 NSTopicsList *getRegisteredTopicList();
\r
162 * get Provider config values
\r
163 * @return ProviderConfig callbaks set
\r
165 ProviderConfig getProviderConfig();
\r
168 * request to get NSConsumer pointer
\r
169 * @param id -id as string
\r
171 * @return pointer to NSConsumer
\r
173 NSConsumer *getConsumer(const std::string &id);
\r
176 * get list of Consumers accepted.
\r
177 * @return m_acceptedConsumers -list of accepted Consumers
\r
179 std::list<NSConsumer *> &getAcceptedConsumers();
\r
182 ProviderConfig m_config;
\r
183 std::list<NSConsumer *> m_acceptedConsumers;
\r
186 NSProviderService()
\r
188 m_config.m_subscribeRequestCb = NULL;
\r
189 m_config.m_syncInfoCb = NULL;
\r
191 ~NSProviderService();
\r
192 NSProviderService(const NSProviderService &) = delete;
\r
193 NSProviderService &operator=(const NSProviderService &) = delete;
\r
194 NSProviderService(const NSProviderService &&) = delete;
\r
195 NSProviderService &operator=(const NSProviderService && ) = delete;
\r
197 ::NSMessage *getNSMessage(NSMessage *msg);
\r
201 #endif /* _NS_PROVIDER_SERVICE_H_ */
\r