],
'sources': [
'notification_api.js',
- 'notification_context.cc',
- 'notification_context.h',
- 'notification_context_desktop.cc',
- 'notification_context_mobile.cc',
+ 'notification_extension.cc',
+ 'notification_extension.h',
+ 'notification_instance_desktop.cc',
+ 'notification_instance_desktop.h',
+ 'notification_instance_mobile.cc',
+ 'notification_instance_mobile.h',
'mobile/notification_manager.cc',
'mobile/notification_manager.h',
+ '../common/extension.h',
+ '../common/extension.cc',
],
'conditions': [
+++ /dev/null
-// Copyright (c) 2013 Intel Corporation. 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_context.h"
-#include "common/picojson.h"
-
-int32_t XW_Initialize(XW_Extension extension, XW_GetInterface get_interface) {
- NotificationContext::PlatformInitialize();
- return ExtensionAdapter<NotificationContext>::Initialize(extension,
- get_interface);
-}
-
-const char NotificationContext::name[] = "tizen.notification";
-
-// This will be generated from notification_api.js.
-extern const char kSource_notification_api[];
-
-const char* NotificationContext::GetJavaScript() {
- return kSource_notification_api;
-}
-
-void NotificationContext::HandleMessage(const char* message) {
- picojson::value v;
-
- std::string err;
- picojson::parse(v, message, message + strlen(message), &err);
- if (!err.empty()) {
- std::cout << "Ignoring message.\n";
- return;
- }
-
- std::string cmd = v.get("cmd").to_str();
- if (cmd == "NotificationPost")
- HandlePost(v);
- else if (cmd == "NotificationRemove")
- HandleRemove(v);
-}
+++ /dev/null
-// Copyright (c) 2013 Intel Corporation. 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_CONTEXT_H_
-#define NOTIFICATION_NOTIFICATION_CONTEXT_H_
-
-#if defined(GENERIC_DESKTOP)
-#include <libnotify/notify.h>
-#endif
-
-#include <map>
-#include <string>
-#include "common/extension_adapter.h"
-
-#if defined(TIZEN_MOBILE)
-#include "notification/mobile/notification_manager.h"
-#endif
-
-namespace picojson {
-class value;
-}
-
-class NotificationContext
-#if defined(TIZEN_MOBILE)
- : public NotificationClient
-#endif
-{
- public:
- explicit NotificationContext(ContextAPI* api);
- ~NotificationContext();
-
- static void PlatformInitialize();
-
- // ExtensionAdapter implementation.
- static const char name[];
- static const char* GetJavaScript();
- void HandleMessage(const char* message);
- void HandleSyncMessage(const char* message) {}
-
- private:
- void HandlePost(const picojson::value& msg);
- void HandleRemove(const picojson::value& msg);
-
- ContextAPI* api_;
-
-#if defined(GENERIC_DESKTOP)
- std::string IdFromNotification(NotifyNotification* notification);
- static void OnNotificationClosedThunk(NotifyNotification* notification,
- gpointer data);
- void OnNotificationClosed(NotifyNotification* notification);
-
- typedef std::map<std::string, NotifyNotification*> NotificationsMap;
- NotificationsMap notifications_;
-#endif
-
-#if defined(TIZEN_MOBILE)
- // NotificationClient implementation.
- virtual void OnNotificationRemoved(const std::string& id);
-
- typedef std::map<std::string, int> NotificationsMap;
- NotificationsMap notifications_;
-#endif
-};
-
-#endif // NOTIFICATION_NOTIFICATION_CONTEXT_H_
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. 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"
+
+#if defined(GENERIC_DESKTOP)
+#include <libnotify/notify.h>
+#include "notification/notification_instance_desktop.h"
+#elif defined(TIZEN_MOBILE)
+#include "notification/notification_instance_mobile.h"
+#endif
+
+common::Extension* CreateExtension() {
+ return new NotificationExtension;
+}
+
+// This will be generated from notification_api.js.
+extern const char kSource_notification_api[];
+
+NotificationExtension::NotificationExtension() {
+#if defined(GENERIC_DESKTOP)
+ notify_init("Crosswalk");
+#endif
+ SetExtensionName("tizen.notification");
+ SetJavaScriptAPI(kSource_notification_api);
+}
+
+NotificationExtension::~NotificationExtension() {}
+
+common::Instance* NotificationExtension::CreateInstance() {
+#if defined(GENERIC_DESKTOP)
+ return new NotificationInstanceDesktop;
+#elif defined(TIZEN_MOBILE)
+ return new NotificationInstanceMobile(&manager_);
+#endif
+ return NULL;
+}
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. 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"
+
+#if defined(TIZEN_MOBILE)
+#include "notification/mobile/notification_manager.h"
+#endif
+
+class NotificationExtension : public common::Extension {
+ public:
+ NotificationExtension();
+ virtual ~NotificationExtension();
+
+ private:
+ // common::Extension implementation.
+ virtual common::Instance* CreateInstance();
+
+#if defined(TIZEN_MOBILE)
+ NotificationManager manager_;
+#endif
+};
+
+#endif // NOTIFICATION_NOTIFICATION_EXTENSION_H_
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "notification/notification_context.h"
+#include "notification/notification_instance_desktop.h"
+
#include "common/picojson.h"
-// static
-void NotificationContext::PlatformInitialize() {
- notify_init("Tizen-WRT");
-}
+NotificationInstanceDesktop::NotificationInstanceDesktop() {}
-NotificationContext::NotificationContext(ContextAPI* api)
- : api_(api) {}
+NotificationInstanceDesktop::~NotificationInstanceDesktop() {}
-NotificationContext::~NotificationContext() {
- NotificationsMap::iterator it;
- for (it = notifications_.begin(); it != notifications_.end(); it++)
- g_object_unref(it->second);
- delete api_;
+void NotificationInstanceDesktop::HandleMessage(const char* message) {
+ picojson::value v;
+
+ std::string err;
+ picojson::parse(v, message, message + strlen(message), &err);
+ if (!err.empty()) {
+ std::cout << "Ignoring message.\n";
+ return;
+ }
+
+ std::string cmd = v.get("cmd").to_str();
+ if (cmd == "NotificationPost")
+ HandlePost(v);
+ else if (cmd == "NotificationRemove")
+ HandleRemove(v);
}
-void NotificationContext::HandlePost(const picojson::value& msg) {
+void NotificationInstanceDesktop::HandlePost(const picojson::value& msg) {
NotifyNotification* notification =
notify_notification_new(msg.get("title").to_str().c_str(),
msg.get("content").to_str().c_str(),
notifications_[id] = notification;
}
-void NotificationContext::HandleRemove(const picojson::value& msg) {
+void NotificationInstanceDesktop::HandleRemove(const picojson::value& msg) {
std::string id = msg.get("id").to_str();
NotificationsMap::iterator it = notifications_.find(id);
if (it == notifications_.end())
notify_notification_close(it->second, NULL);
}
-std::string NotificationContext::IdFromNotification(
+std::string NotificationInstanceDesktop::IdFromNotification(
NotifyNotification* notification) {
NotificationsMap::iterator it;
for (it = notifications_.begin(); it != notifications_.end(); ++it) {
return std::string();
}
-void NotificationContext::OnNotificationClosedThunk(
+void NotificationInstanceDesktop::OnNotificationClosedThunk(
NotifyNotification* notification, gpointer data) {
- NotificationContext* handler = reinterpret_cast<NotificationContext*>(data);
+ NotificationInstanceDesktop* handler =
+ reinterpret_cast<NotificationInstanceDesktop*>(data);
handler->OnNotificationClosed(notification);
}
-void NotificationContext::OnNotificationClosed(
+void NotificationInstanceDesktop::OnNotificationClosed(
NotifyNotification* notification) {
const std::string id = IdFromNotification(notification);
if (id.empty())
o["cmd"] = picojson::value("NotificationRemoved");
o["id"] = picojson::value(id);
picojson::value v(o);
- api_->PostMessage(v.serialize().c_str());
+ PostMessage(v.serialize().c_str());
g_object_unref(notification);
notifications_.erase(id);
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. 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_DESKTOP_H_
+#define NOTIFICATION_NOTIFICATION_INSTANCE_DESKTOP_H_
+
+#if defined(GENERIC_DESKTOP)
+#include <libnotify/notify.h>
+#endif
+
+#include <string>
+#include <map>
+#include "common/extension.h"
+
+namespace picojson {
+class value;
+}
+
+class NotificationInstanceDesktop : public common::Instance {
+ public:
+ NotificationInstanceDesktop();
+ virtual ~NotificationInstanceDesktop();
+
+ private:
+ // common::Instance implementation.
+ virtual void HandleMessage(const char* msg);
+
+ void HandlePost(const picojson::value& msg);
+ void HandleRemove(const picojson::value& msg);
+
+ std::string IdFromNotification(NotifyNotification* notification);
+ static void OnNotificationClosedThunk(NotifyNotification* notification,
+ gpointer data);
+ void OnNotificationClosed(NotifyNotification* notification);
+
+ typedef std::map<std::string, NotifyNotification*> NotificationsMap;
+ NotificationsMap notifications_;
+};
+
+#endif // NOTIFICATION_NOTIFICATION_INSTANCE_DESKTOP_H_
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "notification/notification_context.h"
+#include "notification/notification_instance_mobile.h"
-#include <iostream>
#include "common/picojson.h"
namespace {
-// We have one NotificationManager per extension (so, per process). This is
-// like this because we can have only one callback function to track the
-// eventual removal of notifications.
-NotificationManager* g_notification_manager = NULL;
-
void NotificationSetText(notification_h notification,
notification_text_type_e type,
const std::string& text) {
} // namespace
-// static
-void NotificationContext::PlatformInitialize() {
- // FIXME(cmarcelo): Handle shutdown.
- g_notification_manager = new NotificationManager();
+NotificationInstanceMobile::NotificationInstanceMobile(
+ NotificationManager* manager)
+ : manager_(manager) {}
+
+NotificationInstanceMobile::~NotificationInstanceMobile() {
+ manager_->DetachClient(this);
}
-NotificationContext::NotificationContext(ContextAPI* api)
- : api_(api) {}
+void NotificationInstanceMobile::HandleMessage(const char* message) {
+ picojson::value v;
+
+ std::string err;
+ picojson::parse(v, message, message + strlen(message), &err);
+ if (!err.empty()) {
+ std::cout << "Ignoring message.\n";
+ return;
+ }
-NotificationContext::~NotificationContext() {
- g_notification_manager->DetachClient(this);
- delete api_;
+ std::string cmd = v.get("cmd").to_str();
+ if (cmd == "NotificationPost")
+ HandlePost(v);
+ else if (cmd == "NotificationRemove")
+ HandleRemove(v);
}
-void NotificationContext::HandlePost(const picojson::value& msg) {
- notification_h notification = g_notification_manager->CreateNotification();
+void NotificationInstanceMobile::HandlePost(const picojson::value& msg) {
+ notification_h notification = manager_->CreateNotification();
NotificationSetText(notification, NOTIFICATION_TEXT_TYPE_TITLE,
msg.get("title").to_str());
NotificationSetText(notification, NOTIFICATION_TEXT_TYPE_CONTENT,
msg.get("content").to_str());
std::string id = msg.get("id").to_str();
- if (!g_notification_manager->PostNotification(id, notification, this)) {
+ if (!manager_->PostNotification(id, notification, this)) {
std::cerr << "tizen.notification error: "
<< " couldn't post notification with id '" << id << "'";
return;
}
}
-void NotificationContext::HandleRemove(const picojson::value& msg) {
+void NotificationInstanceMobile::HandleRemove(const picojson::value& msg) {
std::string id = msg.get("id").to_str();
- if (!g_notification_manager->RemoveNotification(id)) {
+ if (!manager_->RemoveNotification(id)) {
std::cerr << "tizen.notification error: "
<< "couldn't remove notification with id '" << id << "'\n";
}
}
-void NotificationContext::OnNotificationRemoved(const std::string& id) {
+void NotificationInstanceMobile::OnNotificationRemoved(const std::string& id) {
picojson::value::object o;
o["cmd"] = picojson::value("NotificationRemoved");
o["id"] = picojson::value(id);
picojson::value v(o);
- api_->PostMessage(v.serialize().c_str());
+ PostMessage(v.serialize().c_str());
}
+
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. 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_MOBILE_H_
+#define NOTIFICATION_NOTIFICATION_INSTANCE_MOBILE_H_
+
+#include <string>
+#include <map>
+#include "common/extension.h"
+#include "notification/mobile/notification_manager.h"
+
+namespace picojson {
+class value;
+}
+
+class NotificationInstanceMobile
+ : public common::Instance,
+ public NotificationClient {
+ public:
+ explicit NotificationInstanceMobile(NotificationManager* manager);
+ virtual ~NotificationInstanceMobile();
+
+ private:
+ // common::Instance implementation.
+ virtual void HandleMessage(const char* msg);
+
+ void HandlePost(const picojson::value& msg);
+ void HandleRemove(const picojson::value& msg);
+
+ // NotificationClient implementation.
+ virtual void OnNotificationRemoved(const std::string& id);
+
+ NotificationManager* manager_;
+};
+
+#endif // NOTIFICATION_NOTIFICATION_INSTANCE_MOBILE_H_