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 "NSErrorCode.h"
\r
41 * @class NSProviderService
\r
42 * @brief This class provides a set of C++APIs for Notification Provider.
\r
44 class NSProviderService
\r
49 * Provider uses this callback function to receive subscription request of consumer
\r
50 * @param[in] consumer Consumer who subscribes the resource
\r
52 typedef void (*ConsumerSubscribedCallback)(NSConsumer *);
\r
55 * Provider use this callback function to receive the status of the message
\r
57 * @param[in] sync Synchronization information of the notification message
\r
59 typedef void (*MessageSynchronizedCallback)(NSSyncInfo *);
\r
63 * @struct ProviderConfig
\r
64 * @brief Provider sets this callback function configuration for registering callbacks
\r
69 /** m_subscribeRequestCb - ConsumerSubscribedCallback callback listener.*/
\r
70 ConsumerSubscribedCallback m_subscribeRequestCb;
\r
71 /** m_syncInfoCb - MessageSynchronizedCallback callback listener.*/
\r
72 MessageSynchronizedCallback m_syncInfoCb;
\r
76 * Access policy exchanged between provider and consumer during subscription process
\r
78 enum class NSAccessPolicy
\r
80 NS_ACCESS_ALLOW = 0,
\r
85 * API for starting the NS Provider
\r
87 * @return NSProviderService Pointer to singleton instance created
\r
89 static NSProviderService *getInstance();
\r
92 * Initialize notification service for provider
\r
93 * @param[in] policy Accepter
\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 Result Start(NSAccessPolicy policy, 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] server address combined with IP address and port number using delimiter :
\r
109 * @return result code of Provider Service
\r
111 Result EnableRemoteService(const std::string &serverAddress);
\r
114 * Request to cancel remote service using cloud server
\r
115 * @param[in] server address combined with IP address and port number using delimiter :
\r
116 * @return result code of Provider Service
\r
118 Result 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 Result SendMessage(NSMessage *msg);
\r
129 * Send read-check to provider in order to synchronize notification status with other consumers
\r
130 * @param[in] messageId 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 * get Provider config values
\r
137 * @return ProviderConfig callbaks set
\r
139 ProviderConfig getProviderConfig();
\r
142 ProviderConfig m_config;
\r
145 NSProviderService()
\r
147 m_config.m_subscribeRequestCb = NULL;
\r
148 m_config.m_syncInfoCb = NULL;
\r
150 ~NSProviderService() = default;
\r
151 NSProviderService(const NSProviderService &) = delete;
\r
152 NSProviderService &operator=(const NSProviderService &) = delete;
\r
153 NSProviderService(const NSProviderService &&) = delete;
\r
154 NSProviderService &operator=(const NSProviderService && ) = delete;
\r
156 ::NSMessage *getNSMessage(NSMessage *msg);
\r
160 #endif /* _NS_PROVIDER_SERVICE_H_ */
\r