From: pius.lee Date: Tue, 27 Jan 2015 13:23:27 +0000 (+0900) Subject: [Notification] initiailize notification implementation from skeleton generator. X-Git-Tag: submit/tizen_mobile/20150603.064609~1^2~560 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=361c9387d8c34e0680858e0bf98913d76ea70594;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Notification] initiailize notification implementation from skeleton generator. [Verification] build test and check on custom web app. Change-Id: I03e60b2feca4823f9ddeac3649874f42b2c8f913 Signed-off-by: pius.lee --- diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 38aabca..a2cece6 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -41,7 +41,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_nbs_support 0 %define tizen_feature_nfc_emulation_support 0 %define tizen_feature_nfc_support 1 -%define tizen_feature_notification_support 0 +%define tizen_feature_notification_support 1 %define tizen_feature_power_support 1 %define tizen_feature_push_support 0 %define tizen_feature_sap_support 0 @@ -248,6 +248,11 @@ BuildRequires: pkgconfig(smartcard-service) BuildRequires: pkgconfig(smartcard-service-common) %endif +%if 0%{?tizen_feature_notification_support} +BuildRequires: pkgconfig(notification) +%endif + + %description Tizen Web APIs implemented. diff --git a/src/notification/notification.gyp b/src/notification/notification.gyp new file mode 100755 index 0000000..02c4989 --- /dev/null +++ b/src/notification/notification.gyp @@ -0,0 +1,29 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_notification', + 'type': 'loadable_module', + 'sources': [ + 'notification_api.js', + 'notification_extension.cc', + 'notification_extension.h', + 'notification_instance.cc', + 'notification_instance.h' + ], + 'conditions': [ + ['tizen == 1', { + 'variables': { + 'packages': [ + 'capi-system-device', + 'notification', + 'vconf', + ] + }, + }], + ], + }, + ], +} diff --git a/src/notification/notification_api.js b/src/notification/notification_api.js new file mode 100644 index 0000000..031c72c --- /dev/null +++ b/src/notification/notification_api.js @@ -0,0 +1,277 @@ +/* global tizen, xwalk, extension */ + +// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +var validator_ = xwalk.utils.validator; +var types_ = validator_.Types; + + +function SetReadOnlyProperty(obj, n, v) { + Object.defineProperty(obj, n, {'value': v, 'writable': false}); +} + +var NotificationType = { + 'STATUS': 'STATUS' +}; +var StatusNotificationType = { + 'SIMPLE': 'SIMPLE', + 'THUMBNAIL': 'THUMBNAIL', + 'ONGOING': 'ONGOING', + 'PROGRESS': 'PROGRESS' +}; +var NotificationProgressType = { + 'PERCENTAGE': 'PERCENTAGE', + 'BYTE': 'BYTE' +}; + + +function NotificationManager() { + // constructor of NotificationManager + +} + + +NotificationManager.prototype.post = function(notification) { + var args = validator_.validateArgs(arguments, [ + {'name': 'notification', 'type': types_.PLATFORM_OBJECT, 'values': ['Notification']} + ]); + + var nativeParam = notificationToNativeParam(notification); + + var id = notification.id; + var type = notification.type; + var ptime = notification.postedTime; + var title = notification.title; + var content = notification.content; + + var nativeParam = { + 'type': notification.type, + 'title' : notification.title, + 'content' : notification.content + }; + + + try { + var syncResult = callNative('NotificationManager_post', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch (e) { + throw e; + } + +}; + +NotificationManager.prototype.update = function(notification) { + var args = validator_.validateArgs(arguments, [ + {'name': 'notification', 'type': types_.PLATFORM_OBJECT, 'values': ['Notification']} + ]); + + var nativeParam = { + }; + + + try { + var syncResult = callNative('NotificationManager_update', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch (e) { + throw e; + } + +}; + +NotificationManager.prototype.remove = function(id) { + var args = validator_.validateArgs(arguments, [ + {'name': 'id', 'type': types_.STRING} + ]); + + var nativeParam = { + 'id': args.id + }; + + + try { + var syncResult = callNative('NotificationManager_remove', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch (e) { + throw e; + } + +}; + +NotificationManager.prototype.removeAll = function() { + + var nativeParam = { + }; + + + try { + var syncResult = callNative('NotificationManager_removeAll', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch (e) { + throw e; + } + +}; + +NotificationManager.prototype.get = function(id) { + var args = validator_.validateArgs(arguments, [ + {'name': 'id', 'type': types_.STRING} + ]); + + var nativeParam = { + 'id': args.id + }; + + + try { + var syncResult = callNative('NotificationManager_get', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch (e) { + throw e; + } + + var returnObject = new Notification(); + return returnObject; +}; + +NotificationManager.prototype.getAll = function() { + + var nativeParam = { + }; + + + try { + var syncResult = callNative('NotificationManager_getAll', nativeParam); + // if you need synchronous result from native function using 'syncResult'. + } catch (e) { + throw e; + } + + var returnObject = new Notification(); + return returnObject; +}; + + + +function Notification() { + // constructor of Notification + + SetReadOnlyProperty(this, 'id', null); // read only property + SetReadOnlyProperty(this, 'type', null); // read only property + SetReadOnlyProperty(this, 'postedTime', null); // read only property + this.title = null; + this.content = null; +} + + +function notificationToNativeParam(n) { + var i; + + var detailInfo = []; + if (n.detailInfo) { + for (i in n.detailInfo) { + detailInfo[i] = n.detailInfo[i]; + } + } + var thumbnails = []; + if (n.thumbnails) { + for (i in n.thumbnails) { + thumbnails[i] = n.thumbnails[i]; + } + } + + var appControl = {}; + if (n.appControl) { + appControl.operation = n.appControl.operation; + appControl.uri = n.appControl.uri; + appControl.mime = n.appControl.mime; + appControl.category = n.appControl.category; + appControl.data = []; + if (n.appControl.data) { + for (i in n.appControl.data) { + var values = n.appControl.data[i].value; + var key = n.appControl.data[i].key; + appControl.data[i] = { + 'key': key, + 'value': values + }; + } + } + } + + return { + 'statusType': args.statusType, + 'title': args.title, + 'content': n.content, + 'iconPath': n.iconPath, + 'soundPath': n.soundPath, + 'vibration': n.vibration, + 'appControl': appControl, + 'appId': n.appId, + 'progressType': n.progressType, + 'progressValue': n.progressValue, + 'number': n.number, + 'subIconPath': n.subIconPath, + 'detailInfo': detailInfo, + 'ledColor': n.ledColor, + 'ledOnPeriod': n.ledOnPeriod, + 'ledOffPeriod': n.ledOffPeriod, + 'backgroundImagePath': n.backgroundImagePath, + 'thumbnails': thumbnails + }; +} + + +// private constructor +function StatusNotification(statusType, title, notificationInitDict) { + // constructor of StatusNotification + + SetHidedProperty(this, 'id', undefined); + SetReadOnlyProperty(this, 'type', 'STATUS'); + SetHidedProperty(this, 'postedTime', undefined); + + this.title = title; + this.content = notificationInitDict.content; + SetReadOnlyProperty(this, 'statusType', statusType); // read only property + this.iconPath = notificationInitDict.iconPath; + this.subIconPath = notificationInitDict.subIconPath; + this.number = notificationInitDict.number; + this.detailInfo = notificationInitDict.detailInfo; + this.ledColor = notificationInitDict.ledColor; + this.ledOnPeriod = notificationInitDict.ledOnPeriod; + this.ledOffPeriod = notificationInitDict.ledOffPeriod; + this.backgroundImagePath = notificationInitDict.backgroundImagePath; + this.thumbnails = notificationInitDict.thumbnails; + this.soundPath = notificationInitDict.soundPath; + this.vibration = notificationInitDict.vibration; + this.appControl = notificationInitDict.appControl; + this.appId = notificationInitDict.appId; + this.progressType = notificationInitDict.progressType; + this.progressValue = notificationInitDict.progressValue; +} + +StatusNotification.prototype = new Notification(); +StatusNotification.prototype.constructor = StatusNotification; + + + +function NotificationDetailInfo(mainText, subText) { + // constructor of NotificationDetailInfo + var nativeParam = { + 'mainText': args.mainText, + 'subText': args.subText + }; + var syncResult = callNative('NotificationDetailInfo_constructor', nativeParam); + + this.mainText = mainText; + this.subText = subText; +} + + + + +exports = new NotificationManager(); +tizen.StatusNotification = StatusNotification; + diff --git a/src/notification/notification_extension.cc b/src/notification/notification_extension.cc new file mode 100644 index 0000000..d5c6512 --- /dev/null +++ b/src/notification/notification_extension.cc @@ -0,0 +1,32 @@ +// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "notification/notification_extension.h" + +#include "notification/notification_instance.h" + +// This will be generated from notification_api.js +extern const char kSource_notification_api[]; + +common::Extension* CreateExtension() { + return new NotificationExtension; +} + +NotificationExtension::NotificationExtension() { + SetExtensionName("tizen.notification"); + SetJavaScriptAPI(kSource_notification_api); + + const char* entry_points[] = { + "tizen.NotificationManager", + "tizen.StatusNotification", + NULL + }; + SetExtraJSEntryPoints(entry_points); +} + +NotificationExtension::~NotificationExtension() {} + +common::Instance* NotificationExtension::CreateInstance() { + return new extension::notification::NotificationInstance; +} diff --git a/src/notification/notification_extension.h b/src/notification/notification_extension.h new file mode 100644 index 0000000..65bcb5a --- /dev/null +++ b/src/notification/notification_extension.h @@ -0,0 +1,19 @@ +// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NOTIFICATION_NOTIFICATION_EXTENSION_H_ +#define NOTIFICATION_NOTIFICATION_EXTENSION_H_ + +#include "common/extension.h" + +class NotificationExtension : public common::Extension { + public: + NotificationExtension(); + virtual ~NotificationExtension(); + + private: + virtual common::Instance* CreateInstance(); +}; + +#endif // NOTIFICATION_NOTIFICATION_EXTENSION_H_ diff --git a/src/notification/notification_instance.cc b/src/notification/notification_instance.cc new file mode 100644 index 0000000..c18ee8e --- /dev/null +++ b/src/notification/notification_instance.cc @@ -0,0 +1,91 @@ +// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "notification/notification_instance.h" + +#include + +#include +#include + +#include "common/picojson.h" +#include "common/logger.h" +#include "common/platform_exception.h" +#include "common/typeutil.h" + +namespace extension { +namespace notification { + +namespace { +// The privileges that required in Notification API +const std::string kPrivilegeNotification = ""; + +} // namespace + +using common::TypeMismatchException; + +NotificationInstance::NotificationInstance() { + using std::placeholders::_1; + using std::placeholders::_2; + #define REGISTER_SYNC(c, x) \ + RegisterSyncHandler(c, std::bind(&NotificationInstance::x, this, _1, _2)); + REGISTER_SYNC("NotificationManager_get", NotificationManagerGet); + REGISTER_SYNC("NotificationManager_update", NotificationManagerUpdate); + REGISTER_SYNC("NotificationManager_remove", NotificationManagerRemove); + REGISTER_SYNC("NotificationManager_getAll", NotificationManagerGetall); + REGISTER_SYNC("NotificationManager_post", NotificationManagerPost); + REGISTER_SYNC("NotificationManager_removeAll", NotificationManagerRemoveall); + #undef REGISTER_SYNC +} + +NotificationInstance::~NotificationInstance() { +} + + + +#define CHECK_EXIST(args, name, out) \ + if (!args.contains(name)) {\ + ReportError(TypeMismatchException(name" is required argument"), out);\ + return;\ + } + +using common::WIDLTypeValidator::WIDLType; +using common::WIDLTypeValidator::IsType; + +void NotificationInstance::NotificationManagerPost( + const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "id", out) + CHECK_EXIST(args, "type", out) + CHECK_EXIST(args, "title", out) + + bool check; + check = IsType(args, "id"); + check = IsType(args, "type"); + check = IsType(args, "title"); + + notification_type_e noti_type = NOTIFICATION_TYPE_NOTI; + + notification_h noti = notification_create(noti_type); +} +void NotificationInstance::NotificationManagerUpdate( + const picojson::value& args, picojson::object& out) { +} +void NotificationInstance::NotificationManagerRemove( + const picojson::value& args, picojson::object& out) { +} +void NotificationInstance::NotificationManagerRemoveall( + const picojson::value& args, picojson::object& out) { +} +void NotificationInstance::NotificationManagerGet( + const picojson::value& args, picojson::object& out) { +} +void NotificationInstance::NotificationManagerGetall( + const picojson::value& args, picojson::object& out) { +} + + +#undef CHECK_EXIST + +} // namespace notification +} // namespace extension diff --git a/src/notification/notification_instance.h b/src/notification/notification_instance.h new file mode 100644 index 0000000..5df9fb2 --- /dev/null +++ b/src/notification/notification_instance.h @@ -0,0 +1,36 @@ +// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NOTIFICATION_NOTIFICATION_INSTANCE_H_ +#define NOTIFICATION_NOTIFICATION_INSTANCE_H_ + +#include "common/extension.h" + +namespace extension { +namespace notification { + +class NotificationInstance : public common::ParsedInstance { + public: + NotificationInstance(); + virtual ~NotificationInstance(); + + private: + void NotificationManagerGet( + const picojson::value& args, picojson::object& out); + void NotificationManagerUpdate( + const picojson::value& args, picojson::object& out); + void NotificationManagerRemove( + const picojson::value& args, picojson::object& out); + void NotificationManagerGetall( + const picojson::value& args, picojson::object& out); + void NotificationManagerPost( + const picojson::value& args, picojson::object& out); + void NotificationManagerRemoveall( + const picojson::value& args, picojson::object& out); +}; + +} // namespace notification +} // namespace extension + +#endif // NOTIFICATION_NOTIFICATION_INSTANCE_H_ diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 36bd4e4..884989c 100644 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -36,6 +36,7 @@ 'systeminfo/systeminfo.gyp:*', #'radio/radio.gyp:*', 'secureelement/secureelement.gyp:*', + 'notification/notification.gyp:*', ], }, ], # end mobile