Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / standards / W3C / Widget / plugin_initializer.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  *
18  * @file       plugin_initializer.cpp
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #include <dpl/log/secure_log.h>
25
26 #include <Commons/plugin_initializer_def.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
28
29 #include "JSWidget.h"
30 #include "JSPreferences.h"
31
32 #include "plugin_config.h"
33
34 #define OBJECT_WIDGET "widget"
35 #define INTERFACE_WIDGET_NAME "Widget"
36 #define OBJECT_PREFERENCES "preferences"
37
38 using namespace WrtPlugins::W3C;
39 using namespace WrtDeviceApis;
40 using namespace WrtDeviceApis::Commons;
41
42 namespace Options {
43 class_definition_options_t WidgetOptions = {
44     JS_CLASS,
45     CREATE_INSTANCE,
46     NONE_NOTICE,
47     IGNORED,
48     NULL,
49     NULL,
50     NULL
51 };
52
53 class_definition_options_t WidgetInterfaceOptions = {
54     JS_INTERFACE,
55     CREATE_INSTANCE,
56     NONE_NOTICE,
57     IGNORED, //ignored
58     NULL,
59     NULL,
60     NULL
61 };
62 };
63
64 void on_widget_init_callback(feature_mapping_interface_t *mapping)
65 {
66     _D("[W3C\\widget] on_widget_init_callback");
67
68     WrtPlugins::W3C::WidgetDeclarations::getMappingInterface(mapping);
69 }
70
71 void on_widget_start_callback(int widgetId)
72 {
73     _D("[W3C\\widget] on_widget_start_callback (%d)", widgetId);
74
75     Try
76     {
77         WrtAccessSingleton::Instance().initialize(widgetId);
78     }
79     Catch(Commons::Exception)
80     {
81         _E("Wrt wrapper registration failed");
82         return;
83     }
84 }
85
86 void on_widget_stop_callback(int widgetId)
87 {
88     _D("[W3C\\widget] on_widget_stop_callback (%d)", widgetId);
89     Try
90     {
91         WrtAccessSingleton::Instance().deinitialize(widgetId);
92     }
93     Catch(Commons::Exception)
94     {
95         _E("Wrt wrapper registration failed");
96         return;
97     }
98 }
99
100 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
101 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
102 PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
103
104 PLUGIN_CLASS_MAP_BEGIN
105 PLUGIN_CLASS_MAP_ADD_INTERFACE(
106     WRT_JS_EXTENSION_OBJECT_GLOBAL,
107     INTERFACE_WIDGET_NAME,
108     (js_class_template_getter) WrtPlugins::W3C::JSWidget::getClassRef,
109     reinterpret_cast<js_class_constructor_cb_t>(WrtPlugins::W3C::JSWidget::
110                                                     callAsConstructor),
111     &Options::WidgetInterfaceOptions)
112 PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(
113     WRT_JS_EXTENSION_OBJECT_GLOBAL,
114     OBJECT_WIDGET,
115     INTERFACE_WIDGET_NAME,
116     &Options::WidgetOptions)
117
118 PLUGIN_CLASS_MAP_END
119
120 #undef OBJECT_WIDGET
121 #undef OBJECT_PREFERENCES