mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-04 23:28:05 +02:00
2003-09-23 Havoc Pennington <hp@pobox.com>
* glib/dbus-gproxy.c (struct DBusGProxy): convert to a GObject subclass. This means dropping the transparent thread safety of the proxy; you now need a separate proxy per-thread, or your own locking on the proxy. Probably right anyway. (dbus_gproxy_ref, dbus_gproxy_unref): nuke, just use g_object_ref
This commit is contained in:
parent
4be7b14fce
commit
0a34a44006
3 changed files with 106 additions and 82 deletions
|
|
@ -1,3 +1,11 @@
|
|||
2003-09-23 Havoc Pennington <hp@pobox.com>
|
||||
|
||||
* glib/dbus-gproxy.c (struct DBusGProxy): convert to a GObject
|
||||
subclass. This means dropping the transparent thread safety of the
|
||||
proxy; you now need a separate proxy per-thread, or your own
|
||||
locking on the proxy. Probably right anyway.
|
||||
(dbus_gproxy_ref, dbus_gproxy_unref): nuke, just use g_object_ref
|
||||
|
||||
2003-09-22 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* glib/dbus-gproxy.c (dbus_gproxy_manager_get): implement
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
/* Nothing */
|
||||
}
|
||||
|
||||
static void
|
||||
dbus_gproxy_class_init (DBusGProxyClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = dbus_gproxy_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
dbus_gproxy_finalize (GObject *object)
|
||||
{
|
||||
DBusGProxy *proxy;
|
||||
|
||||
proxy = g_new0 (DBusGProxy, 1);
|
||||
|
||||
proxy->refcount = 1;
|
||||
proxy->manager = dbus_gproxy_manager_get (connection);
|
||||
proxy = DBUS_GPROXY (object);
|
||||
|
||||
g_static_mutex_init (&proxy->lock);
|
||||
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 */
|
||||
|
|
@ -180,6 +203,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
|
||||
|
|
@ -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);
|
||||
|
|
@ -220,58 +282,6 @@ dbus_gproxy_new_for_service (DBusConnection *connection,
|
|||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue