#include <iostream>
#include <gio/gio.h>
#include <glib.h>
#include <bits/stdc++.h>
using namespace std;
static GDBusNodeInfo *introspection_data = NULL;
/* Introspection data for the service we are exporting */
static const gchar introspection_xml[] =
"<node>"
" <interface name='org.gtk.GDBus.TestPeerInterface'>"
" <method name='HelloWorld'>"
" <arg type='s' name='greeting' direction='in'/>"
" <arg type='s' name='response' direction='out'/>"
" </method>"
" </interface>"
"</node>";
bool flag=true;
static void
handle_method_call (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
cout<<__PRETTY_FUNCTION__<<" "<<method_name<<endl;
}
static const GDBusInterfaceVTable interface_vtable =
{
handle_method_call,
NULL,
NULL,
{ 0 }
};
int main()
{
GError *error = NULL;
GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
if (!connection) {
g_error("Error connecting to session bus: %s", error->message);
}
introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
g_assert (introspection_data != NULL);
auto registration_id = g_dbus_connection_register_object (connection,
"/org/gtk/GDBus/TestObject",
introspection_data->interfaces[0],
&interface_vtable,
NULL, /* user_data */
NULL, /* user_data_free_func */
NULL); /* GError** */
while(flag)
{
g_main_context_iteration(g_main_context_default(),false);
gchar *greeting = "test";
auto value = g_dbus_connection_call_sync (connection,
NULL, /* bus_name */
"/org/gtk/GDBus/TestObject",
"org.gtk.GDBus.TestPeerInterface",
"HelloWorld",
g_variant_new ("(s)", greeting),
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if(error)
{
cout<<error->message<<endl;
g_free(error);
error=0;
}
}
return 0;
}
The above code fails to call HelloWorld , this code is stripped from gdbus-example-peer.c
I am unable to figure out why the method is not getting called.
I get GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod