tizen beta release
[profile/ivi/webkit-efl.git] / debian / libwebkit-engine-dev / usr / include / ewebkit-0 / ewk_js.h
1 /*
2     Copyright (C) 2011 ProFUSION embedded systems
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 /**
21  * @file    ewk_js.h
22  * @brief   Allows to export objects to JavaScript API.
23  */
24
25 #ifndef ewk_js_h
26 #define ewk_js_h
27
28 #include <Eina.h>
29 #include <Evas.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #define EWK_JS_CLASS_META_VERSION 0
36
37 typedef struct _Ewk_JS_Object Ewk_JS_Object;
38 typedef struct _Ewk_JS_Class_Meta Ewk_JS_Class_Meta;
39 typedef struct _Ewk_JS_Variant Ewk_JS_Variant;
40 typedef struct _Ewk_JS_Method Ewk_JS_Method;
41 typedef struct _Ewk_JS_Property Ewk_JS_Property;
42 typedef struct _Ewk_JS_Default Ewk_JS_Default;
43 typedef Eina_Bool (*Ewk_JS_Set_Cb)(Ewk_JS_Object *obj, const char *name, const Ewk_JS_Variant *value);
44 typedef Eina_Bool (*Ewk_JS_Get_Cb)(Ewk_JS_Object *obj, const char *name, Ewk_JS_Variant *value);
45 typedef Eina_Bool (*Ewk_JS_Del_Cb)(Ewk_JS_Object *obj, const char *name);
46 typedef Ewk_JS_Variant* (*Ewk_JS_Invoke_Cb)(Ewk_JS_Object *obj, Ewk_JS_Variant *args, int argCount);
47
48 typedef enum {
49     EWK_JS_VARIANT_VOID,
50     EWK_JS_VARIANT_NULL,
51     EWK_JS_VARIANT_BOOL,
52     EWK_JS_VARIANT_INT32,
53     EWK_JS_VARIANT_DOUBLE,
54     EWK_JS_VARIANT_STRING,
55     EWK_JS_VARIANT_OBJECT
56 } Ewk_JS_Variant_Type;
57
58 typedef enum {
59     EWK_JS_OBJECT_OBJECT,
60     EWK_JS_OBJECT_ARRAY,
61     EWK_JS_OBJECT_FUNCTION,
62     EWK_JS_OBJECT_INVALID
63 } Ewk_JS_Object_Type;
64
65 struct _Ewk_JS_Variant {
66     Ewk_JS_Variant_Type type;
67     union {
68         Eina_Bool b;
69         int i;
70         double d;
71         char *s;
72         Ewk_JS_Object *o;
73     } value;
74 };
75
76 struct _Ewk_JS_Method {
77     const char *name;
78     Ewk_JS_Invoke_Cb invoke;
79 };
80
81 struct _Ewk_JS_Property {
82     const char *name;
83     Ewk_JS_Set_Cb set;
84     Ewk_JS_Get_Cb get;
85     Ewk_JS_Del_Cb del;
86     Ewk_JS_Variant value;
87 };
88
89 struct _Ewk_JS_Default {
90     Ewk_JS_Set_Cb set;
91     Ewk_JS_Get_Cb get;
92     Ewk_JS_Del_Cb del;
93 };
94
95 struct _Ewk_JS_Class_Meta {
96     unsigned int version; // define
97     const Ewk_JS_Method *methods; // null terminated array
98     const Ewk_JS_Property *properties; // null terminated array
99     Ewk_JS_Default default_prop;
100 };
101
102 /**
103  * Gets Eina_Hash with object's properties.
104  *
105  * @param obj Object whose properties are wanted.
106  *
107  * @return object's properties.
108  */
109 EAPI Eina_Hash *ewk_js_object_properties_get(const Ewk_JS_Object *obj);
110
111 /**
112  * Gets name of the object.
113  *
114  * @param obj Object whose name is wanted.
115  *
116  * @return name of object.
117  */
118
119 EAPI const char *ewk_js_object_name_get(const Ewk_JS_Object *obj);
120
121 /**
122  * Release resources allocated by @a var.
123  *
124  * @param var @a Ewk_JS_Variant to be release
125  */
126 EAPI void ewk_js_variant_free(Ewk_JS_Variant *var);
127
128 /**
129  * Release resources allocated by @a var.
130  *
131  * @param var @a Ewk_JS_Variant to be release
132  * @param count @a size of array
133  */
134 EAPI void ewk_js_variant_array_free(Ewk_JS_Variant *var, int count);
135
136 /**
137  * Create a Ewk_JS_Object to be used in @a ewk_view_js_object_add. The Meta class's
138  * methods and properties are not modified but references to it are kept as long
139  * as the object created from it lives. All properties created here
140  * will be added to the object hash of properties. Properties using default_prop's
141  * get/set/del methods should also be added to the objects hash(see:
142  * @a ewk_js_object_properties_get). Methods must free the arguments they receive(see:
143  * @a ewk_js_variang_array_free).
144  *
145  *
146  * @param cls @a Ewk_JS_Class that describes the object to be created.
147  *
148  * @return The Ewk_JS_Object created.
149  */
150 EAPI Ewk_JS_Object *ewk_js_object_new(const Ewk_JS_Class_Meta *meta_cls);
151
152 /**
153  * Release resources allocated by @a obj.
154  *
155  * @param obj @a Ewk_JS_Object to be released.
156  */
157 EAPI void ewk_js_object_free(Ewk_JS_Object *obj);
158
159 /**
160  * Calls the function this object represents.
161  *
162  * @param obj Object that represents function.
163  * @param args Arguments to be passed to function.
164  * @param arg_count Number of arguments.
165  * @param result Return value of the invoked function.
166  *
167  * @return @c EINA_TRUE if function was executed, @c EINA_FALSE if function was not executed.
168  */
169 EAPI Eina_Bool ewk_js_object_invoke(Ewk_JS_Object *obj, Ewk_JS_Variant *args, int arg_count, Ewk_JS_Variant *result);
170
171 /**
172  * Returns the type this object represents.
173  *
174  * @param obj Object
175  *
176  * @return @c EWK_JS_OBJECT if it is an object, @c EWK_JS_ARRAY if it is an array and
177  * @c EWK_JS_FUNCTION if it is a function.
178  */
179 EAPI Ewk_JS_Object_Type ewk_js_object_type_get(Ewk_JS_Object *obj);
180
181 /**
182  * Sets the type this object represents.
183  *
184  * @param obj Object
185  * @param type Type
186  *
187  */
188 EAPI void ewk_js_object_type_set(Ewk_JS_Object *obj, Ewk_JS_Object_Type type);
189
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif // ewk_js_h