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