summaryrefslogtreecommitdiff
path: root/src/bindings/js/eldbus_js
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-09-01 15:08:49 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-12-23 23:59:40 -0200
commita3db1dddd3ba67c81118f7f2c0bc753dc8aac551 (patch)
tree233ee1be7bfa299bff560207135d20940c4e411f /src/bindings/js/eldbus_js
parent1a3cb45f1cc7fdf8d481879e6bd7349d9cb0b3fa (diff)
efl-js: JavaScript Eolian binding
To configure efl sources with bindings to use in nodejs add ––with-js=nodejs in configure flags to generate node files $ configure --with-js=nodejs and compile normally with: $ make $ make install To use, you have to require efl: efl = require('efl') The bindings is divided in two parts: generated and manually written. The generation uses the Eolian library for parsing Eo files and generate C++ code that is compiled against V8 interpreter library to create a efl.node file that can be required in a node.js instance. @feature
Diffstat (limited to 'src/bindings/js/eldbus_js')
-rw-r--r--src/bindings/js/eldbus_js/Eldbus_Js.hh48
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_connection.cc543
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_core.cc183
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_message.cc103
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_object_mapper.cc100
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_util.hh836
6 files changed, 1813 insertions, 0 deletions
diff --git a/src/bindings/js/eldbus_js/Eldbus_Js.hh b/src/bindings/js/eldbus_js/Eldbus_Js.hh
new file mode 100644
index 0000000000..00da9ca924
--- /dev/null
+++ b/src/bindings/js/eldbus_js/Eldbus_Js.hh
@@ -0,0 +1,48 @@
1
2#ifndef EFL_ELDBUS_JS_HH
3#define EFL_ELDBUS_JS_HH
4
5#include <Eina.hh>
6#include <Eina_Js.hh>
7
8#include <Eldbus.h>
9
10#ifdef EAPI
11# undef EAPI
12#endif
13
14#ifdef _WIN32
15# ifdef EFL_EINA_JS_BUILD
16# ifdef DLL_EXPORT
17# define EAPI __declspec(dllexport)
18# else
19# define EAPI
20# endif /* ! DLL_EXPORT */
21# else
22# define EAPI __declspec(dllimport)
23# endif /* ! EFL_ECORE_BUILD */
24#else
25# ifdef __GNUC__
26# if __GNUC__ >= 4
27# define EAPI __attribute__ ((visibility("default")))
28# else
29# define EAPI
30# endif
31# else
32# define EAPI
33# endif
34#endif /* ! _WIN32 */
35
36namespace efl { namespace eldbus { namespace js {
37
38EAPI void register_eldbus_connection(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
39EAPI void register_eldbus_core(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
40EAPI void register_eldbus_message(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
41EAPI void register_eldbus_object_mapper(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
42EAPI void register_eldbus(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
43
44} } }
45
46#include <eldbus_js_util.hh>
47
48#endif
diff --git a/src/bindings/js/eldbus_js/eldbus_js_connection.cc b/src/bindings/js/eldbus_js/eldbus_js_connection.cc
new file mode 100644
index 0000000000..c02dc8c600
--- /dev/null
+++ b/src/bindings/js/eldbus_js/eldbus_js_connection.cc
@@ -0,0 +1,543 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eldbus_Js.hh>
6
7namespace efl { namespace eldbus { namespace js {
8
9namespace {
10
11v8::Local<v8::Object> wrap_event_callback(Eldbus_Connection *conn,
12 Eldbus_Connection_Event_Type type,
13 Eldbus_Connection_Event_Cb cb,
14 void *cb_data, v8::Isolate *isolate)
15{
16 using v8::String;
17 using v8::Integer;
18 using v8::Value;
19 using v8::Object;
20 using v8::ObjectTemplate;
21 using v8::FunctionTemplate;
22
23 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
24 obj_tpl->SetInternalFieldCount(3);
25 auto ret = obj_tpl->NewInstance();
26
27 ret->Set(compatibility_new<String>(isolate, "_type"),
28 compatibility_new<Integer>(isolate, type));
29
30 compatibility_set_pointer_internal_field(ret, 0, conn);
31 compatibility_set_pointer_internal_field(ret, 1, (void*)(cb));
32 compatibility_set_pointer_internal_field(ret, 2, cb_data);
33
34 auto del = [](compatibility_callback_info_type info)
35 -> compatibility_return_type {
36 auto o = info.This();
37 auto isolate = info.GetIsolate();
38
39 auto conn
40 = (compatibility_get_pointer_internal_field<Eldbus_Connection*>
41 (o, 0));
42 auto cb
43 = (compatibility_get_pointer_internal_field
44 <Eldbus_Connection_Event_Cb>(o, 1));
45 auto cb_data
46 = (compatibility_get_pointer_internal_field
47 <efl::eina::js::global_ref<Value>*>(o, 2));
48 auto type
49 = (static_cast<Eldbus_Connection_Event_Type>
50 (o->Get(compatibility_new<String>(isolate, "_type"))
51 ->IntegerValue()));
52
53 eldbus_connection_event_callback_del(conn, type, cb, cb_data);
54
55 delete cb_data;
56 return compatibility_return();
57 };
58
59 ret->Set(compatibility_new<String>(isolate, "del"),
60 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
61
62 return ret;
63}
64
65Eldbus_Connection* extract_eldbus_connection(v8::Local<v8::Object> o)
66{
67 return compatibility_get_pointer_internal_field<Eldbus_Connection*>(o, 0);
68}
69
70void register_timeout_infinite(v8::Isolate *isolate,
71 v8::Handle<v8::Object> global,
72 v8::Handle<v8::String> name)
73{
74 using v8::Integer;
75 global->Set(name, compatibility_new<Integer>(isolate,
76 ELDBUS_TIMEOUT_INFINITE));
77}
78
79void register_connection_type_unknown(v8::Isolate *isolate,
80 v8::Handle<v8::Object> global,
81 v8::Handle<v8::String> name)
82{
83 using v8::Integer;
84 global->Set(name,
85 compatibility_new<Integer>(isolate,
86 ELDBUS_CONNECTION_TYPE_UNKNOWN));
87}
88
89void register_connection_type_session(v8::Isolate *isolate,
90 v8::Handle<v8::Object> global,
91 v8::Handle<v8::String> name)
92{
93 using v8::Integer;
94 global->Set(name,
95 compatibility_new<Integer>(isolate,
96 ELDBUS_CONNECTION_TYPE_SESSION));
97}
98
99void register_connection_type_system(v8::Isolate *isolate,
100 v8::Handle<v8::Object> global,
101 v8::Handle<v8::String> name)
102{
103 using v8::Integer;
104 global->Set(name,
105 compatibility_new<Integer>(isolate,
106 ELDBUS_CONNECTION_TYPE_SYSTEM));
107}
108
109void register_connection_type_starter(v8::Isolate *isolate,
110 v8::Handle<v8::Object> global,
111 v8::Handle<v8::String> name)
112{
113 using v8::Integer;
114 global->Set(name,
115 compatibility_new<Integer>(isolate,
116 ELDBUS_CONNECTION_TYPE_STARTER));
117}
118
119void register_connection_type_address(v8::Isolate *isolate,
120 v8::Handle<v8::Object> global,
121 v8::Handle<v8::String> name)
122{
123 using v8::Integer;
124 global->Set(name,
125 compatibility_new<Integer>(isolate,
126 ELDBUS_CONNECTION_TYPE_ADDRESS));
127}
128
129void register_connection_type_last(v8::Isolate *isolate,
130 v8::Handle<v8::Object> global,
131 v8::Handle<v8::String> name)
132{
133 using v8::Integer;
134 global->Set(name,
135 compatibility_new<Integer>(isolate,
136 ELDBUS_CONNECTION_TYPE_LAST));
137}
138
139void register_connection_event_del(v8::Isolate *isolate,
140 v8::Handle<v8::Object> global,
141 v8::Handle<v8::String> name)
142{
143 using v8::Integer;
144 global->Set(name, compatibility_new<Integer>(isolate,
145 ELDBUS_CONNECTION_EVENT_DEL));
146}
147
148void register_connection_event_disconnected(v8::Isolate *isolate,
149 v8::Handle<v8::Object> global,
150 v8::Handle<v8::String> name)
151{
152 using v8::Integer;
153 global->Set(name,
154 compatibility_new<Integer>
155 (isolate, ELDBUS_CONNECTION_EVENT_DISCONNECTED));
156}
157
158void register_connection_event_last(v8::Isolate *isolate,
159 v8::Handle<v8::Object> global,
160 v8::Handle<v8::String> name)
161{
162 using v8::Integer;
163 global->Set(name, compatibility_new<Integer>(isolate,
164 ELDBUS_CONNECTION_EVENT_LAST));
165}
166
167void register_connection_get(v8::Isolate *isolate,
168 v8::Handle<v8::Object> global,
169 v8::Handle<v8::String> name)
170{
171 using v8::String;
172 using v8::FunctionTemplate;
173
174 auto f = [](compatibility_callback_info_type args)
175 -> compatibility_return_type {
176 if (args.Length() != 1 || !args[0]->IsNumber())
177 return compatibility_return();
178
179 auto isolate = args.GetIsolate();
180 Eldbus_Connection_Type type;
181
182 switch (args[0]->IntegerValue()) {
183 case ELDBUS_CONNECTION_TYPE_UNKNOWN:
184 type = ELDBUS_CONNECTION_TYPE_UNKNOWN;
185 break;
186 case ELDBUS_CONNECTION_TYPE_SESSION:
187 type = ELDBUS_CONNECTION_TYPE_SESSION;
188 break;
189 case ELDBUS_CONNECTION_TYPE_SYSTEM:
190 type = ELDBUS_CONNECTION_TYPE_SYSTEM;
191 break;
192 case ELDBUS_CONNECTION_TYPE_STARTER:
193 type = ELDBUS_CONNECTION_TYPE_STARTER;
194 break;
195 case ELDBUS_CONNECTION_TYPE_ADDRESS:
196 type = ELDBUS_CONNECTION_TYPE_ADDRESS;
197 break;
198 case ELDBUS_CONNECTION_TYPE_LAST:
199 type = ELDBUS_CONNECTION_TYPE_LAST;
200 break;
201 default:
202 return compatibility_return();
203 }
204 auto ret = eldbus_connection_get(type);
205 return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
206 };
207
208 global->Set(name,
209 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
210}
211
212void register_private_connection_get(v8::Isolate *isolate,
213 v8::Handle<v8::Object> global,
214 v8::Handle<v8::String> name)
215{
216 using v8::String;
217 using v8::FunctionTemplate;
218
219 auto f = [](compatibility_callback_info_type args)
220 -> compatibility_return_type {
221 if (args.Length() != 1 || !args[0]->IsNumber())
222 return compatibility_return();
223
224 auto isolate = args.GetIsolate();
225 Eldbus_Connection_Type type;
226
227 switch (args[0]->IntegerValue()) {
228 case ELDBUS_CONNECTION_TYPE_UNKNOWN:
229 type = ELDBUS_CONNECTION_TYPE_UNKNOWN;
230 break;
231 case ELDBUS_CONNECTION_TYPE_SESSION:
232 type = ELDBUS_CONNECTION_TYPE_SESSION;
233 break;
234 case ELDBUS_CONNECTION_TYPE_SYSTEM:
235 type = ELDBUS_CONNECTION_TYPE_SYSTEM;
236 break;
237 case ELDBUS_CONNECTION_TYPE_STARTER:
238 type = ELDBUS_CONNECTION_TYPE_STARTER;
239 break;
240 case ELDBUS_CONNECTION_TYPE_ADDRESS:
241 type = ELDBUS_CONNECTION_TYPE_ADDRESS;
242 break;
243 case ELDBUS_CONNECTION_TYPE_LAST:
244 type = ELDBUS_CONNECTION_TYPE_LAST;
245 break;
246 default:
247 return compatibility_return();
248 }
249 auto ret = eldbus_private_connection_get(type);
250 return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
251 };
252
253 global->Set(name,
254 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
255}
256
257void register_address_connection_get(v8::Isolate *isolate,
258 v8::Handle<v8::Object> global,
259 v8::Handle<v8::String> name)
260
261{
262 using v8::String;
263 using v8::FunctionTemplate;
264
265 auto f = [](compatibility_callback_info_type args)
266 -> compatibility_return_type {
267 if (args.Length() != 1 || !args[0]->IsString())
268 return compatibility_return();
269
270 auto isolate = args.GetIsolate();
271
272 auto ret = eldbus_address_connection_get(*String::Utf8Value(args[0]));
273 return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
274 };
275
276 global->Set(name,
277 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
278}
279
280void register_private_address_connection_get(v8::Isolate *isolate,
281 v8::Handle<v8::Object> global,
282 v8::Handle<v8::String> name)
283
284{
285 using v8::String;
286 using v8::FunctionTemplate;
287
288 auto f = [](compatibility_callback_info_type args)
289 -> compatibility_return_type {
290 if (args.Length() != 1 || !args[0]->IsString())
291 return compatibility_return();
292
293 auto isolate = args.GetIsolate();
294
295 String::Utf8Value address(args[0]);
296
297 auto ret = eldbus_private_address_connection_get(*address);
298 return compatibility_return(wrap_eldbus_connection(ret, isolate), args);
299 };
300
301 global->Set(name,
302 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
303}
304
305}
306
307v8::Local<v8::Object> wrap_eldbus_connection(Eldbus_Connection *conn,
308 v8::Isolate *isolate)
309{
310 using v8::String;
311 using v8::Boolean;
312 using v8::Value;
313 using v8::Handle;
314 using v8::ObjectTemplate;
315 using v8::Function;
316 using v8::FunctionTemplate;
317 using std::unique_ptr;
318
319 typedef efl::eina::js::global_ref<Value> persistent_t;
320
321 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
322 obj_tpl->SetInternalFieldCount(1);
323 auto ret = obj_tpl->NewInstance();
324
325 auto event_callback_add = [](compatibility_callback_info_type info)
326 -> compatibility_return_type {
327 if (info.Length() != 2 || !info[0]->IsNumber()
328 || !info[1]->IsFunction()) {
329 return compatibility_return();
330 }
331
332 auto isolate = info.GetIsolate();
333 auto conn = extract_eldbus_connection(info.This());
334 Eldbus_Connection_Event_Type type;
335
336 switch (info[0]->IntegerValue()) {
337 case ELDBUS_CONNECTION_EVENT_DEL:
338 type = ELDBUS_CONNECTION_EVENT_DEL;
339 break;
340 case ELDBUS_CONNECTION_EVENT_DISCONNECTED:
341 type = ELDBUS_CONNECTION_EVENT_DISCONNECTED;
342 break;
343 case ELDBUS_CONNECTION_EVENT_LAST:
344 type = ELDBUS_CONNECTION_EVENT_LAST;
345 break;
346 default:
347 return compatibility_return();
348 }
349
350 unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
351
352 auto cb = [](void *data, Eldbus_Connection *conn,
353 void */*event_info*/) {
354 auto persistent = reinterpret_cast<persistent_t*>(data);
355 auto o = persistent->handle();
356
357 auto isolate = v8::Isolate::GetCurrent();
358
359 Handle<Value> args{wrap_eldbus_connection(conn, isolate)};
360
361 Function::Cast(*o)->Call(o->ToObject(), 1, &args);
362 };
363
364 eldbus_connection_event_callback_add(conn, type, cb, cb_data.get());
365 auto ret = wrap_event_callback(conn, type, cb, cb_data.release(),
366 isolate);
367 return compatibility_return(ret, info);
368 };
369
370 auto send = [](compatibility_callback_info_type info)
371 -> compatibility_return_type {
372 if (info.Length() != 3 || !info[0]->IsObject() || !info[1]->IsFunction()
373 || !info[2]->IsNumber()) {
374 return compatibility_return();
375 }
376
377 auto isolate = info.GetIsolate();
378 auto conn = extract_eldbus_connection(info.This());
379 auto msg
380 = (compatibility_get_pointer_internal_field<Eldbus_Message*>
381 (info[0]->ToObject(), 0));
382
383 unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
384
385 auto cb = [](void *data, const Eldbus_Message *msg,
386 Eldbus_Pending *pending) {
387 auto persistent = reinterpret_cast<persistent_t*>(data);
388 auto o = persistent->handle();
389
390 auto isolate = v8::Isolate::GetCurrent();
391
392 Handle<Value> args[2] = {
393 wrap_const_eldbus_msg(msg, isolate),
394 wrap_eldbus_pending(pending, persistent, isolate)
395 };
396
397 Function::Cast(*o)->Call(o->ToObject(), 2, args);
398
399 delete persistent;
400 };
401
402 auto ret = eldbus_connection_send(conn, msg, cb, cb_data.get(),
403 info[2]->NumberValue());
404 return compatibility_return(wrap_eldbus_pending(ret, cb_data.release(),
405 isolate),
406 info);
407 };
408
409 auto unique_name_get = [](compatibility_callback_info_type info)
410 -> compatibility_return_type {
411 if (info.Length() != 0)
412 return compatibility_return();
413
414 auto isolate = info.GetIsolate();
415 auto conn = extract_eldbus_connection(info.This());
416
417 auto ret = eldbus_connection_unique_name_get(conn);
418 return compatibility_return(compatibility_new<String>(isolate, ret),
419 info);
420 };
421
422 auto object_get = [](compatibility_callback_info_type info)
423 -> compatibility_return_type {
424 if (info.Length() != 2 || !info[0]->IsString() || !info[1]->IsString())
425 return compatibility_return();
426
427 auto isolate = info.GetIsolate();
428 auto conn = extract_eldbus_connection(info.This());
429
430 auto ret = eldbus_object_get(conn, *String::Utf8Value(info[0]),
431 *String::Utf8Value(info[1]));
432 return compatibility_return(wrap_eldbus_object(ret, isolate), info);
433 };
434
435 auto signal_handler_add = [](compatibility_callback_info_type info)
436 -> compatibility_return_type {
437 if (info.Length() != 5 || !info[0]->IsString() || !info[1]->IsString()
438 || !info[2]->IsString() || !info[3]->IsString()
439 || !info[4]->IsFunction()) {
440 return compatibility_return();
441 }
442
443 auto isolate = info.GetIsolate();
444 auto conn = extract_eldbus_connection(info.This());
445
446 unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[4]}};
447
448 auto cb = [](void *data, const Eldbus_Message *msg) {
449 auto persistent = reinterpret_cast<persistent_t*>(data);
450 auto o = persistent->handle();
451
452 auto isolate = v8::Isolate::GetCurrent();
453
454 Handle<Value> args{wrap_const_eldbus_msg(msg, isolate)};
455
456 Function::Cast(*o)->Call(o->ToObject(), 1, &args);
457 };
458
459 auto ret = eldbus_signal_handler_add(conn, *String::Utf8Value(info[0]),
460 *String::Utf8Value(info[1]),
461 *String::Utf8Value(info[2]),
462 *String::Utf8Value(info[3]),
463 cb, cb_data.get());
464 auto wrapped_ret = wrap_eldbus_signal_handler(ret, cb_data.release(),
465 isolate);
466 return compatibility_return(wrapped_ret, info);
467 };
468
469 ret->Set(compatibility_new<String>(isolate, "event_callback_add"),
470 compatibility_new<FunctionTemplate>(isolate, event_callback_add)
471 ->GetFunction());
472 ret->Set(compatibility_new<String>(isolate, "send"),
473 compatibility_new<FunctionTemplate>(isolate, send)->GetFunction());
474 ret->Set(compatibility_new<String>(isolate, "unique_name_get"),
475 compatibility_new<FunctionTemplate>(isolate, unique_name_get)
476 ->GetFunction());
477 ret->Set(compatibility_new<String>(isolate, "object_get"),
478 compatibility_new<FunctionTemplate>(isolate, object_get)
479 ->GetFunction());
480 ret->Set(compatibility_new<String>(isolate, "signal_handler_add"),
481 compatibility_new<FunctionTemplate>(isolate, signal_handler_add)
482 ->GetFunction());
483
484 compatibility_set_pointer_internal_field(ret, 0, conn);
485
486 return ret;
487}
488
489EAPI
490void register_eldbus_connection(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
491{
492 using v8::String;
493 register_timeout_infinite(isolate, exports,
494 compatibility_new<String>
495 (isolate, "ELDBUS_TIMEOUT_INFINITE"));
496 register_connection_type_unknown(isolate, exports,
497 compatibility_new<String>
498 (isolate, "ELDBUS_CONNECTION_TYPE_UNKNOWN"));
499 register_connection_type_session(isolate, exports,
500 compatibility_new<String>
501 (isolate, "ELDBUS_CONNECTION_TYPE_SESSION"));
502 register_connection_type_system(isolate, exports,
503 compatibility_new<String>
504 (isolate, "ELDBUS_CONNECTION_TYPE_SYSTEM"));
505 register_connection_type_starter(isolate, exports,
506 compatibility_new<String>
507 (isolate, "ELDBUS_CONNECTION_TYPE_STARTER"));
508 register_connection_type_address(isolate, exports,
509 compatibility_new<String>
510 (isolate, "ELDBUS_CONNECTION_TYPE_ADDRESS"));
511 register_connection_type_last(isolate, exports,
512 compatibility_new<String>
513 (isolate, "ELDBUS_CONNECTION_TYPE_LAST"));
514 register_connection_event_del(isolate, exports,
515 compatibility_new<String>
516 (isolate, "ELDBUS_CONNECTION_EVENT_DEL"));
517 register_connection_event_disconnected(isolate, exports,
518 compatibility_new<String>
519 (isolate,
520 "ELDBUS_CONNECTION_EVENT"
521 "_DISCONNECTED"));
522 register_connection_event_last(isolate, exports,
523 compatibility_new<String>
524 (isolate, "ELDBUS_CONNECTION_EVENT_LAST"));
525
526 register_connection_get(isolate, exports,
527 compatibility_new<String>
528 (isolate, "connection_get"));
529
530 register_private_connection_get(isolate, exports,
531 compatibility_new<String>
532 (isolate, "private_connection_get"));
533
534 register_address_connection_get(isolate, exports,
535 compatibility_new<String>
536 (isolate, "address_connection_get"));
537
538 register_private_address_connection_get(isolate, exports,
539 compatibility_new<String>
540 (isolate, "private_address_connection_get"));
541}
542
543} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/js/eldbus_js/eldbus_js_core.cc b/src/bindings/js/eldbus_js/eldbus_js_core.cc
new file mode 100644
index 0000000000..e9a8c3344d
--- /dev/null
+++ b/src/bindings/js/eldbus_js/eldbus_js_core.cc
@@ -0,0 +1,183 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eldbus_Js.hh>
6
7namespace efl { namespace eldbus { namespace js {
8
9namespace {
10
11void register_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
12 v8::Handle<v8::String> name)
13{
14 using v8::Integer;
15 using v8::FunctionTemplate;
16
17 auto init = [](compatibility_callback_info_type args)
18 -> compatibility_return_type {
19 if (args.Length() != 0)
20 return compatibility_return();
21
22 auto isolate = args.GetIsolate();
23 auto ret = eldbus_init();
24 return compatibility_return(compatibility_new<Integer>(isolate, ret),
25 args);
26 };
27
28 global->Set(name,
29 compatibility_new<FunctionTemplate>(isolate, init)
30 ->GetFunction());
31}
32
33void register_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
34 v8::Handle<v8::String> name)
35{
36 using v8::Integer;
37 using v8::FunctionTemplate;
38
39 auto shutdown = [](compatibility_callback_info_type args)
40 -> compatibility_return_type {
41 if (args.Length() != 0)
42 return compatibility_return();
43
44 auto isolate = args.GetIsolate();
45 auto ret = eldbus_shutdown();
46 return compatibility_return(compatibility_new<Integer>(isolate, ret),
47 args);
48 };
49
50 global->Set(name,
51 compatibility_new<FunctionTemplate>(isolate, shutdown)
52 ->GetFunction());
53}
54
55void register_fdo_bus(v8::Isolate *isolate, v8::Handle<v8::Object> global,
56 v8::Handle<v8::String> name)
57{
58 using v8::String;
59 global->Set(name, compatibility_new<String>(isolate, ELDBUS_FDO_BUS));
60}
61
62void register_fdo_path(v8::Isolate *isolate, v8::Handle<v8::Object> global,
63 v8::Handle<v8::String> name)
64{
65 using v8::String;
66 global->Set(name, compatibility_new<String>(isolate, ELDBUS_FDO_PATH));
67}
68
69void register_fdo_interface(v8::Isolate *isolate, v8::Handle<v8::Object> global,
70 v8::Handle<v8::String> name)
71{
72 using v8::String;
73 global->Set(name, compatibility_new<String>(isolate, ELDBUS_FDO_INTERFACE));
74}
75
76void register_fdo_interface_properties(v8::Isolate *isolate,
77 v8::Handle<v8::Object> global,
78 v8::Handle<v8::String> name)
79{
80 using v8::String;
81 global->Set(name,
82 compatibility_new<String>(isolate,
83 ELDBUS_FDO_INTERFACE_PROPERTIES));
84}
85
86void register_fdo_interface_object_manager(v8::Isolate *isolate,
87 v8::Handle<v8::Object> global,
88 v8::Handle<v8::String> name)
89{
90 using v8::String;
91 global->Set(name,
92 compatibility_new<String>(isolate,
93 ELDBUS_FDO_INTERFACE_OBJECT_MANAGER));
94}
95
96void register_fdo_interface_introspectable(v8::Isolate *isolate,
97 v8::Handle<v8::Object> global,
98 v8::Handle<v8::String> name)
99{
100 using v8::String;
101 global->Set(name,
102 compatibility_new<String>(isolate,
103 ELDBUS_FDO_INTERFACE_INTROSPECTABLE));
104}
105
106void register_fdo_inteface_peer(v8::Isolate *isolate,
107 v8::Handle<v8::Object> global,
108 v8::Handle<v8::String> name)
109{
110 using v8::String;
111 global->Set(name,
112 compatibility_new<String>(isolate, ELDBUS_FDO_INTEFACE_PEER));
113}
114
115void register_error_pending_canceled(v8::Isolate *isolate,
116 v8::Handle<v8::Object> global,
117 v8::Handle<v8::String> name)
118{
119 using v8::String;
120 global->Set(name,
121 compatibility_new<String>(isolate,
122 ELDBUS_ERROR_PENDING_CANCELED));
123}
124
125void register_error_pending_timeout(v8::Isolate *isolate,
126 v8::Handle<v8::Object> global,
127 v8::Handle<v8::String> name)
128{
129 using v8::String;
130 global->Set(name,
131 compatibility_new<String>(isolate,
132 ELDBUS_ERROR_PENDING_TIMEOUT));
133}
134
135}
136
137EAPI
138void register_eldbus_core(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
139{
140 using v8::String;
141 register_init(isolate, exports,
142 compatibility_new<String>(isolate, "eldbus_init"));
143 register_shutdown(isolate, exports,
144 compatibility_new<String>(isolate, "eldbus_shutdown"));
145 register_fdo_bus(isolate, exports,
146 compatibility_new<String>(isolate, "ELDBUS_FDO_BUS"));
147 register_fdo_path(isolate, exports,
148 compatibility_new<String>(isolate, "ELDBUS_FDO_PATH"));
149 register_fdo_interface(isolate, exports,
150 compatibility_new<String>(isolate,
151 "ELDBUS_FDO_INTERFACE"));
152 register_fdo_interface_properties(isolate, exports,
153 compatibility_new<String>
154 (isolate,
155 "ELDBUS_FDO_INTERFACE_PROPERTIES"));
156 register_fdo_interface_object_manager(isolate, exports,
157 compatibility_new<String>
158 (isolate, "ELDBUS_FDO_INTERFACE_OBJECT_MANAGER"));
159
160 register_fdo_interface_introspectable
161 (isolate, exports,
162 compatibility_new<String>(isolate,
163 "ELDBUS_FDO_INTERFACE_INTROSPECTABLE"));
164 register_fdo_inteface_peer(isolate, exports,
165 compatibility_new<String>
166 (isolate, "ELDBUS_FDO_INTEFACE_PEER"));
167 register_error_pending_canceled
168 (isolate, exports,
169 compatibility_new<String>(isolate, "ELDBUS_ERROR_PENDING_CANCELED"));
170 register_error_pending_timeout
171 (isolate, exports,
172 compatibility_new<String>(isolate, "ELDBUS_ERROR_PENDING_TIMEOUT"));
173}
174
175EAPI void register_eldbus(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
176{
177 register_eldbus_connection(isolate, exports);
178 register_eldbus_core(isolate, exports);
179 register_eldbus_message(isolate, exports);
180 register_eldbus_object_mapper(isolate, exports);
181}
182
183} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/js/eldbus_js/eldbus_js_message.cc b/src/bindings/js/eldbus_js/eldbus_js_message.cc
new file mode 100644
index 0000000000..f9cfa40b76
--- /dev/null
+++ b/src/bindings/js/eldbus_js/eldbus_js_message.cc
@@ -0,0 +1,103 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eldbus_Js.hh>
6
7namespace efl { namespace eldbus { namespace js {
8
9namespace {
10
11void register_message_method_call_new(v8::Isolate *isolate,
12 v8::Handle<v8::Object> global,
13 v8::Handle<v8::String> name)
14{
15 using v8::String;
16 using v8::FunctionTemplate;
17
18 auto f = [](compatibility_callback_info_type args)
19 -> compatibility_return_type {
20 if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString()
21 || !args[2]->IsString() || !args[3]->IsString()) {
22 return compatibility_return();
23 }
24
25 auto isolate = args.GetIsolate();
26 auto ret = eldbus_message_method_call_new(*String::Utf8Value(args[0]),
27 *String::Utf8Value(args[1]),
28 *String::Utf8Value(args[2]),
29 *String::Utf8Value(args[3]));
30 return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
31 };
32
33 global->Set(name,
34 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
35}
36
37void register_message_error_new(v8::Isolate *isolate,
38 v8::Handle<v8::Object> global,
39 v8::Handle<v8::String> name)
40{
41 using v8::String;
42 using v8::FunctionTemplate;
43
44 auto f = [](compatibility_callback_info_type args)
45 -> compatibility_return_type {
46 if (args.Length() != 3 || !args[0]->IsObject() || !args[1]->IsString()
47 || !args[2]->IsString()) {
48 return compatibility_return();
49 }
50
51 auto isolate = args.GetIsolate();
52 auto ret = eldbus_message_error_new(extract_eldbus_msg(args[0]
53 ->ToObject()),
54 *String::Utf8Value(args[1]),
55 *String::Utf8Value(args[2]));
56 return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
57 };
58
59 global->Set(name,
60 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
61}
62
63void register_message_method_return_new(v8::Isolate *isolate,
64 v8::Handle<v8::Object> global,
65 v8::Handle<v8::String> name)
66{
67 using v8::String;
68 using v8::FunctionTemplate;
69
70 auto f = [](compatibility_callback_info_type args)
71 -> compatibility_return_type {
72 if (args.Length() != 1 || !args[0]->IsObject())
73 return compatibility_return();
74
75 auto isolate = args.GetIsolate();
76 auto eldbus_msg = extract_eldbus_msg(args[0]->ToObject());
77 auto ret = eldbus_message_method_return_new(eldbus_msg);
78 return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
79 };
80
81 global->Set(name,
82 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
83}
84
85}
86
87EAPI
88void register_eldbus_message(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
89{
90 register_message_method_call_new
91 (isolate, exports, compatibility_new<v8::String>
92 (isolate, "message_method_call_new"));
93
94 register_message_error_new
95 (isolate, exports, compatibility_new<v8::String>
96 (isolate, "message_error_new"));
97
98 register_message_method_return_new
99 (isolate, exports, compatibility_new<v8::String>
100 (isolate, "message_method_return_new"));
101}
102
103} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/js/eldbus_js/eldbus_js_object_mapper.cc b/src/bindings/js/eldbus_js/eldbus_js_object_mapper.cc
new file mode 100644
index 0000000000..955ce80948
--- /dev/null
+++ b/src/bindings/js/eldbus_js/eldbus_js_object_mapper.cc
@@ -0,0 +1,100 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eldbus_Js.hh>
6
7namespace efl { namespace eldbus { namespace js {
8
9namespace {
10
11void register_object_event_iface_added(v8::Isolate *isolate,
12 v8::Handle<v8::Object> global,
13 v8::Handle<v8::String> name)
14{
15 using v8::Integer;
16 global->Set(name,
17 compatibility_new<Integer>(isolate,
18 ELDBUS_OBJECT_EVENT_IFACE_ADDED));
19}
20
21void register_object_event_iface_removed(v8::Isolate *isolate,
22 v8::Handle<v8::Object> global,
23 v8::Handle<v8::String> name)
24{
25 using v8::Integer;
26 global->Set(name,
27 compatibility_new<Integer>(isolate,
28 ELDBUS_OBJECT_EVENT_IFACE_REMOVED));
29}
30
31void register_object_event_property_changed(v8::Isolate *isolate,
32 v8::Handle<v8::Object> global,
33 v8::Handle<v8::String> name)
34{
35 using v8::Integer;
36 global->Set(name,
37 compatibility_new<Integer>
38 (isolate, ELDBUS_OBJECT_EVENT_PROPERTY_CHANGED));
39}
40
41void register_object_event_property_removed(v8::Isolate *isolate,
42 v8::Handle<v8::Object> global,
43 v8::Handle<v8::String> name)
44{
45 using v8::Integer;
46 global->Set(name,
47 compatibility_new<Integer>
48 (isolate, ELDBUS_OBJECT_EVENT_PROPERTY_REMOVED));
49}
50
51void register_object_event_del(v8::Isolate *isolate,
52 v8::Handle<v8::Object> global,
53 v8::Handle<v8::String> name)
54{
55 using v8::Integer;
56 global->Set(name,
57 compatibility_new<Integer>(isolate, ELDBUS_OBJECT_EVENT_DEL));
58}
59
60void register_object_event_last(v8::Isolate *isolate,
61 v8::Handle<v8::Object> global,
62 v8::Handle<v8::String> name)
63{
64 using v8::Integer;
65 global->Set(name,
66 compatibility_new<Integer>(isolate, ELDBUS_OBJECT_EVENT_LAST));
67}
68
69}
70
71EAPI
72void register_eldbus_object_mapper(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
73{
74 register_object_event_iface_added
75 (isolate, exports, compatibility_new<v8::String>
76 (isolate, "object_event_iface_added"));
77
78 register_object_event_iface_removed
79 (isolate, exports, compatibility_new<v8::String>
80 (isolate, "object_event_iface_removed"));
81
82 register_object_event_property_changed
83 (isolate, exports, compatibility_new<v8::String>
84 (isolate, "object_event_property_changed"));
85
86 register_object_event_property_removed
87 (isolate, exports, compatibility_new<v8::String>
88 (isolate, "object_event_property_removed"));
89
90 register_object_event_del
91 (isolate, exports, compatibility_new<v8::String>
92 (isolate, "object_event_del"));
93
94 register_object_event_last
95 (isolate, exports, compatibility_new<v8::String>
96 (isolate, "object_event_last"));
97}
98
99
100} } } // namespace efl { namespace eldbus { namespace js {
diff --git a/src/bindings/js/eldbus_js/eldbus_js_util.hh b/src/bindings/js/eldbus_js/eldbus_js_util.hh
new file mode 100644
index 0000000000..c5af5752be
--- /dev/null
+++ b/src/bindings/js/eldbus_js/eldbus_js_util.hh
@@ -0,0 +1,836 @@
1#ifndef ELDBUS_JS_UTIL_HH
2#define ELDBUS_JS_UTIL_HH
3
4namespace efl { namespace eldbus { namespace js {
5
6using eina::js::compatibility_get_pointer_internal_field;
7using eina::js::compatibility_set_pointer_internal_field;
8using eina::js::compatibility_new;
9using eina::js::compatibility_callback_info_type;
10using eina::js::compatibility_return_type;
11using eina::js::compatibility_return;
12
13v8::Local<v8::Object> wrap_eldbus_connection(Eldbus_Connection *conn,
14 v8::Isolate *isolate);
15
16inline
17const Eldbus_Message *extract_const_eldbus_msg(v8::Local<v8::Object> o)
18{
19 return compatibility_get_pointer_internal_field<Eldbus_Message*>(o, 0);
20}
21
22inline
23v8::Local<v8::Object> wrap_const_eldbus_msg(const Eldbus_Message *msg,
24 v8::Isolate *isolate)
25{
26 using v8::String;
27 using v8::Object;
28 using v8::Boolean;
29 using v8::ObjectTemplate;
30 using v8::FunctionTemplate;
31
32 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
33 obj_tpl->SetInternalFieldCount(1);
34 auto ret = obj_tpl->NewInstance();
35
36 auto path_get = [](compatibility_callback_info_type info)
37 -> compatibility_return_type {
38 if (info.Length() != 0)
39 return compatibility_return();
40
41 auto isolate = info.GetIsolate();
42 auto msg = extract_const_eldbus_msg(info.This());
43
44 auto ret = eldbus_message_path_get(msg);
45 return compatibility_return(compatibility_new<String>(isolate, ret),
46 info);
47 };
48
49 auto interface_get = [](compatibility_callback_info_type info)
50 -> compatibility_return_type {
51 if (info.Length() != 0)
52 return compatibility_return();
53
54 auto isolate = info.GetIsolate();
55 auto msg = extract_const_eldbus_msg(info.This());
56
57 auto ret = eldbus_message_interface_get(msg);
58 return compatibility_return(compatibility_new<String>(isolate, ret),
59 info);
60 };
61
62 auto member_get = [](compatibility_callback_info_type info)
63 -> compatibility_return_type {
64 if (info.Length() != 0)
65 return compatibility_return();
66
67 auto isolate = info.GetIsolate();
68 auto msg = extract_const_eldbus_msg(info.This());
69
70 auto ret = eldbus_message_member_get(msg);
71 return compatibility_return(compatibility_new<String>(isolate, ret),
72 info);
73 };
74
75 auto destination_get = [](compatibility_callback_info_type info)
76 -> compatibility_return_type {
77 if (info.Length() != 0)
78 return compatibility_return();
79
80 auto isolate = info.GetIsolate();
81 auto msg = extract_const_eldbus_msg(info.This());
82
83 auto ret = eldbus_message_destination_get(msg);
84 return compatibility_return(compatibility_new<String>(isolate, ret),
85 info);
86 };
87
88 auto sender_get = [](compatibility_callback_info_type info)
89 -> compatibility_return_type {
90 if (info.Length() != 0)
91 return compatibility_return();
92
93 auto isolate = info.GetIsolate();
94 auto msg = extract_const_eldbus_msg(info.This());
95
96 auto ret = eldbus_message_sender_get(msg);
97 return compatibility_return(compatibility_new<String>(isolate, ret),
98 info);
99 };
100
101 auto signature_get = [](compatibility_callback_info_type info)
102 -> compatibility_return_type {
103 if (info.Length() != 0)
104 return compatibility_return();
105
106 auto isolate = info.GetIsolate();
107 auto msg = extract_const_eldbus_msg(info.This());
108
109 auto ret = eldbus_message_signature_get(msg);
110 return compatibility_return(compatibility_new<String>(isolate, ret),
111 info);
112 };
113
114 auto error_get = [](compatibility_callback_info_type info)
115 -> compatibility_return_type {
116 if (info.Length() != 0)
117 return compatibility_return();
118
119 auto isolate = info.GetIsolate();
120 auto msg = extract_const_eldbus_msg(info.This());
121 const char *name = NULL;
122 const char *text = NULL;
123 auto ret = compatibility_new<Object>(isolate);
124
125 auto bret = eldbus_message_error_get(msg, &name, &text);
126 ret->Set(compatibility_new<String>(isolate, "ok"),
127 compatibility_new<Boolean>(isolate, bret));
128
129 if (bret) {
130 ret->Set(compatibility_new<String>(isolate, "name"),
131 compatibility_new<String>(isolate, name));
132 ret->Set(compatibility_new<String>(isolate, "text"),
133 compatibility_new<String>(isolate, text));
134 }
135
136 return compatibility_return(ret, info);
137 };
138
139 ret->Set(compatibility_new<String>(isolate, "path_get"),
140 compatibility_new<FunctionTemplate>(isolate, path_get)
141 ->GetFunction());
142 ret->Set(compatibility_new<String>(isolate, "interface_get"),
143 compatibility_new<FunctionTemplate>(isolate, interface_get)
144 ->GetFunction());
145 ret->Set(compatibility_new<String>(isolate, "member_get"),
146 compatibility_new<FunctionTemplate>(isolate, member_get)
147 ->GetFunction());
148 ret->Set(compatibility_new<String>(isolate, "destination_get"),
149 compatibility_new<FunctionTemplate>(isolate, destination_get)
150 ->GetFunction());
151 ret->Set(compatibility_new<String>(isolate, "sender_get"),
152 compatibility_new<FunctionTemplate>(isolate, sender_get)
153 ->GetFunction());
154 ret->Set(compatibility_new<String>(isolate, "signature_get"),
155 compatibility_new<FunctionTemplate>(isolate, signature_get)
156 ->GetFunction());
157 ret->Set(compatibility_new<String>(isolate, "error_get"),
158 compatibility_new<FunctionTemplate>(isolate, error_get)
159 ->GetFunction());
160
161 compatibility_set_pointer_internal_field(ret, 0,
162 const_cast<Eldbus_Message*>(msg));
163
164 return ret;
165}
166
167inline Eldbus_Message *extract_eldbus_msg(v8::Local<v8::Object> o)
168{
169 return compatibility_get_pointer_internal_field<Eldbus_Message*>(o, 0);
170}
171
172inline
173v8::Local<v8::Object> wrap_eldbus_msg(Eldbus_Message *msg, v8::Isolate *isolate)
174{
175 using v8::String;
176 using v8::FunctionTemplate;
177
178 auto ret = wrap_const_eldbus_msg(msg, isolate);
179
180 auto ref = [](compatibility_callback_info_type info)
181 -> compatibility_return_type {
182 if (info.Length() != 0)
183 return compatibility_return();
184
185 auto msg = extract_eldbus_msg(info.This());
186
187 eldbus_message_ref(msg);
188
189 return compatibility_return();
190 };
191
192 auto unref = [](compatibility_callback_info_type info)
193 -> compatibility_return_type {
194 if (info.Length() != 0)
195 return compatibility_return();
196
197 auto msg = extract_eldbus_msg(info.This());
198
199 eldbus_message_unref(msg);
200
201 return compatibility_return();
202 };
203
204 ret->Set(compatibility_new<String>(isolate, "ref"),
205 compatibility_new<FunctionTemplate>(isolate, ref)->GetFunction());
206 ret->Set(compatibility_new<String>(isolate, "unref"),
207 compatibility_new<FunctionTemplate>(isolate, unref)
208 ->GetFunction());
209
210 return ret;
211}
212
213inline
214v8::Local<v8::Object> wrap_eldbus_pending(Eldbus_Pending *pending,
215 efl::eina::js::global_ref<v8::Value>*
216 persistent,
217 v8::Isolate *isolate)
218{
219 using v8::String;
220 using v8::Object;
221 using v8::Boolean;
222 using v8::ObjectTemplate;
223 using v8::FunctionTemplate;
224
225 typedef decltype(persistent) persistent_ptr_t;
226
227 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
228 obj_tpl->SetInternalFieldCount(2);
229 auto ret = obj_tpl->NewInstance();
230
231 auto cancel = [](compatibility_callback_info_type info)
232 -> compatibility_return_type {
233 if (info.Length() != 0)
234 return compatibility_return();
235
236 auto o = info.This();
237 auto pending
238 = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
239 auto persistent
240 = compatibility_get_pointer_internal_field<persistent_ptr_t>(o, 1);
241
242 eldbus_pending_cancel(pending);
243 delete persistent;
244 return compatibility_return();
245 };
246
247 auto destination_get = [](compatibility_callback_info_type info)
248 -> compatibility_return_type {
249 if (info.Length() != 0)
250 return compatibility_return();
251
252 auto isolate = info.GetIsolate();
253 auto o = info.This();
254 auto pending
255 = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
256
257 auto ret = eldbus_pending_destination_get(pending);
258 return compatibility_return(compatibility_new<String>(isolate, ret),
259 info);
260 };
261
262 auto path_get = [](compatibility_callback_info_type info)
263 -> compatibility_return_type {
264 if (info.Length() != 0)
265 return compatibility_return();
266
267 auto isolate = info.GetIsolate();
268 auto o = info.This();
269 auto pending
270 = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
271
272 auto ret = eldbus_pending_path_get(pending);
273 return compatibility_return(compatibility_new<String>(isolate, ret),
274 info);
275 };
276
277 auto interface_get = [](compatibility_callback_info_type info)
278 -> compatibility_return_type {
279 if (info.Length() != 0)
280 return compatibility_return();
281
282 auto isolate = info.GetIsolate();
283 auto o = info.This();
284 auto pending
285 = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
286
287 auto ret = eldbus_pending_interface_get(pending);
288 return compatibility_return(compatibility_new<String>(isolate, ret),
289 info);
290 };
291
292 auto method_get = [](compatibility_callback_info_type info)
293 -> compatibility_return_type {
294 if (info.Length() != 0)
295 return compatibility_return();
296
297 auto isolate = info.GetIsolate();
298 auto o = info.This();
299 auto pending
300 = compatibility_get_pointer_internal_field<Eldbus_Pending*>(o, 0);
301
302 auto ret = eldbus_pending_method_get(pending);
303 return compatibility_return(compatibility_new<String>(isolate, ret),
304 info);
305 };
306
307 ret->Set(compatibility_new<String>(isolate, "cancel"),
308 compatibility_new<FunctionTemplate>(isolate, cancel)
309 ->GetFunction());
310 ret->Set(compatibility_new<String>(isolate, "destination_get"),
311 compatibility_new<FunctionTemplate>(isolate, destination_get)
312 ->GetFunction());
313 ret->Set(compatibility_new<String>(isolate, "path_get"),
314 compatibility_new<FunctionTemplate>(isolate, path_get)
315 ->GetFunction());
316 ret->Set(compatibility_new<String>(isolate, "interface_get"),
317 compatibility_new<FunctionTemplate>(isolate, interface_get)
318 ->GetFunction());
319 ret->Set(compatibility_new<String>(isolate, "method_get"),
320 compatibility_new<FunctionTemplate>(isolate, method_get)
321 ->GetFunction());
322
323 compatibility_set_pointer_internal_field(ret, 0, pending);
324 compatibility_set_pointer_internal_field(ret, 1, persistent);
325
326 return ret;
327}
328
329inline
330v8::Local<v8::Object>
331wrap_eldbus_signal_handler(Eldbus_Signal_Handler *handler,
332 efl::eina::js::global_ref<v8::Value> *persistent,
333 v8::Isolate *isolate)
334{
335 using v8::String;
336 using v8::Object;
337 using v8::Boolean;
338 using v8::ObjectTemplate;
339 using v8::FunctionTemplate;
340
341 typedef decltype(persistent) persistent_ptr_t;
342
343 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
344 obj_tpl->SetInternalFieldCount(2);
345 auto ret = obj_tpl->NewInstance();
346
347 auto ref = [](compatibility_callback_info_type info)
348 -> compatibility_return_type {
349 if (info.Length() != 0)
350 return compatibility_return();
351
352 auto o = info.This();
353 auto handler
354 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
355 (o, 0));
356
357 eldbus_signal_handler_ref(handler);
358 return compatibility_return();
359 };
360
361 auto unref = [](compatibility_callback_info_type info)
362 -> compatibility_return_type {
363 if (info.Length() != 0)
364 return compatibility_return();
365
366 auto o = info.This();
367 auto handler
368 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
369 (o, 0));
370
371 eldbus_signal_handler_unref(handler);
372 return compatibility_return();
373 };
374
375 auto del = [](compatibility_callback_info_type info)
376 -> compatibility_return_type {
377 if (info.Length() != 0)
378 return compatibility_return();
379
380 auto o = info.This();
381 auto handler
382 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
383 (o, 0));
384 auto persistent
385 = compatibility_get_pointer_internal_field<persistent_ptr_t>(o, 1);
386
387 eldbus_signal_handler_del(handler);
388 delete persistent;
389 return compatibility_return();
390 };
391
392 auto sender_get = [](compatibility_callback_info_type info)
393 -> compatibility_return_type {
394 if (info.Length() != 0)
395 return compatibility_return();
396
397 auto isolate = info.GetIsolate();
398 auto o = info.This();
399 auto handler
400 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
401 (o, 0));
402
403 auto ret = eldbus_signal_handler_sender_get(handler);
404 return compatibility_return(compatibility_new<String>(isolate, ret),
405 info);
406 };
407
408 auto path_get = [](compatibility_callback_info_type info)
409 -> compatibility_return_type {
410 if (info.Length() != 0)
411 return compatibility_return();
412
413 auto isolate = info.GetIsolate();
414 auto o = info.This();
415 auto handler
416 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
417 (o, 0));
418
419 auto ret = eldbus_signal_handler_path_get(handler);
420 return compatibility_return(compatibility_new<String>(isolate, ret),
421 info);
422 };
423
424 auto interface_get = [](compatibility_callback_info_type info)
425 -> compatibility_return_type {
426 if (info.Length() != 0)
427 return compatibility_return();
428
429 auto isolate = info.GetIsolate();
430 auto o = info.This();
431 auto handler
432 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
433 (o, 0));
434
435 auto ret = eldbus_signal_handler_interface_get(handler);
436 return compatibility_return(compatibility_new<String>(isolate, ret),
437 info);
438 };
439
440 auto member_get = [](compatibility_callback_info_type info)
441 -> compatibility_return_type {
442 if (info.Length() != 0)
443 return compatibility_return();
444
445 auto isolate = info.GetIsolate();
446 auto o = info.This();
447 auto handler
448 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
449 (o, 0));
450
451 auto ret = eldbus_signal_handler_member_get(handler);
452 return compatibility_return(compatibility_new<String>(isolate, ret),
453 info);
454 };
455
456 auto match_get = [](compatibility_callback_info_type info)
457 -> compatibility_return_type {
458 if (info.Length() != 0)
459 return compatibility_return();
460
461 auto isolate = info.GetIsolate();
462 auto o = info.This();
463 auto handler
464 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
465 (o, 0));
466
467 auto ret = eldbus_signal_handler_match_get(handler);
468 return compatibility_return(compatibility_new<String>(isolate, ret),
469 info);
470 };
471
472 auto connection_get = [](compatibility_callback_info_type info)
473 -> compatibility_return_type {
474 if (info.Length() != 0)
475 return compatibility_return();
476
477 auto isolate = info.GetIsolate();
478 auto o = info.This();
479 auto handler
480 = (compatibility_get_pointer_internal_field<Eldbus_Signal_Handler*>
481 (o, 0));
482
483 auto ret = eldbus_signal_handler_connection_get(handler);
484 return compatibility_return(wrap_eldbus_connection(ret, isolate), info);
485 };
486
487 ret->Set(compatibility_new<String>(isolate, "ref"),
488 compatibility_new<FunctionTemplate>(isolate, ref)->GetFunction());
489 ret->Set(compatibility_new<String>(isolate, "unref"),
490 compatibility_new<FunctionTemplate>(isolate, unref)
491 ->GetFunction());
492 ret->Set(compatibility_new<String>(isolate, "del"),
493 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
494 ret->Set(compatibility_new<String>(isolate, "sender_get"),
495 compatibility_new<FunctionTemplate>(isolate, sender_get)
496 ->GetFunction());
497 ret->Set(compatibility_new<String>(isolate, "path_get"),
498 compatibility_new<FunctionTemplate>(isolate, path_get)
499 ->GetFunction());
500 ret->Set(compatibility_new<String>(isolate, "interface_get"),
501 compatibility_new<FunctionTemplate>(isolate, interface_get)
502 ->GetFunction());
503 ret->Set(compatibility_new<String>(isolate, "member_get"),
504 compatibility_new<FunctionTemplate>(isolate, member_get)
505 ->GetFunction());
506 ret->Set(compatibility_new<String>(isolate, "match_get"),
507 compatibility_new<FunctionTemplate>(isolate, match_get)
508 ->GetFunction());
509 ret->Set(compatibility_new<String>(isolate, "connection_get"),
510 compatibility_new<FunctionTemplate>(isolate, connection_get)
511 ->GetFunction());
512
513 compatibility_set_pointer_internal_field(ret, 0, handler);
514 compatibility_set_pointer_internal_field(ret, 1, persistent);
515
516 return ret;
517}
518
519static
520v8::Local<v8::Object> wrap_object_event_callback(Eldbus_Object *obj,
521 Eldbus_Object_Event_Type type,
522 Eldbus_Object_Event_Cb cb,
523 void *cb_data,
524 v8::Isolate *isolate)
525{
526 using v8::String;
527 using v8::Integer;
528 using v8::Value;
529 using v8::Object;
530 using v8::ObjectTemplate;
531 using v8::FunctionTemplate;
532
533 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
534 obj_tpl->SetInternalFieldCount(3);
535 auto ret = obj_tpl->NewInstance();
536
537 ret->Set(compatibility_new<String>(isolate, "_type"),
538 compatibility_new<Integer>(isolate, type));
539
540 compatibility_set_pointer_internal_field(ret, 0, obj);
541 compatibility_set_pointer_internal_field(ret, 1, (void*)(cb));
542 compatibility_set_pointer_internal_field(ret, 2, cb_data);
543
544 auto del = [](compatibility_callback_info_type info)
545 -> compatibility_return_type {
546 auto o = info.This();
547 auto isolate = info.GetIsolate();
548
549 auto obj
550 = (compatibility_get_pointer_internal_field<Eldbus_Object*>
551 (o, 0));
552 auto cb
553 = (compatibility_get_pointer_internal_field
554 <Eldbus_Object_Event_Cb>(o, 1));
555 auto cb_data
556 = (compatibility_get_pointer_internal_field
557 <efl::eina::js::global_ref<Value>*>(o, 2));
558 auto type
559 = (static_cast<Eldbus_Object_Event_Type>
560 (o->Get(compatibility_new<String>(isolate, "_type"))
561 ->IntegerValue()));
562
563 eldbus_object_event_callback_del(obj, type, cb, cb_data);
564
565 delete cb_data;
566 return compatibility_return();
567 };
568
569 ret->Set(compatibility_new<String>(isolate, "del"),
570 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
571
572 return ret;
573}
574
575inline
576Eldbus_Object *extract_eldbus_object(v8::Local<v8::Object> o)
577{
578 return compatibility_get_pointer_internal_field<Eldbus_Object*>(o, 0);
579}
580
581inline
582v8::Local<v8::Object> wrap_eldbus_object(Eldbus_Object *object,
583 v8::Isolate *isolate)
584{
585 using v8::String;
586 using v8::Value;
587 using v8::Handle;
588 using v8::Function;
589 using v8::ObjectTemplate;
590 using v8::FunctionTemplate;
591 using std::unique_ptr;
592
593 typedef efl::eina::js::global_ref<Value> persistent_t;
594
595 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
596 obj_tpl->SetInternalFieldCount(1);
597 auto ret = obj_tpl->NewInstance();
598
599 auto ref = [](compatibility_callback_info_type info)
600 -> compatibility_return_type {
601 if (info.Length() != 0)
602 return compatibility_return();
603
604 auto object = extract_eldbus_object(info.This());
605
606 eldbus_object_ref(object);
607 return compatibility_return();
608 };
609
610 auto unref = [](compatibility_callback_info_type info)
611 -> compatibility_return_type {
612 if (info.Length() != 0)
613 return compatibility_return();
614
615 auto object = extract_eldbus_object(info.This());
616
617 eldbus_object_unref(object);
618 return compatibility_return();
619 };
620
621 auto event_callback_add = [](compatibility_callback_info_type info)
622 -> compatibility_return_type {
623 if (info.Length() != 2 || !info[0]->IsNumber()
624 || !info[1]->IsFunction()) {
625 return compatibility_return();
626 }
627
628 Eldbus_Object_Event_Type type;
629
630 switch (info[0]->IntegerValue()) {
631 case ELDBUS_OBJECT_EVENT_IFACE_ADDED:
632 type = ELDBUS_OBJECT_EVENT_IFACE_ADDED;
633 break;
634 case ELDBUS_OBJECT_EVENT_IFACE_REMOVED:
635 type = ELDBUS_OBJECT_EVENT_IFACE_REMOVED;
636 break;
637 case ELDBUS_OBJECT_EVENT_PROPERTY_CHANGED:
638 type = ELDBUS_OBJECT_EVENT_PROPERTY_CHANGED;
639 break;
640 case ELDBUS_OBJECT_EVENT_PROPERTY_REMOVED:
641 type = ELDBUS_OBJECT_EVENT_PROPERTY_REMOVED;
642 break;
643 case ELDBUS_OBJECT_EVENT_DEL:
644 type = ELDBUS_OBJECT_EVENT_DEL;
645 break;
646 case ELDBUS_OBJECT_EVENT_LAST:
647 type = ELDBUS_OBJECT_EVENT_LAST;
648 break;
649 default:
650 return compatibility_return();
651 }
652
653 auto isolate = info.GetIsolate();
654
655 unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
656
657 auto cb = [](void *data, Eldbus_Object *obj, void */*event_info*/) {
658 auto persistent = reinterpret_cast<persistent_t*>(data);
659 auto o = persistent->handle();
660
661 auto isolate = v8::Isolate::GetCurrent();
662
663 Handle<Value> args{wrap_eldbus_object(obj, isolate)};
664
665 Function::Cast(*o)->Call(o->ToObject(), 1, &args);
666 };
667
668 auto object = extract_eldbus_object(info.This());
669
670 eldbus_object_event_callback_add(object, type, cb, cb_data.get());
671 auto ret = wrap_object_event_callback(object, type, cb,
672 cb_data.release(), isolate);
673 return compatibility_return(ret, info);
674 };
675
676 auto connection_get = [](compatibility_callback_info_type info)
677 -> compatibility_return_type {
678 if (info.Length() != 0)
679 return compatibility_return();
680
681 auto isolate = info.GetIsolate();
682 auto object = extract_eldbus_object(info.This());
683
684 auto conn = eldbus_object_connection_get(object);
685 return compatibility_return(wrap_eldbus_connection(conn, isolate),
686 info);
687 };
688
689 auto bus_name_get = [](compatibility_callback_info_type info)
690 -> compatibility_return_type {
691 if (info.Length() != 0)
692 return compatibility_return();
693
694 auto isolate = info.GetIsolate();
695 auto object = extract_eldbus_object(info.This());
696
697 auto ret = eldbus_object_bus_name_get(object);
698 return compatibility_return(compatibility_new<String>(isolate, ret),
699 info);
700 };
701
702 auto path_get = [](compatibility_callback_info_type info)
703 -> compatibility_return_type {
704 if (info.Length() != 0)
705 return compatibility_return();
706
707 auto isolate = info.GetIsolate();
708 auto object = extract_eldbus_object(info.This());
709
710 auto ret = eldbus_object_path_get(object);
711 return compatibility_return(compatibility_new<String>(isolate, ret),
712 info);
713 };
714
715 auto send = [](compatibility_callback_info_type info)
716 -> compatibility_return_type {
717 if (info.Length() != 3 || !info[0]->IsObject() || !info[1]->IsFunction()
718 || !info[2]->IsNumber()) {
719 return compatibility_return();
720 }
721
722 auto isolate = info.GetIsolate();
723 auto obj = extract_eldbus_object(info.This());
724 auto msg
725 = (compatibility_get_pointer_internal_field<Eldbus_Message*>
726 (info[0]->ToObject(), 0));
727
728 unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[1]}};
729
730 auto cb = [](void *data, const Eldbus_Message *msg,
731 Eldbus_Pending *pending) {
732 auto persistent = reinterpret_cast<persistent_t*>(data);
733 auto o = persistent->handle();
734
735 auto isolate = v8::Isolate::GetCurrent();
736
737 Handle<Value> args[2] = {
738 wrap_const_eldbus_msg(msg, isolate),
739 wrap_eldbus_pending(pending, persistent, isolate)
740 };
741
742 Function::Cast(*o)->Call(o->ToObject(), 2, args);
743
744 delete persistent;
745 };
746
747 auto ret = eldbus_object_send(obj, msg, cb, cb_data.get(),
748 info[2]->NumberValue());
749 return compatibility_return(wrap_eldbus_pending(ret, cb_data.release(),
750 isolate),
751 info);
752 };
753
754 auto signal_handler_add = [](compatibility_callback_info_type info)
755 -> compatibility_return_type {
756 if (info.Length() != 3 || !info[0]->IsString() || !info[1]->IsString()
757 || !info[2]->IsFunction()) {
758 return compatibility_return();
759 }
760
761 auto isolate = info.GetIsolate();
762 auto object = extract_eldbus_object(info.This());
763 String::Utf8Value interface(info[0]);
764 String::Utf8Value member(info[1]);
765
766 unique_ptr<persistent_t> cb_data{new persistent_t{isolate, info[2]}};
767
768 auto cb = [](void *data, const Eldbus_Message *msg) {
769 auto persistent = reinterpret_cast<persistent_t*>(data);
770 auto o = persistent->handle();
771
772 auto isolate = v8::Isolate::GetCurrent();
773
774 Handle<Value> args{wrap_const_eldbus_msg(msg, isolate)};
775
776 Function::Cast(*o)->Call(o->ToObject(), 1, &args);
777 };
778
779 auto ret = eldbus_object_signal_handler_add(object, *interface, *member,
780 cb, cb_data.get());
781 return
782 compatibility_return(wrap_eldbus_signal_handler(ret,
783 cb_data.release(),
784 isolate),
785 info);
786 };
787
788 auto method_call_new = [](compatibility_callback_info_type info)
789 -> compatibility_return_type {
790 if (info.Length() != 2 || !info[0]->IsString()
791 || !info[1]->IsString()) {
792 return compatibility_return();
793 }
794
795 auto isolate = info.GetIsolate();
796 auto object = extract_eldbus_object(info.This());
797 auto ret = eldbus_object_method_call_new(object,
798 *String::Utf8Value(info[0]),
799 *String::Utf8Value(info[1]));
800 return compatibility_return(wrap_eldbus_msg(ret, isolate), info);
801 };
802
803 ret->Set(compatibility_new<String>(isolate, "ref"),
804 compatibility_new<FunctionTemplate>(isolate, ref)->GetFunction());
805 ret->Set(compatibility_new<String>(isolate, "unref"),
806 compatibility_new<FunctionTemplate>(isolate, unref)
807 ->GetFunction());
808 ret->Set(compatibility_new<String>(isolate, "event_callback_add"),
809 compatibility_new<FunctionTemplate>(isolate, event_callback_add)
810 ->GetFunction());
811 ret->Set(compatibility_new<String>(isolate, "connection_get"),
812 compatibility_new<FunctionTemplate>(isolate, connection_get)
813 ->GetFunction());
814 ret->Set(compatibility_new<String>(isolate, "bus_name_get"),
815 compatibility_new<FunctionTemplate>(isolate, bus_name_get)
816 ->GetFunction());
817 ret->Set(compatibility_new<String>(isolate, "path_get"),
818 compatibility_new<FunctionTemplate>(isolate, path_get)
819 ->GetFunction());
820 ret->Set(compatibility_new<String>(isolate, "send"),
821 compatibility_new<FunctionTemplate>(isolate, send)->GetFunction());
822 ret->Set(compatibility_new<String>(isolate, "signal_handler_add"),
823 compatibility_new<FunctionTemplate>(isolate, signal_handler_add)
824 ->GetFunction());
825 ret->Set(compatibility_new<String>(isolate, "method_call_new"),
826 compatibility_new<FunctionTemplate>(isolate, method_call_new)
827 ->GetFunction());
828
829 compatibility_set_pointer_internal_field(ret, 0, object);
830
831 return ret;
832}
833
834} } } // namespace efl { namespace eldbus { namespace js {
835
836#endif /* ELDBUS_JS_UTIL_HH */