2 Copyright (C) 2011 ProFUSION embedded systems
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.
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.
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.
22 * @brief Allows to export objects to JavaScript API.
35 #define EWK_JS_CLASS_META_VERSION 0
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);
53 EWK_JS_VARIANT_DOUBLE,
54 EWK_JS_VARIANT_STRING,
56 } Ewk_JS_Variant_Type;
61 EWK_JS_OBJECT_FUNCTION,
65 struct _Ewk_JS_Variant {
66 Ewk_JS_Variant_Type type;
76 struct _Ewk_JS_Method {
78 Ewk_JS_Invoke_Cb invoke;
81 struct _Ewk_JS_Property {
89 struct _Ewk_JS_Default {
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;
103 * Gets Eina_Hash with object's properties.
105 * @param obj Object whose properties are wanted.
107 * @return object's properties.
109 EAPI Eina_Hash *ewk_js_object_properties_get(const Ewk_JS_Object *obj);
112 * Gets name of the object.
114 * @param obj Object whose name is wanted.
116 * @return name of object.
119 EAPI const char *ewk_js_object_name_get(const Ewk_JS_Object *obj);
122 * Release resources allocated by @a var.
124 * @param var @a Ewk_JS_Variant to be release
126 EAPI void ewk_js_variant_free(Ewk_JS_Variant *var);
129 * Release resources allocated by @a var.
131 * @param var @a Ewk_JS_Variant to be release
132 * @param count @a size of array
134 EAPI void ewk_js_variant_array_free(Ewk_JS_Variant *var, int count);
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).
146 * @param cls @a Ewk_JS_Class that describes the object to be created.
148 * @return The Ewk_JS_Object created.
150 EAPI Ewk_JS_Object *ewk_js_object_new(const Ewk_JS_Class_Meta *meta_cls);
153 * Release resources allocated by @a obj.
155 * @param obj @a Ewk_JS_Object to be released.
157 EAPI void ewk_js_object_free(Ewk_JS_Object *obj);
160 * Calls the function this object represents.
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.
167 * @return @c EINA_TRUE if function was executed, @c EINA_FALSE if function was not executed.
169 EAPI Eina_Bool ewk_js_object_invoke(Ewk_JS_Object *obj, Ewk_JS_Variant *args, int arg_count, Ewk_JS_Variant *result);
172 * Returns the type this object represents.
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.
179 EAPI Ewk_JS_Object_Type ewk_js_object_type_get(Ewk_JS_Object *obj);
182 * Sets the type this object represents.
188 EAPI void ewk_js_object_type_set(Ewk_JS_Object *obj, Ewk_JS_Object_Type type);