From b49c9fcf657a4e4c2f494e9a67c6e21f1cadb55f Mon Sep 17 00:00:00 2001 From: joprietoe Date: Sun, 10 Apr 2016 22:20:34 -0300 Subject: [PATCH] 2do --- gdbus-example-client.c | 48 ++++++++++++++++++++++++-------------- gdbus-example-server.c | 53 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 18 deletions(-) mode change 100644 => 100755 gdbus-example-client.c diff --git a/gdbus-example-client.c b/gdbus-example-client.c old mode 100644 new mode 100755 index 9c510ad..0288e4a --- a/gdbus-example-client.c +++ b/gdbus-example-client.c @@ -3,6 +3,8 @@ #include #include +#include +#include #include @@ -10,31 +12,35 @@ #include /* see gdbus-example-server.c for the server implementation */ + static gint -get_server_stdout (GDBusConnection *connection, +get_server_gvariant_stdout (GDBusConnection *connection, const gchar *name_owner, GError **error) { GDBusMessage *method_call_message; GDBusMessage *method_reply_message; - GUnixFDList *fd_list; + // GUnixFDList *fd_list; gint fd; - + const gchar * response; + fd = -1; method_call_message = NULL; method_reply_message = NULL; - method_call_message = g_dbus_message_new_method_call (name_owner, + method_call_message = g_dbus_message_new_method_call (name_owner, "/org/gtk/GDBus/TestObject", "org.gtk.GDBus.TestInterface", - "GimmeStdout"); - method_reply_message = g_dbus_connection_send_message_with_reply_sync (connection, - method_call_message, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, - -1, - NULL, /* out_serial */ - NULL, /* cancellable */ - error); + "ExampleTuple"); + +g_dbus_message_set_body (method_call_message, g_variant_new ("(s)", " Hello Julio! ")); +method_reply_message = g_dbus_connection_send_message_with_reply_sync (connection, + method_call_message, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + -1, + NULL, /* out_serial */ + NULL, /* cancellable */ + error); if (method_reply_message == NULL) goto out; @@ -44,8 +50,13 @@ get_server_stdout (GDBusConnection *connection, goto out; } - fd_list = g_dbus_message_get_unix_fd_list (method_reply_message); - fd = g_unix_fd_list_get (fd_list, 0, error); +fd = 1; +response = g_dbus_message_get_arg0(method_reply_message); + +g_printf("Response: %s\n",response); + + //fd_list = g_dbus_message_get_unix_fd_list (method_reply_message); + //fd = g_unix_fd_list_get (fd_list, 0, error); out: g_object_unref (method_call_message); @@ -54,6 +65,8 @@ get_server_stdout (GDBusConnection *connection, return fd; } + + static void on_name_appeared (GDBusConnection *connection, const gchar *name, @@ -64,10 +77,11 @@ on_name_appeared (GDBusConnection *connection, GError *error; error = NULL; - fd = get_server_stdout (connection, name_owner, &error); + //fd = get_server_stdout (connection, name_owner, &error); + fd = get_server_gvariant_stdout (connection, name_owner, &error); if (fd == -1) { - g_printerr ("Error invoking GimmeStdout(): %s\n", + g_printerr ("Error invoking ExampleTuple: %s\n", error->message); g_error_free (error); exit (1); @@ -85,7 +99,7 @@ on_name_appeared (GDBusConnection *connection, "%c", localtime (&now)); - str = g_strdup_printf ("On %s, gdbus-example-unix-fd-client with pid %d was here!\n", + str = g_strdup_printf ("OK, send message On %s, gdbus-example-unix-fd-client with pid %d was here!\n", now_buf, (gint) getpid ()); len = strlen (str); diff --git a/gdbus-example-server.c b/gdbus-example-server.c index edcfaca..dc69203 100755 --- a/gdbus-example-server.c +++ b/gdbus-example-server.c @@ -1,5 +1,7 @@ #include #include +#include +#include #ifdef G_OS_UNIX #include @@ -22,6 +24,11 @@ static const gchar introspection_xml[] = " " " " " " + " " + " " + " " + " " + " " " " " " " " @@ -94,6 +101,49 @@ handle_method_call (GDBusConnection *connection, g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", response)); g_free (response); + } + } + else if (g_strcmp0 (method_name, "ExampleTuple") == 0) + { + //const int value; + const gchar *cadena; + + g_variant_get(parameters, "(&s)", &cadena); + + + if (g_strcmp0 (cadena, "Return Unregistered") == 0) + { + g_dbus_method_invocation_return_error (invocation, + G_IO_ERROR, + G_IO_ERROR_FAILED_HANDLED, + "As requested, here's a GError not registered (G_IO_ERROR_FAILED_HANDLED)"); + } + else if (g_strcmp0 (cadena, "Return Registered") == 0) + { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_MATCH_RULE_NOT_FOUND, + "As requested, here's a GError that is registered (G_DBUS_ERROR_MATCH_RULE_NOT_FOUND)"); + } + else if (g_strcmp0 (cadena, "Return Raw") == 0) + { + g_dbus_method_invocation_return_dbus_error (invocation, + "org.gtk.GDBus.SomeErrorName", + "As requested, here's a raw D-Bus error"); + } + else + { + gchar *response; + response = g_strdup_printf ("You greeted me with '%s'. Thanks!", cadena); + + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(s)", response)); + + g_printf("%s\n",response); + + g_free (response); + + } } else if (g_strcmp0 (method_name, "EmitSignal") == 0) @@ -354,7 +404,8 @@ on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data) { - exit (1); + g_print("Lost\n"); + exit (1); } int