'Why am i Getting D-Bus argument type error?
I'm trying to invoke "Inhibit" method of org.gnome.SessionManager using D-Bus, but I'm getting no cookie in return and the following error: Argument 0 is specified to be of type "uint32", but is actually of type "string" But all types seems to be ok.
DBusConnection * dbus_conn = nullptr;
DBusError dbus_error;
DBusPendingCall *pending;
const char * szProgramName = "SEER";
const char * szReason = "just because";
dbus_uint32_t xid = 0;
dbus_uint32_t gflags = 0xc;
dbus_uint32_t cookie = 0;
// Initialize D-Bus error
dbus_error_init(&dbus_error);
dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
DBusMessage * dbus_msg = nullptr;
DBusMessage * dbus_reply = nullptr;
if (dbus_error_is_set(&dbus_error))
{
fprintf(stderr, "Connection Error (%s)\n", dbus_error.message);
dbus_error_free(&dbus_error);
}
if (NULL == dbus_conn)
{
exit(1);
}
dbus_msg = dbus_message_new_method_call("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", "Inhibit");
dbus_message_append_args(dbus_msg,
DBUS_TYPE_STRING, &szProgramName,
DBUS_TYPE_UINT32, &xid,
DBUS_TYPE_STRING, &szReason,
DBUS_TYPE_UINT32, &gflags,
DBUS_TYPE_INVALID);
dbus_connection_send_with_reply(dbus_conn, dbus_msg, &pending, -1);
dbus_pending_call_block(pending);
dbus_reply = dbus_pending_call_steal_reply(pending);
if (dbus_reply != NULL)
{
dbus_message_get_args(dbus_reply, &dbus_error,
DBUS_TYPE_UINT32, &cookie,
DBUS_TYPE_INVALID);
}
else
printf("dbus_reply is null\n");
printf("cookie %x error %s\n",cookie, dbus_error.message);
any help would be greatly appreciated!
EDIT
after changing dbus_message_get_args to
dbus_message_get_args(dbus_reply, &dbus_error,
DBUS_TYPE_STRING, &cookie,
DBUS_TYPE_INVALID);
Apparently cookie var holds The name org.gnome.SessionManager was not provided by any .service files and that's a different error entirely..
Solution 1:[1]
Consider replacing
dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
with
dbus_conn = dbus_bus_get(DBUS_BUS_SESSION, &dbus_error);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
