From: pius.lee Date: Wed, 28 Jan 2015 13:14:50 +0000 (+0900) Subject: [Notification] Implement very first post api only with title, content text X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~547 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6e6f694fcfcc45fb1663f0cc7cb4738e01d86e3;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Notification] Implement very first post api only with title, content text [Verification] Test with custom web app. Change-Id: Ifd5a9c958fe0493bdb770b1df3d927c13bdeeae4 Signed-off-by: pius.lee --- diff --git a/src/notification/notification_api.js b/src/notification/notification_api.js index 031c72c2..a0c04914 100644 --- a/src/notification/notification_api.js +++ b/src/notification/notification_api.js @@ -9,6 +9,30 @@ var validator_ = xwalk.utils.validator; var types_ = validator_.Types; +function callNative(cmd, args) { + var json = {'cmd': cmd, 'args': args}; + var argjson = JSON.stringify(json); + var resultString = extension.internal.sendSyncMessage(argjson); + var result = JSON.parse(resultString); + + if (typeof result !== 'object') { + throw new tizen.WebAPIException(tizen.WebAPIException.UNKNOWN_ERR); + } + + if (result['status'] == 'success') { + if (result['result']) { + return result['result']; + } + return true; + } else if (result['status'] == 'error') { + var err = result['error']; + if (err) { + throw new tizen.WebAPIException(err.name, err.message); + } + return false; + } +} + function SetReadOnlyProperty(obj, n, v) { Object.defineProperty(obj, n, {'value': v, 'writable': false}); } @@ -36,23 +60,12 @@ function NotificationManager() { NotificationManager.prototype.post = function(notification) { var args = validator_.validateArgs(arguments, [ - {'name': 'notification', 'type': types_.PLATFORM_OBJECT, 'values': ['Notification']} + {'name': 'notification', 'type': types_.PLATFORM_OBJECT, 'values': [StatusNotification]} ]); 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 - }; - + nativeParam['type'] = notification.type; + nativeParam['content'] = notification.content; try { var syncResult = callNative('NotificationManager_post', nativeParam); @@ -202,8 +215,8 @@ function notificationToNativeParam(n) { } return { - 'statusType': args.statusType, - 'title': args.title, + 'statusType': n.statusType, + 'title': n.title, 'content': n.content, 'iconPath': n.iconPath, 'soundPath': n.soundPath, @@ -228,9 +241,9 @@ function notificationToNativeParam(n) { function StatusNotification(statusType, title, notificationInitDict) { // constructor of StatusNotification - SetHidedProperty(this, 'id', undefined); + SetReadOnlyProperty(this, 'id', undefined); SetReadOnlyProperty(this, 'type', 'STATUS'); - SetHidedProperty(this, 'postedTime', undefined); + SetReadOnlyProperty(this, 'postedTime', undefined); this.title = title; this.content = notificationInitDict.content; diff --git a/src/notification/notification_instance.cc b/src/notification/notification_instance.cc index c18ee8eb..243a1d1b 100644 --- a/src/notification/notification_instance.cc +++ b/src/notification/notification_instance.cc @@ -2,17 +2,17 @@ // 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 "notification/notification_instance.h" #include "common/picojson.h" #include "common/logger.h" #include "common/platform_exception.h" #include "common/typeutil.h" +#include "common/scope_exit.h" namespace extension { namespace notification { @@ -23,7 +23,10 @@ const std::string kPrivilegeNotification = ""; } // namespace +using common::UnknownException; using common::TypeMismatchException; +using common::ScopeExit; +using common::operator+; NotificationInstance::NotificationInstance() { using std::placeholders::_1; @@ -42,31 +45,66 @@ NotificationInstance::NotificationInstance() { 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; +#define WIDL_TYPE_CHECK(args, name, wtype, out) \ + do { if (!IsType(args, name)) {\ + ReportError(TypeMismatchException(name" is not valid type."), out);\ + }} while (0) + 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"); + WIDL_TYPE_CHECK(args, "type", WIDLType::StringType, out); + WIDL_TYPE_CHECK(args, "title", WIDLType::StringType, out); + int err; notification_type_e noti_type = NOTIFICATION_TYPE_NOTI; - notification_h noti = notification_create(noti_type); + SCOPE_EXIT { + notification_free(noti); + }; + + /* + if (IsType(args, "iconPath")) { + err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, + args.get("iconPath").get().c_str()); + if (err != NOTIFICATION_ERROR_NONE) { + LoggerE("Fail to set icon path. [%s]", get_error_message(err)); + return; + } + LoggerD("iconPath : %s", args.get("iconPath").get().c_str()); + } + */ + + const std::string& title = args.get("title").get(); + err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, + title.c_str(), + NULL, + NOTIFICATION_VARIABLE_TYPE_NONE); + if (err != NOTIFICATION_ERROR_NONE) { + LoggerE("Fail to set title. [%s]", get_error_message(err)); + return; + } + + if (IsType(args, "content")) { + const std::string& content = args.get("content").get(); + err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, + content.c_str(), + NULL, + NOTIFICATION_VARIABLE_TYPE_NONE); + + if (err != NOTIFICATION_ERROR_NONE) { + LoggerE("Fail to set content. [%s]", get_error_message(err)); + return; + } + } + + err = notification_post(noti); + if (err != NOTIFICATION_ERROR_NONE) { + ReportError(UnknownException("failed to post notification"), out); + } } void NotificationInstance::NotificationManagerUpdate( const picojson::value& args, picojson::object& out) { @@ -85,7 +123,7 @@ void NotificationInstance::NotificationManagerGetall( } -#undef CHECK_EXIST +#undef WIDL_TYPE_CHECK } // namespace notification } // namespace extension