Commit 91860af3 authored by Eric Koegel's avatar Eric Koegel
Browse files

Port xfce4-session/ to GDBus

And remove the dbus-glib deps.
parent 4163b5a2
......@@ -21,6 +21,7 @@ config.status
config.sub
configure
configure.in
configure.ac
depcomp
engines/mice/generate
engines/mice/preview.h
......@@ -45,6 +46,7 @@ po/stamp-it
scripts/startxfce4
scripts/xinitrc
scripts/xinitrc.in
scripts/xscreensaver.desktop
settings/stamp-xfce4-session-marshal.h
settings/xfce-session-settings.desktop
settings/xfce4-session-marshal.c
......@@ -63,6 +65,7 @@ xfce4-session/chooser-icon.h
xfce4-session/stamp-xfsm-marshal.h
xfce4-session/xfce4-session
xfce4-session/xfsm-manager-dbus.h
xfce4-session/xfsm-manager-dbus.c
xfce4-session/xfsm-marshal.c
xfce4-session/xfsm-marshal.h
xfsm-shutdown-helper/xfsm-shutdown-helper
......@@ -71,3 +74,4 @@ xfce4-session.spec
xfce4-session/org.xfce.session.policy
xfce4-session/xfsm-chooser-icon.h
xfce4-session/xfsm-client-dbus.h
xfce4-session/xfsm-client-dbus.c
......@@ -106,8 +106,6 @@ XDT_CHECK_PACKAGE([GTK], [gtk+-3.0], [3.10.0])
XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.42.0])
XDT_CHECK_PACKAGE([GMODULE], [gmodule-2.0], [2.24.0])
XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-3.0], [3.10])
XDT_CHECK_PACKAGE([DBUS], [dbus-1], [1.1.0])
XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84])
XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.12.0])
dnl Check for Polkit/PolicyKit
......
......@@ -18,7 +18,9 @@ bin_PROGRAMS = xfce4-session
xfce4_session_built_sources = \
xfsm-chooser-icon.h \
xfsm-client-dbus.c \
xfsm-client-dbus.h \
xfsm-manager-dbus.c \
xfsm-manager-dbus.h \
xfsm-marshal.c \
xfsm-marshal.h
......@@ -74,8 +76,6 @@ xfce4_session_CFLAGS = \
$(LIBX11_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
$(GIO_CFLAGS) \
$(DBUS_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
$(LIBWNCK_CFLAGS) \
$(POLKIT_CFLAGS) \
$(XFCONF_CFLAGS) \
......@@ -95,8 +95,6 @@ xfce4_session_LDADD = \
$(LIBXFCE4UI_LIBS) \
$(GMODULE_LIBS) \
$(GIO_LIBS) \
$(DBUS_LIBS) \
$(DBUS_GLIB_LIBS) \
$(LIBWNCK_LIBS) \
$(POLKIT_LIBS) \
$(XFCONF_LIBS) \
......@@ -129,11 +127,19 @@ xfsm-marshal.c: $(srcdir)/xfsm-marshal.list Makefile
$(AM_V_GEN) echo "#include <xfce4-session/xfsm-marshal.h>" > $@ \
&& glib-genmarshal --prefix=xfsm_marshal --body $< >> $@
xfsm-manager-dbus.h: $(srcdir)/xfsm-manager-dbus.xml
$(AM_V_GEN) dbus-binding-tool --mode=glib-server --prefix=xfsm_manager $< > $@
xfsm-client-dbus.h: $(srcdir)/xfsm-client-dbus.xml
$(AM_V_GEN) dbus-binding-tool --mode=glib-server --prefix=xfsm_client $< > $@
xfsm-client-dbus.c xfsm-client-dbus.h : $(srcdir)/xfsm-client-dbus.xml Makefile.am
gdbus-codegen \
--c-namespace=XfsmDbus \
--interface-prefix=org.xfce.Session. \
--generate-c-code=xfsm-client-dbus \
$(srcdir)/xfsm-client-dbus.xml
xfsm-manager-dbus.c xfsm-manager-dbus.h : $(srcdir)/xfsm-manager-dbus.xml Makefile.am
gdbus-codegen \
--c-namespace=XfsmDbus \
--interface-prefix=org.xfce.Session. \
--generate-c-code=xfsm-manager-dbus \
$(srcdir)/xfsm-manager-dbus.xml
BUILT_SOURCES = \
$(xfce4_session_built_sources)
......
......@@ -46,8 +46,7 @@
#include <unistd.h>
#endif
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <gio/gio.h>
#include <xfconf/xfconf.h>
......@@ -70,6 +69,8 @@
static gboolean opt_disable_tcp = FALSE;
static gboolean opt_version = FALSE;
static XfsmManager *manager = NULL;
static XfconfChannel *channel = NULL;
static GOptionEntry option_entries[] =
{
......@@ -145,50 +146,115 @@ init_display (XfsmManager *manager,
}
static void
xfsm_dbus_init (void)
bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
DBusGConnection *dbus_conn;
int ret;
GError *error = NULL;
GdkDisplay *dpy;
xfsm_error_dbus_init ();
g_debug ("bus_acquired %s\n", name);
manager = xfsm_manager_new (connection);
if (manager == NULL) {
g_critical ("Could not create XfsmManager");
}
setup_environment ();
dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (G_UNLIKELY (!dbus_conn))
channel = xfsm_open_config ();
dpy = gdk_display_get_default ();
init_display (manager, dpy, channel, opt_disable_tcp);
if (!opt_disable_tcp && xfconf_channel_get_bool (channel, "/security/EnableTcp", FALSE))
{
g_critical ("Unable to contact D-Bus session bus: %s", error ? error->message : "Unknown error");
if (error)
g_error_free (error);
return;
/* verify that the DNS settings are ok */
xfsm_splash_screen_next (splash_screen, _("Verifying DNS settings"));
xfsm_dns_check ();
}
ret = dbus_bus_request_name (dbus_g_connection_get_connection (dbus_conn),
"org.xfce.SessionManager",
DBUS_NAME_FLAG_DO_NOT_QUEUE,
NULL);
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
xfsm_splash_screen_next (splash_screen, _("Loading session data"));
xfsm_startup_init (channel);
xfsm_manager_load (manager, channel);
xfsm_manager_restart (manager);
}
static void
name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_debug ("name_acquired\n");
}
static void
name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
GError *error = NULL;
XfsmShutdownType shutdown_type;
XfsmShutdown *shutdown_helper;
gboolean succeed = TRUE;
g_debug ("name_lost\n");
/* Release the object */
g_debug ("Disconnected from D-Bus");
shutdown_type = xfsm_manager_get_shutdown_type (manager);
/* take over the ref before we release the manager */
shutdown_helper = xfsm_shutdown_get ();
g_object_unref (manager);
g_object_unref (channel);
ice_cleanup ();
if (shutdown_type == XFSM_SHUTDOWN_SHUTDOWN
|| shutdown_type == XFSM_SHUTDOWN_RESTART)
{
g_printerr ("%s: Another session manager is already running\n", PACKAGE_NAME);
exit (EXIT_FAILURE);
succeed = xfsm_shutdown_try_type (shutdown_helper, shutdown_type, &error);
if (!succeed)
g_warning ("Failed to shutdown/restart: %s", ERROR_MSG (error));
}
g_object_unref (shutdown_helper);
gtk_main_quit ();
}
static void
xfsm_dbus_cleanup (void)
xfsm_dbus_init (void)
{
DBusGConnection *dbus_conn;
/* this is all not really necessary, but... */
int ret;
dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
if (G_UNLIKELY (!dbus_conn))
return;
ret = g_bus_own_name (G_BUS_TYPE_SESSION,
"org.xfce.SessionManager",
G_BUS_NAME_OWNER_FLAGS_NONE,
bus_acquired, name_acquired, name_lost,
NULL, NULL);
dbus_bus_release_name (dbus_g_connection_get_connection (dbus_conn),
"org.xfce.SessionManager", NULL);
if (ret == 0)
{
g_printerr ("%s: Another session manager is already running\n", PACKAGE_NAME);
exit (EXIT_FAILURE);
}
}
static gboolean
xfsm_dbus_require_session (gint argc, gchar **argv)
{
......@@ -232,12 +298,7 @@ xfsm_dbus_require_session (gint argc, gchar **argv)
int
main (int argc, char **argv)
{
XfsmManager *manager;
GError *error = NULL;
GdkDisplay *dpy;
XfconfChannel *channel;
XfsmShutdownType shutdown_type;
XfsmShutdown *shutdown_helper;
gboolean succeed = TRUE;
if (!xfsm_dbus_require_session (argc, argv))
......@@ -260,7 +321,7 @@ main (int argc, char **argv)
if (opt_version)
{
g_print ("%s %s (Xfce %s)\n\n", G_LOG_DOMAIN, PACKAGE_VERSION, xfce_version_string ());
g_print ("%s\n", "Copyright (c) 2003-2014");
g_print ("%s\n", "Copyright (c) 2003-2016");
g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
g_print ("\n");
......@@ -281,51 +342,7 @@ main (int argc, char **argv)
xfsm_dbus_init ();
manager = xfsm_manager_new ();
setup_environment ();
channel = xfsm_open_config ();
dpy = gdk_display_get_default ();
init_display (manager, dpy, channel, opt_disable_tcp);
if (!opt_disable_tcp && xfconf_channel_get_bool (channel, "/security/EnableTcp", FALSE))
{
/* verify that the DNS settings are ok */
xfsm_splash_screen_next (splash_screen, _("Verifying DNS settings"));
xfsm_dns_check ();
}
xfsm_splash_screen_next (splash_screen, _("Loading session data"));
xfsm_startup_init (channel);
xfsm_manager_load (manager, channel);
xfsm_manager_restart (manager);
gtk_main ();
xfsm_startup_shutdown ();
shutdown_type = xfsm_manager_get_shutdown_type (manager);
/* take over the ref before we release the manager */
shutdown_helper = xfsm_shutdown_get ();
g_object_unref (manager);
g_object_unref (channel);
xfsm_dbus_cleanup ();
ice_cleanup ();
if (shutdown_type == XFSM_SHUTDOWN_SHUTDOWN
|| shutdown_type == XFSM_SHUTDOWN_RESTART)
{
succeed = xfsm_shutdown_try_type (shutdown_helper, shutdown_type, &error);
if (!succeed)
g_warning ("Failed to shutdown/restart: %s", ERROR_MSG (error));
}
g_object_unref (shutdown_helper);
return succeed ? EXIT_SUCCESS : EXIT_FAILURE;
}
......@@ -28,7 +28,7 @@
#include <string.h>
#endif
#include <dbus/dbus-glib.h>
#include <gio/gio.h>
#include <libxfsm/xfsm-util.h>
......@@ -37,12 +37,13 @@
#include <xfce4-session/xfsm-global.h>
#include <xfce4-session/xfsm-marshal.h>
#include <xfce4-session/xfsm-error.h>
#include <xfce4-session/xfsm-client-dbus.h>
#define XFSM_CLIENT_OBJECT_PATH_PREFIX "/org/xfce/SessionClients/"
struct _XfsmClient
{
GObject parent;
XfsmDbusClientSkeleton parent;
XfsmManager *manager;
......@@ -53,24 +54,12 @@ struct _XfsmClient
XfsmProperties *properties;
SmsConn sms_conn;
DBusGConnection *dbus_conn;
GDBusConnection *connection;
};
typedef struct _XfsmClientClass
{
GObjectClass parent;
/*< signals >*/
void (*state_changed) (XfsmClient *client,
XfsmClientState old_state,
XfsmClientState new_state);
void (*sm_property_changed) (XfsmClient *client,
const gchar *name,
const GValue *value);
void (*sm_property_deleted) (XfsmClient *client,
const gchar *name);
XfsmDbusClientSkeletonClass parent;
} XfsmClientClass;
typedef struct
......@@ -79,13 +68,6 @@ typedef struct
gint count;
} HtToPropsData;
enum
{
SIG_STATE_CHANGED = 0,
SIG_SM_PROPERTY_CHANGED,
SIG_SM_PROPERTY_DELETED,
N_SIGS
};
static void xfsm_client_finalize (GObject *obj);
......@@ -94,13 +76,11 @@ static void xfsm_properties_discard_command_changed (XfsmProperties *properti
gchar **old_discard);
static void xfsm_client_dbus_class_init (XfsmClientClass *klass);
static void xfsm_client_dbus_init (XfsmClient *client);
static void xfsm_client_iface_init (XfsmDbusClientIface *iface);
static void xfsm_client_dbus_cleanup (XfsmClient *client);
static guint signals[N_SIGS] = { 0, };
G_DEFINE_TYPE(XfsmClient, xfsm_client, G_TYPE_OBJECT)
G_DEFINE_TYPE_WITH_CODE (XfsmClient, xfsm_client, XFSM_DBUS_TYPE_CLIENT_SKELETON, G_IMPLEMENT_INTERFACE (XFSM_DBUS_TYPE_CLIENT, xfsm_client_iface_init));
static void
......@@ -110,36 +90,6 @@ xfsm_client_class_init (XfsmClientClass *klass)
gobject_class->finalize = xfsm_client_finalize;
signals[SIG_STATE_CHANGED] = g_signal_new ("state-changed",
XFSM_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfsmClientClass,
state_changed),
NULL, NULL,
xfsm_marshal_VOID__UINT_UINT,
G_TYPE_NONE, 2,
G_TYPE_UINT, G_TYPE_UINT);
signals[SIG_SM_PROPERTY_CHANGED] = g_signal_new ("sm-property-changed",
XFSM_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfsmClientClass,
sm_property_changed),
NULL, NULL,
xfsm_marshal_VOID__STRING_BOXED,
G_TYPE_NONE, 2,
G_TYPE_STRING, G_TYPE_VALUE);
signals[SIG_SM_PROPERTY_DELETED] = g_signal_new ("sm-property-deleted",
XFSM_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XfsmClientClass,
sm_property_deleted),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
xfsm_client_dbus_class_init (klass);
}
......@@ -201,13 +151,33 @@ xfsm_client_signal_prop_change (XfsmClient *client,
const gchar *name)
{
const GValue *value;
GVariant *variant = NULL;
XfsmProperties *properties = client->properties;
value = xfsm_properties_get (properties, name);
if (value)
{
g_signal_emit (client, signals[SIG_SM_PROPERTY_CHANGED], 0,
name, value);
/* convert the gvalue to gvariant because gdbus requires it */
if (G_VALUE_HOLDS_STRING (value))
{
variant = g_dbus_gvalue_to_gvariant(value, G_VARIANT_TYPE_STRING);
}
else if (G_VALUE_HOLDS_UCHAR (value))
{
variant = g_dbus_gvalue_to_gvariant(value, G_VARIANT_TYPE ("y"));
}
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
{
variant = g_dbus_gvalue_to_gvariant(value, G_VARIANT_TYPE_STRING_ARRAY);
}
else
{
g_warning ("xfsm_client.c:xfsm_client_signal_prop_change: Value type not supported");
return;
}
// xfsm_dbus_client_emit_sm_property_changed (XFSM_DBUS_CLIENT (client), name, variant);
g_variant_unref (variant);
}
}
......@@ -215,7 +185,8 @@ xfsm_client_signal_prop_change (XfsmClient *client,
XfsmClient*
xfsm_client_new (XfsmManager *manager,
SmsConn sms_conn)
SmsConn sms_conn,
GDBusConnection *connection)
{
XfsmClient *client;
......@@ -225,6 +196,7 @@ xfsm_client_new (XfsmManager *manager,
client->manager = manager;
client->sms_conn = sms_conn;
client->connection = g_object_ref (connection);
client->state = XFSM_CLIENT_IDLE;
return client;
......@@ -273,7 +245,7 @@ xfsm_client_set_state (XfsmClient *client,
{
XfsmClientState old_state = client->state;
client->state = state;
g_signal_emit (client, signals[SIG_STATE_CHANGED], 0, old_state, state);
xfsm_dbus_client_emit_state_changed (XFSM_DBUS_CLIENT (client), old_state, state);
}
}
......@@ -373,8 +345,7 @@ xfsm_client_delete_properties (XfsmClient *client,
{
if (xfsm_properties_remove (properties, prop_names[n]))
{
g_signal_emit (client, signals[SIG_SM_PROPERTY_DELETED], 0,
prop_names[n]);
xfsm_dbus_client_emit_sm_property_deleted (XFSM_DBUS_CLIENT (client), prop_names[n]);
}
}
}
......@@ -393,27 +364,23 @@ xfsm_client_get_object_path (XfsmClient *client)
* dbus server impl
*/
static gboolean xfsm_client_dbus_get_id (XfsmClient *client,
gchar **OUT_id,
GError **error);
static gboolean xfsm_client_dbus_get_state (XfsmClient *client,
guint *OUT_state,
GError **error);
static gboolean xfsm_client_dbus_get_all_sm_properties (XfsmClient *client,
GHashTable **OUT_properties,
GError **error);
static gboolean xfsm_client_dbus_get_sm_properties (XfsmClient *client,
gchar **names,
GHashTable **OUT_values,
GError **error);
static gboolean xfsm_client_dbus_set_sm_properties (XfsmClient *client,
GHashTable *properties,
GError **error);
static gboolean xfsm_client_dbus_delete_sm_properties (XfsmClient *client,
gchar **names,
GError **error);
static gboolean xfsm_client_dbus_terminate (XfsmClient *client,
GError **error);
static gboolean xfsm_client_dbus_get_id (XfsmDbusClient *object,
GDBusMethodInvocation *invocation);
static gboolean xfsm_client_dbus_get_state (XfsmDbusClient *object,
GDBusMethodInvocation *invocation);
static gboolean xfsm_client_dbus_get_all_sm_properties (XfsmDbusClient *object,
GDBusMethodInvocation *invocation);
static gboolean xfsm_client_dbus_get_sm_properties (XfsmDbusClient *object,
GDBusMethodInvocation *invocation,
const gchar *const *arg_names);
static gboolean xfsm_client_dbus_set_sm_properties (XfsmDbusClient *object,
GDBusMethodInvocation *invocation,
GVariant *arg_properties);
static gboolean xfsm_client_dbus_delete_sm_properties (XfsmDbusClient *object,
GDBusMethodInvocation *invocation,
const gchar *const *arg_names);
static gboolean xfsm_client_dbus_terminate (XfsmDbusClient *object,
GDBusMethodInvocation *invocation);
/* header needs the above fwd decls */
......@@ -423,8 +390,6 @@ static gboolean xfsm_client_dbus_terminate (XfsmClient *client,
static void
xfsm_client_dbus_class_init (XfsmClientClass *klass)
{
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
&dbus_glib_xfsm_client_object_info);
}
......@@ -433,169 +398,236 @@ xfsm_client_dbus_init (XfsmClient *client)
{
GError *error = NULL;
client->dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (G_UNLIKELY(!client->dbus_conn))
if (G_UNLIKELY(!client->connection))
{
g_critical ("Unable to contact D-Bus session bus: %s", error ? error->message : "Unknown error");
if (error)
g_error_free (error);
g_clear_error (&error);
return;
}
dbus_g_connection_register_g_object (client->dbus_conn, client->object_path,
G_OBJECT (client));
g_debug ("exporting path %s", client->object_path);
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (XFSM_DBUS_CLIENT (client)),
client->connection,
client->object_path,
&error)) {
if (error != NULL) {
g_critical ("error exporting interface: %s", error->message);
g_clear_error (&error);
return;
}
}
g_debug ("exported on %s", g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (XFSM_DBUS_CLIENT (client))));
}
static void
xfsm_client_iface_init (XfsmDbusClientIface *iface)
{
iface->handle_delete_sm_properties = xfsm_client_dbus_delete_sm_properties;
iface->handle_get_all_sm_properties = xfsm_client_dbus_get_all_sm_properties;
iface->handle_get_id = xfsm_client_dbus_get_id;
iface->handle_get_sm_properties = xfsm_client_dbus_get_sm_properties;
iface->handle_get_state = xfsm_client_dbus_get_state;
iface->handle_set_sm_properties = xfsm_client_dbus_set_sm_properties;
iface->handle_terminate = xfsm_client_dbus_terminate;
}
static void
xfsm_client_dbus_cleanup (XfsmClient *client)
{
if (G_LIKELY (client->dbus_conn))
if (G_LIKELY (client->connection))
{
dbus_g_connection_unref (client->dbus_conn);
client->dbus_conn = NULL;
g_object_unref (client->connection);
client->connection = NULL;
}
}
static gboolean
xfsm_client_dbus_get_id (XfsmClient *client,
gchar **OUT_id,
GError **error)
xfsm_client_dbus_get_id (XfsmDbusClient *object,
GDBusMethodInvocation *invocation)
{
*OUT_id = g_strdup (client->id);
xfsm_dbus_client_complete_get_id (object, invocation, XFSM_CLIENT(object)->id);
return TRUE;
}