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});
}
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);
}
return {
- 'statusType': args.statusType,
- 'title': args.title,
+ 'statusType': n.statusType,
+ 'title': n.title,
'content': n.content,
'iconPath': n.iconPath,
'soundPath': n.soundPath,
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;
// 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 <notification.h>
#include <string>
#include <functional>
+#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 {
} // namespace
+using common::UnknownException;
using common::TypeMismatchException;
+using common::ScopeExit;
+using common::operator+;
NotificationInstance::NotificationInstance() {
using std::placeholders::_1;
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<wtype>(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<WIDLType::StringType>(args, "id");
- check = IsType<WIDLType::StringType>(args, "type");
- check = IsType<WIDLType::StringType>(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<WIDLType::StringType>(args, "iconPath")) {
+ err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
+ args.get("iconPath").get<std::string>().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<std::string>().c_str());
+ }
+ */
+
+ const std::string& title = args.get("title").get<std::string>();
+ 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<WIDLType::StringType>(args, "content")) {
+ const std::string& content = args.get("content").get<std::string>();
+ 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) {
}
-#undef CHECK_EXIST
+#undef WIDL_TYPE_CHECK
} // namespace notification
} // namespace extension