Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / support / wrt_plugin_export.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  * @file    wrt_plugin_export.h
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   Header file for plugin export API
21  */
22 #ifndef WRT_PLUGIN_EXPORT_H
23 #define WRT_PLUGIN_EXPORT_H
24
25 #include <stddef.h>
26 #include <dpl/wrt-dao-ro/wrt_db_types.h>
27
28 /**
29  * Widget handle type
30  */
31 typedef int widget_handle_t;
32
33 /**
34  * Parameter which should be used during policy evaluation.
35  */
36 typedef struct ace_param_s
37 {
38     const char *name;
39     const char *value;
40 } ace_param_t;
41
42 /**
43  * List of additional parameters which should be used during policy evaluation.
44  */
45 typedef struct ace_param_list_s
46 {
47     size_t count;
48     ace_param_t *param;
49 } ace_param_list_t;
50
51 /**
52  * Contains list of device capabilities. Each device capability may have
53  * associated list of function params.
54  */
55 typedef struct ace_device_cap_s
56 {
57     size_t devcapsCount;
58     const char**      dev_cap_names;
59     size_t paramsCount;
60     ace_param_list_t* params;
61 } ace_device_cap_t;
62
63 /**
64  * List of device capabilities which must be check.
65  */
66 typedef struct ace_device_capabilities_s
67 {
68     size_t count;
69     const char **device_cap;
70 } ace_device_capabilities_t;
71
72 /**
73  * List of api features that must be checked
74  */
75 typedef struct ace_api_features_s
76 {
77     size_t count;
78     const char **api_feature;
79 } ace_api_features_t;
80
81 /**
82  * Data from request will be used to evaluate policy file.
83  */
84 typedef struct ace_request_s
85 {
86     widget_handle_t widget_handle;
87     const char*                 feature_api;
88     const char*                 function_name;
89     ace_device_capabilities_t device_capabilities;
90     ace_param_list_t param_list;
91 } ace_request_t;
92
93 /**
94  * Data from request will be used to evaluate policy file.
95  */
96 typedef struct ace_request_2_s
97 {
98     widget_handle_t widget_handle;
99     ace_api_features_t api_features;
100     const char*                 function_name;
101     ace_device_cap_t device_capabilities;
102 } ace_request_2_t;
103
104 /**
105  * info returned by plugin_api_check_access
106  */
107 #define PLUGIN_API_ACCESS_GRANTED 1
108 #define PLUGIN_API_ACCESS_DENIED 0
109 #define PLUGIN_API_ACCESS_ERROR -1
110
111 typedef const void* java_script_context_t;
112
113 typedef struct js_object_properties_s
114 {
115     size_t count;
116     char** properties;
117 } js_object_properties_t;
118
119 typedef const void* js_class_template_t;
120 typedef void* js_object_ref_t;
121 typedef const void* js_value_ref_t;
122
123 typedef js_class_template_t (*js_class_template_getter)(void);
124 typedef void* (*js_class_constructor_cb_t)(js_class_template_t,
125                                            js_object_ref_t, size_t,
126                                            js_value_ref_t[],
127                                            js_value_ref_t*);
128
129 typedef enum class_definition_type_e
130 {
131     JS_CLASS,
132     JS_FUNCTION,
133     JS_INTERFACE
134 } class_definition_type_t;
135
136 typedef enum class_definition_iframe_behaviour_e
137 {
138     //object should not be initalized in iframes
139     //it is default one
140     NONE,
141     //object should be copied as reference to each iframe
142     REFERENCE, // deprecated
143     //object should be created for each iframe and NOT inform plugin
144     CREATE_INSTANCE
145 } class_definition_iframe_behaviour_t;
146
147 typedef enum class_definition_iframe_notice_e
148 {
149     //it is default one
150     NONE_NOTICE,
151     ALWAYS_NOTICE
152 } class_definition_iframe_notice_t;
153
154 typedef enum class_definition_iframe_overlay_e
155 {
156     IGNORED,
157     USE_OVERLAYED, //deprecated
158     OVERLAYED_BEFORE_ORIGINAL //deprecated
159 } class_definition_iframe_overlay_t; //deprecated
160
161 typedef void* js_object_instance_t;
162 //global_context - id
163 typedef void (*iframe_loaded_cb)(java_script_context_t global_context,
164                                  js_object_instance_t iframe,
165                                  js_object_instance_t object);
166
167 typedef void* (*js_function_impl)(void*);
168
169 typedef struct class_definition_options_s
170 {
171     class_definition_type_t type;
172     class_definition_iframe_behaviour_t iframe_option;
173     class_definition_iframe_notice_t iframe_notice;
174     class_definition_iframe_overlay_t iframe_overlay;   //deprecated
175     iframe_loaded_cb cb;
176     void * private_data;
177     js_function_impl function;
178 } class_definition_options_t;
179
180 /*
181  * list of device caps
182  */
183 typedef struct devcaps_s
184 {
185     char** deviceCaps;
186     size_t devCapsCount;
187 } devcaps_t;
188
189 /*
190  * mapping from a feature to corresponding list of device capabilities
191  */
192 typedef struct feature_devcaps_s
193 {
194     char* feature_name;
195     devcaps_t devCaps;
196 } feature_devcaps_t;
197
198 /*
199  * list of feature_devcaps_t structs
200  */
201 typedef struct feature_mapping_s
202 {
203     feature_devcaps_t* features;
204     size_t featuresCount;
205 } feature_mapping_t;
206
207 typedef feature_mapping_t* pfeature_mapping_t;
208
209 typedef pfeature_mapping_t (*features_getter)(void);
210
211 typedef const devcaps_t* (*devcaps_getter)(pfeature_mapping_t /*features*/,
212                                            const char* /*featureName*/);
213 typedef void (*deinitializer)(pfeature_mapping_t /*features*/);
214
215 typedef struct feature_mapping_interface_s
216 {
217     features_getter featGetter;  /* returns a list of api features */
218     devcaps_getter dcGetter;     /*
219                                   * for a given api feature returns a list of
220                                   * corresponding device capabilities
221                                   */
222
223     deinitializer release;       /* as memory ownership of features is
224                                   * transfered to callee you have to call
225                                   * the release function ptr on features
226                                   */
227 } feature_mapping_interface_t;
228
229 /*
230  * This is a structure describing a JS entity template (a class, an interface
231  * or function), object name and it's parent class name (parent_name). JS
232  * entity will be bind to a parent class name (parent_name.js_entity_name).
233  * @param parent_name - parent name (ie Widget.Device)
234  * @param object_name - object name (DeviceStatus)
235  * @param interface_name - interface name (e.g. Widget)
236  * @param js_class_template_getter_fun - js_class_template required to create
237  *          JS object
238  * @param js_class_consturctor_cb - constructor to call to when instance of
239  *          certain interface is created
240  * @param private_data private data for object creator if required (usually
241  *          NULL)
242  */
243 typedef struct js_entity_definition_s
244 {
245     const char *parent_name;
246     const char *object_name;
247     const char *interface_name;
248     js_class_template_getter js_class_template_getter_fun;
249     js_class_constructor_cb_t js_class_constructor_cb;
250     //class options may be null - default
251     class_definition_options_t* class_options;
252 } js_entity_definition_t;
253
254 typedef const js_entity_definition_t *js_entity_definition_ptr_t;
255
256 /**
257  * Plugin export names
258  */
259 #define PLUGIN_WIDGET_START_PROC        on_widget_start
260 #define PLUGIN_WIDGET_INIT_PROC         on_widget_init
261 #define PLUGIN_WIDGET_STOP_PROC         on_widget_stop
262 #define PLUGIN_FRAME_LOAD_PROC          on_frame_load
263 #define PLUGIN_FRAME_UNLOAD_PROC        on_frame_unload
264 #define PLUGIN_CLASS_MAP                class_map
265 #define PLUGIN_GET_CLASS_PROC_MAP       get_widget_class_map
266
267 #define PLUGIN_WIDGET_START_PROC_NAME   "on_widget_start"
268 #define PLUGIN_WIDGET_INIT_PROC_NAME    "on_widget_init"
269 #define PLUGIN_WIDGET_STOP_PROC_NAME    "on_widget_stop"
270 #define PLUGIN_FRAME_LOAD_PROC_NAME     "on_frame_load"
271 #define PLUGIN_FRAME_UNLOAD_PROC_NAME   "on_frame_unload"
272 #define PLUGIN_CLASS_MAP_NAME           "class_map"
273 #define PLUGIN_GET_CLASS_MAP_PROC_NAME  "get_widget_class_map"
274
275 /**
276  * Plugin export typedefs
277  */
278 typedef void (*on_widget_start_proc)(WidgetHandle widgetId);
279
280 typedef void (*on_widget_init_proc)(feature_mapping_interface_t *interface);
281
282 /**
283  * FIXME: Add documentation
284  */
285 typedef void (*on_widget_stop_proc)(WidgetHandle widgetId);
286
287 typedef void (*on_frame_load_proc)(java_script_context_t context);
288
289 typedef void (*on_frame_unload_proc)(java_script_context_t context);
290
291 typedef const js_entity_definition_t* (*get_widget_entity_map_proc)();
292
293 #endif // WRT_PLUGIN_EXPORT_H