Skip to content
Permalink
Browse files

Migrate from dbus-glib to gdbus

- tools/Makefile.am
- tools/mate-session-save.c
  • Loading branch information...
yetist authored and monsta committed Dec 10, 2018
1 parent f20dad8 commit 413050e91f814dbda33758f3f332ad48d3479f64
Showing with 56 additions and 83 deletions.
  1. +1 −3 tools/Makefile.am
  2. +55 −80 tools/mate-session-save.c
@@ -2,7 +2,6 @@ bin_PROGRAMS = mate-session-save mate-session-inhibit

AM_CPPFLAGS = \
$(MATE_SESSION_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
-DLOCALE_DIR=\""$(datadir)/locale"\" \
$(DISABLE_DEPRECATED_CFLAGS)

@@ -14,8 +13,7 @@ mate_session_save_SOURCES = \
mate_session_save_LDADD = \
$(SM_LIBS) \
$(ICE_LIBS) \
$(MATE_SESSION_LIBS) \
$(DBUS_GLIB_LIBS)
$(MATE_SESSION_LIBS)

mate_session_inhibit_SOURCES = \
mate-session-inhibit.c
@@ -30,9 +30,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>

#define GSM_SERVICE_DBUS "org.gnome.SessionManager"
#define GSM_PATH_DBUS "/org/gnome/SessionManager"
#define GSM_INTERFACE_DBUS "org.gnome.SessionManager"
@@ -95,59 +92,38 @@ static void display_error(const char* message)
}
}

static DBusGConnection* get_session_bus(void)
{
GError* error = NULL;
DBusGConnection* bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);

if (bus == NULL)
{
g_warning("Couldn't connect to session bus: %s", error->message);
g_error_free(error);
}

return bus;
}

static DBusGProxy* create_proxy(DBusGConnection *connection, const char *name, const char *path, const char *iface)
static GDBusProxy* get_sm_proxy(void)
{
GError* error = NULL;
DBusGProxy* proxy = dbus_g_proxy_new_for_name_owner(connection, name, path, iface, &error);

if (proxy == NULL)
{
g_warning("Couldn't create DBus proxy: %s", error->message);
g_error_free(error);
}

return proxy;
}

static DBusGProxy* get_sm_proxy(void)
{
DBusGConnection* connection;
DBusGProxy* sm_proxy;

connection = get_session_bus();

if (connection == NULL)
{
display_error(_("Could not connect to the session manager"));
return NULL;
}

sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS, GSM_PATH_DBUS, GSM_INTERFACE_DBUS);

GError *error = NULL;
GDBusProxy *sm_proxy = NULL;

sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
GSM_SERVICE_DBUS,
GSM_PATH_DBUS,
GSM_INTERFACE_DBUS,
NULL,
&error);
if (sm_proxy == NULL)
{
g_warning ("Couldn't create DBus proxy: %s", error->message);
g_error_free (error);

/* Try the old name - for the case when we've just upgraded from 1.10
* so the old m-s-m is currently running */
sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS_OLD, GSM_PATH_DBUS_OLD, GSM_INTERFACE_DBUS_OLD);

sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
GSM_SERVICE_DBUS_OLD,
GSM_PATH_DBUS_OLD,
GSM_INTERFACE_DBUS_OLD,
NULL,
NULL);
if (sm_proxy == NULL)
{
/* Okay, it wasn't the upgrade case, so now we can give up. */
display_error(_("Could not connect to the session manager"));
display_error (_("Could not connect to the session manager"));
return NULL;
}
}
@@ -157,71 +133,70 @@ static DBusGProxy* get_sm_proxy(void)

static void do_logout(unsigned int mode)
{
DBusGProxy* sm_proxy;
GDBusProxy* sm_proxy;
GError* error;
gboolean res;
GVariant *ret;

sm_proxy = get_sm_proxy();
sm_proxy = get_sm_proxy ();

if (sm_proxy == NULL)
{
return;
}

error = NULL;
res = dbus_g_proxy_call(sm_proxy, "Logout", &error, G_TYPE_UINT, mode, G_TYPE_INVALID, G_TYPE_INVALID);

if (!res)
ret = g_dbus_proxy_call_sync (sm_proxy, "Logout",
g_variant_new ("(u)", mode),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

if (ret == NULL)
{
if (error != NULL)
{
g_warning("Failed to call logout: %s", error->message);
g_error_free(error);
}
else
{
g_warning("Failed to call logout");
}
g_warning ("Failed to call logout: %s", error->message);
g_error_free (error);
} else {
g_variant_unref (ret);
}

if (sm_proxy != NULL)
{
g_object_unref(sm_proxy);
g_object_unref (sm_proxy);
}
}

static void do_shutdown_dialog(void)
{
DBusGProxy* sm_proxy;
GDBusProxy* sm_proxy;
GError* error;
gboolean res;
GVariant *ret;

sm_proxy = get_sm_proxy();
sm_proxy = get_sm_proxy ();

if (sm_proxy == NULL)
{
return;
}

error = NULL;
res = dbus_g_proxy_call(sm_proxy, "Shutdown", &error, G_TYPE_INVALID, G_TYPE_INVALID);

if (!res)
ret = g_dbus_proxy_call_sync (sm_proxy, "Shutdown",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (ret == NULL)
{
if (error != NULL)
{
g_warning("Failed to call shutdown: %s", error->message);
g_error_free(error);
}
else
{
g_warning("Failed to call shutdown");
}
g_warning ("Failed to call shutdown: %s", error->message);
g_error_free (error);
} else {
g_variant_unref (ret);
}

if (sm_proxy != NULL)
{
g_object_unref(sm_proxy);
g_object_unref (sm_proxy);
}
}

0 comments on commit 413050e

Please sign in to comment.
You can’t perform that action at this time.