Skip to content
Snippets Groups Projects
Commit 8e02aafb authored by Peter de Ridder's avatar Peter de Ridder Committed by Eric Koegel
Browse files

Ported xfpm-dbus to lowlevel commands.

Ideally the usage of these functions is replaced by g_dbus_watch_name and
g_dbus_own_name.
parent 08b4182a
No related branches found
No related tags found
No related merge requests found
...@@ -21,46 +21,70 @@ ...@@ -21,46 +21,70 @@
#include "xfpm-dbus.h" #include "xfpm-dbus.h"
gboolean gboolean
xfpm_dbus_name_has_owner (DBusConnection *connection, const gchar *name) xfpm_dbus_name_has_owner (GDBusConnection *connection, const gchar *name)
{ {
DBusError error; GError *error = NULL;
const gchar *owner;
gboolean ret; gboolean ret;
GVariant *var;
var = g_dbus_connection_call_sync (connection,
"org.freedesktop.DBus", /* name */
"/org/freedesktop/DBus", /* object path */
"org.freedesktop.DBus", /* interface */
"GetNameOwner",
g_variant_new ("(s)", name),
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout */
NULL,
&error);
if (var)
g_variant_get (var, "(&s)", &owner);
ret = (owner != NULL);
g_variant_unref (var);
dbus_error_init (&error); if ( error )
ret = dbus_bus_name_has_owner(connection, name, &error);
if ( dbus_error_is_set(&error) )
{ {
g_warning("Failed to get name owner: %s\n",error.message); g_warning("Failed to get name owner: %s\n",error->message);
dbus_error_free(&error); g_error_free(error);
return FALSE; return FALSE;
} }
return ret; return ret;
} }
gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name) gboolean xfpm_dbus_register_name(GDBusConnection *connection, const gchar *name)
{ {
DBusError error; GError *error = NULL;
int ret; guint32 ret;
GVariant *var;
dbus_error_init(&error);
ret = var = g_dbus_connection_call_sync (connection,
dbus_bus_request_name(connection, "org.freedesktop.DBus", /* bus name */
name, "/org/freedesktop/DBus", /* object path */
DBUS_NAME_FLAG_DO_NOT_QUEUE, "org.freedesktop.DBus", /* interface name */
&error); "RequestName", /* method name */
g_variant_new ("(su)",
if ( dbus_error_is_set(&error) ) name,
0x4), /* DBUS_NAME_FLAG_DO_NOT_QUEUE */
G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (var)
g_variant_get (var, "(u)", &ret);
g_variant_unref (var);
if ( error )
{ {
g_warning("Error: %s\n",error.message); g_warning("Error: %s\n",error->message);
dbus_error_free(&error); g_error_free(error);
return FALSE; return FALSE;
} }
if ( ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ) if ( ret == 1 ) /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
{ {
return TRUE; return TRUE;
} }
...@@ -68,26 +92,30 @@ gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name) ...@@ -68,26 +92,30 @@ gboolean xfpm_dbus_register_name(DBusConnection *connection, const gchar *name)
return FALSE; return FALSE;
} }
gboolean xfpm_dbus_release_name(DBusConnection *connection, const gchar *name) gboolean xfpm_dbus_release_name(GDBusConnection *connection, const gchar *name)
{ {
DBusError error; GError *error = NULL;
int ret; GVariant *var;
dbus_error_init(&error);
ret = var = g_dbus_connection_call_sync (connection,
dbus_bus_release_name(connection, "org.freedesktop.DBus", /* bus name */
name, "/org/freedesktop/DBus", /* object path */
&error); "org.freedesktop.DBus", /* interface name */
"ReleaseName", /* method name */
g_variant_new ("(s)", name),
G_VARIANT_TYPE ("(u)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
g_variant_unref (var);
if ( dbus_error_is_set(&error) ) if ( error )
{ {
g_warning("Error: %s\n",error.message); g_warning("Error: %s\n",error->message);
dbus_error_free(&error); g_error_free(error);
return FALSE; return FALSE;
} }
if ( ret == -1 ) return FALSE;
return TRUE; return TRUE;
} }
...@@ -24,12 +24,12 @@ ...@@ -24,12 +24,12 @@
#include <glib.h> #include <glib.h>
#include <gio/gio.h> #include <gio/gio.h>
gboolean xfpm_dbus_name_has_owner (DBusConnection *bus, gboolean xfpm_dbus_name_has_owner (GDBusConnection *bus,
const gchar *name); const gchar *name);
gboolean xfpm_dbus_register_name (DBusConnection *bus, gboolean xfpm_dbus_register_name (GDBusConnection *bus,
const gchar *name); const gchar *name);
gboolean xfpm_dbus_release_name (DBusConnection *bus, gboolean xfpm_dbus_release_name (GDBusConnection *bus,
const gchar *name); const gchar *name);
#endif /* __XFPM_DBUS_H */ #endif /* __XFPM_DBUS_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment