wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / plugin_initializer.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <Commons/plugin_initializer_def.h>
19 #include <Commons/WrtAccess/WrtAccess.h>
20 #include "JSMessagingServiceManager.h"
21 #include "JSMessagingStorage.h"
22 #include "JSMessage.h"
23 #include "JSMessageAttachment.h"
24 #include "MessageAsyncCallbackManager.h"
25 #include "MessageListenerManager.h"
26
27 #include <GlobalContextManager.h>
28 #include <Logger.h>
29
30 #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
31
32 namespace DeviceAPI {
33 namespace Messaging {
34
35 namespace Options{
36
37 class_definition_options_t TizenOptions =
38 {
39     JS_CLASS,
40     CREATE_INSTANCE,
41     NONE_NOTICE,
42     USE_OVERLAYED, //ignored
43     NULL,
44     NULL
45 };
46
47 class_definition_options_t MessagingInterfaceOptions = {
48     JS_INTERFACE,
49     CREATE_INSTANCE,
50     NONE_NOTICE,
51     USE_OVERLAYED, //ignored
52     NULL, // JSWidget::acquireGlobalContext,
53     NULL,
54     NULL
55 };
56
57 }
58
59 using namespace WrtDeviceApis;
60 using namespace WrtDeviceApis::Commons;
61
62 void on_widget_start_callback(int widgetId) {
63         LoggerD("[Tizen\\MessagingServiceManager] on_widget_start_callback ("<<widgetId<<")");
64     Try {
65         WrtAccessSingleton::Instance().initialize(widgetId);
66     } Catch(Commons::Exception) {
67         LoggerE("WrtAccess initialization failed");
68     }
69 }
70
71 void on_widget_stop_callback(int widgetId) {
72         LoggerD("[Tizen\\MessagingServiceManager] on_widget_stop_callback ("<<widgetId<<")");
73     Try {
74         WrtAccessSingleton::Instance().deinitialize(widgetId);
75     } Catch(Commons::Exception) {
76         LoggerE("WrtAccess deinitialization failed");
77     }
78 }
79
80 void on_frame_load_callback(const void * context)
81 {
82     LoggerD("[Tizen\\contact] on_frame_load_callback (" << context << ")");
83     DeviceAPI::Common::GlobalContextManager::getInstance()->addGlobalContext(static_cast<JSContextRef>(context));
84 }
85
86 void on_frame_unload_callback(const void * context)
87 {
88     LoggerD("[Tizen\\contact] on_frame_unload_callback (" << context << ")");
89
90     DeviceAPI::Common::GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(context));
91     DeviceAPI::Messaging::MessageAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
92     DeviceAPI::Messaging::MessageListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
93 }
94
95
96 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
97 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
98
99 PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
100 PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
101
102 PLUGIN_CLASS_MAP_BEGIN
103         PLUGIN_CLASS_MAP_ADD_CLASS(
104                 WRT_JS_EXTENSION_OBJECT_TIZEN,
105                 "messaging",
106                 (js_class_template_getter)DeviceAPI::Messaging::JSMessagingServiceManager::getClassRef,
107                 NULL)
108
109     PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
110                                "Message",
111                                (js_class_template_getter)DeviceAPI::Messaging::JSMessage::getClassRef,
112                                (js_class_constructor_cb_t)DeviceAPI::Messaging::JSMessage::constructor,
113                                &Options::MessagingInterfaceOptions)
114
115     PLUGIN_CLASS_MAP_ADD_INTERFACE(WRT_JS_EXTENSION_OBJECT_TIZEN,
116                                "MessageAttachment",
117                                (js_class_template_getter)DeviceAPI::Messaging::JSMessageAttachment::getClassRef,
118                                (js_class_constructor_cb_t)DeviceAPI::Messaging::JSMessageAttachment::constructor,
119                                &Options::MessagingInterfaceOptions)
120
121 PLUGIN_CLASS_MAP_END
122
123 } // Messaging
124 } // DeviceAPI