gdbus: Make GDBusClient work without ObjectManager
Luiz Augusto von Dentz
maintainerPATCH 1/2 gdbus: Make GDBusClient work without ObjectManager
From: Luiz Augusto von Dentz <[email protected]>
This makes GDBusClient work normally without ObjectManager.
--- gdbus/client.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
gdbus/client.c +7 -2
@@ -1111,7 +1111,8 @@ static void get_managed_objects(GDBusClient *client)if (!client->connected)return ; -if (!client->proxy_added && !client->proxy_removed) { +if ((!client->proxy_added && !client->proxy_removed) || + !client->root_path) {refresh_properties (client);return ; }
@@ -1212,7 +1213,7 @@ GDBusClient *g_dbus_client_new_full(DBusConnection *connection,GDBusClient *client;unsigned int i; -if (!connection || !service || !root_path) +if (!connection || !service)return NULL ; client =g_try_new0 (GDBusClient,1 );
@@ -1238,6 +1239,10 @@ GDBusClient *g_dbus_client_new_full(DBusConnection *connection, service_connect, service_disconnect, client, NULL); + +if (!root_path) +return g_dbus_client_ref (client); + client->added_watch = g_dbus_add_signal_watch(connection, service, client->root_path, DBUS_INTERFACE_OBJECT_MANAGER,
Signature · 1 line
2.1.0
Luiz Augusto von Dentz
maintainerPATCH 2/2 unit/test-dbus-client: Add client_no_object_manager test
From: Michael Janssen <[email protected]>
Adds a test for the functionality of g_dbus_client_new_full passing NULL as root_path.
--- unit/test-gdbus-client.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
unit/test-gdbus-client.c +54 -1
@@ -353,7 +353,7 @@ static void proxy_get_string(GDBusProxy *proxy, void *user_data)g_assert (dbus_message_iter_get_arg_type (&iter) ==DBUS_TYPE_STRING );dbus_message_iter_get_basic (&iter, &string); -g_assert (g_strcmp0 (string,"value" ) ==0 ); + g_assert_cmpstr(string, ==, "value");g_dbus_client_unref (context->dbus_client); }
@@ -908,6 +908,56 @@ static void client_proxy_removed(void)destroy_context (context); } +static void client_no_object_manager (void ) +{ +struct context *context =create_context (); +DBusConnection *conn; +DBusMessageIter iter; +static const GDBusPropertyTable string_properties[] = { + {"String" ,"s" , get_string, set_string, string_exists }, + { }, + }; + +if (context ==NULL ) +return ; + + conn =g_dbus_setup_private (DBUS_BUS_SESSION ,SERVICE_NAME1 ,NULL ); +g_assert (conn !=NULL ); + + context->data =g_strdup ("value" ); + +g_dbus_register_interface (conn, +SERVICE_PATH ,SERVICE_NAME1 , + methods, signals, string_properties, + context,NULL ); + + context->dbus_client =g_dbus_client_new_full (context->dbus_conn, +SERVICE_NAME1 ,SERVICE_PATH , +NULL ); + +g_dbus_client_set_disconnect_watch (context->dbus_client, + disconnect_handler, context); + + context->proxy =g_dbus_proxy_new (context->dbus_client,SERVICE_PATH , +SERVICE_NAME1 ); + +g_dbus_client_set_proxy_handlers (context->dbus_client, proxy_get_string, +NULL ,NULL , context); + +g_assert (!g_dbus_proxy_get_property (context->proxy,"String" , &iter)); + +g_main_loop_run (context->main_loop); + +g_dbus_proxy_unref (context->proxy); +g_dbus_unregister_interface (conn,SERVICE_PATH ,SERVICE_NAME1 ); + +dbus_connection_flush (conn); +dbus_connection_close (conn); +dbus_connection_unref (conn); + +destroy_context (context); +} +static void proxy_force_disconnect (GDBusProxy *proxy,void *user_data) {struct context *context = user_data;
@@ -1051,6 +1101,9 @@ int main(int argc, char *argv[])g_test_add_func ("/gdbus/client_proxy_removed" , client_proxy_removed); +g_test_add_func ("/gdbus/client_no_object_manager" , + client_no_object_manager); +g_test_add_func ("/gdbus/client_force_disconnect" , client_force_disconnect);
Signature · 1 line
2.1.0
Hi,
Quoted 42 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This makes GDBusClient work normally without ObjectManager.
--- gdbus/client.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)gdbus/client.c +7
-3@@ -1111,7 +1111,8 @@ static void get_managed_objects(GDBusClient *client)if (!client->connected)return ; -if (!client->proxy_added && !client->proxy_removed) { +if ((!client->proxy_added && !client->proxy_removed) || + !client->root_path) {refresh_properties (client);return ; }@@ -1212,7 +1213,7 @@ GDBusClient *g_dbus_client_new_full(DBusConnection *connection,GDBusClient *client;unsigned int i; -if (!connection || !service || !root_path) +if (!connection || !service)return NULL ; client =g_try_new0 (GDBusClient,1 );@@ -1238,6 +1239,10 @@ GDBusClient *g_dbus_client_new_full(DBusConnection *connection, service_connect, service_disconnect, client, NULL); + +if (!root_path) +return g_dbus_client_ref (client); + client->added_watch = g_dbus_add_signal_watch(connection, service, client->root_path, DBUS_INTERFACE_OBJECT_MANAGER, --
Quoted 1 line
2.1.0
Applied.
Signature · 1 line
Luiz Augusto von Dentz