9bc32d85ed1e2920ecff4a17497ddd95a5f4f901
[framework/web/wrt-plugins-tizen.git] / src / Tizen / 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 /**
19  * @file        plugin_initializer.cpp
20  * @author      Karol Majewski (k.majewski@samsung.com)
21  * @version     0.1
22  * @brief
23  */
24
25 #include <dpl/log/log.h>
26 #include <Commons/plugin_initializer_def.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
28 #include <Commons/Exception.h>
29 #include "JSTizen.h"
30 #include "JSAttributeFilter.h"
31 #include "JSAttributeRangeFilter.h"
32 #include "JSCompositeFilter.h"
33 #include "JSSortMode.h"
34 #include "JSSimpleCoordinates.h"
35
36 #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
37
38 #define OBJECT_TIZEN "tizen"
39
40 namespace Options{
41
42 class_definition_options_t TizenOptions =
43 {
44     JS_CLASS,
45     CREATE_INSTANCE,
46     NONE_NOTICE,
47     USE_OVERLAYED, //ignored
48     NULL,
49     NULL
50 };
51
52 }
53
54 using namespace WrtDeviceApis;
55 using namespace WrtDeviceApis::Commons;
56
57 void on_widget_start_callback(int widgetId)
58 {
59     LogDebug("[Tizen\\xxx] on_widget_start_callback ("<<widgetId<<")");
60     Try
61     {
62         WrtAccessSingleton::Instance().initialize(widgetId);
63     }
64     Catch(Commons::Exception)
65     {
66         LogError("WrtAccess initialization failed");
67     }
68 }
69
70 void on_widget_stop_callback(int widgetId)
71 {
72     LogDebug("[Tizen\\xxx] on_widget_stop_callback ("<<widgetId<<")");
73     Try
74     {
75         WrtAccessSingleton::Instance().deinitialize(widgetId);
76     }
77     Catch(WrtDeviceApis::Commons::Exception)
78     {
79         LogError("WrtAccess deinitialization failed");
80     }
81 }
82
83 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
84 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
85
86 PLUGIN_CLASS_MAP_BEGIN
87     PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_GLOBAL,
88                                OBJECT_TIZEN,
89                                (js_class_template_getter)DeviceAPI::Tizen::JSTizen::getClassRef,
90                                &Options::TizenOptions)
91     PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
92                                "AttributeFilter",
93                                (js_class_template_getter)DeviceAPI::Tizen::JSAttributeFilter::getClassRef,
94                                &Options::TizenOptions)
95     PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
96                                "AttributeRangeFilter",
97                                (js_class_template_getter)DeviceAPI::Tizen::JSAttributeRangeFilter::getClassRef,
98                                &Options::TizenOptions)
99     PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
100                                "CompositeFilter",
101                                (js_class_template_getter)DeviceAPI::Tizen::JSCompositeFilter::getClassRef,
102                                &Options::TizenOptions)
103     PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
104                                "SortMode",
105                                (js_class_template_getter)DeviceAPI::Tizen::JSSortMode::getClassRef,
106                                &Options::TizenOptions)
107     PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
108                                "SimpleCoordinates",
109                                (js_class_template_getter)DeviceAPI::Tizen::JSSimpleCoordinates::getClassRef,
110                                &Options::TizenOptions)
111 PLUGIN_CLASS_MAP_END
112
113 #undef OBJECT_TIZEN