0

Using gdbus-codegen for dbus method call, server side works but response string on client side is always NULL. Specifically the buffer in the call new_cfg_gdbus_call_receive_new_config_sync(proxy, "new_cfg", buf, NULL, &error); is NULL, I am not sure how to populate that on the server side.

Command line:

gdbus-codegen --generate-c-code new_cfg_gen --c-namespace NewCfg --interface-prefix com.new_cfg. com.new_cfg.GDBUS.xml

XML:

<node>
    <interface name="com.new_cfg.GDBUS">
        <method name="ReceiveNewConfig">
            <arg name="greeting" direction="in" type="s"/>
            <arg name="response" direction="out" type="s"/>
        </method>
    </interface>
</node>

Client:

NewCfgGDBUS *proxy;
GError *error;
gchar **buf = NULL;
error = NULL;
proxy = new_cfg_gdbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
        "com.new_cfg", "/com/new_cfg/GDBUS", NULL, &error);
new_cfg_gdbus_call_receive_new_config_sync(proxy, "new_cfg", buf, NULL, &error);
if(NULL != buf && NULL != *buf)
{
    g_print("resp: %s\n", *buf);
}
else
{
    g_print("resp is NULL");
}
g_object_unref(proxy);

Server:

static gboolean
on_rcv_new_cfg (NewCfgGDBUS *interface, GDBusMethodInvocation *invocation,
                const gchar *greeting, gpointer user_data)
{
    gchar *response;
    response = g_strdup_printf ("New Config %s is valid.", greeting);
    new_cfg_gdbus_complete_receive_new_config (interface, invocation, response);
    g_print("%s\n", response);
    g_free (response);
    return TRUE;
}

static void
on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
{
    NewCfgGDBUS *interface;
    GError *error;
    interface = new_cfg_gdbus_skeleton_new();
    g_signal_connect (interface, "handle-receive-new-config", G_CALLBACK (on_rcv_new_cfg), NULL);
    error = NULL;
    (void)!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (interface), connection, "/com/new_cfg/GDBUS", &error);
}

Server side loop:

GMainLoop *loop;
loop = g_main_loop_new (NULL, FALSE);
g_bus_own_name(G_BUS_TYPE_SYSTEM, "com.new_cfg", G_BUS_NAME_OWNER_FLAGS_NONE, NULL,
            on_name_acquired, NULL, NULL, NULL);
g_main_loop_run (loop);
zarzar
  • 1
  • 4

1 Answers1

0

Solved: The correct parameter in this case is just char*, gdbus does not generate (allocate) a pointer to string and a string. It only allocates the string, returns the address.

zarzar
  • 1
  • 4