diff options
Diffstat (limited to 'glib')
-rw-r--r-- | glib/dbus-glib.h | 20 | ||||
-rw-r--r-- | glib/dbus-gproxy.c | 160 |
2 files changed, 98 insertions, 82 deletions
diff --git a/glib/dbus-glib.h b/glib/dbus-glib.h index 7fd88e71..556d896e 100644 --- a/glib/dbus-glib.h +++ b/glib/dbus-glib.h @@ -87,6 +87,17 @@ void dbus_connection_register_g_object (DBusConnection *connection, typedef struct DBusGProxy DBusGProxy; +typedef struct DBusGProxyClass DBusGProxyClass; + + +#define DBUS_TYPE_GPROXY (dbus_gproxy_get_type ()) +#define DBUS_GPROXY(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), DBUS_TYPE_GPROXY, DBusGProxy)) +#define DBUS_GPROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUS_TYPE_GPROXY, DBusGProxyClass)) +#define DBUS_IS_GPROXY(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), DBUS_TYPE_GPROXY)) +#define DBUS_IS_GPROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUS_TYPE_GPROXY)) +#define DBUS_GPROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUS_TYPE_GPROXY, DBusGProxyClass)) + +GType dbus_gproxy_get_type (void) G_GNUC_CONST; DBusGProxy* dbus_gproxy_new_for_service (DBusConnection *connection, const char *service_name, @@ -104,11 +115,16 @@ DBusGProxy* dbus_gproxy_new_for_peer (DBusConnection *connection void dbus_gproxy_ref (DBusGProxy *proxy); void dbus_gproxy_unref (DBusGProxy *proxy); gboolean dbus_gproxy_connect_signal (DBusGProxy *proxy, + const char *interface_name, const char *signal_name, GCallback callback, void *data, - GFreeFunc free_data_func, - GError **error); + GFreeFunc free_data_func); +gboolean dbus_gproxy_disconnect_signal (DBusGProxy *proxy, + const char *interface_name, + const char *signal_name, + GCallback callback, + void *data); DBusPendingCall* dbus_gproxy_begin_call (DBusGProxy *proxy, const char *method, int first_arg_type, diff --git a/glib/dbus-gproxy.c b/glib/dbus-gproxy.c index 57cdab2f..05a073bf 100644 --- a/glib/dbus-gproxy.c +++ b/glib/dbus-gproxy.c @@ -146,32 +146,55 @@ dbus_gproxy_manager_unref (DBusGProxyManager *manager) */ struct DBusGProxy { - GStaticMutex lock; /**< Thread lock */ - int refcount; /**< Reference count */ + GObject parent; + DBusGProxyManager *manager; /**< Proxy manager */ - char *service; /**< Service messages go to or NULL */ - char *path; /**< Path messages go to or NULL */ - char *interface; /**< Interface messages go to or NULL */ + char *service; /**< Service messages go to or NULL */ + char *path; /**< Path messages go to or NULL */ + char *interface; /**< Interface messages go to or NULL */ }; -/** Lock the DBusGProxy */ -#define LOCK_PROXY(proxy) (g_static_mutex_lock (&(proxy)->lock)) -/** Unlock the DBusGProxy */ -#define UNLOCK_PROXY(proxy) (g_static_mutex_unlock (&(proxy)->lock)) +struct DBusGProxyClass +{ + GObjectClass parent_class; +}; -static DBusGProxy* -_dbus_gproxy_new (DBusConnection *connection) +static void dbus_gproxy_init (DBusGProxy *proxy); +static void dbus_gproxy_class_init (DBusGProxyClass *klass); +static void dbus_gproxy_finalize (GObject *object); + +static void *parent_class; + +static void +dbus_gproxy_init (DBusGProxy *proxy) { - DBusGProxy *proxy; + /* Nothing */ +} - proxy = g_new0 (DBusGProxy, 1); +static void +dbus_gproxy_class_init (DBusGProxyClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); - proxy->refcount = 1; - proxy->manager = dbus_gproxy_manager_get (connection); + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = dbus_gproxy_finalize; +} - g_static_mutex_init (&proxy->lock); +static void +dbus_gproxy_finalize (GObject *object) +{ + DBusGProxy *proxy; + + proxy = DBUS_GPROXY (object); + + if (proxy->manager) + dbus_gproxy_manager_unref (proxy->manager); + g_free (proxy->service); + g_free (proxy->path); + g_free (proxy->interface); - return proxy; + G_OBJECT_CLASS (parent_class)->finalize (object); } /** @} End of DBusGLibInternals */ @@ -181,6 +204,39 @@ _dbus_gproxy_new (DBusConnection *connection) */ /** + * Standard GObject get_type() function for DBusGProxy. + * + * @returns type ID for DBusGProxy class + */ +GType +dbus_gproxy_get_type (void) +{ + static GType object_type = 0; + + if (!object_type) + { + static const GTypeInfo object_info = + { + sizeof (DBusGProxyClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) dbus_gproxy_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (DBusGProxy), + 0, /* n_preallocs */ + (GInstanceInitFunc) dbus_gproxy_init, + }; + + object_type = g_type_register_static (G_TYPE_OBJECT, + "DBusGProxy", + &object_info, 0); + } + + return object_type; +} + +/** * Creates a new proxy for a remote interface. Method calls and signal * connections over this proxy will go to the service owner; the * service owner is expected to support the given interface name. THE @@ -211,8 +267,14 @@ dbus_gproxy_new_for_service (DBusConnection *connection, g_return_val_if_fail (path_name != NULL, NULL); g_return_val_if_fail (interface_name != NULL, NULL); - proxy = _dbus_gproxy_new (connection); + proxy = g_object_new (DBUS_TYPE_GPROXY, NULL); + /* These should all be construct-only mandatory properties, + * for now we just don't let people use g_object_new(). + */ + + proxy->manager = dbus_gproxy_manager_get (connection); + proxy->service = g_strdup (service_name); proxy->path = g_strdup (path_name); proxy->interface = g_strdup (interface_name); @@ -221,58 +283,6 @@ dbus_gproxy_new_for_service (DBusConnection *connection, } /** - * Increment reference count on proxy object. - * - * @todo use GAtomic to avoid locking - * - * @param proxy the proxy - */ -void -dbus_gproxy_ref (DBusGProxy *proxy) -{ - g_return_if_fail (proxy != NULL); - - LOCK_PROXY (proxy); - - proxy->refcount += 1; - - UNLOCK_PROXY (proxy); -} - -/** - * Decrement reference count on proxy object. - * - * @todo use GAtomic to avoid locking - * - * @param proxy the proxy - */ -void -dbus_gproxy_unref (DBusGProxy *proxy) -{ - g_return_if_fail (proxy != NULL); - - LOCK_PROXY (proxy); - - proxy->refcount -= 1; - - if (proxy->refcount == 0) - { - UNLOCK_PROXY (proxy); - - dbus_gproxy_manager_unref (proxy->manager); - g_free (proxy->service); - g_free (proxy->path); - g_free (proxy->interface); - g_static_mutex_free (&proxy->lock); - g_free (proxy); - } - else - { - UNLOCK_PROXY (proxy); - } -} - -/** * Invokes a method on a remote interface. This function does not * block; instead it returns an opaque #DBusPendingCall object that * tracks the pending call. The method call will not be sent over the @@ -302,7 +312,6 @@ dbus_gproxy_begin_call (DBusGProxy *proxy, va_list args; g_return_val_if_fail (proxy != NULL, NULL); - LOCK_PROXY (proxy); message = dbus_message_new_method_call (proxy->service, proxy->path, @@ -322,8 +331,6 @@ dbus_gproxy_begin_call (DBusGProxy *proxy, &pending, -1)) goto oom; - - UNLOCK_PROXY (proxy); return pending; @@ -375,8 +382,6 @@ dbus_gproxy_end_call (DBusGProxy *proxy, g_return_val_if_fail (proxy != NULL, FALSE); g_return_val_if_fail (pending != NULL, FALSE); - - LOCK_PROXY (proxy); dbus_pending_call_block (pending); message = dbus_pending_call_get_reply (pending); @@ -392,8 +397,6 @@ dbus_gproxy_end_call (DBusGProxy *proxy, } va_end (args); - UNLOCK_PROXY (proxy); - return TRUE; error: @@ -426,7 +429,6 @@ dbus_gproxy_send (DBusGProxy *proxy, dbus_uint32_t *client_serial) { g_return_if_fail (proxy != NULL); - LOCK_PROXY (proxy); if (proxy->service) { @@ -446,8 +448,6 @@ dbus_gproxy_send (DBusGProxy *proxy, if (!dbus_connection_send (proxy->manager->connection, message, client_serial)) g_error ("Out of memory\n"); - - UNLOCK_PROXY (proxy); } /** @} End of DBusGLib public */ |