2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file plugin_initializer.cpp
19 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
24 #include <dpl/log/secure_log.h>
26 #include <Commons/plugin_initializer_def.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
28 #include <ExportedApi.h>
29 #include <ObjectFactory.h>
31 #include <PluginRegistration.h>
34 #include "JSPreferences.h"
36 #include "plugin_config.h"
38 #define OBJECT_WIDGET "widget"
39 #define INTERFACE_WIDGET_NAME "Widget"
41 using namespace WrtPlugins::W3C;
42 using namespace WrtDeviceApis;
43 using namespace WrtDeviceApis::Commons;
44 using namespace WrtPluginsApi;
47 class_definition_options_t WidgetOptions = {
57 class_definition_options_t WidgetInterfaceOptions = {
68 //TODO: remove this after switch to wrt-plugin-installer
69 void on_widget_init_callback(feature_mapping_interface_t *mapping)
71 _D("[W3C\\widget] on_widget_init_callback");
73 WrtPlugins::W3C::WidgetDeclarations::getMappingInterface(mapping);
77 void on_widget_start_callback(int widgetId)
79 _D("[W3C\\widget] on_widget_start_callback (%d)", widgetId);
83 WrtAccessSingleton::Instance().initialize(widgetId);
85 Catch(Commons::Exception)
87 _E("Wrt wrapper registration failed");
92 void on_widget_stop_callback(int widgetId)
94 _D("[W3C\\widget] on_widget_stop_callback (%d)", widgetId);
97 WrtAccessSingleton::Instance().deinitialize(widgetId);
99 Catch(Commons::Exception)
101 _E("Wrt wrapper registration failed");
106 void Register(PluginRegistration& r)
108 Plugin* plugin = new Plugin();
110 auto widgetObject = ObjectFactory::createObjectWithInterface(
112 (js_class_template_getter) WrtPlugins::W3C::JSWidget::getClassRef,
113 INTERFACE_WIDGET_NAME,
114 reinterpret_cast<js_class_constructor_cb_t>(WrtPlugins::W3C::JSWidget::callAsConstructor));
116 plugin->AddObject(widgetObject);
118 r.Connect<OnWidgetStart>(on_widget_start_callback);
119 r.Connect<OnWidgetStop>(on_widget_stop_callback);
121 r.AddPlugin(*plugin);
124 void Unregister(PluginRegistration& r, Plugin* plugin)
130 void GetProvidedFeatures(feature_mapping_interface_t *mapping)
132 WrtPlugins::W3C::WidgetDeclarations::getMappingInterface(mapping);
135 ExportedApi dll_api={Register, Unregister, GetProvidedFeatures};
137 //TODO: remove this after switch to wrt-plugin-installer
138 PLUGIN_ON_WIDGET_START(on_widget_start_callback)
139 PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
140 PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
142 PLUGIN_CLASS_MAP_BEGIN
143 PLUGIN_CLASS_MAP_ADD_INTERFACE(
144 WRT_JS_EXTENSION_OBJECT_GLOBAL,
145 INTERFACE_WIDGET_NAME,
146 (js_class_template_getter) WrtPlugins::W3C::JSWidget::getClassRef,
147 reinterpret_cast<js_class_constructor_cb_t>(WrtPlugins::W3C::JSWidget::
149 &Options::WidgetInterfaceOptions)
150 PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(
151 WRT_JS_EXTENSION_OBJECT_GLOBAL,
153 INTERFACE_WIDGET_NAME,
154 &Options::WidgetOptions)
160 #undef INTERFACE_WIDGET_NAME