[Push] refactored module for using multiple managers 86/85486/6
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 25 Aug 2016 09:33:31 +0000 (11:33 +0200)
committertaekeun.kang <taekeun.kang@samsung.com>
Tue, 1 Nov 2016 06:09:33 +0000 (15:09 +0900)
[Feature] This commit is the first step for applying new policy
  about push module. There would be used different behaviour, dependant
  to current version of application. Currently module was refactored to
  hold tizen 2.4 behaviour. Tizen 3.0 would be implemented in next commits.

[Verification] Code compiles without errors.
  Passrate didn't change.

Change-Id: If26e03352db134b2a5fb5b1a8def46343732c41b
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/push/push.gyp
src/push/push_extension.cc
src/push/push_extension.h
src/push/push_instance.cc
src/push/push_instance.h
src/push/push_manager.cc
src/push/push_manager.h
src/push/push_manager_common.cc [new file with mode: 0644]
src/push/push_manager_common.h [new file with mode: 0644]

index 317c0a6..5cdb2ad 100644 (file)
@@ -16,7 +16,9 @@
         'push_instance.cc',
         'push_instance.h',
         'push_manager.cc',
-        'push_manager.h'
+        'push_manager.h',
+        'push_manager_common.cc',
+        'push_manager_common.h'
       ],
       'includes': [
         '../common/pkg-config.gypi',
index e2028e2..e231f0b 100644 (file)
@@ -30,11 +30,6 @@ PushExtension::PushExtension() {
 
 PushExtension::~PushExtension() {}
 
-PushManager& PushExtension::manager() {
-    // Initialize API on first request
-    return PushManager::getInstance();
-}
-
 common::Instance* PushExtension::CreateInstance() {
     return new PushInstance;
 }
index 4a86d6a..4118bb2 100644 (file)
@@ -28,8 +28,6 @@ class PushExtension : public common::Extension {
     PushExtension();
     virtual ~PushExtension();
 
-    PushManager& manager();
-
  private:
     virtual common::Instance* CreateInstance();
 };
index c588132..cb347f8 100644 (file)
@@ -54,7 +54,8 @@ PushInstance::PushInstance(): m_ignoreNotificationEvents(true) {
         std::bind(&PushInstance::getUnreadNotifications, this, _1, _2));
     REGISTER_SYNC("Push_getPushMessage",
         std::bind(&PushInstance::getPushMessage, this, _1, _2));
-    PushManager::getInstance().setListener(this);
+    impl = new PushManager();
+    impl->setListener(this);
 
     #undef REGISTER_ASYNC
     #undef REGISTER_SYNC
@@ -65,7 +66,7 @@ void PushInstance::registerApplication(const picojson::value& args,
     LoggerD("Enter");
 
     CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
-    common::PlatformResult result = PushManager::getInstance().registerApplication(
+    common::PlatformResult result = impl->registerApplication(
             args.get("callbackId").get<double>());
     if (result.IsError()) {
         LogAndReportError(result, &out, ("Error occured"));
@@ -81,8 +82,8 @@ void PushInstance::unregisterApplication(const picojson::value& args,
 
     CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
 
-    common::PlatformResult result = PushManager::getInstance()
-            .unregisterApplication(args.get("callbackId").get<double>());
+    common::PlatformResult result = impl->unregisterApplication(
+        args.get("callbackId").get<double>());
     if (result.IsError()) {
         LogAndReportError(result, &out, ("Error occured"));
     } else {
@@ -120,8 +121,7 @@ void PushInstance::getRegistrationId(const picojson::value& args,
     CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
 
     std::string id;
-    common::PlatformResult result = PushManager::getInstance()
-            .getRegistrationId(id);
+    common::PlatformResult result = impl->getRegistrationId(id);
     if (result.IsError()) {
         // this method should fail silently and return null
         picojson::value res = picojson::value();
@@ -138,8 +138,7 @@ void PushInstance::getUnreadNotifications(const picojson::value& args,
 
     CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
 
-    common::PlatformResult result = PushManager::getInstance()
-            .getUnreadNotifications();
+    common::PlatformResult result = impl->getUnreadNotifications();
     if (result.IsError()) {
         LogAndReportError(result, &out, ("Error occured"));
     } else {
@@ -155,7 +154,7 @@ void PushInstance::getPushMessage(const picojson::value& args,
   CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
 
   picojson::value msg;
-  common::PlatformResult result = PushManager::getInstance().getPushMessage(&msg);
+  common::PlatformResult result = impl->getPushMessage(&msg);
 
   if (result.IsError()) {
     LoggerE("Error occurred");
@@ -186,7 +185,7 @@ void PushInstance::onPushNotify(push_service_notification_h noti) {
     }
     picojson::value::object dict;
     picojson::value::object pushMessage;
-    PushManager::getInstance().notificationToJson(noti, &pushMessage);
+    impl->notificationToJson(noti, &pushMessage);
 
     dict["listenerId"] = picojson::value("Push_Notification_Listener");
     dict["pushMessage"] = picojson::value(pushMessage);
@@ -208,7 +207,7 @@ void PushInstance::onDeregister(double callbackId,
 
 PushInstance::~PushInstance() {
     LoggerD("Enter");
-    PushManager::getInstance().setListener(nullptr);
+    impl->setListener(nullptr);
 }
 
 }  // namespace push
index 90fb829..b2d03ad 100644 (file)
@@ -43,6 +43,7 @@ class PushInstance: public common::ParsedInstance, public EventListener {
      void getPushMessage(const picojson::value& args, picojson::object& out);
 
      bool m_ignoreNotificationEvents;
+     IPushManager* impl;
 };
 
 }  // namespace push
index 9b6711c..f3e0aab 100644 (file)
@@ -21,7 +21,9 @@
 #include <app_control_internal.h>
 #include <app_manager.h>
 #include <bundle.h>
+#include <memory>
 
+#include "push/push_manager_common.h"
 #include "common/extension.h"
 #include "common/logger.h"
 
@@ -31,33 +33,6 @@ namespace push {
 using common::PlatformResult;
 using common::ErrorCode;
 
-namespace {
-
-ErrorCode ConvertPushError(int e) {
-  ErrorCode error;
-
-  switch(e) {
-    case PUSH_SERVICE_ERROR_NONE:
-      error = ErrorCode::NO_ERROR;
-      break;
-
-    case PUSH_SERVICE_ERROR_INVALID_PARAMETER:
-      error = ErrorCode::INVALID_VALUES_ERR;
-      break;
-
-    case PUSH_SERVICE_ERROR_OUT_OF_MEMORY:
-    case PUSH_SERVICE_ERROR_NOT_CONNECTED:
-    case PUSH_SERVICE_ERROR_OPERATION_FAILED:
-    default:
-      error = ErrorCode::ABORT_ERR;
-      break;
-  }
-
-  return error;
-}
-
-}  // namespace
-
 PushManager::PushManager() :
     m_handle(NULL),
     m_listener(NULL),
@@ -69,7 +44,7 @@ PushManager::PushManager() :
     initAppId();
     InitAppControl();
 
-    int ret = push_service_connect(m_pkgId.c_str(), onPushState, onPushNotify, NULL,
+    int ret = push_service_connect(m_pkgId.c_str(), onPushState, onPushNotify, this,
         &m_handle);
     if (ret != PUSH_SERVICE_ERROR_NONE) {
         LoggerE("Failed to connect to push (%d)", ret);
@@ -156,40 +131,36 @@ void PushManager::InitAppControl() {
   }
 }
 
-PushManager& PushManager::getInstance() {
-  static PushManager instance;
-  return instance;
-}
-
 PlatformResult PushManager::registerApplication(double callbackId) {
   LoggerD("Enter");
 
-  double* pcallback = new double(callbackId);
+  PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
 
-  int ret = push_service_register(m_handle, onApplicationRegister, static_cast<void*>(pcallback));
+  int ret = push_service_register(m_handle, onApplicationRegister, static_cast<void*>(holder));
   if (ret != PUSH_SERVICE_ERROR_NONE) {
-    delete pcallback;
+    delete holder;
 
-    return LogAndCreateResult(
-        ConvertPushError(ret), "Failed to register", ("push_service_register failed (%d)", ret));
+    return LogAndCreateResult(PushManagerCommon::ConvertPushError(ret),
+                              "Failed to register", ("push_service_register failed (%d)", ret));
   }
   return common::PlatformResult(ErrorCode::NO_ERROR);
 }
 
 common::PlatformResult PushManager::unregisterApplication(double callbackId) {
     LoggerD("Enter");
-    double* pcallbackId = new double(callbackId);
+    PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
+
     if (m_state == PUSH_SERVICE_STATE_UNREGISTERED) {
         LoggerD("Already unregister, call unregister callback");
-        if (!g_idle_add(onFakeDeregister, pcallbackId)) {
-            delete pcallbackId;
+        if (!g_idle_add(onFakeDeregister, holder)) {
+            delete holder;
             return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
                 "Unknown error", ("g_idle_add failed"));
         }
     } else {
-        int ret = push_service_deregister(m_handle, onDeregister, pcallbackId);
+        int ret = push_service_deregister(m_handle, onDeregister, holder);
         if (ret != PUSH_SERVICE_ERROR_NONE) {
-            delete pcallbackId;
+            delete holder;
             if (ret == PUSH_SERVICE_ERROR_INVALID_PARAMETER) {
               LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_INVALID_PARAMETER");
             } else if (ret == PUSH_SERVICE_ERROR_OUT_OF_MEMORY) {
@@ -253,7 +224,7 @@ PlatformResult PushManager::getPushMessage(picojson::value* out) {
       return common::PlatformResult(ErrorCode::NO_ERROR);
     } else {
       return LogAndCreateResult(
-              ConvertPushError(ret), "Failed to get message",
+          PushManagerCommon::ConvertPushError(ret), "Failed to get message",
               ("push_service_app_control_to_notification failed: (%d)", ret));
     }
   }
@@ -267,113 +238,47 @@ PlatformResult PushManager::getPushMessage(picojson::value* out) {
   return common::PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void PushManager::notificationToJson(push_service_notification_h noti, picojson::object* obj) {
-  LoggerD("Enter");
-
-  char* temp = nullptr;
-  int ret = push_service_get_notification_data(noti, &temp);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get appData");
-    return;
-  }
-  (*obj)["appData"] = picojson::value(temp);
-  free(temp);
-
-  char* fullMessage = nullptr;
-  ret = push_service_get_notification_message(noti, &fullMessage);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get message");
-    return;
-  }
-  (*obj)["message"] = picojson::value(fullMessage);
-
-  // parse query string and find value for alertMessage
-  pcrecpp::StringPiece input(fullMessage);
-  pcrecpp::RE re("([^=]+)=([^&]*)&?");
-  string key;
-  string value;
-  while (re.Consume(&input, &key, &value)) {
-    if (key == "alertMessage") {
-      (*obj)["alertMessage"] = picojson::value(key);
-      break;
-    }
-  }
-  free(fullMessage);
-
-  long long int date = -1;
-  ret = push_service_get_notification_time(noti, &date);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get date");
-    return;
-  }
-  (*obj)["date"] = picojson::value(static_cast<double>(date));
-
-  ret = push_service_get_notification_sender(noti, &temp);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get sender");
-    return;
-  }
-  (*obj)["sender"] = picojson::value(temp);
-  free(temp);
-
-  ret = push_service_get_notification_session_info(noti, &temp);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get session info");
-    return;
-  }
-  std::string session_info = temp;
-  (*obj)["sesionInfo"] = picojson::value(temp);
-  free(temp);
-
-  ret = push_service_get_notification_request_id(noti, &temp);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get request id");
-    return;
-  }
-  (*obj)["requestId"] = picojson::value(temp);
-  free(temp);
-
-  int type;
-  ret = push_service_get_notification_type(noti, &type);
-  if (ret != PUSH_SERVICE_ERROR_NONE) {
-    LoggerE("Failed to get type");
-    return;
-  }
-  (*obj)["type"] = picojson::value(static_cast<double>(type));
-}
-
 void PushManager::onPushState(push_service_state_e state, const char* err,
         void* user_data) {
     LoggerD("Enter %d, err: %s", state, err);
-    getInstance().m_state = state;
+    PushManager* impl = static_cast<PushManager*>(user_data);
+    if (nullptr != impl) {
+      impl->m_state = state;
+    }
 }
 
 void PushManager::onPushNotify(push_service_notification_h noti, void* user_data) {
     LoggerD("Enter");
-    if (!getInstance().m_listener) {
+    PushManager* impl = static_cast<PushManager*>(user_data);
+    if (nullptr == impl || !impl->m_listener) {
         LoggerW("Listener not set, ignoring");
         return;
     }
 
-    getInstance().m_listener->onPushNotify(noti);
+    impl->m_listener->onPushNotify(noti);
 }
 
 void PushManager::onApplicationRegister(push_service_result_e result, const char* msg, void* user_data) {
   LoggerD("Enter");
 
-  if (!getInstance().m_listener) {
+  PushManagerHolder* holder = static_cast<PushManagerHolder*>(user_data);
+  // automatically releases memory
+  std::unique_ptr<PushManagerHolder> holder_ptr(holder);
+  PushManager* impl = dynamic_cast<PushManager*>(holder->impl);
+  double callbackId = holder->callbackId;
+
+  if (nullptr == impl || !impl->m_listener) {
     LoggerW("Listener not set, ignoring");
     return;
   }
 
-  double* callbackId = static_cast<double*>(user_data);
   std::string id;
   PlatformResult res(ErrorCode::NO_ERROR);
 
   if (PUSH_SERVICE_RESULT_SUCCESS == result) {
     LoggerD("Success");
     char *temp = nullptr;
-    int ret = push_service_get_registration_id(getInstance().m_handle, &temp);
+    int ret = push_service_get_registration_id(impl->m_handle, &temp);
     if (PUSH_SERVICE_ERROR_NONE == ret) {
       LoggerD("Registration id retrieved");
       id = temp;
@@ -395,41 +300,45 @@ void PushManager::onApplicationRegister(push_service_result_e result, const char
   }
 
   // onPushState is not always called when onPushRegister is successful
-  getInstance().m_state = PUSH_SERVICE_STATE_REGISTERED;
-  getInstance().m_listener->onPushRegister(*callbackId, res, id);
-  delete callbackId;
+  impl->m_state = PUSH_SERVICE_STATE_REGISTERED;
+  impl->m_listener->onPushRegister(callbackId, res, id);
 }
 
 gboolean PushManager::onFakeDeregister(gpointer user_data) {
     LoggerD("Enter");
-    if (!getInstance().m_listener) {
+    PushManagerHolder* holder = static_cast<PushManagerHolder*>(user_data);
+    // automatically releases memory
+    std::unique_ptr<PushManagerHolder> holder_ptr(holder);
+    PushManager* impl = dynamic_cast<PushManager*>(holder->impl);
+    double callbackId = holder->callbackId;
+
+    if (nullptr == impl || !impl->m_listener) {
         LoggerW("Listener not set, ignoring");
         return G_SOURCE_REMOVE;
     }
-    double* callbackId = static_cast<double*>(user_data);
-    getInstance().m_listener->onDeregister(*callbackId,
-        PlatformResult(ErrorCode::NO_ERROR));
-    delete callbackId;
+    impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
     return G_SOURCE_REMOVE;
 }
 
 void PushManager::onDeregister(push_service_result_e result, const char* msg,
         void* user_data) {
     LoggerD("Enter");
-    if (!getInstance().m_listener) {
+    PushManagerHolder* holder = static_cast<PushManagerHolder*>(user_data);
+    // automatically releases memory
+    PushManager* impl = dynamic_cast<PushManager*>(holder->impl);
+    std::unique_ptr<PushManagerHolder> holder_ptr(holder);
+    double callbackId = holder->callbackId;
+
+    if (nullptr == impl || !impl->m_listener) {
         LoggerW("Listener not set, ignoring");
         return;
     }
-    double* callbackId = static_cast<double*>(user_data);
     if (result == PUSH_SERVICE_RESULT_SUCCESS) {
-        getInstance().m_listener->onDeregister(*callbackId,
-            PlatformResult(ErrorCode::NO_ERROR));
+        impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
     } else {
-        getInstance().m_listener->onDeregister(*callbackId,
-            LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+        impl->m_listener->onDeregister(callbackId, LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
                 msg == NULL ? "Unknown error" : msg));
     }
-    delete callbackId;
 }
 
 
index 6f4906d..ba4dbb8 100644 (file)
 #include <vector>
 #include <map>
 #include "common/platform_result.h"
+#include "push_manager_common.h"
 
 namespace extension {
 namespace push {
 
-class EventListener {
+class PushManager : public IPushManager {
  public:
-    virtual void onPushRegister(double callbackId,
-            common::PlatformResult result, const std::string& id) = 0;
-    virtual void onPushNotify(push_service_notification_h noti) = 0;
-    virtual void onDeregister(double callbackId,
-            common::PlatformResult result) = 0;
-    virtual ~EventListener() {}
-};
-
-class PushManager {
- public:
-    static PushManager& getInstance();
+    PushManager();
     virtual ~PushManager();
 
     void setListener(EventListener* listener);
@@ -49,10 +40,8 @@ class PushManager {
     common::PlatformResult getRegistrationId(std::string &id);
     common::PlatformResult getUnreadNotifications();
     common::PlatformResult getPushMessage(picojson::value* out);
-    void notificationToJson(push_service_notification_h noti, picojson::object* obj);
 
  private:
-    PushManager();
     void initAppId();
     void InitAppControl();
 
diff --git a/src/push/push_manager_common.cc b/src/push/push_manager_common.cc
new file mode 100644 (file)
index 0000000..d29c464
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "push/push_manager_common.h"
+#include <unistd.h>
+#include <pcrecpp.h>
+#include <app_control.h>
+#include <app_control_internal.h>
+#include <app_manager.h>
+#include <bundle.h>
+#include <memory>
+
+#include "common/extension.h"
+#include "common/logger.h"
+
+namespace extension {
+namespace push {
+
+using common::PlatformResult;
+using common::ErrorCode;
+
+ErrorCode PushManagerCommon::ConvertPushError(int e) {
+  ErrorCode error;
+
+  switch(e) {
+    case PUSH_SERVICE_ERROR_NONE:
+      error = ErrorCode::NO_ERROR;
+      break;
+
+    case PUSH_SERVICE_ERROR_INVALID_PARAMETER:
+      error = ErrorCode::INVALID_VALUES_ERR;
+      break;
+
+    case PUSH_SERVICE_ERROR_OUT_OF_MEMORY:
+    case PUSH_SERVICE_ERROR_NOT_CONNECTED:
+    case PUSH_SERVICE_ERROR_OPERATION_FAILED:
+    default:
+      error = ErrorCode::ABORT_ERR;
+      break;
+  }
+
+  return error;
+}
+
+IPushManager::IPushManager() {
+  LoggerD("Enter");
+}
+
+IPushManager::~IPushManager() {
+  LoggerD("Enter");
+}
+
+void IPushManager::notificationToJson(push_service_notification_h noti, picojson::object* obj) {
+  LoggerD("Enter");
+
+  char* temp = nullptr;
+  int ret = push_service_get_notification_data(noti, &temp);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get appData");
+    return;
+  }
+  (*obj)["appData"] = picojson::value(temp);
+  free(temp);
+
+  char* fullMessage = nullptr;
+  ret = push_service_get_notification_message(noti, &fullMessage);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get message");
+    return;
+  }
+  (*obj)["message"] = picojson::value(fullMessage);
+
+  // parse query string and find value for alertMessage
+  pcrecpp::StringPiece input(fullMessage);
+  pcrecpp::RE re("([^=]+)=([^&]*)&?");
+  string key;
+  string value;
+  while (re.Consume(&input, &key, &value)) {
+    if (key == "alertMessage") {
+      (*obj)["alertMessage"] = picojson::value(value);
+      break;
+    }
+  }
+  free(fullMessage);
+
+  long long int date = -1;
+  ret = push_service_get_notification_time(noti, &date);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get date");
+    return;
+  }
+  (*obj)["date"] = picojson::value(static_cast<double>(date));
+
+  ret = push_service_get_notification_sender(noti, &temp);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get sender");
+    return;
+  }
+  (*obj)["sender"] = picojson::value(temp);
+  free(temp);
+
+  ret = push_service_get_notification_session_info(noti, &temp);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get session info");
+    return;
+  }
+  std::string session_info = temp;
+  (*obj)["sesionInfo"] = picojson::value(temp);
+  free(temp);
+
+  ret = push_service_get_notification_request_id(noti, &temp);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get request id");
+    return;
+  }
+  (*obj)["requestId"] = picojson::value(temp);
+  free(temp);
+
+  int type;
+  ret = push_service_get_notification_type(noti, &type);
+  if (ret != PUSH_SERVICE_ERROR_NONE) {
+    LoggerE("Failed to get type");
+    return;
+  }
+  (*obj)["type"] = picojson::value(static_cast<double>(type));
+}
+
+}  // namespace push
+}  // namespace extension
+
diff --git a/src/push/push_manager_common.h b/src/push/push_manager_common.h
new file mode 100644 (file)
index 0000000..40dc857
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef SRC_PUSH_PUSH_MANAGER_COMMON_H_
+#define SRC_PUSH_PUSH_MANAGER_COMMON_H_
+
+#include <push-service.h>
+#include <glib.h>
+#include <string>
+#include <vector>
+#include <map>
+#include "common/platform_result.h"
+
+namespace extension {
+namespace push {
+
+class EventListener {
+ public:
+    virtual void onPushRegister(double callbackId,
+            common::PlatformResult result, const std::string& id) = 0;
+    virtual void onPushNotify(push_service_notification_h noti) = 0;
+    virtual void onDeregister(double callbackId,
+            common::PlatformResult result) = 0;
+    virtual ~EventListener() {}
+};
+
+class IPushManager {
+ public:
+    IPushManager();
+    virtual ~IPushManager();
+
+    virtual void setListener(EventListener* listener) = 0;
+
+    virtual common::PlatformResult registerApplication(double callbackId) = 0;
+    virtual common::PlatformResult unregisterApplication(double callbackId) = 0;
+    virtual common::PlatformResult getRegistrationId(std::string &id) = 0;
+    virtual common::PlatformResult getUnreadNotifications() = 0;
+    virtual common::PlatformResult getPushMessage(picojson::value* out) = 0;
+
+    void notificationToJson(push_service_notification_h noti, picojson::object* obj);
+};
+
+struct PushManagerHolder {
+  IPushManager* impl;
+  double callbackId;
+};
+
+class PushManagerCommon {
+  public :
+    static common::ErrorCode ConvertPushError(int e);
+};
+
+}  // namespace push
+}  // namespace extension
+
+#endif  // SRC_PUSH_PUSH_MANAGER_COMMON_H_
+