summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-23 15:45:22 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-23 15:45:22 +0900
commit86d9b4ed7153e91c9028af9a577c2d3a0dd32b52 (patch)
tree5e4e19741995b6215a77963254b1729ed791feec /src
parent316dc52d2f758bba2263cd25b940d1e4457910fd (diff)
Registers a fallback handler for a given subsection of the object hierarchy.
Summary: Goal of this patch is cover in Eldbus library function dbus_connection_register_fallback. http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#gac4473b37bfa74ccf7459959d27e7bc59 Reviewers: stanluk, raster Reviewed By: raster Differential Revision: https://phab.enlightenment.org/D479
Diffstat (limited to 'src')
-rw-r--r--src/lib/eldbus/eldbus_private_types.h2
-rw-r--r--src/lib/eldbus/eldbus_service.c40
-rw-r--r--src/lib/eldbus/eldbus_service.h15
3 files changed, 51 insertions, 6 deletions
diff --git a/src/lib/eldbus/eldbus_private_types.h b/src/lib/eldbus/eldbus_private_types.h
index bc4765d769..8ebe682544 100644
--- a/src/lib/eldbus/eldbus_private_types.h
+++ b/src/lib/eldbus/eldbus_private_types.h
@@ -146,6 +146,8 @@ struct _Eldbus_Service_Object
146 Eldbus_Service_Object *parent; 146 Eldbus_Service_Object *parent;
147 Eina_Inlist *children; 147 Eina_Inlist *children;
148 148
149 Eina_Bool fallback :1; /* Fallback mechanism flag */
150
149 //ObjectManager data 151 //ObjectManager data
150 Eldbus_Service_Interface *objmanager; 152 Eldbus_Service_Interface *objmanager;
151 Eina_List *iface_added; 153 Eina_List *iface_added;
diff --git a/src/lib/eldbus/eldbus_service.c b/src/lib/eldbus/eldbus_service.c
index bb300c0865..3149a58a2f 100644
--- a/src/lib/eldbus/eldbus_service.c
+++ b/src/lib/eldbus/eldbus_service.c
@@ -647,7 +647,7 @@ _eldbus_service_object_parent_find(Eldbus_Service_Object *obj)
647} 647}
648 648
649static Eldbus_Service_Object * 649static Eldbus_Service_Object *
650_eldbus_service_object_add(Eldbus_Connection *conn, const char *path) 650_eldbus_service_object_add(Eldbus_Connection *conn, const char *path, Eina_Bool fallback)
651{ 651{
652 Eldbus_Service_Object *obj, *rootobj; 652 Eldbus_Service_Object *obj, *rootobj;
653 Eina_Inlist *safe; 653 Eina_Inlist *safe;
@@ -656,8 +656,9 @@ _eldbus_service_object_add(Eldbus_Connection *conn, const char *path)
656 obj = calloc(1, sizeof(Eldbus_Service_Object)); 656 obj = calloc(1, sizeof(Eldbus_Service_Object));
657 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL); 657 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
658 658
659 if (!dbus_connection_register_object_path(conn->dbus_conn, path, &vtable, 659 obj->fallback = fallback;
660 obj)) 660 if ((fallback && !dbus_connection_register_fallback(conn->dbus_conn, path, &vtable, obj)) ||
661 (!fallback && !dbus_connection_register_object_path(conn->dbus_conn, path, &vtable, obj)))
661 { 662 {
662 free(obj); 663 free(obj);
663 return NULL; 664 return NULL;
@@ -668,6 +669,8 @@ _eldbus_service_object_add(Eldbus_Connection *conn, const char *path)
668 obj->interfaces = eina_hash_string_superfast_new(NULL); 669 obj->interfaces = eina_hash_string_superfast_new(NULL);
669 eldbus_connection_free_cb_add(conn, _on_connection_free, obj); 670 eldbus_connection_free_cb_add(conn, _on_connection_free, obj);
670 671
672 if (obj->fallback) return obj;
673
671 eina_hash_add(obj->interfaces, introspectable->name, introspectable); 674 eina_hash_add(obj->interfaces, introspectable->name, introspectable);
672 eina_hash_add(obj->interfaces, properties_iface->name, properties_iface); 675 eina_hash_add(obj->interfaces, properties_iface->name, properties_iface);
673 676
@@ -924,8 +927,8 @@ fail_signature:
924 return NULL; 927 return NULL;
925} 928}
926 929
927EAPI Eldbus_Service_Interface * 930static Eldbus_Service_Interface *
928eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc) 931_eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc, Eina_Bool fallback)
929{ 932{
930 Eldbus_Service_Object *obj; 933 Eldbus_Service_Object *obj;
931 Eldbus_Service_Interface *iface; 934 Eldbus_Service_Interface *iface;
@@ -950,7 +953,7 @@ eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, con
950 return NULL; 953 return NULL;
951 954
952 if (!obj) 955 if (!obj)
953 obj = _eldbus_service_object_add(conn, path); 956 obj = _eldbus_service_object_add(conn, path, fallback);
954 else 957 else
955 obj->introspection_dirty = EINA_TRUE; 958 obj->introspection_dirty = EINA_TRUE;
956 EINA_SAFETY_ON_NULL_GOTO(obj, fail); 959 EINA_SAFETY_ON_NULL_GOTO(obj, fail);
@@ -982,6 +985,18 @@ fail:
982 return NULL; 985 return NULL;
983} 986}
984 987
988EAPI Eldbus_Service_Interface *
989eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc)
990{
991 return _eldbus_service_interface_register(conn, path, desc, EINA_FALSE);
992}
993
994EAPI Eldbus_Service_Interface *
995eldbus_service_interface_fallback_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc)
996{
997 return _eldbus_service_interface_register(conn, path, desc, EINA_TRUE);
998}
999
985static Eina_Bool 1000static Eina_Bool
986_idler_propschanged(void *data) 1001_idler_propschanged(void *data)
987{ 1002{
@@ -1275,11 +1290,18 @@ _object_handler(DBusConnection *dbus_conn EINA_UNUSED, DBusMessage *msg, void *u
1275 const Eldbus_Method *method; 1290 const Eldbus_Method *method;
1276 Eldbus_Message *eldbus_msg, *reply; 1291 Eldbus_Message *eldbus_msg, *reply;
1277 Eldbus_Connection *conn; 1292 Eldbus_Connection *conn;
1293 const char* fallback_path = NULL;
1278 1294
1279 obj = user_data; 1295 obj = user_data;
1280 if (!obj) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 1296 if (!obj) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1281 conn = obj->conn; 1297 conn = obj->conn;
1282 1298
1299 if (obj->fallback)
1300 {
1301 fallback_path = eina_stringshare_add(obj->path);
1302 eina_stringshare_replace(&obj->path, dbus_message_get_path(msg));
1303 }
1304
1283 DBG("Connection@%p Got message:\n" 1305 DBG("Connection@%p Got message:\n"
1284 " Type: %s\n" 1306 " Type: %s\n"
1285 " Path: %s\n" 1307 " Path: %s\n"
@@ -1331,6 +1353,12 @@ _object_handler(DBusConnection *dbus_conn EINA_UNUSED, DBusMessage *msg, void *u
1331 eldbus_connection_unref(conn); 1353 eldbus_connection_unref(conn);
1332 eldbus_shutdown(); 1354 eldbus_shutdown();
1333 1355
1356 if (obj->fallback)
1357 {
1358 eina_stringshare_replace(&obj->path, fallback_path);
1359 eina_stringshare_del(fallback_path);
1360 }
1361
1334 return DBUS_HANDLER_RESULT_HANDLED; 1362 return DBUS_HANDLER_RESULT_HANDLED;
1335} 1363}
1336 1364
diff --git a/src/lib/eldbus/eldbus_service.h b/src/lib/eldbus/eldbus_service.h
index 5fa839d395..e5915dc15c 100644
--- a/src/lib/eldbus/eldbus_service.h
+++ b/src/lib/eldbus/eldbus_service.h
@@ -109,6 +109,21 @@ typedef struct _Eldbus_Service_Interface_Desc
109EAPI Eldbus_Service_Interface *eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc) EINA_ARG_NONNULL(1, 2, 3); 109EAPI Eldbus_Service_Interface *eldbus_service_interface_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc) EINA_ARG_NONNULL(1, 2, 3);
110 110
111/** 111/**
112 * @brief Register a fallback interface handler for a given subsection of the object hierarchy.
113 * Note: Use eldbus_service_interface_unregister() to unregister a interface.
114 * @param conn where the interface should listen
115 * @param path a '/' delimited string of path elements
116 * @param desc description of interface
117 * @see eldbus_service_interface_unregister()
118 *
119 * @since 1.9
120 *
121 * @return Interface
122 */
123EAPI Eldbus_Service_Interface *
124eldbus_service_interface_fallback_register(Eldbus_Connection *conn, const char *path, const Eldbus_Service_Interface_Desc *desc) EINA_ARG_NONNULL(1, 2, 3);
125
126/**
112 * @brief Unregister a interface. 127 * @brief Unregister a interface.
113 * Note: This doesn't unregister the object path if interface count reaches 0. 128 * Note: This doesn't unregister the object path if interface count reaches 0.
114 * Use eldbus_service_object_unregister() to unregister the object. 129 * Use eldbus_service_object_unregister() to unregister the object.