summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@novell.com>2011-07-06 02:36:27 +0200
committerVincent Untz <vuntz@novell.com>2011-07-06 02:41:55 +0200
commitdbf56332354cf736f8e1e43c164473a5345ed457 (patch)
tree46efa7488b3c5f07c882154edf12cb2ecabed0e3
parent863171518f83604854f86d00599bcdf1c4b3dba4 (diff)
Port to GDBus
This includes various small other changes (moving our internal cups API to use GVariant instead of GHashTable, for instance).
-rw-r--r--configure.ac7
-rw-r--r--src/Makefile.am24
-rw-r--r--src/cups-pk-helper-mechanism.c1000
-rw-r--r--src/cups-pk-helper-mechanism.h197
-rw-r--r--src/cups.c229
-rw-r--r--src/cups.h38
-rw-r--r--src/main.c142
7 files changed, 917 insertions, 720 deletions
diff --git a/configure.ac b/configure.ac
index 48f4fd0..7c6b30a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,7 @@ if test "x$enable_deprecation_flags" = "xyes"; then
fi
# Dependencies
-GLIB_REQUIRED=2.14.0
+GLIB_REQUIRED=2.29.8
DBUS_REQUIRED=1.1.2
DBUS_GLIB_REQUIRED=0.74
POLKIT_REQUIRED=0.92
@@ -42,8 +42,7 @@ POLKIT_REQUIRED=0.92
PKG_CHECK_MODULES(CUPS_PK, glib-2.0 >= $GLIB_REQUIRED \
gobject-2.0 \
gthread-2.0 \
- dbus-1 >= $DBUS_REQUIRED \
- dbus-glib-1 >= $DBUS_GLIB_REQUIRED \
+ gio-2.0 \
polkit-gobject-1 >= $POLKIT_REQUIRED)
AC_SUBST(CUPS_PK_CFLAGS)
AC_SUBST(CUPS_PK_LIBS)
@@ -59,6 +58,8 @@ AC_CHECK_HEADERS(cups/cups.h cups/http.h cups/ipp.h)
CUPS_LIBS=-lcups
AC_SUBST(CUPS_LIBS)
+AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen])
+
AC_OUTPUT([
Makefile
src/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 078a2b3..b3f7356 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,11 +14,26 @@ cups_pk_helper_mechanism_SOURCES = \
cups.h \
cups-pk-helper-mechanism.c \
cups-pk-helper-mechanism.h \
- main.c
+ main.c \
+ $(cph_iface_mechanism)
cups_pk_helper_mechanism_LDADD = \
$(CUPS_PK_LIBS) \
$(CUPS_LIBS)
+cph_iface_mechanism = \
+ cph-iface-mechanism.c \
+ cph-iface-mechanism.h
+
+$(cph_iface_mechanism): $(srcdir)/cups-pk-helper-mechanism.xml
+ $(AM_V_GEN)$(GDBUS_CODEGEN) \
+ --interface-prefix=org.opensuse.CupsPkHelper. \
+ --c-namespace CphIface \
+ --generate-c-code cph-iface-mechanism \
+ --c-generate-object-manager \
+ $<
+
+BUILT_SOURCES = $(cph_iface_mechanism)
+
test_cups_SOURCES = \
cups.c \
cups.h \
@@ -37,13 +52,6 @@ test_cups_pk_LDADD = \
$(CUPS_PK_LIBS) \
$(CUPS_LIBS)
-cups-pk-helper-mechanism-glue.h: $(srcdir)/cups-pk-helper-mechanism.xml
- $(AM_V_GEN)dbus-binding-tool --prefix=cph_mechanism --mode=glib-server \
- --output=cups-pk-helper-mechanism-glue.h \
- $(srcdir)/cups-pk-helper-mechanism.xml
-
-BUILT_SOURCES = cups-pk-helper-mechanism-glue.h
-
dbus_confdir = $(sysconfdir)/dbus-1/system.d
dbus_conf_DATA = org.opensuse.CupsPkHelper.Mechanism.conf
diff --git a/src/cups-pk-helper-mechanism.c b/src/cups-pk-helper-mechanism.c
index 273c262..75db745 100644
--- a/src/cups-pk-helper-mechanism.c
+++ b/src/cups-pk-helper-mechanism.c
@@ -41,18 +41,20 @@
#include <glib.h>
#include <glib-object.h>
-
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include <polkit/polkit.h>
#include <pwd.h>
#include "cups-pk-helper-mechanism.h"
-#include "cups-pk-helper-mechanism-glue.h"
+#include "cph-iface-mechanism.h"
#include "cups.h"
+#define CPH_SERVICE_DBUS "org.freedesktop.DBus"
+#define CPH_PATH_DBUS "/org/freedesktop/DBus"
+#define CPH_INTERFACE_DBUS "org.freedesktop.DBus"
+
/* exit timer */
static gboolean
@@ -79,60 +81,50 @@ reset_killtimer (CphMechanism *mechanism)
/* error */
+static const GDBusErrorEntry cph_error_entries[] =
+{
+ { CPH_MECHANISM_ERROR_GENERAL, "org.opensuse.CupsPkHelper.Mechanism.GeneralError" },
+ { CPH_MECHANISM_ERROR_NOT_PRIVILEGED, "org.opensuse.CupsPkHelper.Mechanism.NotPrivileged" }
+};
+
GQuark
cph_mechanism_error_quark (void)
{
static GQuark ret = 0;
- if (ret == 0)
- ret = g_quark_from_static_string ("cph_mechanism_error");
-
- return ret;
-}
-
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+ if (ret == 0) {
+ g_assert (CPH_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (cph_error_entries));
-GType
-cph_mechanism_error_get_type (void)
-{
- static GType etype = 0;
-
- if (etype == 0) {
- static const GEnumValue values[] =
- {
- ENUM_ENTRY (CPH_MECHANISM_ERROR_GENERAL,
- "GeneralError"),
- ENUM_ENTRY (CPH_MECHANISM_ERROR_NOT_PRIVILEGED,
- "NotPrivileged"),
- { 0, 0, 0 }
- };
-
- g_assert (CPH_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
-
- etype = g_enum_register_static ("CphMechanismError", values);
+ g_dbus_error_register_error_domain ("cph-mechanism-error",
+ &ret,
+ cph_error_entries,
+ G_N_ELEMENTS (cph_error_entries));
}
- return etype;
+ return ret;
}
/* mechanism object */
-G_DEFINE_TYPE (CphMechanism, cph_mechanism, G_TYPE_OBJECT)
+G_DEFINE_TYPE (CphMechanism, cph_mechanism, CPH_IFACE_TYPE_MECHANISM_SKELETON)
#define CPH_MECHANISM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CPH_TYPE_MECHANISM, CphMechanismPrivate))
struct CphMechanismPrivate
{
- DBusGConnection *system_bus_connection;
+ gboolean exported;
PolkitAuthority *pol_auth;
CphCups *cups;
+ GDBusProxy *dbus_proxy;
};
static GObject *cph_mechanism_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties);
+static void cph_mechanism_dispose (GObject *object);
static void cph_mechanism_finalize (GObject *object);
+static void cph_mechanism_connect_signals (CphMechanism *mechanism);
static void
cph_mechanism_class_init (CphMechanismClass *klass)
@@ -140,15 +132,10 @@ cph_mechanism_class_init (CphMechanismClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = cph_mechanism_constructor;
+ object_class->dispose = cph_mechanism_dispose;
object_class->finalize = cph_mechanism_finalize;
g_type_class_add_private (klass, sizeof (CphMechanismPrivate));
-
- dbus_g_object_type_install_info (CPH_TYPE_MECHANISM,
- &dbus_glib_cph_mechanism_object_info);
-
- dbus_g_error_domain_register (CPH_MECHANISM_ERROR, NULL,
- CPH_MECHANISM_TYPE_ERROR);
}
static GObject *
@@ -180,11 +167,14 @@ cph_mechanism_init (CphMechanism *mechanism)
{
mechanism->priv = CPH_MECHANISM_GET_PRIVATE (mechanism);
+ mechanism->priv->exported = FALSE;
+ mechanism->priv->pol_auth = NULL;
mechanism->priv->cups = NULL;
+ mechanism->priv->dbus_proxy = NULL;
}
static void
-cph_mechanism_finalize (GObject *object)
+cph_mechanism_dispose (GObject *object)
{
CphMechanism *mechanism;
@@ -193,43 +183,38 @@ cph_mechanism_finalize (GObject *object)
mechanism = CPH_MECHANISM (object);
- if (mechanism->priv->cups)
+ if (mechanism->priv->pol_auth != NULL)
+ g_object_unref (mechanism->priv->pol_auth);
+ mechanism->priv->pol_auth = NULL;
+
+ if (mechanism->priv->cups != NULL)
g_object_unref (mechanism->priv->cups);
mechanism->priv->cups = NULL;
- G_OBJECT_CLASS (cph_mechanism_parent_class)->finalize (object);
+ if (mechanism->priv->dbus_proxy != NULL)
+ g_object_unref (mechanism->priv->dbus_proxy);
+ mechanism->priv->dbus_proxy = NULL;
+
+ G_OBJECT_CLASS (cph_mechanism_parent_class)->dispose (object);
}
-static gboolean
-register_mechanism (CphMechanism *mechanism)
+static void
+cph_mechanism_finalize (GObject *object)
{
- GError *error;
+ CphMechanism *mechanism;
- mechanism->priv->pol_auth = polkit_authority_get ();
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (CPH_IS_MECHANISM (object));
- error = NULL;
- mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM,
- &error);
- if (mechanism->priv->system_bus_connection == NULL) {
- if (error != NULL) {
- g_critical ("error getting system bus: %s",
- error->message);
- g_error_free (error);
- } else {
- g_critical ("error getting system bus");
- }
- return FALSE;
- }
+ mechanism = CPH_MECHANISM (object);
- dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/",
- G_OBJECT (mechanism));
+ if (mechanism->priv->exported)
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (mechanism));
+ mechanism->priv->exported = FALSE;
- reset_killtimer (mechanism);
-
- return TRUE;
+ G_OBJECT_CLASS (cph_mechanism_parent_class)->finalize (object);
}
-
CphMechanism *
cph_mechanism_new (void)
{
@@ -237,22 +222,50 @@ cph_mechanism_new (void)
object = g_object_new (CPH_TYPE_MECHANISM, NULL);
- if (!register_mechanism (CPH_MECHANISM (object))) {
- g_object_unref (object);
- return NULL;
- }
-
return CPH_MECHANISM (object);
}
+gboolean
+cph_mechanism_register (CphMechanism *mechanism,
+ GDBusConnection *connection,
+ const char *object_path,
+ GError **error)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (CPH_IS_MECHANISM (mechanism), FALSE);
+ g_return_val_if_fail (!mechanism->priv->exported, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (mechanism),
+ connection,
+ object_path,
+ error);
+
+ if (!ret)
+ return FALSE;
+
+ g_assert (mechanism->priv->pol_auth == NULL);
+
+ mechanism->priv->exported = TRUE;
+ mechanism->priv->pol_auth = polkit_authority_get ();
+ cph_mechanism_connect_signals (mechanism);
+
+ reset_killtimer (mechanism);
+
+ return TRUE;
+}
+
+/* polkit helpers */
+
static gboolean
_check_polkit_for_action_internal (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
+ GDBusMethodInvocation *context,
const char *action_method,
gboolean allow_user_interaction,
GError **error)
{
- char *sender;
+ const char *sender;
PolkitSubject *subject;
PolkitAuthorizationResult *pk_result;
char *action;
@@ -266,9 +279,8 @@ _check_polkit_for_action_internal (CphMechanism *mechanism,
action_method);
/* Check that caller is privileged */
- sender = dbus_g_method_get_sender (context);
+ sender = g_dbus_method_invocation_get_sender (context);
subject = polkit_system_bus_name_new (sender);
- g_free (sender);
pk_result = polkit_authority_check_authorization_sync (mechanism->priv->pol_auth,
subject,
@@ -307,7 +319,7 @@ _check_polkit_for_action_internal (CphMechanism *mechanism,
static gboolean
_check_polkit_for_action_v (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
+ GDBusMethodInvocation *context,
const char *first_action_method,
...)
{
@@ -358,7 +370,7 @@ _check_polkit_for_action_v (CphMechanism *mechanism,
"authorization");
}
- dbus_g_method_return_error (context, error);
+ g_dbus_method_invocation_return_gerror (context, error);
g_error_free (error);
}
@@ -367,7 +379,7 @@ _check_polkit_for_action_v (CphMechanism *mechanism,
static gboolean
_check_polkit_for_action (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
+ GDBusMethodInvocation *context,
const char *action_method)
{
return _check_polkit_for_action_v (mechanism, context,
@@ -376,7 +388,7 @@ _check_polkit_for_action (CphMechanism *mechanism,
static gboolean
_check_polkit_for_printer (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
+ GDBusMethodInvocation *context,
const char *printer_name,
const char *uri)
{
@@ -396,7 +408,7 @@ _check_polkit_for_printer (CphMechanism *mechanism,
static gboolean
_check_polkit_for_printer_class (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
+ GDBusMethodInvocation *context,
const char *printer_name)
{
if (cph_cups_is_class (mechanism->priv->cups, printer_name)) {
@@ -423,55 +435,102 @@ _cph_mechanism_get_action_for_name (CphMechanism *mechanism,
return "printer-remote-edit";
}
+static void
+_cph_mechanism_ensure_dbus_proxy (CphMechanism *mechanism,
+ GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (mechanism->priv->dbus_proxy != NULL)
+ return;
+
+ mechanism->priv->dbus_proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ CPH_SERVICE_DBUS,
+ CPH_PATH_DBUS,
+ CPH_INTERFACE_DBUS,
+ NULL,
+ &error);
+
+ if (mechanism->priv->dbus_proxy == NULL) {
+ if (error)
+ g_warning ("Could not get proxy to dbus service: %s", error->message);
+ else
+ g_warning ("Could not get proxy to dbus service user");
+
+ g_error_free (error);
+ }
+}
+
+static gboolean
+_cph_mechanism_get_sender_uid (CphMechanism *mechanism,
+ GDBusMethodInvocation *context,
+ unsigned int *sender_uid)
+{
+ GError *error;
+ GDBusConnection *connection;
+ const char *sender;
+ GVariant *result;
+
+ *sender_uid = 0;
+
+ connection = g_dbus_method_invocation_get_connection (context);
+ _cph_mechanism_ensure_dbus_proxy (mechanism, connection);
+ if (mechanism->priv->dbus_proxy == NULL)
+ return FALSE;
+
+ sender = g_dbus_method_invocation_get_sender (context);
+
+ error = NULL;
+ result = g_dbus_proxy_call_sync (mechanism->priv->dbus_proxy,
+ "GetConnectionUnixUser",
+ g_variant_new ("(s)", sender),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result == NULL) {
+ if (error)
+ g_warning ("Could not get unix user: %s", error->message);
+ else
+ g_warning ("Could not get unix user");
+
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_variant_get (result, "(u)", sender_uid);
+ g_variant_unref (result);
+
+ return TRUE;
+}
+
static char *
-_cph_mechanism_get_callers_user_name (CphMechanism *mechanism,
- DBusGMethodInvocation *context)
+_cph_mechanism_get_sender_user_name (CphMechanism *mechanism,
+ GDBusMethodInvocation *context)
{
- unsigned long sender_uid;
+ unsigned int sender_uid;
struct passwd *password_entry;
- DBusError dbus_error;
- gchar *sender;
char *user_name = NULL;
- sender = dbus_g_method_get_sender (context);
- dbus_error_init (&dbus_error);
- sender_uid = dbus_bus_get_unix_user (
- dbus_g_connection_get_connection (mechanism->priv->system_bus_connection),
- sender, &dbus_error);
+ if (!_cph_mechanism_get_sender_uid (mechanism, context, &sender_uid))
+ return NULL;
+
password_entry = getpwuid ((uid_t) sender_uid);
if (password_entry != NULL)
user_name = g_strdup (password_entry->pw_name);
- g_free (sender);
-
return user_name;
}
/* helpers */
-static void
-_cph_mechanism_return_error (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
- gboolean failed)
-{
- const char *error;
-
- if (failed) {
- error = cph_cups_last_status_to_string (mechanism->priv->cups);
- if (!error || error[0] == '\0')
- error = "Unknown error";
- } else
- error = "";
-
- dbus_g_method_return (context, error);
-}
-
-static void
-_cph_mechanism_return_error_and_value (CphMechanism *mechanism,
- DBusGMethodInvocation *context,
- gboolean failed,
- gpointer value)
+static const char *
+_cph_mechanism_return_error (CphMechanism *mechanism,
+ gboolean failed)
{
const char *error;
@@ -482,86 +541,113 @@ _cph_mechanism_return_error_and_value (CphMechanism *mechanism,
} else
error = "";
- dbus_g_method_return (context, error, value);
+ return error;
}
/* exported methods */
-void
-cph_mechanism_file_get (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_file_get (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *resource,
- const char *filename,
- DBusGMethodInvocation *context)
+ const char *filename)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_action (mechanism, context, "server-settings"))
- return;
+ return TRUE;
ret = cph_cups_file_get (mechanism->priv->cups, resource, filename);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_file_get (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_file_put (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_file_put (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *resource,
- const char *filename,
- DBusGMethodInvocation *context)
+ const char *filename)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_action (mechanism, context, "server-settings"))
- return;
+ return TRUE;
ret = cph_cups_file_put (mechanism->priv->cups, resource, filename);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_file_put (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_server_get_settings (CphMechanism *mechanism,
- DBusGMethodInvocation *context)
+static gboolean
+cph_mechanism_server_get_settings (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context)
{
- GHashTable *settings;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
+ GVariant *settings = NULL;
reset_killtimer (mechanism);
if (!_check_polkit_for_action (mechanism, context, "server-settings"))
- return;
+ return TRUE;
+
+ ret = cph_cups_server_get_settings (mechanism->priv->cups,
+ &settings);
- settings = cph_cups_server_get_settings (mechanism->priv->cups);
- _cph_mechanism_return_error_and_value (mechanism, context,
- settings == NULL, settings);
+ if (settings == NULL)
+ settings = g_variant_new_array (G_VARIANT_TYPE_DICT_ENTRY, NULL, 0);
+
+ cph_iface_mechanism_complete_server_get_settings (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret),
+ settings);
+ return TRUE;
}
-void
-cph_mechanism_server_set_settings (CphMechanism *mechanism,
- GHashTable *settings,
- DBusGMethodInvocation *context)
+static gboolean
+cph_mechanism_server_set_settings (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
+ GVariant *settings)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_action (mechanism, context, "server-settings"))
- return;
+ return TRUE;
ret = cph_cups_server_set_settings (mechanism->priv->cups, settings);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_server_set_settings (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_devices_get (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_devices_get (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
int timeout,
int limit,
- const char **include_schemes,
- const char **exclude_schemes,
- DBusGMethodInvocation *context)
+ const char *const *include_schemes,
+ const char *const *exclude_schemes)
{
- GHashTable *devices;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
+ GVariant *devices = NULL;
reset_killtimer (mechanism);
@@ -569,85 +655,109 @@ cph_mechanism_devices_get (CphMechanism *mechanism,
"all-edit",
"devices-get",
NULL))
- return;
-
- devices = cph_cups_devices_get (mechanism->priv->cups,
- timeout,
- limit,
- include_schemes,
- exclude_schemes);
- _cph_mechanism_return_error_and_value (mechanism, context,
- devices == NULL, devices);
+ return TRUE;
+
+ ret = cph_cups_devices_get (mechanism->priv->cups,
+ timeout,
+ limit,
+ include_schemes,
+ exclude_schemes,
+ &devices);
+
+ if (devices == NULL)
+ devices = g_variant_new_array (G_VARIANT_TYPE_DICT_ENTRY, NULL, 0);
+
+ cph_iface_mechanism_complete_devices_get (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret),
+ devices);
+ return TRUE;
}
-void
-cph_mechanism_printer_add (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_add (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
const char *uri,
const char *ppd,
const char *info,
- const char *location,
- DBusGMethodInvocation *context)
+ const char *location)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer (mechanism, context, name, uri))
- return;
+ return TRUE;
ret = cph_cups_printer_add (mechanism->priv->cups,
name, uri, ppd, info, location);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_add (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_add_with_ppd_file (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_add_with_ppd_file (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
const char *uri,
const char *ppdfile,
const char *info,
- const char *location,
- DBusGMethodInvocation *context)
+ const char *location)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer (mechanism, context, name, uri))
- return;
+ return TRUE;
ret = cph_cups_printer_add_with_ppd_file (mechanism->priv->cups,
name, uri, ppdfile,
info, location);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_add_with_ppd_file (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_device (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_device (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *device,
- DBusGMethodInvocation *context)
+ const char *device)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer (mechanism, context, name, device))
- return;
+ return TRUE;
ret = cph_cups_printer_set_uri (mechanism->priv->cups,
name, device);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_device (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_default (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context)
+static gboolean
+cph_mechanism_printer_set_default (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
+ const char *name)
{
- gboolean ret;
- const char *last_action;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
+ const char *last_action;
reset_killtimer (mechanism);
@@ -664,20 +774,25 @@ cph_mechanism_printer_set_default (CphMechanism *mechanism,
* printer */
last_action,
NULL))
- return;
+ return TRUE;
ret = cph_cups_printer_set_default (mechanism->priv->cups, name);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_default (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_enabled (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_enabled (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- gboolean enabled,
- DBusGMethodInvocation *context)
+ gboolean enabled)
{
- gboolean ret;
- const char *last_action;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
+ const char *last_action;
reset_killtimer (mechanism);
@@ -694,58 +809,73 @@ cph_mechanism_printer_set_enabled (CphMechanism *mechanism,
* printer */
last_action,
NULL))
- return;
+ return TRUE;
ret = cph_cups_printer_set_enabled (mechanism->priv->cups,
name, enabled);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_enabled (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_accept_jobs (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_accept_jobs (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
gboolean enabled,
- const char *reason,
- DBusGMethodInvocation *context)
+ const char *reason)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer (mechanism, context, name, NULL))
- return;
+ return TRUE;
if (reason && reason[0] == '\0')
reason = NULL;
ret = cph_cups_printer_set_accept_jobs (mechanism->priv->cups,
name, enabled, reason);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_accept_jobs (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_delete (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context)
+static gboolean
+cph_mechanism_printer_delete (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
+ const char *name)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer (mechanism, context, name, NULL))
- return;
+ return TRUE;
ret = cph_cups_printer_delete (mechanism->priv->cups, name);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_delete (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_class_add_printer (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_class_add_printer (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *printer,
- DBusGMethodInvocation *context)
+ const char *printer)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
@@ -754,20 +884,25 @@ cph_mechanism_class_add_printer (CphMechanism *mechanism,
"printeraddremove",
"class-edit",
NULL))
- return;
+ return TRUE;
ret = cph_cups_class_add_printer (mechanism->priv->cups,
name, printer);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_class_add_printer (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_class_delete_printer (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_class_delete_printer (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *printer,
- DBusGMethodInvocation *context)
+ const char *printer)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
@@ -776,19 +911,24 @@ cph_mechanism_class_delete_printer (CphMechanism *mechanism,
"printeraddremove",
"class-edit",
NULL))
- return;
+ return TRUE;
ret = cph_cups_class_delete_printer (mechanism->priv->cups,
name, printer);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_class_delete_printer (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_class_delete (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context)
+static gboolean
+cph_mechanism_class_delete (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
+ const char *name)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
@@ -797,216 +937,262 @@ cph_mechanism_class_delete (CphMechanism *mechanism,
"printeraddremove",
"class-edit",
NULL))
- return;
+ return TRUE;
ret = cph_cups_class_delete (mechanism->priv->cups, name);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_class_delete (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_info (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_info (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *info,
- DBusGMethodInvocation *context)
+ const char *info)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_info (mechanism->priv->cups,
name, info);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_info (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_location (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_location (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *location,
- DBusGMethodInvocation *context)
+ const char *location)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_location (mechanism->priv->cups,
name, location);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_location (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_shared (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_shared (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- gboolean shared,
- DBusGMethodInvocation *context)
+ gboolean shared)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_shared (mechanism->priv->cups,
name, shared);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_shared (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_job_sheets (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_job_sheets (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
const char *start,
- const char *end,
- DBusGMethodInvocation *context)
+ const char *end)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_job_sheets (mechanism->priv->cups,
name, start, end);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_job_sheets (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_error_policy (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_error_policy (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *policy,
- DBusGMethodInvocation *context)
+ const char *policy)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_error_policy (mechanism->priv->cups,
name, policy);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_error_policy (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_op_policy (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_op_policy (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *policy,
- DBusGMethodInvocation *context)
+ const char *policy)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_op_policy (mechanism->priv->cups,
name, policy);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_op_policy (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_users_allowed (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_users_allowed (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char **users,
- DBusGMethodInvocation *context)
+ const char *const *users)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_users_allowed (mechanism->priv->cups,
name, users);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_set_users_allowed (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_set_users_denied (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_set_users_denied (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char **users,
- DBusGMethodInvocation *context)
+ const char *const *users)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_users_denied (mechanism->priv->cups,
name, users);
- _cph_mechanism_return_error (mechanism, context, !ret);
-}
+ cph_iface_mechanism_complete_printer_set_users_denied (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
+}
-void
-cph_mechanism_printer_add_option_default (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_add_option_default (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
const char *option,
- const char **values,
- DBusGMethodInvocation *context)
+ const char *const *values)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_option_default (mechanism->priv->cups,
name, option, values);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_printer_add_option_default (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_printer_delete_option_default (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_printer_delete_option_default (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
const char *name,
- const char *option,
- DBusGMethodInvocation *context)
+ const char *option)
{
- gboolean ret;
+ CphMechanism *mechanism = CPH_MECHANISM (object);
+ gboolean ret;
reset_killtimer (mechanism);
if (!_check_polkit_for_printer_class (mechanism, context, name))
- return;
+ return TRUE;
ret = cph_cups_printer_class_set_option_default (mechanism->priv->cups,
name, option, NULL);
- _cph_mechanism_return_error (mechanism, context, !ret);
-}
-void
-cph_mechanism_job_cancel (CphMechanism *mechanism,
- int id,
- DBusGMethodInvocation *context)
-{
- cph_mechanism_job_cancel_purge (mechanism, id, FALSE, context);
+ cph_iface_mechanism_complete_printer_delete_option_default (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
+ return TRUE;
}
-void
-cph_mechanism_job_cancel_purge (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_job_cancel_purge (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
int id,
- gboolean purge,
- DBusGMethodInvocation *context)
+ gboolean purge)
{
+ CphMechanism *mechanism = CPH_MECHANISM (object);
CphJobStatus job_status;
gboolean ret;
char *user_name;
reset_killtimer (mechanism);
- user_name = _cph_mechanism_get_callers_user_name (mechanism, context);
+ user_name = _cph_mechanism_get_sender_user_name (mechanism, context);
job_status = cph_cups_job_get_status (mechanism->priv->cups,
id, user_name);
@@ -1029,30 +1215,48 @@ cph_mechanism_job_cancel_purge (CphMechanism *mechanism,
break;
}
case CPH_JOB_STATUS_INVALID: {
- _cph_mechanism_return_error (mechanism, context, TRUE);
+ cph_iface_mechanism_complete_job_cancel_purge (
+ object, context,
+ _cph_mechanism_return_error (mechanism, TRUE));
goto out;
}
}
ret = cph_cups_job_cancel (mechanism->priv->cups, id, purge, user_name);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_job_cancel_purge (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
out:
g_free (user_name);
+
+ return TRUE;
}
-void
-cph_mechanism_job_restart (CphMechanism *mechanism,
- int id,
- DBusGMethodInvocation *context)
+static gboolean
+cph_mechanism_job_cancel (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
+ int id)
+{
+ /* This only works because cph_iface_mechanism_complete_job_cancel and
+ * cph_iface_mechanism_complete_job_cancel_purge do the same thing. */
+ return cph_mechanism_job_cancel_purge (object, context, id, FALSE);
+}
+
+static gboolean
+cph_mechanism_job_restart (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
+ int id)
{
+ CphMechanism *mechanism = CPH_MECHANISM (object);
CphJobStatus job_status;
gboolean ret;
char *user_name;
reset_killtimer (mechanism);
- user_name = _cph_mechanism_get_callers_user_name (mechanism, context);
+ user_name = _cph_mechanism_get_sender_user_name (mechanism, context);
job_status = cph_cups_job_get_status (mechanism->priv->cups,
id, user_name);
@@ -1075,31 +1279,39 @@ cph_mechanism_job_restart (CphMechanism *mechanism,
break;
}
case CPH_JOB_STATUS_INVALID: {
- _cph_mechanism_return_error (mechanism, context, TRUE);
+ cph_iface_mechanism_complete_job_restart (
+ object, context,
+ _cph_mechanism_return_error (mechanism, TRUE));
goto out;
}
}
ret = cph_cups_job_restart (mechanism->priv->cups, id, user_name);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_job_restart (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
out:
g_free (user_name);
+
+ return TRUE;
}
-void
-cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
+static gboolean
+cph_mechanism_job_set_hold_until (CphIfaceMechanism *object,
+ GDBusMethodInvocation *context,
int id,
- const char *job_hold_until,
- DBusGMethodInvocation *context)
+ const char *job_hold_until)
{
+ CphMechanism *mechanism = CPH_MECHANISM (object);
CphJobStatus job_status;
gboolean ret;
char *user_name;
reset_killtimer (mechanism);
- user_name = _cph_mechanism_get_callers_user_name (mechanism, context);
+ user_name = _cph_mechanism_get_sender_user_name (mechanism, context);
job_status = cph_cups_job_get_status (mechanism->priv->cups,
id, user_name);
@@ -1122,14 +1334,146 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
break;
}
case CPH_JOB_STATUS_INVALID: {
- _cph_mechanism_return_error (mechanism, context, TRUE);
+ cph_iface_mechanism_complete_job_set_hold_until (
+ object, context,
+ _cph_mechanism_return_error (mechanism, TRUE));
goto out;
}
}
ret = cph_cups_job_set_hold_until (mechanism->priv->cups, id, job_hold_until, user_name);
- _cph_mechanism_return_error (mechanism, context, !ret);
+
+ cph_iface_mechanism_complete_job_set_hold_until (
+ object, context,
+ _cph_mechanism_return_error (mechanism, !ret));
out:
g_free (user_name);
+
+ return TRUE;
+}
+
+/* connect methors */
+
+static void
+cph_mechanism_connect_signals (CphMechanism *mechanism)
+{
+ g_return_if_fail (CPH_IS_MECHANISM (mechanism));
+
+ g_signal_connect (mechanism,
+ "handle-class-add-printer",
+ G_CALLBACK (cph_mechanism_class_add_printer),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-class-delete",
+ G_CALLBACK (cph_mechanism_class_delete),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-class-delete-printer",
+ G_CALLBACK (cph_mechanism_class_delete_printer),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-devices-get",
+ G_CALLBACK (cph_mechanism_devices_get),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-file-get",
+ G_CALLBACK (cph_mechanism_file_get),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-file-put",
+ G_CALLBACK (cph_mechanism_file_put),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-job-cancel",
+ G_CALLBACK (cph_mechanism_job_cancel),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-job-cancel-purge",
+ G_CALLBACK (cph_mechanism_job_cancel_purge),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-job-restart",
+ G_CALLBACK (cph_mechanism_job_restart),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-job-set-hold-until",
+ G_CALLBACK (cph_mechanism_job_set_hold_until),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-add",
+ G_CALLBACK (cph_mechanism_printer_add),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-add-option-default",
+ G_CALLBACK (cph_mechanism_printer_add_option_default),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-add-with-ppd-file",
+ G_CALLBACK (cph_mechanism_printer_add_with_ppd_file),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-delete",
+ G_CALLBACK (cph_mechanism_printer_delete),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-delete-option-default",
+ G_CALLBACK (cph_mechanism_printer_delete_option_default),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-accept-jobs",
+ G_CALLBACK (cph_mechanism_printer_set_accept_jobs),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-default",
+ G_CALLBACK (cph_mechanism_printer_set_default),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-device",
+ G_CALLBACK (cph_mechanism_printer_set_device),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-enabled",
+ G_CALLBACK (cph_mechanism_printer_set_enabled),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-error-policy",
+ G_CALLBACK (cph_mechanism_printer_set_error_policy),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-info",
+ G_CALLBACK (cph_mechanism_printer_set_info),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-job-sheets",
+ G_CALLBACK (cph_mechanism_printer_set_job_sheets),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-location",
+ G_CALLBACK (cph_mechanism_printer_set_location),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-op-policy",
+ G_CALLBACK (cph_mechanism_printer_set_op_policy),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-shared",
+ G_CALLBACK (cph_mechanism_printer_set_shared),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-users-allowed",
+ G_CALLBACK (cph_mechanism_printer_set_users_allowed),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-printer-set-users-denied",
+ G_CALLBACK (cph_mechanism_printer_set_users_denied),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-server-get-settings",
+ G_CALLBACK (cph_mechanism_server_get_settings),
+ NULL);
+ g_signal_connect (mechanism,
+ "handle-server-set-settings",
+ G_CALLBACK (cph_mechanism_server_set_settings),
+ NULL);
}
diff --git a/src/cups-pk-helper-mechanism.h b/src/cups-pk-helper-mechanism.h
index d5daf64..7634628 100644
--- a/src/cups-pk-helper-mechanism.h
+++ b/src/cups-pk-helper-mechanism.h
@@ -30,7 +30,9 @@
#define CPH_MECHANISM_H
#include <glib-object.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
+
+#include "cph-iface-mechanism.h"
G_BEGIN_DECLS
@@ -45,210 +47,33 @@ typedef struct CphMechanismPrivate CphMechanismPrivate;
typedef struct
{
- GObject parent;
- CphMechanismPrivate *priv;
+ CphIfaceMechanismSkeleton parent;
+ CphMechanismPrivate *priv;
} CphMechanism;
typedef struct
{
- GObjectClass parent_class;
+ CphIfaceMechanismSkeletonClass parent_class;
} CphMechanismClass;
typedef enum
{
- CPH_MECHANISM_ERROR_GENERAL,
+ CPH_MECHANISM_ERROR_GENERAL = 0,
CPH_MECHANISM_ERROR_NOT_PRIVILEGED,
CPH_MECHANISM_NUM_ERRORS
} CphMechanismError;
#define CPH_MECHANISM_ERROR cph_mechanism_error_quark ()
-GType cph_mechanism_error_get_type (void);
-#define CPH_MECHANISM_TYPE_ERROR (cph_mechanism_error_get_type ())
-
-
GQuark cph_mechanism_error_quark (void);
GType cph_mechanism_get_type (void);
CphMechanism *cph_mechanism_new (void);
-/* exported methods */
-
-void
-cph_mechanism_file_get (CphMechanism *mechanism,
- const char *resource,
- const char *filename,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_file_put (CphMechanism *mechanism,
- const char *resource,
- const char *filename,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_server_get_settings (CphMechanism *mechanism,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_server_set_settings (CphMechanism *mechanism,
- GHashTable *settings,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_devices_get (CphMechanism *mechanism,
- int timeout,
- int limit,
- const char **include_schemes,
- const char **exclude_schemes,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_add (CphMechanism *mechanism,
- const char *name,
- const char *uri,
- const char *ppd,
- const char *info,
- const char *location,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_add_with_ppd_file (CphMechanism *mechanism,
- const char *name,
- const char *uri,
- const char *ppdfile,
- const char *info,
- const char *location,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_device (CphMechanism *mechanism,
- const char *name,
- const char *device,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_default (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_enabled (CphMechanism *mechanism,
- const char *name,
- gboolean enabled,
- DBusGMethodInvocation *context);
-
-
-void
-cph_mechanism_printer_set_accept_jobs (CphMechanism *mechanism,
- const char *name,
- gboolean enabled,
- const char *reason,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_delete (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_class_add_printer (CphMechanism *mechanism,
- const char *name,
- const char *printer,
- DBusGMethodInvocation *context);
-void
-cph_mechanism_class_delete_printer (CphMechanism *mechanism,
- const char *name,
- const char *printer,
- DBusGMethodInvocation *context);
-void
-cph_mechanism_class_delete (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_info (CphMechanism *mechanism,
- const char *name,
- const char *info,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_location (CphMechanism *mechanism,
- const char *name,
- const char *location,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_shared (CphMechanism *mechanism,
- const char *name,
- gboolean shared,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_job_sheets (CphMechanism *mechanism,
- const char *name,
- const char *start,
- const char *end,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_error_policy (CphMechanism *mechanism,
- const char *name,
- const char *policy,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_op_policy (CphMechanism *mechanism,
- const char *name,
- const char *policy,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_users_allowed (CphMechanism *mechanism,
- const char *name,
- const char **users,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_set_users_denied (CphMechanism *mechanism,
- const char *name,
- const char **users,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_add_option_default (CphMechanism *mechanism,
- const char *name,
- const char *option,
- const char **values,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_printer_delete_option_default (CphMechanism *mechanism,
- const char *name,
- const char *option,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_job_cancel (CphMechanism *mechanism,
- int id,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_job_cancel_purge (CphMechanism *mechanism,
- int id,
- gboolean purge,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_job_restart (CphMechanism *mechanism,
- int id,
- DBusGMethodInvocation *context);
-
-void
-cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
- int id,
- const char *job_hold_until,
- DBusGMethodInvocation *context);
+gboolean cph_mechanism_register (CphMechanism *mechanism,
+ GDBusConnection *connection,
+ const char *object_path,
+ GError **error);
G_END_DECLS
diff --git a/src/cups.c b/src/cups.c
index 3c64242..0d831f6 100644
--- a/src/cups.c
+++ b/src/cups.c
@@ -824,11 +824,11 @@ out:
}
static gboolean
-_cph_cups_printer_class_set_users (CphCups *cups,
- const char *printer_name,
- const char **users,
- const char *request_name,
- const char *default_value)
+_cph_cups_printer_class_set_users (CphCups *cups,
+ const char *printer_name,
+ const char *const *users,
+ const char *request_name,
+ const char *default_value)
{
int real_len;
int len;
@@ -1091,45 +1091,52 @@ cph_cups_file_put (CphCups *cups,
/* Functions that are for the server in general */
-GHashTable *
-cph_cups_server_get_settings (CphCups *cups)
+gboolean
+cph_cups_server_get_settings (CphCups *cups,
+ GVariant **settings)
{
- int retval;
- GHashTable *hash;
- cups_option_t *settings;
- int num_settings, i;
+ int retval;
+ GVariantBuilder *builder;
+ cups_option_t *cups_settings;
+ int num_settings, i;
- g_return_val_if_fail (CPH_IS_CUPS (cups), NULL);
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
+ g_return_val_if_fail (settings != NULL, FALSE);
+
+ *settings = NULL;
retval = cupsAdminGetServerSettings (cups->priv->connection,
- &num_settings, &settings);
+ &num_settings, &cups_settings);
if (retval == 0) {
_cph_cups_set_internal_status (cups,
"Cannot get server settings.");
- return NULL;
+ return FALSE;
}
- hash = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_free);
+ builder = g_variant_builder_new (G_VARIANT_TYPE ("a{ss}"));
for (i = 0; i < num_settings; i++)
- g_hash_table_replace (hash,
- g_strdup (settings[i].name),
- g_strdup (settings[i].value));
+ g_variant_builder_add (builder, "{ss}",
+ cups_settings[i].name,
+ cups_settings[i].value);
- cupsFreeOptions (num_settings, settings);
+ cupsFreeOptions (num_settings, cups_settings);
+
+ *settings = g_variant_builder_end (builder);
- return hash;
+ g_variant_builder_unref (builder);
+
+ return TRUE;
}
gboolean
-cph_cups_server_set_settings (CphCups *cups,
- GHashTable *settings)
+cph_cups_server_set_settings (CphCups *cups,
+ GVariant *settings)
{
int retval;
- GHashTableIter iter;
+ GVariantIter *iter;
/* key and value are strings, but we want to avoid compiler warnings */
gpointer key;
gpointer value;
@@ -1140,22 +1147,24 @@ cph_cups_server_set_settings (CphCups *cups,
g_return_val_if_fail (settings != NULL, FALSE);
/* First pass to check the validity of the hashtable content */
- g_hash_table_iter_init (&iter, settings);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
+ g_variant_get (settings, "a{ss}", &iter);
+ while (g_variant_iter_loop (iter, "{ss}", &key, &value)) {
if (!_cph_cups_is_option_valid (cups, key))
return FALSE;
if (!_cph_cups_is_option_value_valid (cups, value))
return FALSE;
}
+ g_variant_iter_free (iter);
/* Second pass to actually set the settings */
cups_settings = NULL;
num_settings = 0;
- g_hash_table_iter_init (&iter, settings);
- while (g_hash_table_iter_next (&iter, &key, &value))
+ g_variant_get (settings, "a{ss}", &iter);
+ while (g_variant_iter_loop (iter, "{ss}", &key, &value))
num_settings = cupsAddOption (key, value,
num_settings, &cups_settings);
+ g_variant_iter_free (iter);
retval = cupsAdminSetServerSettings (cups->priv->connection,
num_settings, cups_settings);
@@ -1176,9 +1185,9 @@ cph_cups_server_set_settings (CphCups *cups,
}
typedef struct {
- int iter;
- int limit;
- GHashTable *hash;
+ int iter;
+ int limit;
+ GVariantBuilder *builder;
} CphCupsGetDevices;
static void
@@ -1191,56 +1200,63 @@ _cph_cups_get_devices_cb (const char *device_class,
void *user_data)
{
CphCupsGetDevices *data = user_data;
+ char *key;
g_return_if_fail (data != NULL);
if (data->limit > 0 && data->iter >= data->limit)
return;
- if (device_class && device_class[0] != '\0')
- g_hash_table_replace (data->hash,
- g_strdup_printf ("device-class:%d",
- data->iter),
- g_strdup (device_class));
- if (device_id && device_id[0] != '\0')
- g_hash_table_replace (data->hash,
- g_strdup_printf ("device-id:%d",
- data->iter),
- g_strdup (device_id));
- if (device_info && device_info[0] != '\0')
- g_hash_table_replace (data->hash,
- g_strdup_printf ("device-info:%d",
- data->iter),
- g_strdup (device_info));
- if (device_make_and_model && device_make_and_model[0] != '\0')
- g_hash_table_replace (data->hash,
- g_strdup_printf ("device-make-and-model:%d",
- data->iter),
- g_strdup (device_make_and_model));
- if (device_uri && device_uri[0] != '\0')
- g_hash_table_replace (data->hash,
- g_strdup_printf ("device-uri:%d",
- data->iter),
- g_strdup (device_uri));
- if (device_location && device_location[0] != '\0')
- g_hash_table_replace (data->hash,
- g_strdup_printf ("device-location:%d ",
- data->iter),
- g_strdup (device_location));
+ if (device_class && device_class[0] != '\0') {
+ key = g_strdup_printf ("device-class:%d", data->iter);
+ g_variant_builder_add (data->builder, "{ss}",
+ key, device_class);
+ g_free (key);
+ }
+ if (device_id && device_id[0] != '\0') {
+ key = g_strdup_printf ("device-id:%d", data->iter);
+ g_variant_builder_add (data->builder, "{ss}",
+ key, device_id);
+ g_free (key);
+ }
+ if (device_info && device_info[0] != '\0') {
+ key = g_strdup_printf ("device-info:%d", data->iter);
+ g_variant_builder_add (data->builder, "{ss}",
+ key, device_info);
+ g_free (key);
+ }
+ if (device_make_and_model && device_make_and_model[0] != '\0') {
+ key = g_strdup_printf ("device-make-and-model:%d", data->iter);
+ g_variant_builder_add (data->builder, "{ss}",
+ key, device_make_and_model);
+ g_free (key);
+ }
+ if (device_uri && device_uri[0] != '\0') {
+ key = g_strdup_printf ("device-uri:%d", data->iter);
+ g_variant_builder_add (data->builder, "{ss}",
+ key, device_uri);
+ g_free (key);
+ }
+ if (device_location && device_location[0] != '\0') {
+ key = g_strdup_printf ("device-location:%d", data->iter);
+ g_variant_builder_add (data->builder, "{ss}",
+ key, device_location);
+ g_free (key);
+ }
data->iter++;
}
#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1
static gboolean
-_cph_cups_devices_get_14 (CphCups *cups,
- int timeout,
- int limit,
- const char **include_schemes,
- const char **exclude_schemes,
- int len_include,
- int len_exclude,
- CphCupsGetDevices *data)
+_cph_cups_devices_get_14 (CphCups *cups,
+ int timeout,
+ int limit,
+ const char *const *include_schemes,
+ const char *const *exclude_schemes,
+ int len_include,
+ int len_exclude,
+ CphCupsGetDevices *data)
{
ipp_status_t retval;
int timeout_param = CUPS_TIMEOUT_DEFAULT;
@@ -1280,14 +1296,14 @@ _cph_cups_devices_get_14 (CphCups *cups,
}
#else
static gboolean
-_cph_cups_devices_get_old (CphCups *cups,
- int timeout,
- int limit,
- const char **include_schemes,
- const char **exclude_schemes,
- int len_include,
- int len_exclude,
- CphCupsGetDevices *data)
+_cph_cups_devices_get_old (CphCups *cups,
+ int timeout,
+ int limit,
+ const char *const *include_schemes,
+ const char *const *exclude_schemes,
+ int len_include,
+ int len_exclude,
+ CphCupsGetDevices *data)
{
ipp_t *request;
const char *resource_char;
@@ -1392,26 +1408,30 @@ _cph_cups_devices_get_old (CphCups *cups,
}
#endif
-GHashTable *
-cph_cups_devices_get (CphCups *cups,
- int timeout,
- int limit,
- const char **include_schemes,
- const char **exclude_schemes)
+gboolean
+cph_cups_devices_get (CphCups *cups,
+ int timeout,
+ int limit,
+ const char *const *include_schemes,
+ const char *const *exclude_schemes,
+ GVariant **devices)
{
CphCupsGetDevices data;
int len_include;
int len_exclude;
gboolean retval;
- g_return_val_if_fail (CPH_IS_CUPS (cups), NULL);
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
+ g_return_val_if_fail (devices != NULL, FALSE);
+
+ *devices = NULL;
/* check the validity of values */
len_include = 0;
if (include_schemes) {
while (include_schemes[len_include] != NULL) {
if (!_cph_cups_is_scheme_valid (cups, include_schemes[len_include]))
- return NULL;
+ return FALSE;
len_include++;
}
}
@@ -1420,15 +1440,14 @@ cph_cups_devices_get (CphCups *cups,
if (exclude_schemes) {
while (exclude_schemes[len_exclude] != NULL) {
if (!_cph_cups_is_scheme_valid (cups, exclude_schemes[len_exclude]))
- return NULL;
+ return FALSE;
len_exclude++;
}
}
- data.iter = 0;
- data.limit = -1;
- data.hash = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_free);
+ data.iter = 0;
+ data.limit = -1;
+ data.builder = g_variant_builder_new (G_VARIANT_TYPE ("a{ss}"));
if (limit > 0)
data.limit = limit;
@@ -1445,11 +1464,11 @@ cph_cups_devices_get (CphCups *cups,
#endif
if (retval)
- return data.hash;
- else {
- g_hash_table_destroy (data.hash);
- return NULL;
- }
+ *devices = g_variant_builder_end (data.builder);
+
+ g_variant_builder_unref (data.builder);
+
+ return retval;
}
/* Functions that work on a printer */
@@ -1957,9 +1976,9 @@ cph_cups_printer_class_set_op_policy (CphCups *cups,
/* set users to NULL to allow all users */
gboolean
-cph_cups_printer_class_set_users_allowed (CphCups *cups,
- const char *printer_name,
- const char **users)
+cph_cups_printer_class_set_users_allowed (CphCups *cups,
+ const char *printer_name,
+ const char *const *users)
{
int len;
@@ -1985,9 +2004,9 @@ cph_cups_printer_class_set_users_allowed (CphCups *cups,
/* set users to NULL to deny no user */
gboolean
-cph_cups_printer_class_set_users_denied (CphCups *cups,
- const char *printer_name,
- const char **users)
+cph_cups_printer_class_set_users_denied (CphCups *cups,
+ const char *printer_name,
+ const char *const *users)
{
int len;
@@ -2013,10 +2032,10 @@ cph_cups_printer_class_set_users_denied (CphCups *cups,
/* set values to NULL to delete the default */
gboolean
-cph_cups_printer_class_set_option_default (CphCups *cups,
- const char *printer_name,
- const char *option,
- const char **values)
+cph_cups_printer_class_set_option_default (CphCups *cups,
+ const char *printer_name,
+ const char *option,
+ const char *const *values)
{
char *option_name;
int len;
diff --git a/src/cups.h b/src/cups.h
index b68e7ce..a555299 100644
--- a/src/cups.h
+++ b/src/cups.h
@@ -78,16 +78,18 @@ gboolean cph_cups_file_put (CphCups *cups,
const char *resource,
const char *filename);
-GHashTable *cph_cups_server_get_settings (CphCups *cups);
+gboolean cph_cups_server_get_settings (CphCups *cups,
+ GVariant **settings);
-gboolean cph_cups_server_set_settings (CphCups *cups,
- GHashTable *settings);
+gboolean cph_cups_server_set_settings (CphCups *cups,
+ GVariant *settings);
-GHashTable *cph_cups_devices_get (CphCups *cups,
- int timeout,
- int limit,
- const char **include_schemes,
- const char **exclude_schemes);
+gboolean cph_cups_devices_get (CphCups *cups,
+ int timeout,
+ int limit,
+ const char *const *include_schemes,
+ const char *const *exclude_schemes,
+ GVariant **devices);
gboolean cph_cups_printer_add (CphCups *cups,
const char *printer_name,
@@ -158,18 +160,18 @@ gboolean cph_cups_printer_class_set_op_policy (CphCups *cups,
const char *printer_name,
const char *policy);
-gboolean cph_cups_printer_class_set_users_allowed (CphCups *cups,
- const char *printer_name,
- const char **users);
+gboolean cph_cups_printer_class_set_users_allowed (CphCups *cups,
+ const char *printer_name,
+ const char *const *users);
-gboolean cph_cups_printer_class_set_users_denied (CphCups *cups,
- const char *printer_name,
- const char **users);
+gboolean cph_cups_printer_class_set_users_denied (CphCups *cups,
+ const char *printer_name,
+ const char *const *users);
-gboolean cph_cups_printer_class_set_option_default (CphCups *cups,
- const char *printer_name,
- const char *option,
- const char **values);
+gboolean cph_cups_printer_class_set_option_default (CphCups *cups,
+ const char *printer_name,
+ const char *option,
+ const char *const *values);
gboolean cph_cups_job_cancel (CphCups *cups,
int job_id,
diff --git a/src/main.c b/src/main.c
index 134c1b0..949c022 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,106 +42,104 @@
#include <glib.h>
#include <glib-object.h>
-
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include "cups-pk-helper-mechanism.h"
-#define BUS_NAME "org.opensuse.CupsPkHelper.Mechanism"
+#define CPH_SERVICE "org.opensuse.CupsPkHelper.Mechanism"
+#define CPH_PATH "/"
-static DBusGProxy *
-get_bus_proxy (DBusGConnection *connection)
+typedef struct
+{
+ CphMechanism *mechanism;
+ GMainLoop *loop;
+ gboolean name_acquired;
+} cph_main;
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
{
- DBusGProxy *bus_proxy;
+ cph_main *data = (cph_main *) user_data;
+ GError *error = NULL;
+
+ if (!cph_mechanism_register (data->mechanism,
+ connection, CPH_PATH,
+ &error)) {
+ if (error)
+ g_printerr ("Could not register mechanism object: %s\n", error->message);
+ else
+ g_printerr ("Could not register mechanism object\n");
- bus_proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- return bus_proxy;
+ g_error_free (error);
+ g_main_loop_quit (data->loop);
+
+ return;
+ }
}
-static gboolean
-acquire_name_on_proxy (DBusGProxy *bus_proxy,
- GError **error)
+static void
+on_name_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
{
- guint result;
- gboolean res;
-
- g_assert (bus_proxy != NULL);
-
- res = dbus_g_proxy_call (bus_proxy,
- "RequestName",
- error,
- G_TYPE_STRING, BUS_NAME,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &result,
- G_TYPE_INVALID);
- if (!res ||
- result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
- return FALSE;
-
- return TRUE;
+ cph_main *data = (cph_main *) user_data;
+
+ data->name_acquired = TRUE;
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ cph_main *data = (cph_main *) user_data;
+
+ if (connection == NULL)
+ g_printerr ("Cannot connect to the bus\n");
+ else if (!data->name_acquired)
+ g_printerr ("Cannot acquire %s on the bus\n", CPH_SERVICE);
+
+ g_main_loop_quit (data->loop);
}
int
main (int argc, char **argv)
{
- GError *error;
- GMainLoop *loop;
- CphMechanism *mechanism;
- DBusGProxy *bus_proxy;
- DBusGConnection *connection;
+ cph_main data;
+ guint owner_id;
if (!g_thread_supported ())
g_thread_init (NULL);
- dbus_g_thread_init ();
g_type_init ();
- error = NULL;
+ memset (&data, 0, sizeof (data));
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (connection == NULL) {
- g_warning ("Could not connect to system bus: %s",
- error->message);
- g_error_free (error);
- return 1;
- }
+ data.mechanism = cph_mechanism_new ();
- bus_proxy = get_bus_proxy (connection);
- if (bus_proxy == NULL) {
- g_warning ("Could not construct bus_proxy objects");
+ if (data.mechanism == NULL) {
+ g_printerr ("Could not create mechanism object\n");
return 1;
}
- if (!acquire_name_on_proxy (bus_proxy, &error) ) {
- if (error != NULL) {
- g_warning ("Could not acquire name: %s",
- error->message);
- g_error_free (error);
- } else {
- g_warning ("Could not acquire name");
- }
-
- return 1;
- }
-
- mechanism = cph_mechanism_new ();
-
- if (mechanism == NULL) {
- g_warning ("Could not create mechanism object");
- return 1;
- }
+ data.loop = g_main_loop_new (NULL, FALSE);
- loop = g_main_loop_new (NULL, FALSE);
+ owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
+ CPH_SERVICE,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ &data,
+ NULL);
- g_main_loop_run (loop);
+ g_main_loop_run (data.loop);
- g_object_unref (mechanism);
- g_main_loop_unref (loop);
+ g_object_unref (data.mechanism);
+ g_bus_unown_name (owner_id);
+ g_main_loop_unref (data.loop);
return 0;
}