*
* @code
*
- // Creates a listener to override the methods of IPushManagerListener and IPushEventListener.
-
- class PushListener : public IPushManagerListener, public IPushEventListener, public Object
- {
- public:
- void OnPushServiceRegistered(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg);
- void OnPushServiceUnregistered(RequestId reqId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg);
- void OnPushMessageReceived(const PushMessage& message);
- };
- void PushListener::OnPushServiceRegistered(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg)
- {
- if (E_SUCCESS == r) {
- // The application must send registrationId to the application server.
- } else {
- // Error
- }
- }
- void PushListener::OnPushServiceUnregistered(RequestId reqId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg)
- {
- // Do something
- }
- void PushListener::OnPushMessageReceived(const PushMessage& message)
- {
- // Do something
- }
-
- class PushManagerSample : public Object
- {
- public:
- void Initialize(void);
- void EnablePushService(void);
- void DisablePushService(void);
- private:
- PushListener* pPushListener;
- PushManager* pPushManager;
- };
- void PushManagerSample::Initialize(void)
- {
- // Creates a PushListener instance.
- pPushListener = new PushListener();
-
- // Creates a PushManager instance.
- pPushManager = new PushManager();
- pPushManager->Construct(*pPushListener, *pPushListener);
- }
- void PushManagerSample::EnablePushService(void)
- {
- RequestId reqId;
- result r = E_SUCCESS;
-
- r = pPushManager->RegisterPushService(reqId);
- if (IsFailed(r)) {
- // Error
- return;
- }
-
- // The result of registration will be notified by IPushManagerListener::OnPushServiceRegistered().
- }
- void PushManagerSample::DisablePushService(void)
- {
- // The application must notify the application server to stop sending push messages for this device.
-
- RequestId reqId;
- result r = E_SUCCESS;
-
- r = pPushManager->UnregisterPushService(reqId);
- if (IsFailed(r)) {
- // Error
- return;
- }
-
- // The result of unregistration will be notified by IPushManagerListener::OnPushServiceUnregistered().
- }
+ #include <FBase.h>
+ #include <FMessaging.h>
+
+ using namespace Tizen::Base;
+ using namespace Tizen::Messaging;
+
+ // Creates a listener to override the methods of IPushManagerListener and IPushEventListener.
+ class MyClass
+ : public Object
+ , public IPushEventListener
+ , public IPushManagerListener
+ {
+ public:
+ MyClass(void) {}
+ ~MyClass(void) {}
+
+ //IPushManagerListener and IPushEventListener
+ void OnPushServiceRegistered(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg);
+ void OnPushServiceUnregistered(RequestId reqId, result r, const String& errorCode, const String& errorMsg);
+ void OnPushMessageReceived(const PushMessage& message);
+
+ void Initialize(void);
+ void EnablePushService(void);
+ void DisablePushService(void);
+
+ private:
+ PushManager* pPushManager;
+ };
+
+ void
+ MyClass::OnPushServiceRegistered(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg)
+ {
+ if (E_SUCCESS == r)
+ {
+ // The application must send registrationId to the application server.
+ }
+ else
+ {
+ // Error
+ }
+ }
+
+ void
+ MyClass::OnPushServiceUnregistered(RequestId reqId, result r, const String& errorCode, const String& errorMsg)
+ {
+ // Do something
+ }
+
+ void
+ MyClass::OnPushMessageReceived(const PushMessage& message)
+ {
+ // Do something
+ }
+
+ void
+ MyClass::Initialize(void)
+ {
+ // Creates a PushManager instance.
+ pPushManager = new PushManager();
+ pPushManager->Construct(*this, *this);
+ }
+
+ void
+ MyClass::EnablePushService(void)
+ {
+ RequestId reqId;
+ result r = E_SUCCESS;
+
+ r = pPushManager->RegisterPushService(reqId);
+ if (IsFailed(r))
+ {
+ return;
+ }
+
+ // The result of registration will be notified by IPushManagerListener::OnPushServiceRegistered().
+ }
+
+ void
+ MyClass::DisablePushService(void)
+ {
+ // The application must notify the application server to stop sending push messages for this device.
+
+ RequestId reqId;
+ result r = E_SUCCESS;
+
+ r = pPushManager->UnregisterPushService(reqId);
+ if (IsFailed(r))
+ {
+ return;
+ }
+
+ // The result of unregistration will be notified by IPushManagerListener::OnPushServiceUnregistered().
+ }
+
*
* @endcode
*/