Update change log and spec for wrt-plugins-tizen_0.4.70
[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 #include <Security.h>
27 #include "plugin_config.h"
28
29 #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
30
31 namespace DeviceAPI {
32 namespace Alarm {
33
34 using namespace WrtDeviceApis;
35 using namespace WrtDeviceApis::Commons;
36 using namespace WrtDeviceApis::CommonsJavaScript;
37
38 AceSecurityStatus alarmAceCheckAccessFunction(const char* functionName)
39 {
40     return ALARM_CHECK_ACCESS(functionName);
41 }
42
43 DEFINE_GLOBAL_SECURITY_ACCESSOR(gSecurityAccessor);
44
45 DEFINE_SECURITY_ACCESSOR_SETTER(AceCheckerAlarmSetter,
46                                 DeviceAPI::Common::SecurityAccessor,
47                                 gSecurityAccessor);
48
49 class_definition_options_t ClassOptions =
50 {
51     JS_CLASS,
52     NONE,
53     ALWAYS_NOTICE,
54     IGNORED,
55     AceCheckerAlarmSetter,
56     NULL,
57     NULL
58 };
59
60 class_definition_options_t ConstructorClassOptions =
61 {
62     JS_INTERFACE,
63     CREATE_INSTANCE,
64     NONE_NOTICE,
65     USE_OVERLAYED, //ignored
66     NULL,
67     NULL,
68     NULL
69 };
70
71 void on_widget_start_callback(int widgetId)
72 {
73     LoggerI("[Tizen\\AlarmManager ] on_widget_start_callback (" << widgetId << ")");
74     Try
75     {
76                 TIME_TRACER_INIT();
77         WrtAccessSingleton::Instance().initialize(widgetId);
78     }
79     Catch(Commons::Exception)
80     {
81         LoggerE("WrtAccess initialization failed");
82     }
83
84     INITAILIZE_GLOBAL_SECURITY_ACCESSOR(gSecurityAccessor, alarmAceCheckAccessFunction);
85 }
86
87 void on_widget_stop_callback(int widgetId)
88 {
89     LoggerI("[Tizen\\AlarmManager ] on_widget_stop_callback (" << widgetId << ")");
90     Try
91     {
92                 TIME_TRACER_EXPORT_REPORT_TO(TIME_TRACER_EXPORT_FILE,"Alarm");
93                 TIME_TRACER_RELEASE();
94        WrtAccessSingleton::Instance().deinitialize(widgetId);
95     }
96     Catch(Commons::Exception)
97     {
98         LoggerE("WrtAccess deinitialization failed");
99     }
100
101     FINALIZE_GLOBAL_SECURITY_ACCESSOR(gSecurityAccessor);
102 }
103
104 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
105 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
106
107 PLUGIN_CLASS_MAP_BEGIN
108 PLUGIN_CLASS_MAP_ADD_CLASS(
109         WRT_JS_EXTENSION_OBJECT_TIZEN,
110         "alarm",
111         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmManager::getClassRef,
112         &ClassOptions)
113 PLUGIN_CLASS_MAP_ADD_INTERFACE(
114         WRT_JS_EXTENSION_OBJECT_TIZEN,
115         TIZEN_ALARM_ABSOLUTE_INTERFACE,
116         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmAbsolute::getClassRef,
117         reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmAbsolute::constructor),
118         &ConstructorClassOptions)
119 PLUGIN_CLASS_MAP_ADD_INTERFACE(
120         WRT_JS_EXTENSION_OBJECT_TIZEN,
121         TIZEN_ALARM_RELATIVE_INTERFACE,
122         (js_class_template_getter)DeviceAPI::Alarm::JSAlarmRelative::getClassRef,
123         reinterpret_cast<js_class_constructor_cb_t>(DeviceAPI::Alarm::JSAlarmRelative::constructor),
124         &ConstructorClassOptions)
125 PLUGIN_CLASS_MAP_END
126
127 } // Alarm
128 } // DeviceAPI