diff options
Diffstat (limited to 'mobile_src/Push')
-rw-r--r-- | mobile_src/Push/CMakeLists.txt | 55 | ||||
-rw-r--r-- | mobile_src/Push/JSPushManager.cpp | 334 | ||||
-rw-r--r-- | mobile_src/Push/JSPushManager.h | 107 | ||||
-rw-r--r-- | mobile_src/Push/JSPushMessage.cpp | 137 | ||||
-rw-r--r-- | mobile_src/Push/JSPushMessage.h | 71 | ||||
-rwxr-xr-x | mobile_src/Push/PushManager.cpp | 505 | ||||
-rwxr-xr-x | mobile_src/Push/PushManager.h | 66 | ||||
-rw-r--r-- | mobile_src/Push/PushMessage.cpp | 68 | ||||
-rw-r--r-- | mobile_src/Push/PushMessage.h | 54 | ||||
-rw-r--r-- | mobile_src/Push/PushTypes.h | 34 | ||||
-rw-r--r-- | mobile_src/Push/config.xml | 12 | ||||
-rw-r--r-- | mobile_src/Push/plugin_config.cpp | 126 | ||||
-rw-r--r-- | mobile_src/Push/plugin_config.h | 52 | ||||
-rwxr-xr-x | mobile_src/Push/plugin_initializer.cpp | 86 |
14 files changed, 1707 insertions, 0 deletions
diff --git a/mobile_src/Push/CMakeLists.txt b/mobile_src/Push/CMakeLists.txt new file mode 100644 index 0000000..bd40cb2 --- /dev/null +++ b/mobile_src/Push/CMakeLists.txt @@ -0,0 +1,55 @@ + +SET(TARGET_NAME ${push_target}) +SET(DESTINATION_NAME ${push_dest}) +SET(TARGET_IMPL_NAME ${push_impl}) + +IF(ENABLE_OPTIONAL_PUSH) +PKG_CHECK_MODULES(platform_pkgs_push REQUIRED push capi-appfw-application) + +INCLUDE_DIRECTORIES( + ${INCLUDE_COMMON} + ${TOP}/Application + ${platform_pkgs_push_INCLUDE_DIRS} +) + +SET(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${tizen_dest} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${application_dest} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME} +) + +SET(SRCS_IMPL + JSPushManager.cpp + JSPushMessage.cpp + PushManager.cpp + PushMessage.cpp +) + +ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) + +TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME} + ${LIBS_COMMON} + ${tizen_impl} + ${application_impl} + ${platform_pkgs_push_LIBRARIES} +) + +SET(SRCS + plugin_config.cpp + plugin_initializer.cpp +) + +ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${TARGET_NAME} + ${TARGET_IMPL_NAME} +) + +INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}) +ENDIF(ENABLE_OPTIONAL_PUSH) +INSTALL( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/push + FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE +) diff --git a/mobile_src/Push/JSPushManager.cpp b/mobile_src/Push/JSPushManager.cpp new file mode 100644 index 0000000..4bc71e7 --- /dev/null +++ b/mobile_src/Push/JSPushManager.cpp @@ -0,0 +1,334 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 <SecurityExceptions.h> + +#include <JSUtil.h> +#include <ArgumentValidator.h> +#include <GlobalContextManager.h> +#include <MultiCallbackUserData.h> +#include <PlatformException.h> + +#include <JSApplicationControl.h> +#include <TimeTracer.h> + +#include "plugin_config.h" + +#include "JSPushManager.h" + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Push { + +JSClassDefinition JSPushManager::m_classInfo = { + 0, + kJSClassAttributeNone, + "PushManager", + NULL, //ParentClass + NULL, //StaticValues + m_function, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticFunction JSPushManager::m_function[] = { + { PUSH_MANAGER_API_REGISTER_SERVICE, registerService, kJSPropertyAttributeNone }, + { PUSH_MANAGER_API_UNREGISTER_SERVICE, unregisterService, kJSPropertyAttributeNone }, + { PUSH_MANAGER_API_CONNECT_SERVICE, connectService, kJSPropertyAttributeNone }, + { PUSH_MANAGER_API_DISCONNECT_SERVICE, disconnectService, kJSPropertyAttributeNone }, + { PUSH_MANAGER_API_GET_REGISTRATION_ID, getRegistrationId, kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; + +JSClassRef JSPushManager::m_jsClassRef = JSClassCreate(JSPushManager::getClassInfo()); + +const JSClassRef JSPushManager::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSPushManager::getClassInfo() +{ + return &m_classInfo; +} + +void JSPushManager::initialize(JSContextRef context, JSObjectRef object) +{ + if (!JSObjectGetPrivate(object)) { + PushManager *priv = PushManager::getInstance(); + JSObjectSetPrivate(object, static_cast<void*>(priv)); + } +} + +void JSPushManager::finalize(JSObjectRef object) +{ +} + +JSValueRef JSPushManager::registerService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + + TIME_TRACER_ITEM_BEGIN("PUSH_registerService_ACE", 0); + AceSecurityStatus status = PUSH_CHECK_ACCESS(PUSH_MANAGER_API_REGISTER_SERVICE); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + TIME_TRACER_ITEM_END("PUSH_registerService_ACE", 0); + + try { + // Private Object + PushManager *priv = static_cast<PushManager *>(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + + ArgumentValidator validator(context, argumentCount, arguments); + + // appControl + DeviceAPI::Application::ApplicationControlPtr appControl(NULL); + JSObjectRef appControlObj = validator.toObject(0, DeviceAPI::Application::JSApplicationControl::getClassRef()); + if (appControlObj) { + JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv *>(JSObjectGetPrivate(appControlObj)); + if (!priv) { + throw TypeMismatchException("ApplicationControl's private object is NULL."); + } + appControl = priv->getObject(); + } + + MultiCallbackUserDataPtr callback(new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + + // successCallback + JSObjectRef successCallbackObj = validator.toFunction(1); + if (successCallbackObj) { + callback->setCallback("onsuccess", successCallbackObj); + } + + // errorCallback + JSObjectRef errorCallbackObj = validator.toFunction(2, true); + if (errorCallbackObj) { + callback->setCallback("onerror", errorCallbackObj); + } + + // perform + priv->registerService(appControl, callback); + + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.registerService()."); + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSPushManager::unregisterService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + + TIME_TRACER_ITEM_BEGIN("PUSH_unregisterService_ACE", 0); + AceSecurityStatus status = PUSH_CHECK_ACCESS(PUSH_MANAGER_API_UNREGISTER_SERVICE); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + TIME_TRACER_ITEM_END("PUSH_unregisterService_ACE", 0); + + try { + // Private Object + PushManager *priv = static_cast<PushManager *>(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + + ArgumentValidator validator(context, argumentCount, arguments); + + MultiCallbackUserDataPtr callback(new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + + // successCallback + JSObjectRef successCallbackObj = validator.toFunction(0, true); + if (successCallbackObj) { + callback->setCallback("onsuccess", successCallbackObj); + } + + // errorCallback + JSObjectRef errorCallbackObj = validator.toFunction(1, true); + if (errorCallbackObj) { + callback->setCallback("onerror", errorCallbackObj); + } + + // perform + priv->unregisterService(callback); + + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.unregisterService()."); + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSPushManager::connectService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + + TIME_TRACER_ITEM_BEGIN("PUSH_connectService_ACE", 0); + AceSecurityStatus status = PUSH_CHECK_ACCESS(PUSH_MANAGER_API_CONNECT_SERVICE); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + TIME_TRACER_ITEM_END("PUSH_connectService_ACE", 0); + + try { + // Private Object + PushManager *priv = static_cast<PushManager *>(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + + ArgumentValidator validator(context, argumentCount, arguments); + + // notificationCallback + MultiCallbackUserDataPtr callback; + JSObjectRef notificationCallbackObj = validator.toFunction(0); + if (notificationCallbackObj) { + callback.reset(new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + callback->setCallback("onsuccess", notificationCallbackObj); + } + + // perform + priv->connectService(callback); + + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.connectService()."); + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSPushManager::disconnectService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + + TIME_TRACER_ITEM_BEGIN("PUSH_disconnectService_ACE", 0); + AceSecurityStatus status = PUSH_CHECK_ACCESS(PUSH_MANAGER_API_DISCONNECT_SERVICE); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + TIME_TRACER_ITEM_END("PUSH_disconnectService_ACE", 0); + + try { + // Private Object + PushManager *priv = static_cast<PushManager *>(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + + // perform + priv->disconnectService(); + + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.disconnectService()."); + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSPushManager::getRegistrationId(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + + TIME_TRACER_ITEM_BEGIN("PUSH_getRegistrationId_ACE", 0); + AceSecurityStatus status = PUSH_CHECK_ACCESS(PUSH_MANAGER_API_GET_REGISTRATION_ID); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + TIME_TRACER_ITEM_END("PUSH_getRegistrationId_ACE", 0); + + try { + // Private Object + PushManager *priv = static_cast<PushManager *>(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + + // perform + std::string ret = priv->getRegistrationId(); + if (ret.empty()) { + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return JSValueMakeNull(context); + } else { + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return JSUtil::toJSValueRef(context, ret); + } + } catch (const BasePlatformException &err) { + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in PushManager.getRegistrationId()."); + LOGE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + + +} // Push +} // DeviceAPI diff --git a/mobile_src/Push/JSPushManager.h b/mobile_src/Push/JSPushManager.h new file mode 100644 index 0000000..888c08e --- /dev/null +++ b/mobile_src/Push/JSPushManager.h @@ -0,0 +1,107 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 __TIZEN_JS_PUSH_MANAGER_H__ +#define __TIZEN_JS_PUSH_MANAGER_H__ + +#include <JavaScriptCore/JavaScript.h> + +#include "PushManager.h" + +namespace DeviceAPI { +namespace Push { + +class JSPushManager +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + static JSValueRef registerService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef unregisterService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef connectService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef disconnectService(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef getRegistrationId(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + /** + * This structure describes a statically declared function property. + */ + static JSStaticFunction m_function[]; + + /** + * This member variable contains the initialization values for the + * properties of this class. The values are given according to + * the data structure JSPropertySpec + */ + static JSStaticValue m_property[]; + + static JSClassRef m_jsClassRef; +}; + + + +} // Push +} // DeviceAPI + +#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__ diff --git a/mobile_src/Push/JSPushMessage.cpp b/mobile_src/Push/JSPushMessage.cpp new file mode 100644 index 0000000..338e200 --- /dev/null +++ b/mobile_src/Push/JSPushMessage.cpp @@ -0,0 +1,137 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 <SecurityExceptions.h> + +#include <JSUtil.h> +#include <JSWebAPIErrorFactory.h> +#include <ArgumentValidator.h> +#include <GlobalContextManager.h> +#include <MultiCallbackUserData.h> +#include <PlatformException.h> + +#include "plugin_config.h" + +#include "JSPushMessage.h" + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Push { + +JSClassDefinition JSPushMessage::m_classInfo = { + 0, + kJSClassAttributeNone, + "PushMessage", + NULL, //ParentClass + NULL, //StaticValues + NULL, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + + +JSClassRef JSPushMessage::m_jsClassRef = JSClassCreate(JSPushMessage::getClassInfo()); + +const JSClassRef JSPushMessage::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSPushMessage::getClassInfo() +{ + return &m_classInfo; +} + +void JSPushMessage::initialize(JSContextRef context, JSObjectRef object) +{ + if (!JSObjectGetPrivate(object)) { + PushMessage *priv = new PushMessage(); + if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) { + delete priv; + } + } +} + +void JSPushMessage::finalize(JSObjectRef object) +{ + PushMessage *priv = static_cast<PushMessage *>(JSObjectGetPrivate(object)); + if (priv) { + JSObjectSetPrivate(object, NULL); + delete priv; + } +} + +PushMessage* JSPushMessage::getPrivateObject(JSContextRef context, JSObjectRef object) +{ + PushMessage *priv = static_cast<PushMessage *>(JSObjectGetPrivate(object)); + if (!priv) { + throw TypeMismatchException("PushMessage's private object is NULL."); + } + + // appData + JSValueRef appData = JSUtil::getProperty(context, object, PUSH_MESSAGE_APP_DATA); + priv->setAppData(JSUtil::JSValueToString(context, appData)); + + // alertMessage + JSValueRef alertMessage = JSUtil::getProperty(context, object, PUSH_MESSAGE_ALERT_MESSAGE); + priv->setAlertMessage(JSUtil::JSValueToString(context, alertMessage)); + + // date + JSValueRef date = JSUtil::getProperty(context, object, PUSH_MESSAGE_DATE); + priv->setDate(JSUtil::JSValueToTimeT(context, date)); + + return priv; +} + +void JSPushMessage::setPrivateObject(JSContextRef context, JSObjectRef object, PushMessage *priv) +{ + if (!priv) { + throw TypeMismatchException("PushMessage's private object is NULL."); + } + + JSObjectSetPrivate(object, static_cast<void*>(priv)); + + // appData + JSUtil::setProperty(context, object, PUSH_MESSAGE_APP_DATA, + JSUtil::toJSValueRef(context, priv->getAppData()), kJSPropertyAttributeNone); + + // alertMessage + JSUtil::setProperty(context, object, PUSH_MESSAGE_ALERT_MESSAGE, + JSUtil::toJSValueRef(context, priv->getAlertMessage()), kJSPropertyAttributeNone); + + // date + JSUtil::setProperty(context, object, PUSH_MESSAGE_DATE, + JSUtil::makeDateObject(context, priv->getDate()), kJSPropertyAttributeNone); +} + + +} // Push +} // DeviceAPI diff --git a/mobile_src/Push/JSPushMessage.h b/mobile_src/Push/JSPushMessage.h new file mode 100644 index 0000000..0850a94 --- /dev/null +++ b/mobile_src/Push/JSPushMessage.h @@ -0,0 +1,71 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 __TIZEN_JS_PUSH_MESSAGE_H__ +#define __TIZEN_JS_PUSH_MESSAGE_H__ + +#include <JavaScriptCore/JavaScript.h> + +#include "PushMessage.h" + +namespace DeviceAPI { +namespace Push { + +class JSPushMessage +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); + + static PushMessage* getPrivateObject(JSContextRef context, JSObjectRef object); + static void setPrivateObject(JSContextRef context, JSObjectRef object, PushMessage *priv); +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + + /** + * This member variable contains the initialization values for the + * properties of this class. The values are given according to + * the data structure JSPropertySpec + */ + static JSStaticValue m_property[]; + + static JSClassRef m_jsClassRef; +}; + + + +} // Push +} // DeviceAPI + +#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__ diff --git a/mobile_src/Push/PushManager.cpp b/mobile_src/Push/PushManager.cpp new file mode 100755 index 0000000..7a200e6 --- /dev/null +++ b/mobile_src/Push/PushManager.cpp @@ -0,0 +1,505 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 <JSUtil.h> +#include <JSWebAPIErrorFactory.h> +#include <PlatformException.h> + +#include <app_manager.h> + +#include "JSPushMessage.h" +#include "PushMessage.h" +#include "PushManager.h" + +#include <Logger.h> +#include <TimeTracer.h> + +#ifdef ENABLE_TIME_TRACER +#define _P(T, x) \ + (TIME_TRACER_ITEM_BEGIN("PUSH_" #T "_PLATFORM", 0), x); \ + TIME_TRACER_ITEM_END("PUSH_" #T "_PLATFORM", 0); +#else +#define _P(T, x) x +#endif + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Push { + +std::string PushManager::m_appId; +std::string PushManager::m_pkgId; + +static std::string _get_internal_error(int err) +{ + bool success = false; + std::string msg = ""; + + switch (err) { + case PUSH_ERROR_INVALID_PARAMETER: + msg = "Invalid parameter"; + break; + case PUSH_ERROR_OUT_OF_MEMORY: + msg = "Out of memory"; + break; + case PUSH_ERROR_NOT_CONNECTED: + msg = "Network is unreachable"; + break; + case PUSH_ERROR_NO_DATA: + msg = "No data available"; + break; + case PUSH_ERROR_OPERATION_FAILED: + msg = "Internal operation failed"; + break; + case SERVICE_ERROR_APP_NOT_FOUND: + msg = "The application was not found"; + break; + case SERVICE_ERROR_KEY_NOT_FOUND: + msg = "Specified key not found"; + break; + case SERVICE_ERROR_KEY_REJECTED: + msg = "Not available key"; + break; + case SERVICE_ERROR_INVALID_DATA_TYPE: + msg = "Invalid data type"; + break; + case PUSH_ERROR_NONE: + success = true; + break; + + default: + msg = "Unknown error"; + } + + if (!success) { + LOGE("Platform error %d <%s>", err, msg.c_str()); + } + + return msg; +} + +static void get_param(const char *msg, const char *name, char **value) +{ + int step = 0; + int pos = 0; + int tokenpos = 0; + + while (step >= 0) { + switch (step) { + case 0: // key + switch (msg[pos]) { + case '=': + if (!strncmp(name, &msg[tokenpos], strlen(name))) { + step = 2; + tokenpos = pos + 1; + } else { + step = 1; + } + break; + case '&': + tokenpos = pos + 1; + step = 0; + break; + case 0: + step = -1; + tokenpos = pos; + break; + default: + break; + } + break; + case 1: // skip + switch (msg[pos]) { + case '&': + tokenpos = pos + 1; + step = 0; + break; + case 0: + step = -1; + tokenpos = pos; + break; + default: + break; + } + break; + case 2: // value + switch (msg[pos]) { + case '&': + case 0: + step = -1; + break; + default: + break; + } + break; + default: + break; + } + + pos++; + } + + *value = (char*)calloc(1, pos - tokenpos); + if (*value != NULL) { + strncpy(*value, &msg[tokenpos], pos - tokenpos - 1); + } +} + +static void push_connection_state_cb(push_state_e state, const char *err, void *user_data) +{ + LOGD("Push connection state cb with state: %d, err: %s", state, err); + + PushManager *thisPushManager = static_cast<PushManager*>(user_data); + if (!thisPushManager) { + LOGE("user_data of push_connection_state_cb() is NULL."); + } else { + thisPushManager->m_connectionState = state; + } +} + +static void push_notify_cb(push_notification_h noti, void *user_data) +{ + int ret; + char *appData = NULL; + char *rawMessage = NULL; + char *alertMessage = NULL; + long long int date = -1; + + LOGD("Push notification cb"); + + try { + PushManager *thisPushManager = static_cast<PushManager*>(user_data); + if (!thisPushManager) { + throw UnknownException("user_data of push_notify_cb() is NULL."); + } + + MultiCallbackUserDataPtr callback = thisPushManager->m_notificationCallback; + if (!callback) { + LOGW("notification callback is not set. ignored."); + return; + } + + ret = push_get_notification_data(noti, &appData); + if (ret != PUSH_ERROR_NONE) { + throw UnknownException(("Platform error while getting notification data. " + _get_internal_error(ret)).c_str()); + } + + ret = push_get_notification_message(noti, &rawMessage); + if (ret != PUSH_ERROR_NONE) { + throw UnknownException(("Platform error while getting notification message. " + _get_internal_error(ret)).c_str()); + } else { + get_param(rawMessage, "alertMessage", &alertMessage); + if (!alertMessage) { + throw UnknownException(("Platform error while getting alert message from raw message. " + _get_internal_error(ret)).c_str()); + } + free(rawMessage); + } + + ret = push_get_notification_time(noti, &date); + if (ret != PUSH_ERROR_NONE) { + LOGE("Platform error while getting notification date/time. %s", _get_internal_error(ret).c_str()); + } + + PushMessage *pushMessage = new PushMessage(); + if (appData) { + pushMessage->setAppData(appData); + free(appData); + } + if (alertMessage) { + pushMessage->setAlertMessage(alertMessage); + free(alertMessage); + } + if (date >= 0) { + pushMessage->setDate((time_t)date); + } + + JSObjectRef pushMessageObj = JSObjectMake(callback->getContext(), JSPushMessage::getClassRef(), NULL); + JSPushMessage::setPrivateObject(callback->getContext(), pushMessageObj, pushMessage); + + callback->invokeCallback("onsuccess", pushMessageObj); + } catch (const BasePlatformException &err) { + LOGE("%s", err.getMessage().c_str()); + } +} + +static void push_registration_result_cb(push_result_e result, const char *msg, void *user_data) +{ + int ret; + char *tmp = NULL; + + LOGD("Push registration cb"); + + try { + PushManager *thisPushManager = static_cast<PushManager*>(user_data); + if (!thisPushManager) { + throw UnknownException("user_data of push_registration_result_cb() is NULL."); + } + + MultiCallbackUserDataPtr callback = thisPushManager->m_registrationCallback; + if (!callback) { + throw UnknownException("the callback for registration is NULL."); + } + + if (result == PUSH_RESULT_SUCCESS) { + ret = push_get_registration_id(thisPushManager->m_connectionHandle, &tmp); + if (PUSH_ERROR_NONE != ret) { + throw UnknownException("Platform error while getting registration id."); + } + if (tmp) { + std::string registrationId(tmp); + callback->invokeCallback("onsuccess", JSUtil::toJSValueRef(callback->getContext(), registrationId)); + free(tmp); + } + } else { + UnknownException error(msg == NULL ? "Unknown" : msg); + JSObjectRef errorObj = JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), error); + callback->invokeCallback("onerror", errorObj); + } + } catch (const BasePlatformException &err) { + LOGE("%s", err.getMessage().c_str()); + } +} + +static void push_unregistration_result_cb(push_result_e result, const char *msg, void *user_data) +{ + LOGD("Push unregistration cb"); + + try { + PushManager *thisPushManager = static_cast<PushManager*>(user_data); + if (!thisPushManager) { + throw UnknownException("user_data of push_unregistration_result_cb() is NULL."); + } + + MultiCallbackUserDataPtr callback = thisPushManager->m_unregistrationCallback; + if (!callback) { + throw UnknownException("the callback for unregistration is NULL."); + } + + if (result == PUSH_RESULT_SUCCESS) { + callback->invokeCallback("onsuccess"); + } else { + UnknownException error(msg == NULL ? "Unknown" : msg); + JSObjectRef errorObj = JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), error); + callback->invokeCallback("onerror", errorObj); + } + } catch (const BasePlatformException &err) { + LOGE("%s", err.getMessage().c_str()); + } +} + +PushManager::PushManager(): + m_connectionState(PUSH_STATE_UNREGISTERED), + m_connectionHandle(NULL) +{ + LOGD("Connecting to the push service..."); + + setAppId(); + + int ret = push_connect(m_pkgId.c_str(), push_connection_state_cb, push_notify_cb, this, &m_connectionHandle); + if (PUSH_ERROR_NONE!=ret) { + LOGE("Error while connecting to the push service: %d", ret); + return; + } +} + +PushManager::~PushManager() +{ + LOGD("Disconnecting to the push service..."); + + push_disconnect(m_connectionHandle); +} + +PushManager *PushManager::getInstance() { + LOGD("Getting instance of PushManager..."); + static PushManager instance; + return &instance; +} + +void PushManager::setAppId() { + app_info_h handle; + char *_pkg_id = NULL; + char *app_id = NULL; + int pid = getpid(); + int ret = app_manager_get_app_id(pid, &app_id); + if (ret != APP_MANAGER_ERROR_NONE) { + LOGE("Fail to get appid"); + return; + } + + m_appId = app_id; + free(app_id); + + ret = app_manager_get_app_info(m_appId.c_str(), &handle); + if (ret != APP_MANAGER_ERROR_NONE) { + LOGE("WrtAccess initialization failed"); + return; + } + + ret = app_info_get_package(handle, &_pkg_id); + if ((ret != APP_MANAGER_ERROR_NONE) || (_pkg_id == NULL)) { + LOGW("Fail to get pkg id"); + } + + ret = app_info_destroy(handle); + if (ret != APP_MANAGER_ERROR_NONE) { + LOGE("WrtAccess initialization failed"); + return; + } + + if (_pkg_id) { + m_pkgId = _pkg_id; + free(_pkg_id); + } +} + +void PushManager::registerService(ApplicationControlPtr appControl, MultiCallbackUserDataPtr callback) +{ + int ret; + service_h service; + + ret = _P(registerService, service_create(&service)); + if (ret != SERVICE_ERROR_NONE) { + throw UnknownException(("Platform error while creating service. " + _get_internal_error(ret)).c_str()); + } + + if (appControl->getOperation().compare("") != 0) { + ret = _P(registerService, service_set_operation(service, appControl->getOperation().c_str())); + if (ret != SERVICE_ERROR_NONE) { + throw UnknownException(("Platform error while setting operation to appControl. " + _get_internal_error(ret)).c_str()); + } + } else { + throw InvalidValuesException("the operation of application control is invalid."); + } + + if (appControl->getUri().compare("") != 0) { + ret = _P(registerService, service_set_uri(service, appControl->getUri().c_str())); + if (ret != SERVICE_ERROR_NONE) { + LOGW("Platform error while setting uri to appControl. %s", _get_internal_error(ret).c_str()); + } + } + + if (appControl->getMime().compare("") != 0) { + ret = _P(registerService, service_set_mime(service, appControl->getMime().c_str())); + if (ret != SERVICE_ERROR_NONE) { + LOGW("Platform error while setting mime to appControl. %s", _get_internal_error(ret).c_str()); + } + } + + ret = _P(registerService, service_set_app_id(service, m_appId.c_str())); + if (ret != SERVICE_ERROR_NONE) { + throw UnknownException(("Platform error while setting appId to appControl. " + _get_internal_error(ret)).c_str()); + } + + std::vector<ApplicationControlDataPtr> controlDataArray = appControl->getAppControlDataArray(); + if (!controlDataArray.empty()) { + std::string key; + const char **arr = NULL; + + for (size_t i = 0; i < controlDataArray.size(); i++) { + key = controlDataArray.at(i)->getKey(); + if (key.empty()) { + LOGW("Invalid key for %d in ApplicationControl's data array.", i); + } else { + std::vector<std::string> valueArray = controlDataArray.at(i)->getValue(); + size_t size = valueArray.size(); + + arr = (const char**)calloc(sizeof(char*), size); + if (arr == NULL) { + throw UnknownException("Out of Memory: Can't allocate value array for ApplicationControl's data"); + } + + for (size_t j = 0; j < size; j++) { + arr[j] = valueArray.at(j).c_str(); + } + + if (size == 1) { + ret = _P(registerService, service_add_extra_data(service, (const char*)key.c_str(), arr[0])); + if (ret != SERVICE_ERROR_NONE) { + LOGW("Platform error while adding extra data to appControl. %s", _get_internal_error(ret).c_str()); + } + } else { + ret = _P(registerService, service_add_extra_data_array(service, (const char*)key.c_str(), arr, size)); + if (ret != SERVICE_ERROR_NONE) { + LOGW("Platform error while adding extra data array to appControl. %s", _get_internal_error(ret).c_str()); + } + } + + if (arr) { + free(arr); + } + } + } + } + + m_registrationCallback = callback; + + ret = _P(registerService, push_register(m_connectionHandle, service, push_registration_result_cb, this)); + if (ret != PUSH_ERROR_NONE) { + _P(registerService, service_destroy(service)); + throw UnknownException(("Platform error while registering the application to the push service. " + _get_internal_error(ret)).c_str()); + } + + _P(registerService, service_destroy(service)); +} + +void PushManager::unregisterService(MultiCallbackUserDataPtr callback) +{ + int ret; + + m_unregistrationCallback = callback; + + ret = _P(unregisterService, push_deregister(m_connectionHandle, push_unregistration_result_cb, this)); + if (ret != PUSH_ERROR_NONE) { + throw UnknownException(("Platform error while unregistering the application from the push service. " + _get_internal_error(ret)).c_str()); + } +} + +void PushManager::connectService(MultiCallbackUserDataPtr notificationCallback) +{ + if (notificationCallback) { + m_notificationCallback = notificationCallback; + } else { + throw UnknownException("notificationCallback of arguments is NULL."); + } +} + +void PushManager::disconnectService() +{ + m_notificationCallback.reset(); +} + +std::string PushManager::getRegistrationId() +{ + int ret; + char *regId = NULL; + std::string str = ""; + + ret = _P(getRegistrationId, push_get_registration_id(m_connectionHandle, ®Id)); + if (ret != PUSH_ERROR_NONE) { + LOGW("Platform error while getting registration id. %s", _get_internal_error(ret).c_str()); + } else { + if (regId) { + str = regId; + free(regId); + } + } + + return str; +} + +} // Push +} // DeviceAPI diff --git a/mobile_src/Push/PushManager.h b/mobile_src/Push/PushManager.h new file mode 100755 index 0000000..9dcfbab --- /dev/null +++ b/mobile_src/Push/PushManager.h @@ -0,0 +1,66 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 __TIZEN_PUSH_MANAGER_H__ +#define __TIZEN_PUSH_MANAGER_H__ + +#include <MultiCallbackUserData.h> + +#include <JSApplicationControl.h> + +#include <push.h> + +#include "PushTypes.h" + +using namespace DeviceAPI::Common; +using namespace DeviceAPI::Application; + +namespace DeviceAPI { +namespace Push { + +class PushManager +{ +public: + void registerService(ApplicationControlPtr appControl, MultiCallbackUserDataPtr callback); + void unregisterService(MultiCallbackUserDataPtr callback); + void connectService(MultiCallbackUserDataPtr notificationCallback); + void disconnectService(); + std::string getRegistrationId(); + + static PushManager* getInstance(); + void setAppId(); + +private: + PushManager(); + virtual ~PushManager(); + +public: + push_state_e m_connectionState; + push_connection_h m_connectionHandle; + MultiCallbackUserDataPtr m_registrationCallback; + MultiCallbackUserDataPtr m_unregistrationCallback; + MultiCallbackUserDataPtr m_notificationCallback; + +private: + static std::string m_appId; + static std::string m_pkgId; +}; + +} // Push +} // DeviceAPI + +#endif // __TIZEN_PUSH_MANAGER_H__ diff --git a/mobile_src/Push/PushMessage.cpp b/mobile_src/Push/PushMessage.cpp new file mode 100644 index 0000000..356f6f6 --- /dev/null +++ b/mobile_src/Push/PushMessage.cpp @@ -0,0 +1,68 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 <PlatformException.h> +#include <Logger.h> + +#include "PushMessage.h" + +namespace DeviceAPI { +namespace Push { + +PushMessage::PushMessage(): + m_appData(""), + m_alertMessage("") +{ +} + +PushMessage::~PushMessage() +{ +} + +std::string PushMessage::getAppData() const +{ + return m_appData; +} + +void PushMessage::setAppData(std::string appData) +{ + m_appData = appData; +} + +std::string PushMessage::getAlertMessage() const +{ + return m_alertMessage; +} + +void PushMessage::setAlertMessage(std::string alertMessage) +{ + m_alertMessage = alertMessage; +} + +time_t PushMessage::getDate() const +{ + return m_date; +} + +void PushMessage::setDate(time_t date) +{ + m_date = date; +} + + +} // Push +} // DeviceAPI diff --git a/mobile_src/Push/PushMessage.h b/mobile_src/Push/PushMessage.h new file mode 100644 index 0000000..2e6b233 --- /dev/null +++ b/mobile_src/Push/PushMessage.h @@ -0,0 +1,54 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 __TIZEN_PUSH_MESSAGE_H__ +#define __TIZEN_PUSH_MESSAGE_H__ + +#include <MultiCallbackUserData.h> + +#include "PushTypes.h" + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Push { + +class PushMessage +{ +public: + PushMessage(); + virtual ~PushMessage(); + + std::string getAppData() const; + void setAppData(std::string appData); + + std::string getAlertMessage() const; + void setAlertMessage(std::string alertMessage); + + time_t getDate() const; + void setDate(time_t date); + +private: + std::string m_appData; + std::string m_alertMessage; + time_t m_date; +}; + +} // Push +} // DeviceAPI + +#endif // __TIZEN_PUSH_MESSAGE_H__
\ No newline at end of file diff --git a/mobile_src/Push/PushTypes.h b/mobile_src/Push/PushTypes.h new file mode 100644 index 0000000..2048323 --- /dev/null +++ b/mobile_src/Push/PushTypes.h @@ -0,0 +1,34 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 _PUSH_TYPES_H_ +#define _PUSH_TYPES_H_ + +#include <string> +#include <vector> +#include <map> + +namespace DeviceAPI { +namespace Push { + +// typedef PushRegistrationId +typedef std::string PushRegistrationId; + +} // Push +} // DeviceAPI + +#endif // _PUSH_TYPES_H_ diff --git a/mobile_src/Push/config.xml b/mobile_src/Push/config.xml new file mode 100644 index 0000000..f50c830 --- /dev/null +++ b/mobile_src/Push/config.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" ?> +<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd"> +<plugin-properties> + <library-name>libwrt-plugins-tizen-push.so</library-name> + <feature-install-uri>push.install.uri</feature-install-uri> + + <api-feature> + <name>http://tizen.org/privilege/push</name> + <device-capability>push</device-capability> + </api-feature> + +</plugin-properties> diff --git a/mobile_src/Push/plugin_config.cpp b/mobile_src/Push/plugin_config.cpp new file mode 100644 index 0000000..1c3c0cd --- /dev/null +++ b/mobile_src/Push/plugin_config.cpp @@ -0,0 +1,126 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 <Commons/FunctionDefinition.h> +#include <Commons/FunctionDeclaration.h> +#include <Commons/Exception.h> +#include <map> + +#include "plugin_config.h" + +#define PUSH_FEATURE_API "http://tizen.org/privilege/push" + +#define PUSH_DEVICE_CAP "push" + +using namespace WrtDeviceApis::Commons; + +namespace DeviceAPI { +namespace Push { + +static FunctionMapping createPushFunctions(); +static FunctionMapping PushFunctions = createPushFunctions(); + +#pragma GCC visibility push(default) + +DEFINE_FUNCTION_GETTER(Push, PushFunctions); + +#pragma GCC visibility pop + +static FunctionMapping createPushFunctions() +{ + /** + * Device capabilities + */ + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_PUSH, PUSH_DEVICE_CAP); + + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_PUSH); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_PUSH, DEVICE_CAP_PUSH); + + /** + * Api Features + */ + ACE_CREATE_FEATURE(FEATURE_PUSH, PUSH_FEATURE_API); + + ACE_CREATE_FEATURE_LIST(PUSH_FEATURES); + ACE_ADD_API_FEATURE(PUSH_FEATURES, FEATURE_PUSH); + + /** + * Functions + */ + FunctionMapping pushMapping; + + // registerService + AceFunction registerServiceFunc = ACE_CREATE_FUNCTION( + FUNCTION_REGISTER_SERVICE, + PUSH_MANAGER_API_REGISTER_SERVICE, + PUSH_FEATURES, + DEVICE_LIST_PUSH); + + pushMapping.insert(std::make_pair( + PUSH_MANAGER_API_REGISTER_SERVICE, + registerServiceFunc)); + + // unregisterService + AceFunction unregisterServiceFunc = ACE_CREATE_FUNCTION( + FUNCTION_UNREGISTER_SERVICE, + PUSH_MANAGER_API_UNREGISTER_SERVICE, + PUSH_FEATURES, + DEVICE_LIST_PUSH); + + pushMapping.insert(std::make_pair( + PUSH_MANAGER_API_UNREGISTER_SERVICE, + unregisterServiceFunc)); + + // connectService + AceFunction connectServiceFunc = ACE_CREATE_FUNCTION( + FUNCTION_CONNECT_SERVICE, + PUSH_MANAGER_API_CONNECT_SERVICE, + PUSH_FEATURES, + DEVICE_LIST_PUSH); + + pushMapping.insert(std::make_pair( + PUSH_MANAGER_API_CONNECT_SERVICE, + connectServiceFunc)); + + // disconnectService + AceFunction disconnectServiceFunc = ACE_CREATE_FUNCTION( + FUNCTION_DISCONNECT_SERVICE, + PUSH_MANAGER_API_DISCONNECT_SERVICE, + PUSH_FEATURES, + DEVICE_LIST_PUSH); + + pushMapping.insert(std::make_pair( + PUSH_MANAGER_API_DISCONNECT_SERVICE, + disconnectServiceFunc)); + + // getRegistrationId + AceFunction getRegistrationIdFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_REGISTRATION_ID, + PUSH_MANAGER_API_GET_REGISTRATION_ID, + PUSH_FEATURES, + DEVICE_LIST_PUSH); + + pushMapping.insert(std::make_pair( + PUSH_MANAGER_API_GET_REGISTRATION_ID, + getRegistrationIdFunc)); + + return pushMapping; +} + +} // Push +} // DeviceAPI diff --git a/mobile_src/Push/plugin_config.h b/mobile_src/Push/plugin_config.h new file mode 100644 index 0000000..21af37a --- /dev/null +++ b/mobile_src/Push/plugin_config.h @@ -0,0 +1,52 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 _PUSH_PLUGIN_CONFIG_H_ +#define _PUSH_PLUGIN_CONFIG_H_ + +#include <string> +#include <Commons/FunctionDeclaration.h> + +#include <Logger.h> + +namespace DeviceAPI { +namespace Push { + +// attributes +#define PUSH_MESSAGE_APP_DATA "appData" +#define PUSH_MESSAGE_ALERT_MESSAGE "alertMessage" +#define PUSH_MESSAGE_DATE "date" + +// functions +#define PUSH_MANAGER_API_REGISTER_SERVICE "registerService" +#define PUSH_MANAGER_API_UNREGISTER_SERVICE "unregisterService" +#define PUSH_MANAGER_API_CONNECT_SERVICE "connectService" +#define PUSH_MANAGER_API_DISCONNECT_SERVICE "disconnectService" +#define PUSH_MANAGER_API_GET_REGISTRATION_ID "getRegistrationId" + +DECLARE_FUNCTION_GETTER(Push); + +#define PUSH_CHECK_ACCESS(functionName) \ + aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \ + getPushFunctionData, \ + functionName) + +} +} + +#endif // _PUSH_PLUGIN_CONFIG_H_
\ No newline at end of file diff --git a/mobile_src/Push/plugin_initializer.cpp b/mobile_src/Push/plugin_initializer.cpp new file mode 100755 index 0000000..075cd09 --- /dev/null +++ b/mobile_src/Push/plugin_initializer.cpp @@ -0,0 +1,86 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 <dpl/string.h> + +#include <Commons/plugin_initializer_def.h> +#include <Commons/WrtAccess/WrtAccess.h> + +#include <GlobalContextManager.h> + +#include "JSPushManager.h" +#include "PushManager.h" + +#include <TimeTracer.h> +#include <Logger.h> + +using namespace WrtDeviceApis; +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Push { + +void on_widget_start_callback(int widgetId) +{ + LOGD("[Tizen\\Push] on_widget_start_callback (%d)", widgetId); + TIME_TRACER_INIT(); + try { + WrtAccessSingleton::Instance().initialize(widgetId); + } catch (...) { + LOGE("WrtAccess initialization failed"); + } +} + +void on_widget_stop_callback(int widgetId) +{ + LOGD("[Tizen\\Push] on_widget_stop_callback (%d)", widgetId); + TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"Push"); + TIME_TRACER_RELEASE(); + try { + WrtAccessSingleton::Instance().deinitialize(widgetId); + } catch (...) { + LOGE("WrtAccess deinitialization failed"); + } +} + +void on_frame_load_callback(const void * context) +{ + LOGD("[Tizen\\Push] on_frame_load_callback (%p)", context); + GlobalContextManager::getInstance()->addGlobalContext(static_cast<JSContextRef>(context)); +} + +void on_frame_unload_callback(const void * context) +{ + LOGD("[Tizen\\Push] on_frame_unload_callback (%p)", context); + GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(context)); +} + +PLUGIN_ON_WIDGET_START(on_widget_start_callback) +PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback) +PLUGIN_ON_FRAME_LOAD(on_frame_load_callback) +PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback) + +PLUGIN_CLASS_MAP_BEGIN +PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "push", + (js_class_template_getter)JSPushManager::getClassRef, + NULL) +PLUGIN_CLASS_MAP_END + +} // Push +} // DeviceAPI |