2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FMsgPushManager.h
19 * @brief This is the header file for the %PushManager class.
21 * This header file contains the declarations of the %PushManager class.
24 #ifndef _FMSG_PUSH_MANAGER_H_
25 #define _FMSG_PUSH_MANAGER_H_
28 #include <FMsgIPushManagerListener.h>
29 #include <FMsgIPushEventListener.h>
31 namespace Tizen { namespace Messaging
33 class _PushManagerImpl;
37 * @brief This class provides methods to use the push messaging service.
41 * @remarks If an application package contains multiple applications, only one application can use the push messaging service at a time.
43 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
46 * The %PushManager class provides methods to register, unregister, and use the push messaging service.
48 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/messaging.htm">Messaging Guide</a>.
50 * @see Tizen::Shell::NotificationManager
52 * The following example demonstrates how to use the %PushManager class.
57 #include <FMessaging.h>
59 using namespace Tizen::Base;
60 using namespace Tizen::Messaging;
62 // Creates a listener to override the methods of IPushManagerListener and IPushEventListener.
65 , public IPushEventListener
66 , public IPushManagerListener
72 //IPushManagerListener and IPushEventListener
73 void OnPushServiceRegistered(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg);
74 void OnPushServiceUnregistered(RequestId reqId, result r, const String& errorCode, const String& errorMsg);
75 void OnPushMessageReceived(const PushMessage& message);
77 void Initialize(void);
78 void EnablePushService(void);
79 void DisablePushService(void);
82 PushManager* pPushManager;
86 MyClass::OnPushServiceRegistered(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg)
90 // The application must send registrationId to the application server.
99 MyClass::OnPushServiceUnregistered(RequestId reqId, result r, const String& errorCode, const String& errorMsg)
105 MyClass::OnPushMessageReceived(const PushMessage& message)
111 MyClass::Initialize(void)
113 // Creates a PushManager instance.
114 pPushManager = new PushManager();
115 pPushManager->Construct(*this, *this);
119 MyClass::EnablePushService(void)
122 result r = E_SUCCESS;
124 r = pPushManager->RegisterPushService(reqId);
130 // The result of registration will be notified by IPushManagerListener::OnPushServiceRegistered().
134 MyClass::DisablePushService(void)
136 // The application must notify the application server to stop sending push messages for this device.
139 result r = E_SUCCESS;
141 r = pPushManager->UnregisterPushService(reqId);
147 // The result of unregistration will be notified by IPushManagerListener::OnPushServiceUnregistered().
153 class _OSP_EXPORT_ PushManager
154 : public Tizen::Base::Object
158 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
165 * This destructor overrides Tizen::Base::Object::~Object().
169 virtual ~PushManager(void);
173 * Initializes this instance of the %PushManager class with the specified parameters.
177 * @privilege %http://tizen.org/privilege/push
179 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
180 * @feature %http://tizen.org/feature/network.push
181 * @return An error code
182 * @param[in] managerListener A listener that receives the result of the %PushManager
183 * class asynchronous methods
184 * @param[in] eventListener A listener that receives the incoming push messages
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_OUT_OF_MEMORY The memory is insufficient.
187 * @exception E_SYSTEM A system error has occurred.
188 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
189 * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1
190 * For more information, see <a href="../org.tizen.gettingstarted/html/tizen_overview/application_filtering.htm">Application Filtering</a>.
191 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
192 * @remarks Before calling this method, check whether the feature is supported by
193 * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&).
194 * @see IPushManagerListener
195 * @see IPushEventListener
197 result Construct(IPushManagerListener& managerListener, IPushEventListener& eventListener);
200 * Registers the push messaging service for the current application. @n
201 * This method is asynchronous.
205 * @privilege %http://tizen.org/privilege/push
207 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
209 * @return An error code
210 * @param[out] reqId The request ID
211 * @exception E_SUCCESS The method is successful.
212 * @exception E_OUT_OF_MEMORY The memory is insufficient.
213 * @exception E_SYSTEM A system error has occurred.
214 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
215 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
216 * @see IPushManagerListener::OnPushServiceRegistered()
218 result RegisterPushService(RequestId& reqId);
221 * Unregisters the push messaging service for the current application. @n
222 * This method is asynchronous.
226 * @privilege %http://tizen.org/privilege/push
228 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
230 * @return An error code
231 * @param[out] reqId The request ID
232 * @exception E_SUCCESS The method is successful.
233 * @exception E_OUT_OF_MEMORY The memory is insufficient.
234 * @exception E_SYSTEM A system error has occurred.
235 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
236 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
237 * @see IPushManagerListener::OnPushServiceUnregistered()
239 result UnregisterPushService(RequestId& reqId);
242 * Checks whether the push messaging service registration has been completed for the current application.
246 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
248 * @return @c true if the registration is completed, @n
251 bool IsPushServiceRegistered(void) const;
254 * Gets the unread push messages. @n
255 * If an application receives unread messages with this method, the messages are removed from the system.
259 * @privilege %http://tizen.org/privilege/push
261 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
263 * @return A pointer to the list that contains unread push messages
264 * @exception E_SUCCESS The method is successful.
265 * @exception E_OUT_OF_MEMORY The memory is insufficient.
266 * @exception E_SYSTEM A system error has occurred.
267 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
268 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
269 * @remarks The specific error code can be accessed using the GetLastResult() method.
270 * If the user launches the application using a ticker or a quick panel,
271 * the push message related to the notification is delivered to the application
272 * as a launch argument.
273 * The launch arguments are the input parameters for
274 * Tizen::App::IAppControlProviderEventListener::OnAppControlRequestReceivedN().
275 * This function returns all the unread messages including the message
276 * delivered as a launch argument.
277 * @see Tizen::App::IAppControlProviderEventListener
279 Tizen::Base::Collection::IList* GetUnreadMessagesN(void);
282 * Sends the push message to a single recipient. @n
283 * This method is asynchronous.
287 * @privilege %http://tizen.org/privilege/push and %http://tizen.org/privilege/http @n
288 * Both privileges are required
290 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
292 * @return An error code
293 * @param[in] message The push message
294 * @param[in] registrationId The registration ID of the recipient
295 * @param[in] appSecret The secret code of the application issued by the push server to authenticate the application
296 * @param[out] reqId The request ID
297 * @exception E_SUCCESS The method is successful.
298 * @exception E_INVALID_ARG A specified input parameter is invalid.
299 * @exception E_OUT_OF_MEMORY The memory is insufficient.
300 * @exception E_SYSTEM A system error has occurred.
301 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
302 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
303 * @see IPushManagerListener::OnPushMessageSent()
305 result SendPushMessage(const PushMessage& message, const Tizen::Base::String& registrationId, const Tizen::Base::String& appSecret, RequestId& reqId);
309 * Sends the push message to multiple recipients. @n
310 * This method is asynchronous.
314 * @privilege %http://tizen.org/privilege/push and %http://tizen.org/privilege/http @n
315 * Both privileges are required
317 * @pre In order to use the push messaging service, see <a href="../org.tizen.native.appprogramming/html/guide/messaging/push_messaging.htm">Push Messaging Guide</a>.
319 * @return An error code
320 * @param[in] message The push message
321 * @param[in] registrationIdList The list of registration IDs of the recipients
322 * @param[in] appSecret The secret code of the application issued by the push server to authenticate the application
323 * @param[out] reqId The request ID
324 * @exception E_SUCCESS The method is successful.
325 * @exception E_INVALID_ARG A specified input parameter is invalid.
326 * @exception E_MAX_EXCEEDED The number of registration IDs has crossed the maximum limit.
327 * @exception E_OUT_OF_MEMORY The memory is insufficient.
328 * @exception E_SYSTEM A system error has occurred.
329 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
330 * @exception E_USER_NOT_CONSENTED The user blocks an application from calling this method. @b Since: @b 2.1
331 * @remarks The maximum limit can be checked by using GetMaxRecipientCount().
332 * @see IPushManagerListener::OnPushMessageSent()
334 result SendPushMessage(const PushMessage& message, const Tizen::Base::Collection::IList& registrationIdList, const Tizen::Base::String& appSecret, RequestId& reqId);
337 * Gets the maximum number of recipients sent by a multiple SendPushMessage() method.
341 * @return The maximum number of recipients
343 static int GetMaxRecipientCount(void);
347 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
349 * @param[in] rhs An instance of PushManager
351 PushManager(const PushManager& rhs);
354 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
356 * @return A reference to this instance
357 * @param[in] rhs An instance of PushManager
359 PushManager& operator =(const PushManager& rhs);
362 _PushManagerImpl* __pPushManagerImpl;
364 friend class _PushManagerImpl;
367 } } // Tizen::Messaging
368 #endif // _FMSG_PUSH_MANAGER_H_