summaryrefslogtreecommitdiff
path: root/src/lib/eldbus/eldbus_service.c
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-07-03 16:28:22 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-07-03 16:28:23 +0900
commit30df128be5dd3d2cea4c976ed5d5c9b85a15aa77 (patch)
tree8fe7a9c6c61677f46e82199075856a45717b4e98 /src/lib/eldbus/eldbus_service.c
parentddac21534f9eaa8bc01f8c72c1bff5926de27bd6 (diff)
eldbus-cxx: Implementation of eldbus C++ API
Summary: Applications can: void method_callback(void* data, const Eldbus_Service_Interface* iface, const Eldbus_Message* message); struct { ... } data_struct; Eldbus_Method methods[] = { "method1", ELDBUS_ARGS("b", "bool"), ELDBUS_ARGS("b", "bool"), ELDBUS_METHOD_FLAG_HAS_DATA , (Eldbus_Method_Cb)&method_callback, &data_struct }; And method_callback will be called with data parameter pointing to data_struct global object. Also, Eldbus-cxx supports registering an interface passing a lambda or function object as method. For example: edb::service_interface iface = edb::service_interface_register (c, path, interface , es::method("SendStringAndBool" , [expected_string, expected_bool] (std::string const& n, bool b , bool* out) { std::cout << "Running SendStringAndBool" << std::endl; ck_assert(n == expected_string); ck_assert(b == expected_bool); *out = b; return n; } , es::ins<std::string, bool>("string", "bool") , es::outs<std::string, bool>("string", "bool") ) ); When a request for "SendStringAndBool" with the proper signature is called, executes the lambda and replies with the return value and its bool* out parameter value. Reviewers: cedric, woohyun, raster CC: savio, cedric Differential Revision: https://phab.enlightenment.org/D1052
Diffstat (limited to 'src/lib/eldbus/eldbus_service.c')
-rw-r--r--src/lib/eldbus/eldbus_service.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/lib/eldbus/eldbus_service.c b/src/lib/eldbus/eldbus_service.c
index 4b7295ca8d..0b06fa37de 100644
--- a/src/lib/eldbus/eldbus_service.c
+++ b/src/lib/eldbus/eldbus_service.c
@@ -395,7 +395,7 @@ cb_introspect(const Eldbus_Service_Interface *_iface, const Eldbus_Message *mess
395} 395}
396 396
397static const Eldbus_Method introspect = { 397static const Eldbus_Method introspect = {
398 "Introspect", NULL, ELDBUS_ARGS({ "s", "xml" }), cb_introspect, 0 398 "Introspect", NULL, ELDBUS_ARGS({ "s", "xml" }), cb_introspect, 0, 0
399}; 399};
400 400
401static void 401static void
@@ -435,15 +435,15 @@ _default_interfaces_free(void)
435static const Eldbus_Method _property_methods[] = { 435static const Eldbus_Method _property_methods[] = {
436 { 436 {
437 "Get", ELDBUS_ARGS({"s", "interface"}, {"s", "property"}), 437 "Get", ELDBUS_ARGS({"s", "interface"}, {"s", "property"}),
438 ELDBUS_ARGS({"v", "value"}), _cb_property_get, 0 438 ELDBUS_ARGS({"v", "value"}), _cb_property_get, 0, NULL
439 }, 439 },
440 { 440 {
441 "Set", ELDBUS_ARGS({"s", "interface"}, {"s", "property"}, {"v", "value"}), 441 "Set", ELDBUS_ARGS({"s", "interface"}, {"s", "property"}, {"v", "value"}),
442 NULL, _cb_property_set, 0 442 NULL, _cb_property_set, 0, NULL
443 }, 443 },
444 { 444 {
445 "GetAll", ELDBUS_ARGS({"s", "interface"}), ELDBUS_ARGS({"a{sv}", "props"}), 445 "GetAll", ELDBUS_ARGS({"s", "interface"}), ELDBUS_ARGS({"a{sv}", "props"}),
446 _cb_property_getall, 0 446 _cb_property_getall, 0, NULL
447 } 447 }
448}; 448};
449 449
@@ -570,7 +570,7 @@ _cb_managed_objects(const Eldbus_Service_Interface *iface, const Eldbus_Message
570 570
571static Eldbus_Method get_managed_objects = { 571static Eldbus_Method get_managed_objects = {
572 "GetManagedObjects", NULL, ELDBUS_ARGS({"a{oa{sa{sv}}}", "objects"}), 572 "GetManagedObjects", NULL, ELDBUS_ARGS({"a{oa{sa{sv}}}", "objects"}),
573 _cb_managed_objects, 0 573 _cb_managed_objects, 0, NULL
574}; 574};
575 575
576static const Eldbus_Signal _object_manager_signals[] = { 576static const Eldbus_Signal _object_manager_signals[] = {
@@ -1282,6 +1282,20 @@ _object_unregister(DBusConnection *conn EINA_UNUSED, void *user_data)
1282 _object_free(obj); 1282 _object_free(obj);
1283} 1283}
1284 1284
1285static Eldbus_Message*
1286_eldbus_method_call(Eldbus_Method const* method, Eldbus_Service_Interface* iface, Eldbus_Message* msg)
1287{
1288 if(method->flags & ELDBUS_METHOD_FLAG_HAS_DATA)
1289 {
1290 Eldbus_Method_Data_Cb cb = (Eldbus_Method_Data_Cb)method->cb;
1291 return cb(method->data, iface, msg);
1292 }
1293 else
1294 {
1295 return method->cb(iface, msg);
1296 }
1297}
1298
1285static DBusHandlerResult 1299static DBusHandlerResult
1286_object_handler(DBusConnection *dbus_conn EINA_UNUSED, DBusMessage *msg, void *user_data) 1300_object_handler(DBusConnection *dbus_conn EINA_UNUSED, DBusMessage *msg, void *user_data)
1287{ 1301{
@@ -1331,19 +1345,19 @@ _object_handler(DBusConnection *dbus_conn EINA_UNUSED, DBusMessage *msg, void *u
1331 1345
1332 if (!_have_signature(method->in, eldbus_msg)) 1346 if (!_have_signature(method->in, eldbus_msg))
1333 reply = eldbus_message_error_new(eldbus_msg, DBUS_ERROR_INVALID_SIGNATURE, 1347 reply = eldbus_message_error_new(eldbus_msg, DBUS_ERROR_INVALID_SIGNATURE,
1334 "See introspectable to know the expected signature"); 1348 "See introspectable to know the expected signature");
1335 else 1349 else
1336 { 1350 {
1337 if (iface->obj) 1351 if (iface->obj)
1338 reply = method->cb(iface, eldbus_msg); 1352 reply = _eldbus_method_call(method, iface, eldbus_msg);
1339 else 1353 else
1340 { 1354 {
1341 /* if iface does have obj it is some of FreeDesktop interfaces: 1355 /* if iface does have obj it is some of FreeDesktop interfaces:
1342 Introspectable, Properties or ObjectManager */ 1356 Introspectable, Properties or ObjectManager */
1343 iface->obj = obj; 1357 iface->obj = obj;
1344 reply = method->cb(iface, eldbus_msg); 1358 reply = _eldbus_method_call(method, iface, eldbus_msg);
1345 iface->obj = NULL; 1359 iface->obj = NULL;
1346 } 1360 }
1347 } 1361 }
1348 1362
1349 eldbus_message_unref(eldbus_msg); 1363 eldbus_message_unref(eldbus_msg);