4c8c3863add01c70c84e9f50ba4448b0e618c2a9
[platform/framework/web/wrt-plugins-tizen.git] / src / Alarm / 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 <Commons/Exception.h>
21 #include <TimeTracer.h>
22 #include "JSAlarmManager.h"
23 #include "JSAlarmAbsolute.h"
24 #include "JSAlarmRelative.h"
25 #include <Logger.h>
26
27 #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
28
29 namespace DeviceAPI {
30 namespace Alarm {
31
32 using namespace WrtDeviceApis;
33 using namespace WrtDeviceApis::Commons;
34 using namespace WrtDeviceApis::CommonsJavaScript;
35
36 class_definition_options_t ConstructorClassOptions =
37 {
38     JS_INTERFACE,
39     CREATE_INSTANCE,
40     NONE_NOTICE,
41     USE_OVERLAYED, //ignored
42     NULL,
43     NULL,
44     NULL
45 };
46
47 void on_widget_start_callback(int widgetId)
48 {
49     LoggerD("[Tizen\\AlarmManager ] on_widget_start_callback (" << widgetId << ")");
50     Try
51     {
52                 TIME_TRACER_INIT();
53         WrtAccessSingleton::Instance().initialize(widgetId);
54     }
55     Catch(Commons::Exception)
56     {
57         LoggerE("WrtAccess initialization failed");
58     }
59 }
60
61 void on_widget_stop_callback(int widgetId)
62 {
63     LoggerD("[Tizen\\AlarmManager ] on_widget_stop_callback (" << widgetId << ")");
64     Try
65     {
66                 TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"Alarm");
67                 TIME_TRACER_RELEASE();
68        WrtAccessSingleton::Instance().deinitialize(widgetId);
69     }
70     Catch(Commons::Exception)
71     {
72         LoggerE("WrtAccess deinitialization failed");
73     }
74 }
75
76 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
77 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
78
79 PLUGIN_CLASS_MAP_BEGIN
80 PLUGIN_CLASS_MAP_ADD_CLASS(
81         WRT_JS_EXTENSION_OBJECT_TIZEN,
82         "alarm",
83         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmManager::getClassRef,
84         NULL)
85 PLUGIN_CLASS_MAP_ADD_INTERFACE(
86         WRT_JS_EXTENSION_OBJECT_TIZEN,
87         TIZEN_ALARM_ABSOLUTE_INTERFACE,
88         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmAbsolute::getClassRef,
89         reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmAbsolute::constructor),
90         &ConstructorClassOptions)
91 PLUGIN_CLASS_MAP_ADD_INTERFACE(
92         WRT_JS_EXTENSION_OBJECT_TIZEN,
93         TIZEN_ALARM_RELATIVE_INTERFACE,
94         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmRelative::getClassRef,
95         reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmRelative::constructor),
96         &ConstructorClassOptions)
97 PLUGIN_CLASS_MAP_END
98
99 } // Alarm
100 } // DeviceAPI