[Feature] Added register/unregister and connect/disconnect functions.
[Verification] Code compiles without errors.
Checked in chrome console, tct tests need to be updated.
Change-Id: I040954fea6ba6359df1f86c41cb7074a983c3f80
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
'push_instance.h',
'push_manager.cc',
'push_manager.h',
- 'push_manager_old.cc',
- 'push_manager_old.h',
'push_manager_common.cc',
'push_manager_common.h'
],
* @type {string}
*/
var NOTIFICATION_LISTENER = 'Push_Notification_Listener';
+var STATE_LISTENER = 'Push_State_Listener';
+
+var listener2_4 = undefined;
+var listener3_0 = undefined;
+
+var listenerFunction = function(msg) {
+ // try to call each listener
+ listener2_4 && listener2_4(msg);
+ listener3_0 && listener3_0(msg);
+}
function PushMessage(dict) {
for (var key in dict) {
}
PushManager.prototype.registerService = function() {
- validator.validateArgs(arguments, [
+ console.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.');
+ var data = validator.validateArgs(arguments, [
{
name: 'appControl',
type: validator.Types.PLATFORM_OBJECT,
values: tizen.ApplicationControl
+ },
+ {
+ name: 'successCallback',
+ type: validator.Types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: validator.Types.FUNCTION,
+ optional: true,
+ nullable: true
}
]);
- console.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.');
- this.register.apply(this, Array.prototype.slice.call(arguments, 1));
+
+ var ret = native.call('Push_registerService', {}, function(msg) {
+ if (msg.error) {
+ if (validatorType.isFunction(data.errorCallback)) {
+ data.errorCallback(native.getErrorObject(msg));
+ }
+ } else {
+ data.successCallback(msg.registrationId);
+ }
+ });
+ if (native.isFailure(ret)) {
+ throw native.getErrorObject(ret);
+ }
};
PushManager.prototype.register = function() {
PushManager.prototype.unregisterService = function() {
console.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.');
- this.unregister.apply(this, arguments);
+ var data = validator.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: validator.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'errorCallback',
+ type: validator.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+ var result = native.call('Push_unregisterService', {}, function(msg) {
+ if (msg.error) {
+ if (validatorType.isFunction(data.errorCallback)) {
+ data.errorCallback(native.getErrorObject(msg));
+ }
+ } else if (validatorType.isFunction(data.successCallback)) {
+ data.successCallback();
+ }
+ });
+
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
};
PushManager.prototype.unregister = function() {
};
PushManager.prototype.connectService = function(notificationCallback) {
+ console.warn('DEPRECATION WARNING: connectService() is deprecated and will be removed from next release. Use connect() instead.');
var data = validator.validateArgs(arguments, [
{
name: 'notificationCallback',
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
- native.addListener(NOTIFICATION_LISTENER, function(msg) {
+
+ listener2_4 = function(msg) {
data.notificationCallback(new PushMessage(msg.pushMessage));
+ };
+ native.addListener(NOTIFICATION_LISTENER, listenerFunction);
+};
+
+PushManager.prototype.connect = function(notificationCallback) {
+ var data = validator.validateArgs(arguments, [
+ {
+ name: 'stateChangeCallback',
+ type: validator.Types.FUNCTION
+ },
+ {
+ name: 'notificationCallback',
+ type: validator.Types.FUNCTION
+ },
+ {
+ name: 'errorCallback',
+ type: validator.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+ var result = native.call('Push_connect', {}, function(msg) {
+ // in case of error, call errorCallback
+ if (msg.error) {
+ if (validatorType.isFunction(data.errorCallback)) {
+ data.errorCallback(native.getErrorObject(msg));
+ }
+ }
});
+ if (native.isFailure(result)) {
+ throw native.getErrorObject(result);
+ }
+ // in case of successfully connect, below listener would be called automatically
+ native.addListener(STATE_LISTENER, function(msg) {
+ if (msg.error) {
+ if (validatorType.isFunction(data.errorCallback)) {
+ data.errorCallback(native.getErrorObject(msg));
+ }
+ } else {
+ data.stateChangeCallback(msg.state);
+ }
+ });
+
+ listener3_0 = function(msg) {
+ data.notificationCallback(new PushMessage(msg.pushMessage));
+ };
+ native.addListener(NOTIFICATION_LISTENER, listenerFunction);
};
PushManager.prototype.disconnectService = function() {
+ console.warn('DEPRECATION WARNING: disconnectService() is deprecated and will be removed from next release. Use disconnect() instead.');
var ret = native.callSync('Push_disconnectService', {});
if (native.isFailure(ret)) {
throw native.getErrorObject(ret);
}
+ listener2_4 = undefined;
+ native.removeListener(NOTIFICATION_LISTENER);
+};
+
+PushManager.prototype.disconnect = function() {
+ var ret = native.callSync('Push_disconnect', {});
+ if (native.isFailure(ret)) {
+ throw native.getErrorObject(ret);
+ }
+ listener3_0 = undefined;
native.removeListener(NOTIFICATION_LISTENER);
};
#include "common/logger.h"
#include "common/tools.h"
#include "push/push_manager.h"
-#include "push/push_manager_old.h"
namespace extension {
namespace push {
} // namespace
-PushInstance::PushInstance() : impl(nullptr) {
+PushInstance::PushInstance() {
LoggerD("Enter");
using std::placeholders::_1;
using std::placeholders::_2;
#define REGISTER_SYNC(c, func) \
RegisterSyncHandler(c, func);
+ REGISTER_ASYNC("Push_registerService",
+ std::bind(&PushInstance::registerService, this, _1, _2));
REGISTER_ASYNC("Push_registerApplication",
std::bind(&PushInstance::registerApplication, this, _1, _2));
+ REGISTER_ASYNC("Push_unregisterService",
+ std::bind(&PushInstance::unregisterService, this, _1, _2));
REGISTER_ASYNC("Push_unregisterApplication",
std::bind(&PushInstance::unregisterApplication, this, _1, _2));
REGISTER_SYNC("Push_connectService",
std::bind(&PushInstance::connectService, this, _1, _2));
+ REGISTER_SYNC("Push_connect",
+ std::bind(&PushInstance::connect, this, _1, _2));
REGISTER_SYNC("Push_disconnectService",
std::bind(&PushInstance::disconnectService, this, _1, _2));
+ REGISTER_SYNC("Push_disconnect",
+ std::bind(&PushInstance::disconnect, this, _1, _2));
REGISTER_SYNC("Push_getRegistrationId",
std::bind(&PushInstance::getRegistrationId, this, _1, _2));
REGISTER_SYNC("Push_getUnreadNotifications",
#undef REGISTER_ASYNC
#undef REGISTER_SYNC
+
+ impl = new PushManager(this);
}
-void PushInstance::initApi(ApiVersionType type) {
- LoggerD("Enter");
- if (!impl) {
- if (PUSH_API_2_4 == type) {
- LoggerD("No API already initialized - using Tizen 2.4 API");
- impl = new PushManagerOld(this);
+
+void PushInstance::registerService(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+
+ CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
+ common::PlatformResult result = impl->registerService(
+ args.get("callbackId").get<double>());
+ if (result.IsError()) {
+ LogAndReportError(result, &out, ("Error occured"));
} else {
- LoggerD("No API already initialized - using Tizen 3.0 API");
- impl = new PushManager(this);
+ ReportSuccess(out);
}
- } else {
- LoggerD("API already initialized - use currently initialized API");
- }
}
void PushInstance::registerApplication(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_2_4);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
common::PlatformResult result = impl->registerApplication(
}
}
+void PushInstance::unregisterService(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+
+ CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
+
+ common::PlatformResult result = impl->unregisterService(
+ args.get("callbackId").get<double>());
+ if (result.IsError()) {
+ LogAndReportError(result, &out, ("Error occured"));
+ } else {
+ ReportSuccess(out);
+ }
+}
+
void PushInstance::unregisterApplication(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_2_4);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
void PushInstance::connectService(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_3_0);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
+void PushInstance::connect(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+
+ CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
+
+ common::PlatformResult result = impl->connect();
+ if (result.IsError()) {
+ LogAndReportError(result, &out, ("Error while connect service"));
+ } else {
+ ReportSuccess(out);
+ }
+}
+
void PushInstance::disconnectService(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_2_4);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
} else {
ReportSuccess(out);
}
+}
+void PushInstance::disconnect(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+
+ CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
+
+ common::PlatformResult result = impl->disconnect();
+ if (result.IsError()) {
+ LogAndReportError(result, &out, ("Error while disconnect service"));
+ } else {
+ ReportSuccess(out);
+ }
}
+
void PushInstance::getRegistrationId(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_2_4);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
void PushInstance::getUnreadNotifications(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_2_4);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
void PushInstance::getPushMessage(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- initApi(PUSH_API_2_4);
CHECK_PRIVILEGE_ACCESS(kPrivilegePush, &out);
}
}
+void PushInstance::onPushState(push_service_state_e state, common::PlatformResult result) {
+ LoggerD("Enter");
+ picojson::value res{picojson::object()};
+ picojson::object& dict = res.get<picojson::object>();
+
+ dict["listenerId"] = picojson::value("Push_State_Listener");
+ if (result.IsError()) {
+ dict["error"] = result.ToJSON();
+ } else {
+ dict["state"] = picojson::value(PushManagerCommon::StateToString(state));
+ }
+ Instance::PostMessage(this, res.serialize().c_str());
+}
+
void PushInstance::onPushRegister(double callbackId,
common::PlatformResult result, const std::string& id) {
- picojson::value::object dict;
+ picojson::value res{picojson::object()};
+ picojson::object& dict = res.get<picojson::object>();
+
dict["callbackId"] = picojson::value(callbackId);
if (result.IsError()) {
dict["error"] = result.ToJSON();
} else {
dict["registrationId"] = picojson::value(id);
}
- picojson::value res(dict);
Instance::PostMessage(this, res.serialize().c_str());
}
void PushInstance::onPushNotify(push_service_notification_h noti) {
LoggerD("Enter");
- picojson::value::object dict;
- picojson::value::object pushMessage;
- impl->notificationToJson(noti, &pushMessage);
+ picojson::value res{picojson::object()};
+ picojson::object& dict = res.get<picojson::object>();
+
+ picojson::value push_message{picojson::object()};
+ picojson::object& push_message_obj = push_message.get<picojson::object>();
+
+ PushManagerCommon::notificationToJson(noti, &push_message_obj);
dict["listenerId"] = picojson::value("Push_Notification_Listener");
- dict["pushMessage"] = picojson::value(pushMessage);
- picojson::value resultListener(dict);
- Instance::PostMessage(this, resultListener.serialize().c_str());
+ dict["pushMessage"] = push_message;
+ Instance::PostMessage(this, res.serialize().c_str());
}
void PushInstance::onDeregister(double callbackId,
common::PlatformResult result) {
LoggerD("Enter");
- picojson::value::object dict;
+ picojson::value res{picojson::object()};
+ picojson::object& dict = res.get<picojson::object>();
+
dict["callbackId"] = picojson::value(callbackId);
if (result.IsError()) {
dict["error"] = result.ToJSON();
}
- picojson::value res(dict);
Instance::PostMessage(this, res.serialize().c_str());
}
namespace extension {
namespace push {
-enum ApiVersionType{
- PUSH_API_2_4,
- PUSH_API_3_0
-} ;
-
class PushInstance: public common::ParsedInstance, public EventListener {
public:
PushInstance();
virtual ~PushInstance();
+ virtual void onPushState(push_service_state_e state, common::PlatformResult result);
virtual void onPushRegister(double callbackId,
common::PlatformResult result, const std::string& id);
virtual void onPushNotify(push_service_notification_h noti);
virtual void onDeregister(double callbackId, common::PlatformResult result);
private:
+ void registerService(const picojson::value& args, picojson::object& out);
void registerApplication(const picojson::value& args, picojson::object& out);
+ void unregisterService(const picojson::value& args, picojson::object& out);
void unregisterApplication(const picojson::value& args, picojson::object& out);
void connectService(const picojson::value& args, picojson::object& out);
+ void connect(const picojson::value& args, picojson::object& out);
void disconnectService(const picojson::value& args, picojson::object& out);
+ void disconnect(const picojson::value& args, picojson::object& out);
void getRegistrationId(const picojson::value& args, picojson::object& out);
void getUnreadNotifications(const picojson::value& args, picojson::object& out);
void getPushMessage(const picojson::value& args, picojson::object& out);
- void initApi(ApiVersionType type);
- IPushManager* impl;
+ PushManager* impl;
};
} // namespace push
using common::PlatformResult;
using common::ErrorCode;
+struct PushManagerHolder {
+ PushManager* impl;
+ double callbackId;
+};
+
+// TODO remove on next release - 2.4 API only
+#define CHECK_CONNECTION() \
+ if (!m_handle) { \
+ 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);\
+ }\
+ m_ignoreNotificationEvents = true;\
+ }
+
+
PushManager::PushManager(EventListener* listener) :
- IPushManager(listener) {
+ m_listener (listener),
+ m_handle (nullptr),
+ app_control_(nullptr),
+ operation_(nullptr),
+ m_ignoreNotificationEvents (true) {
LoggerD("Enter");
+ initPkgId();
+ InitAppControl();
}
PushManager::~PushManager() {
LoggerD("Enter");
+ m_listener = nullptr;
+
+ if (m_handle) {
+ push_service_disconnect(m_handle);
+ m_handle = nullptr;
+ }
+
+ if (app_control_ && (APP_CONTROL_ERROR_NONE != app_control_destroy(app_control_))) {
+ LoggerE("Failed to destroy app control");
+ }
+
+ if (operation_) {
+ free(operation_);
+ }
+}
+
+void PushManager::initPkgId() {
+ LoggerD("Enter");
+ int pid = getpid();
+ char *temp = nullptr;
+ int ret = app_manager_get_app_id(pid, &temp);
+ if (APP_MANAGER_ERROR_NONE != ret || nullptr == temp) {
+ LoggerE("Failed to get appid (%d)", ret);
+ return;
+ }
+
+ std::string m_appId = temp;
+ free(temp);
+ temp = NULL;
+
+ app_info_h info;
+ ret = app_manager_get_app_info(m_appId.c_str(), &info);
+ if (ret != APP_MANAGER_ERROR_NONE) {
+ LoggerE("Failed to get app info (%d)", ret);
+ return;
+ }
+
+ ret = app_info_get_package(info, &temp);
+ if (ret == APP_MANAGER_ERROR_NONE && temp != NULL) {
+ m_pkgId = temp;
+ free(temp);
+ } else {
+ LoggerE("Failed to get pkg id (%d)", ret);
+ }
+ app_info_destroy(info);
+}
+
+void PushManager::InitAppControl() {
+ LoggerD("Enter");
+
+ const auto encoded_bundle = PushManagerCommon::GetEncodedBundle();
+
+ auto bundle = bundle_decode((bundle_raw*) (encoded_bundle.c_str()),
+ encoded_bundle.length());
+ if (nullptr == bundle) {
+ LoggerE("Failed to decode bundle");
+ return;
+ }
+
+ int ret = app_control_create_event(bundle, &app_control_);
+ bundle_free(bundle);
+
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LoggerE("app_control_create_event() failed: %d (%s)", ret, get_error_message(ret));
+ } else {
+ ret = app_control_get_operation(app_control_, &operation_);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LoggerE("app_control_get_operation() failed: %d (%s)", ret, get_error_message(ret));
+ }
+ }
+}
+
+bool PushManager::checkRegistered_2_4() {
+ LoggerD("Enter");
+ bool result = false;
+ char* temp = NULL;
+ int ret = push_service_get_registration_id(m_handle, &temp);
+ if (ret != PUSH_SERVICE_ERROR_NONE) {
+ return result;
+ }
+ result = (NULL != temp ? true : false);
+ free(temp);
+ return result;
}
PlatformResult PushManager::connectService() {
LoggerD("Enter");
+ CHECK_CONNECTION();
+ m_ignoreNotificationEvents = false;
+ return common::PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult PushManager::connect() {
+ LoggerD("Enter");
- int ret = push_service_connect(m_pkgId.c_str(), onPushState, onPushNotify, this,
- &m_handle);
- if (PUSH_SERVICE_ERROR_NONE != ret) {
- return LogAndCreateResult(ConvertPushError(ret), "Failed to connect to push service",
- ("push_service_connect failed (%d)", ret));
+ if (!m_handle) {
+ int ret = push_service_connect(m_pkgId.c_str(), onPushState,
+ onPushNotify, this, &m_handle);
+ if (PUSH_SERVICE_ERROR_NONE != ret) {
+ return LogAndCreateResult(PushManagerCommon::ConvertPushError(ret), "Failed to connect to push service",
+ ("push_service_connect failed (%d)", ret));
+ }
}
return common::PlatformResult(ErrorCode::NO_ERROR);
}
+
PlatformResult PushManager::disconnectService() {
LoggerD("Enter");
+ // disconnecting from push server
if (m_handle) {
push_service_disconnect(m_handle);
m_handle = nullptr;
+ m_ignoreNotificationEvents = true;
}
return common::PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult PushManager::disconnect() {
+ LoggerD("Enter");
+ if (m_handle) {
+ push_service_disconnect(m_handle);
+ m_handle = nullptr;
+ }
+ return common::PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult PushManager::registerService(double callbackId) {
+ LoggerD("Enter");
+ CHECK_CONNECTION();
+
+ PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
+
+ int ret = push_service_register(m_handle, onApplicationRegister_2_4, static_cast<void*>(holder));
+ if (ret != PUSH_SERVICE_ERROR_NONE) {
+ delete holder;
+
+ return LogAndCreateResult(PushManagerCommon::ConvertPushError_2_4(ret), "Failed to register",
+ ("push_service_register failed (%d)", ret));
+ }
+ return common::PlatformResult(ErrorCode::NO_ERROR);
+}
PlatformResult PushManager::registerApplication(double callbackId) {
LoggerD("Enter");
if (PUSH_SERVICE_ERROR_NONE != ret) {
delete holder;
- return LogAndCreateResult(ConvertPushError(ret), "Failed to register",
+ return LogAndCreateResult(PushManagerCommon::ConvertPushError(ret), "Failed to register",
("push_service_register failed (%d)", ret));
}
return common::PlatformResult(ErrorCode::NO_ERROR);
}
+common::PlatformResult PushManager::unregisterService(double callbackId) {
+ LoggerD("Enter");
+ CHECK_CONNECTION();
+ PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
+
+ if (!checkRegistered_2_4()) {
+ LoggerD("Already unregistered, call unregister callback");
+ if (!g_idle_add(onFakeDeregister_2_4, holder)) {
+ delete holder;
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Unknown error", ("g_idle_add failed"));
+ }
+ } else {
+ int ret = push_service_deregister(m_handle, onDeregister_2_4, holder);
+ if (ret != PUSH_SERVICE_ERROR_NONE) {
+ 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) {
+ LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_OUT_OF_MEMORY");
+ } else if (ret == PUSH_SERVICE_ERROR_NOT_CONNECTED) {
+ LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_NOT_CONNECTED");
+ } else if (ret == PUSH_SERVICE_ERROR_OPERATION_FAILED) {
+ LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_OPERATION_FAILED");
+ }
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Unknown error",
+ ("Failed to deregister: push_service_deregister failed (%d)", ret));
+ }
+ }
+ return common::PlatformResult(ErrorCode::NO_ERROR);
+}
+
common::PlatformResult PushManager::unregisterApplication(double callbackId) {
LoggerD("Enter");
PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
int ret = push_service_deregister(m_handle, onDeregister, holder);
if (PUSH_SERVICE_ERROR_NONE != ret) {
delete holder;
- return LogAndCreateResult(ConvertPushError(ret), "Failed to deregister",
+ return LogAndCreateResult(PushManagerCommon::ConvertPushError(ret), "Failed to deregister",
("push_service_deregister failed (%d)", ret));
}
char* temp = nullptr;
int ret = push_service_get_registration_id(m_handle, &temp);
if (PUSH_SERVICE_ERROR_NONE != ret) {
- return LogAndCreateResult(ConvertPushError(ret), "Failed to get registration id",
+ return LogAndCreateResult(PushManagerCommon::ConvertPushError_2_4(ret), "Failed to get registration id",
("push_service_get_registration_id failed (%d)", ret));
}
id = temp;
LoggerD("Enter");
int ret = push_service_request_unread_notification(m_handle);
if (PUSH_SERVICE_ERROR_NONE != ret) {
- return LogAndCreateResult(ConvertPushError(ret), "Failed to get unread notifications",
+ return LogAndCreateResult(PushManagerCommon::ConvertPushError_2_4(ret), "Failed to get unread notifications",
("push_service_request_unread_notification failed (%d)", ret));
}
return common::PlatformResult(ErrorCode::NO_ERROR);
if (PUSH_SERVICE_ERROR_NONE != ret) {
if (PUSH_SERVICE_ERROR_NO_DATA == ret || PUSH_SERVICE_ERROR_NOT_SUPPORTED == ret) {
- LoggerD("ret: %s", ConvertPushError(ret));
+ LoggerD("ret: %s", get_error_message(ret));
// application was not started by push service, return null
*out = picojson::value{};
return common::PlatformResult(ErrorCode::NO_ERROR);
}
picojson::object notification;
- notificationToJson(handle, ¬ification);
+ PushManagerCommon::notificationToJson(handle, ¬ification);
push_service_free_notification(handle);
*out = picojson::value{notification};
return common::PlatformResult(ErrorCode::NO_ERROR);
}
-void PushManager::onPushState(push_service_state_e state, const char* err,
- void* user_data) {
+
+void PushManager::onPushState(push_service_state_e state, const char* err, void* user_data) {
LoggerD("Enter %d, err: %s", state, err);
+ PushManager* impl = static_cast<PushManager*>(user_data);
+ if (nullptr == impl || !impl->m_listener) {
+ LoggerW("Listener not set, ignoring");
+ return;
+ }
+
+ // checking errors
+ common::PlatformResult result(ErrorCode::NO_ERROR);
+ if (err || (state != PUSH_SERVICE_STATE_REGISTERED && state != PUSH_SERVICE_STATE_UNREGISTERED)) {
+ result = LogAndCreateResult(ErrorCode::ABORT_ERR, nullptr == err ? "Abort error" : err);
+ }
+ impl->m_listener->onPushState(state, result);
}
void PushManager::onPushNotify(push_service_notification_h noti, void* user_data) {
}
} else {
if (PUSH_SERVICE_RESULT_TIMEOUT == result) {
+ res = LogAndCreateResult(ErrorCode::TIMEOUT_ERR, nullptr == msg ? "Timeout error" : msg);
+ } else {
+ res = LogAndCreateResult(ErrorCode::ABORT_ERR, nullptr == msg ? "Abort error" : msg);
+ }
+ }
+
+ impl->m_listener->onPushRegister(callbackId, res, id);
+}
+
+// TODO duplicated code due to different error handling in 2.4 API. remove on next release
+void PushManager::onApplicationRegister_2_4(push_service_result_e result, const char* msg, void* user_data) {
+ LoggerD("Enter");
+
+ 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;
+ }
+
+ 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(impl->m_handle, &temp);
+ if (PUSH_SERVICE_ERROR_NONE == ret) {
+ LoggerD("Registration id retrieved");
+ id = temp;
+ free(temp);
+ } else {
+ res = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to retrieve registration id",
+ ("Failed to retrieve registration id: push_service_get_registration_id(%d)", ret));
+ }
+ } else {
+ if (PUSH_SERVICE_RESULT_TIMEOUT == result) {
LoggerE("PUSH_SERVICE_RESULT_TIMEOUT");
} else if (PUSH_SERVICE_RESULT_SERVER_ERROR == result) {
LoggerE("PUSH_SERVICE_RESULT_SERVER_ERROR");
} else if (PUSH_SERVICE_RESULT_SYSTEM_ERROR == result) {
LoggerE("PUSH_SERVICE_RESULT_SYSTEM_ERROR");
}
- res = LogAndCreateResult(ErrorCode::ABORT_ERR, nullptr == msg ? "Abort error" : msg);
+ res = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, nullptr == msg ? "Unknown error" : msg);
}
impl->m_listener->onPushRegister(callbackId, res, id);
if (PUSH_SERVICE_RESULT_SUCCESS == result) {
impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
} else {
- impl->m_listener->onDeregister(callbackId, LogAndCreateResult(ErrorCode::ABORT_ERR,
+ PlatformResult res(ErrorCode::NO_ERROR);
+ if (PUSH_SERVICE_RESULT_TIMEOUT == result) {
+ res = LogAndCreateResult(ErrorCode::TIMEOUT_ERR, nullptr == msg ? "Timeout error" : msg);
+ } else {
+ res = LogAndCreateResult(ErrorCode::ABORT_ERR, msg == nullptr ? "Abort error" : msg);
+ }
+ impl->m_listener->onDeregister(callbackId, res);
+ }
+}
+
+// TODO duplicated code due to different error handling in 2.4 API. remove on next release
+void PushManager::onDeregister_2_4(push_service_result_e result, const char* msg,
+ void* user_data) {
+ LoggerD("Enter");
+ 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;
+ }
+ if (PUSH_SERVICE_RESULT_SUCCESS == result) {
+ impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
+ } else {
+ impl->m_listener->onDeregister(callbackId, LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
msg == nullptr ? "Unknown error" : msg));
}
}
+gboolean PushManager::onFakeDeregister_2_4(gpointer user_data) {
+ LoggerD("Enter");
+ 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;
+ }
+ impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
+ return G_SOURCE_REMOVE;
+}
+
} // namespace push
} // namespace extension
namespace extension {
namespace push {
-class PushManager : public IPushManager {
+class PushManager {
public:
PushManager(EventListener* listener);
virtual ~PushManager();
common::PlatformResult connectService();
+ common::PlatformResult connect();
common::PlatformResult disconnectService();
+ common::PlatformResult disconnect();
+ common::PlatformResult registerService(double callbackId);
common::PlatformResult registerApplication(double callbackId);
+ common::PlatformResult unregisterService(double callbackId);
common::PlatformResult unregisterApplication(double callbackId);
common::PlatformResult getRegistrationId(std::string &id);
common::PlatformResult getUnreadNotifications();
common::PlatformResult getPushMessage(picojson::value* out);
+
private:
+ void initPkgId();
+ void InitAppControl();
+
+ // TODO remove on next release - 2.4 API only
+ bool checkRegistered_2_4();
+ static gboolean onFakeDeregister_2_4(gpointer user_data);
+ static void onApplicationRegister_2_4(push_service_result_e result, const char *msg,
+ void *user_data);
+ static void onDeregister_2_4(push_service_result_e result, const char *msg,
+ void *user_data);
+ /////////////////////////////////////////////
+
static void onPushState(push_service_state_e state, const char *err,
void *user_data);
static void onPushNotify(push_service_notification_h noti, void *user_data);
void *user_data);
static void onDeregister(push_service_result_e result, const char *msg,
void *user_data);
+
+ EventListener* m_listener;
+ push_service_connection_h m_handle;
+ std::string m_pkgId;
+ app_control_h app_control_;
+ char* operation_;
+
+ // TODO remove on next release - 2.4 API only
+ bool m_ignoreNotificationEvents;
+ /////////////////////////////////////////////
};
} // namespace push
using common::PlatformResult;
using common::ErrorCode;
+std::string PushManagerCommon::StateToString(push_service_state_e state) {
+ LoggerD("Entered");
+
+ switch(state) {
+ case PUSH_SERVICE_STATE_REGISTERED :
+ return "REGISTERED";
+ default:
+ return "UNREGISTERED";
+ }
+}
+
std::string PushManagerCommon::GetEncodedBundle() {
LoggerD("Entered");
return result;
}
-IPushManager::IPushManager(EventListener* listener) :
- m_listener (listener),
- m_handle (nullptr),
- app_control_(nullptr),
- operation_(nullptr) {
- LoggerD("Enter");
- initPkgId();
- InitAppControl();
-}
-
-IPushManager::~IPushManager() {
- LoggerD("Enter");
- m_listener = nullptr;
-
- if (m_handle) {
- push_service_disconnect(m_handle);
- m_handle = nullptr;
- }
-
- if (app_control_ && (APP_CONTROL_ERROR_NONE != app_control_destroy(app_control_))) {
- LoggerE("Failed to destroy app control");
- }
-
- if (operation_) {
- free(operation_);
- }
-}
-
-void IPushManager::notificationToJson(push_service_notification_h noti, picojson::object* obj) {
+void PushManagerCommon::notificationToJson(push_service_notification_h noti, picojson::object* obj) {
LoggerD("Enter");
char* temp = nullptr;
(*obj)["type"] = picojson::value(static_cast<double>(type));
}
-void IPushManager::initPkgId() {
- LoggerD("Enter");
- int pid = getpid();
- char *temp = nullptr;
- int ret = app_manager_get_app_id(pid, &temp);
- if (APP_MANAGER_ERROR_NONE != ret || nullptr == temp) {
- LoggerE("Failed to get appid (%d)", ret);
- return;
- }
-
- std::string m_appId = temp;
- free(temp);
- temp = NULL;
-
- app_info_h info;
- ret = app_manager_get_app_info(m_appId.c_str(), &info);
- if (ret != APP_MANAGER_ERROR_NONE) {
- LoggerE("Failed to get app info (%d)", ret);
- return;
- }
-
- ret = app_info_get_package(info, &temp);
- if (ret == APP_MANAGER_ERROR_NONE && temp != NULL) {
- m_pkgId = temp;
- free(temp);
- } else {
- LoggerE("Failed to get pkg id (%d)", ret);
- }
- app_info_destroy(info);
-}
-
-void IPushManager::InitAppControl() {
+// 3.0 version errors mappings
+ErrorCode PushManagerCommon::ConvertPushError(int e) {
LoggerD("Enter");
+ ErrorCode error;
- const auto encoded_bundle = PushManagerCommon::GetEncodedBundle();
-
- auto bundle = bundle_decode((bundle_raw*) (encoded_bundle.c_str()),
- encoded_bundle.length());
- if (nullptr == bundle) {
- LoggerE("Failed to decode bundle");
- return;
+ switch(e) {
+ case PUSH_SERVICE_ERROR_NONE:
+ error = ErrorCode::NO_ERROR;
+ break;
+ case PUSH_SERVICE_ERROR_INVALID_PARAMETER:
+ case PUSH_SERVICE_ERROR_NOT_CONNECTED:
+ case PUSH_SERVICE_ERROR_NOT_SUPPORTED:
+ error = ErrorCode::INVALID_STATE_ERR;
+ break;
+ default:
+ error = ErrorCode::ABORT_ERR;
+ break;
}
- int ret = app_control_create_event(bundle, &app_control_);
- bundle_free(bundle);
-
- if (APP_CONTROL_ERROR_NONE != ret) {
- LoggerE("app_control_create_event() failed: %d (%s)", ret, get_error_message(ret));
- } else {
- ret = app_control_get_operation(app_control_, &operation_);
- if (APP_CONTROL_ERROR_NONE != ret) {
- LoggerE("app_control_get_operation() failed: %d (%s)", ret, get_error_message(ret));
- }
- }
+ return error;
}
-// new version errors mappings, to check mappings for *_old impl, check overloaded method
-ErrorCode IPushManager::ConvertPushError(int e) {
+// Different error code mappings for 2.4 implementation
+ErrorCode PushManagerCommon::ConvertPushError_2_4(int e) {
LoggerD("Enter");
ErrorCode error;
case PUSH_SERVICE_ERROR_NONE:
error = ErrorCode::NO_ERROR;
break;
+
case PUSH_SERVICE_ERROR_INVALID_PARAMETER:
- case PUSH_SERVICE_ERROR_NOT_CONNECTED:
- case PUSH_SERVICE_ERROR_NOT_SUPPORTED:
- error = ErrorCode::INVALID_STATE_ERR;
+ 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;
}
class EventListener {
public:
+ virtual void onPushState(push_service_state_e state, common::PlatformResult result) = 0;
+ virtual void onPushNotify(push_service_notification_h noti) = 0;
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(EventListener* listener);
- virtual ~IPushManager();
-
- virtual common::PlatformResult connectService() = 0;
- virtual common::PlatformResult disconnectService() = 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);
- protected :
- void initPkgId();
- void InitAppControl();
- static common::ErrorCode ConvertPushError(int e);
-
- EventListener* m_listener;
- push_service_connection_h m_handle;
- std::string m_pkgId;
- app_control_h app_control_;
- char* operation_;
-};
-
-struct PushManagerHolder {
- IPushManager* impl;
- double callbackId;
-};
-
class PushManagerCommon {
public :
+ static std::string StateToString(push_service_state_e state);
static std::string GetEncodedBundle();
+ static void notificationToJson(push_service_notification_h noti, picojson::object* obj);
+ static common::ErrorCode ConvertPushError(int e);
+ static common::ErrorCode ConvertPushError_2_4(int e);
};
} // namespace push
+++ /dev/null
-/*
- * 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_old.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 "push/push_manager_common.h"
-#include "common/extension.h"
-#include "common/logger.h"
-
-namespace extension {
-namespace push {
-
-using common::PlatformResult;
-using common::ErrorCode;
-
-#define CHECK_CONNECTION() \
- if (!m_handle) { \
- 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);\
- }\
- m_state = PUSH_SERVICE_STATE_UNREGISTERED;\
- m_ignoreNotificationEvents = true;\
- }
-
-
-PushManagerOld::PushManagerOld(EventListener* listener) :
- IPushManager(listener),
- m_state(PUSH_SERVICE_STATE_UNREGISTERED),
- m_ignoreNotificationEvents (true) {
- LoggerD("Enter");
- 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);
- }
-}
-
-PushManagerOld::~PushManagerOld() {
- LoggerD("Enter");
-}
-
-PlatformResult PushManagerOld::connectService() {
- LoggerD("Enter");
- CHECK_CONNECTION();
- m_ignoreNotificationEvents = false;
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult PushManagerOld::disconnectService() {
- LoggerD("Enter");
- // disconnecting from push server
- if (m_handle) {
- push_service_disconnect(m_handle);
- m_handle = nullptr;
- m_state = PUSH_SERVICE_STATE_UNREGISTERED;
- m_ignoreNotificationEvents = true;
- }
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-
-PlatformResult PushManagerOld::registerApplication(double callbackId) {
- LoggerD("Enter");
- CHECK_CONNECTION();
-
- PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
-
- int ret = push_service_register(m_handle, onApplicationRegister, static_cast<void*>(holder));
- if (ret != PUSH_SERVICE_ERROR_NONE) {
- delete holder;
-
- return LogAndCreateResult(ConvertPushError(ret), "Failed to register",
- ("push_service_register failed (%d)", ret));
- }
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-bool PushManagerOld::checkRegistered() {
- LoggerD("Enter");
- bool result = false;
- char* temp = NULL;
- int ret = push_service_get_registration_id(m_handle, &temp);
- if (ret != PUSH_SERVICE_ERROR_NONE) {
- return result;
- }
- result = (NULL != temp ? true : false);
- free(temp);
- return result;
-}
-
-
-common::PlatformResult PushManagerOld::unregisterApplication(double callbackId) {
- LoggerD("Enter");
- CHECK_CONNECTION();
- PushManagerHolder* holder = new PushManagerHolder{this, callbackId};
-
- if (!checkRegistered()) {
- LoggerD("Already unregistered, call unregister callback");
- 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, holder);
- if (ret != PUSH_SERVICE_ERROR_NONE) {
- 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) {
- LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_OUT_OF_MEMORY");
- } else if (ret == PUSH_SERVICE_ERROR_NOT_CONNECTED) {
- LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_NOT_CONNECTED");
- } else if (ret == PUSH_SERVICE_ERROR_OPERATION_FAILED) {
- LoggerE("[push_service_deregister] PUSH_SERVICE_ERROR_OPERATION_FAILED");
- }
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Unknown error",
- ("Failed to deregister: push_service_deregister failed (%d)", ret));
- }
- }
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-common::PlatformResult PushManagerOld::getRegistrationId(std::string& id) {
- LoggerD("Enter");
- CHECK_CONNECTION();
- char* temp = NULL;
- int ret = push_service_get_registration_id(m_handle, &temp);
- if (ret != PUSH_SERVICE_ERROR_NONE) {
- if (ret == PUSH_SERVICE_ERROR_INVALID_PARAMETER) {
- LoggerE("[push_service_get_registration_id] PUSH_SERVICE_ERROR_INVALID_PARAMETER");
- } else if (ret == PUSH_SERVICE_ERROR_OUT_OF_MEMORY) {
- LoggerE("[push_service_get_registration_id] PUSH_SERVICE_ERROR_OUT_OF_MEMORY");
- } else if (ret == PUSH_SERVICE_ERROR_NO_DATA) {
- LoggerE("[push_service_get_registration_id] PUSH_SERVICE_ERROR_NO_DATA");
- }
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Unknown error",
- ("Failed to get id: push_service_get_registration_id failed (%d)", ret));
- }
- id = temp;
- free(temp);
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-common::PlatformResult PushManagerOld::getUnreadNotifications() {
- LoggerD("Enter");
- CHECK_CONNECTION();
- int ret = push_service_request_unread_notification(m_handle);
- if (ret != PUSH_SERVICE_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Unknown error",
- ("Failed to send request: push_service_request_unread_notification failed (%d)", ret));
- }
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult PushManagerOld::getPushMessage(picojson::value* out) {
- LoggerD("Enter");
- CHECK_CONNECTION();
-
- push_service_notification_h handle = nullptr;
- int ret = push_service_app_control_to_notification(app_control_, operation_,
- &handle);
-
- if (ret != PUSH_SERVICE_ERROR_NONE) {
- if (PUSH_SERVICE_ERROR_NO_DATA == ret || PUSH_SERVICE_ERROR_NOT_SUPPORTED == ret) {
- // application was not started by push service, return null
- *out = picojson::value{};
- return common::PlatformResult(ErrorCode::NO_ERROR);
- } else {
- return LogAndCreateResult(ConvertPushError(ret), "Failed to get message",
- ("push_service_app_control_to_notification failed: (%d)", ret));
- }
- }
-
- picojson::object notification;
- notificationToJson(handle, ¬ification);
- push_service_free_notification(handle);
-
- *out = picojson::value{notification};
-
- return common::PlatformResult(ErrorCode::NO_ERROR);
-}
-
-void PushManagerOld::onPushState(push_service_state_e state, const char* err,
- void* user_data) {
- LoggerD("Enter %d, err: %s", state, err);
- PushManagerOld* impl = static_cast<PushManagerOld*>(user_data);
- if (nullptr != impl) {
- impl->m_state = state;
- }
-}
-
-void PushManagerOld::onPushNotify(push_service_notification_h noti, void* user_data) {
- LoggerD("Enter");
- PushManagerOld* impl = static_cast<PushManagerOld*>(user_data);
- if (nullptr == impl || !impl->m_listener) {
- LoggerW("Listener not set, ignoring");
- return;
- }
-
- if (!impl->m_ignoreNotificationEvents) {
- impl->m_listener->onPushNotify(noti);
- } else {
- LoggerD("Listener not set, ignoring event");
- }
-}
-
-void PushManagerOld::onApplicationRegister(push_service_result_e result, const char* msg, void* user_data) {
- LoggerD("Enter");
-
- PushManagerHolder* holder = static_cast<PushManagerHolder*>(user_data);
- // automatically releases memory
- std::unique_ptr<PushManagerHolder> holder_ptr(holder);
- PushManagerOld* impl = dynamic_cast<PushManagerOld*>(holder->impl);
- double callbackId = holder->callbackId;
-
- if (nullptr == impl || !impl->m_listener) {
- LoggerW("Listener not set, ignoring");
- return;
- }
-
- 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(impl->m_handle, &temp);
- if (PUSH_SERVICE_ERROR_NONE == ret) {
- LoggerD("Registration id retrieved");
- id = temp;
- free(temp);
- } else {
- res = LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Failed to retrieve registration id",
- ("Failed to retrieve registration id: push_service_get_registration_id(%d)", ret));
- }
- } else {
- if (PUSH_SERVICE_RESULT_TIMEOUT == result) {
- LoggerE("PUSH_SERVICE_RESULT_TIMEOUT");
- } else if (PUSH_SERVICE_RESULT_SERVER_ERROR == result) {
- LoggerE("PUSH_SERVICE_RESULT_SERVER_ERROR");
- } else if (PUSH_SERVICE_RESULT_SYSTEM_ERROR == result) {
- LoggerE("PUSH_SERVICE_RESULT_SYSTEM_ERROR");
- }
- res = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, msg == nullptr ? "Unknown error" : msg);
- }
-
- // onPushState is not always called when onPushRegister is successful
- impl->m_state = PUSH_SERVICE_STATE_REGISTERED;
- impl->m_listener->onPushRegister(callbackId, res, id);
-}
-
-gboolean PushManagerOld::onFakeDeregister(gpointer user_data) {
- LoggerD("Enter");
- PushManagerHolder* holder = static_cast<PushManagerHolder*>(user_data);
- // automatically releases memory
- std::unique_ptr<PushManagerHolder> holder_ptr(holder);
- PushManagerOld* impl = dynamic_cast<PushManagerOld*>(holder->impl);
- double callbackId = holder->callbackId;
-
- if (nullptr == impl || !impl->m_listener) {
- LoggerW("Listener not set, ignoring");
- return G_SOURCE_REMOVE;
- }
- impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
- return G_SOURCE_REMOVE;
-}
-
-void PushManagerOld::onDeregister(push_service_result_e result, const char* msg,
- void* user_data) {
- LoggerD("Enter");
- PushManagerHolder* holder = static_cast<PushManagerHolder*>(user_data);
- // automatically releases memory
- PushManagerOld* impl = dynamic_cast<PushManagerOld*>(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;
- }
- if (result == PUSH_SERVICE_RESULT_SUCCESS) {
- impl->m_listener->onDeregister(callbackId, PlatformResult(ErrorCode::NO_ERROR));
- } else {
- impl->m_listener->onDeregister(callbackId, LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- msg == NULL ? "Unknown error" : msg));
- }
-}
-
-// Different error code mappings for previous implementation
-ErrorCode PushManagerOld::ConvertPushError(int e) {
- LoggerD("Enter");
- 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 push
-} // namespace extension
-
+++ /dev/null
-/*
- * 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_OLD_H_
-#define SRC_PUSH_PUSH_MANAGER_OLD_H_
-
-#include <push-service.h>
-#include <glib.h>
-#include <string>
-#include <vector>
-#include <map>
-#include "common/platform_result.h"
-#include "push_manager_common.h"
-
-namespace extension {
-namespace push {
-
-class PushManagerOld : public IPushManager {
- public:
- PushManagerOld(EventListener* listener);
- virtual ~PushManagerOld();
-
- common::PlatformResult connectService();
- common::PlatformResult disconnectService();
- common::PlatformResult registerApplication(double callbackId);
- common::PlatformResult unregisterApplication(double callbackId);
- common::PlatformResult getRegistrationId(std::string &id);
- common::PlatformResult getUnreadNotifications();
- common::PlatformResult getPushMessage(picojson::value* out);
-
- protected:
- static common::ErrorCode ConvertPushError(int e);
-
- private:
- bool checkRegistered();
- static void onPushState(push_service_state_e state, const char *err,
- void *user_data);
- static void onPushNotify(push_service_notification_h noti, void *user_data);
- static void onApplicationRegister(push_service_result_e result, const char *msg,
- void *user_data);
- static gboolean onFakeDeregister(gpointer user_data);
- static void onDeregister(push_service_result_e result, const char *msg,
- void *user_data);
-
- push_service_state_e m_state;
- bool m_ignoreNotificationEvents;
-};
-
-} // namespace push
-} // namespace extension
-
-#endif // SRC_PUSH_PUSH_MANAGER_OLD_H_
-