Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / Commons / plugin_initializer_def.h
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  * @author      Karol Majewski (k.majewski@samsung.com)
18  * @version     0.1
19  * @brief       This is a file that you provides interface for wrt-engine while
20  * loading and using plugin
21  *              If you are a plugin developer you need to plugin_initializer.cpp
22  * in your module and provide implementation for macros below
23  */
24
25 #ifndef WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_
26 #define WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_
27
28 #include <wrt_plugin_export.h>
29
30 typedef java_script_context_t JavaScriptContext;
31
32 #define EXPORT_SYMBOL __attribute__((__visibility__("default")))
33
34 //DEFINES FOR GLOBAL OBJECTS AVAILABLE IN JAVASCRIPT
35 /**
36  * each object which declare this object as parent
37  * will ba available as global object in javascript
38  */
39 #define WRT_JS_EXTENSION_OBJECT_GLOBAL  "GLOBAL_OBJECT"
40
41 /**
42  * global object bondi
43  * */
44 #define WRT_JS_EXTENSION_OBJECT_BONDI "bondi"
45
46 /**
47  * global object Widget
48  * */
49 #define WRT_JS_EXTENSION_OBJECT_WIDGET "Widget"
50
51 /**
52  * global object deviceapis
53  * */
54 #define WRT_JS_EXTENSION_OBJECT_DEVICEAPIS "deviceapis"
55
56 /**
57  * global object tizen
58  * */
59 #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
60
61 //HAVE TO BE IMPLEMENTED IN EVERY PLUGIN
62 /*
63  * You have to(!) call this macro in your plugin_initializer.cpp(!) file
64  * providing callback that will be called while loading each widget (for every
65  * loaded widget this function will be called)
66  *  Example:
67  *       plugin_initializer.cpp
68  *        void on_widget_start_callback(int widgetId, JSContextRef context,
69  * const engine_interface_t *interface)
70  *        {
71  *          //...
72  *        }
73  *        PLUGIN_ON_WIDGET_START(on_widget_start_callback)
74  */
75 #define PLUGIN_ON_WIDGET_START(CALLBACK_NAME) extern "C" const \
76     on_widget_start_proc PLUGIN_WIDGET_START_PROC EXPORT_SYMBOL = CALLBACK_NAME;
77
78 /*
79  *  You have to(!) call this macro in your plugin_initializer.cpp(!) file
80  *  providing callback that will be called while loading each widget
81  * (for every loaded widget this function will be called)
82  *  Example:
83  *       plugin_initializer.cpp
84  *        void on_widget_init_callback(feature_mapping_interface_t *mapping)
85  *        {
86  *          //...
87  *        }
88  *        PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
89  */
90 #define PLUGIN_ON_WIDGET_INIT(CALLBACK_NAME) extern "C" \
91     const on_widget_init_proc PLUGIN_WIDGET_INIT_PROC EXPORT_SYMBOL = \
92         CALLBACK_NAME;
93
94 /*
95  *  You have to(!) call this macro in your plugin_initializer.cpp(!) file
96  * providing callback that will be called while unloading each widget (for
97  * every unloaded widget this function will be called)
98  *  Example:
99  *        void on_widget_stop_callback(int widgetId)
100  *        {
101  *          //...
102  *        }
103  *        PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
104  */
105 #define PLUGIN_ON_WIDGET_STOP(CALLBACK_NAME) extern "C" const \
106     on_widget_stop_proc PLUGIN_WIDGET_STOP_PROC EXPORT_SYMBOL = CALLBACK_NAME;
107
108 /*
109  *  You have to(!) call this macro in your plugin_initializer.cpp(!) file
110  * providing callback that will be called while unloading each page (for every
111  * loaded page, including nested page, this function will be called)
112  *  Example:
113  *        void on_frame_load_callback(java_script_context_t context)
114  *        {
115  *          //...
116  *        }
117  *        PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
118  */
119 #define PLUGIN_ON_FRAME_LOAD(CALLBACK_NAME) extern "C" const on_frame_load_proc \
120     PLUGIN_FRAME_LOAD_PROC EXPORT_SYMBOL = CALLBACK_NAME;
121
122 /*
123  *  You have to(!) call this macro in your plugin_initializer.cpp(!) file
124  * providing callback that will be called while ununloading each page (for
125  * every unloaded page, including nested page, this function will be called)
126  *  Example:
127  *        void on_frame_unload_callback(java_script_context_t context)
128  *        {
129  *          //...
130  *        }
131  *        PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
132  */
133 #define PLUGIN_ON_FRAME_UNLOAD(CALLBACK_NAME) extern "C" const \
134     on_frame_unload_proc PLUGIN_FRAME_UNLOAD_PROC EXPORT_SYMBOL = CALLBACK_NAME;
135
136 /*
137  * You have to(!) define an array of structures in your
138  * plugin_initializer.cpp(!) file describing a JS class (class_definition) and
139  * it's parent class name (parent_name).
140  * JS class will be bind to a parent class name (parent_name.jsclass_name).
141  * Example:
142  *    plugin_initializer.cpp
143  *      PLUGIN_CLASS_MAP_BEGIN
144  *          PLUGIN_CLASS_MAP_ADD_CLASS(
145  *              "bondi",
146  *              WrtPluginBondi::JSICameraManager::getClassInfo())
147  *          PLUGIN_CLASS_MAP_ADD_CLASS(
148  *              "bondi",
149  *              WrtPluginBondi::JSICameraAnotherClass::getClassInfo())
150  *      PLUGIN_CLASS_MAP_END
151  *
152  */
153 #define PLUGIN_CLASS_MAP_BEGIN extern "C" const js_entity_definition_t \
154     PLUGIN_CLASS_MAP[] EXPORT_SYMBOL = {
155
156 #define PLUGIN_CLASS_MAP_ADD_INTERFACE(PARENTNAME, \
157                                        INTERFACENAME, \
158                                        JSPRODUCTCLASSTEMPLATE, \
159                                        PRODUCTCONSTRUCTORCB, \
160                                        PRIVDATA) \
161     { PARENTNAME, INTERFACENAME, "", JSPRODUCTCLASSTEMPLATE, \
162       PRODUCTCONSTRUCTORCB, PRIVDATA },
163
164 #define PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(PARENTNAME, OBJECTNAME, \
165                                                INTERFACENAME, PRIVDATA) \
166     { PARENTNAME, OBJECTNAME, INTERFACENAME, NULL, NULL, PRIVDATA },
167
168 #define PLUGIN_CLASS_MAP_ADD_CLASS(PARENTNAME, CLASSNAME, JSCLASSTEMPLATE, \
169                                    PRIVDATA) \
170     { PARENTNAME, CLASSNAME, "", JSCLASSTEMPLATE, NULL, PRIVDATA },
171
172 #define PLUGIN_CLASS_MAP_END { NULL, NULL, NULL, NULL, NULL, NULL } };
173
174 #define PLUGIN_CLASS_MAP_BEGIN_STATIC static const js_entity_definition_t \
175     PLUGIN_CLASS_MAP[] = {
176
177 #define PLUGIN_GET_CLASS_MAP(CALLBACK_NAME) extern "C" const \
178     get_widget_entity_map_proc \
179     PLUGIN_GET_CLASS_PROC_MAP EXPORT_SYMBOL = CALLBACK_NAME;
180
181 #endif // WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_