DBusGProxy as parent gobject [PATCH]
Ricardo Kekki
ricardo.kekki at movial.fi
Tue Jan 3 02:26:53 PST 2006
I have now made a proposal for fixing the inheritance of DBusGProxy.
The first patch adds a property to the DBusGProxy so that it can
be initialized also by g_object_new calls.
The second patch is not that nice. I'm not sure how this should be done.
The patch moves the DBusGProxy, DBusGProxyClass and DBusGProxyManager
definitions to the dbus-glib.h file.
The problem with the header patch is that DBusGProxyManager uses
DBusConnection which is defined in the dbus-connection.h. And including
dbus-connection.h is the problem. Another way to fix this would be to
change DBusGProxyManager to use DBusGConnect instead of DBusConnect.
Ricardo
-------------- next part --------------
--- dbus/glib/dbus-gproxy.c 2005-11-30 19:32:26.000000000 +0000
+++ dbus-0.61/glib/dbus-gproxy.c 2006-01-02 14:28:01.000000000 +0000
@@ -1268,7 +1268,8 @@
PROP_0,
PROP_NAME,
PROP_PATH,
- PROP_INTERFACE
+ PROP_INTERFACE,
+ PROP_MANAGER
};
enum
@@ -1287,6 +1288,9 @@
g_datalist_init (&proxy->signal_signatures);
proxy->pending_calls = g_hash_table_new_full (NULL, NULL, NULL,
(GDestroyNotify) dbus_pending_call_unref);
+
+ proxy->name_call = 0;
+ proxy->associated = FALSE;
}
static GObject *
@@ -1306,8 +1310,6 @@
construct_properties));
proxy->for_owner = (proxy->name[0] == ':');
- proxy->name_call = 0;
- proxy->associated = FALSE;
return G_OBJECT (proxy);
}
@@ -1346,6 +1348,14 @@
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_MANAGER,
+ g_param_spec_boxed ("manager",
+ "manager",
+ "manager",
+ DBUS_TYPE_G_CONNECTION,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
object_class->finalize = dbus_g_proxy_finalize;
object_class->dispose = dbus_g_proxy_dispose;
object_class->constructor = dbus_g_proxy_constructor;
@@ -1435,6 +1445,7 @@
GParamSpec *pspec)
{
DBusGProxy *proxy = DBUS_G_PROXY (object);
+ DBusGConnection *connection;
switch (prop_id)
{
@@ -1447,6 +1458,14 @@
case PROP_INTERFACE:
proxy->interface = g_strdup (g_value_get_string (value));
break;
+ case PROP_MANAGER:
+ connection = g_value_get_boxed(value);
+ if(connection != NULL)
+ {
+ proxy->manager = dbus_g_proxy_manager_get (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
+ dbus_g_proxy_manager_register (proxy->manager, proxy);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1472,6 +1491,9 @@
case PROP_INTERFACE:
g_value_set_string (value, proxy->interface);
break;
+ case PROP_MANAGER:
+ g_value_set_boxed (value, proxy->manager);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1703,6 +1725,7 @@
"name", DBUS_SERVICE_DBUS,
"path", DBUS_PATH_DBUS,
"interface", DBUS_INTERFACE_DBUS,
+ "manager", NULL,
NULL);
manager->bus_proxy->manager = manager;
}
@@ -1767,16 +1790,12 @@
g_assert (connection != NULL);
- proxy = g_object_new (DBUS_TYPE_G_PROXY, "name", name, "path", path_name, "interface", interface_name, NULL);
+ proxy = g_object_new (DBUS_TYPE_G_PROXY,
+ "name", name,
+ "path", path_name,
+ "interface", interface_name,
+ "manager", connection, NULL);
- /* These should all be construct-only mandatory properties,
- * for now we just don't let people use g_object_new().
- */
-
- proxy->manager = dbus_g_proxy_manager_get (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
-
- dbus_g_proxy_manager_register (proxy->manager, proxy);
-
return proxy;
}
-------------- next part --------------
--- dbus-cvs/glib/dbus-gproxy.c 2006-01-03 08:18:49.000000000 +0000
+++ dbus/glib/dbus-gproxy.c 2006-01-03 08:22:52.000000000 +0000
@@ -42,44 +42,6 @@
* @{
*/
-/**
- * DBusGProxyManager typedef
- */
-
-typedef struct _DBusGProxyManager DBusGProxyManager;
-
-/**
- * Internals of DBusGProxy
- */
-struct _DBusGProxy
-{
- GObject parent; /**< Parent instance */
-
- DBusGProxyManager *manager; /**< Proxy manager */
- char *name; /**< Name messages go to or NULL */
- char *path; /**< Path messages go to or NULL */
- char *interface; /**< Interface messages go to or NULL */
-
- DBusGProxyCall *name_call; /**< Pending call id to retrieve name owner */
- guint for_owner : 1; /**< Whether or not this proxy is for a name owner */
- guint associated : 1; /**< Whether or not this proxy is associated (for name proxies) */
-
- /* FIXME: make threadsafe? */
- guint call_id_counter; /**< Integer counter for pending calls */
-
- GData *signal_signatures; /**< D-BUS signatures for each signal */
-
- GHashTable *pending_calls; /**< Calls made on this proxy which have not yet returned */
-};
-
-/**
- * Class struct for DBusGProxy
- */
-struct _DBusGProxyClass
-{
- GObjectClass parent_class; /**< Parent class */
-};
-
static void dbus_g_proxy_init (DBusGProxy *proxy);
static void dbus_g_proxy_class_init (DBusGProxyClass *klass);
static GObject *dbus_g_proxy_constructor (GType type,
@@ -134,32 +96,6 @@
} DBusGProxyList;
-/**
- * DBusGProxyManager's primary task is to route signals to the proxies
- * those signals are emitted on. In order to do this it also has to
- * track the owners of the names proxies are bound to.
- */
-struct _DBusGProxyManager
-{
- GStaticMutex lock; /**< Thread lock */
- int refcount; /**< Reference count */
- DBusConnection *connection; /**< Connection we're associated with. */
-
- DBusGProxy *bus_proxy; /**< Special internal proxy used to talk to the bus */
-
- GHashTable *proxy_lists; /**< Hash used to route incoming signals
- * and iterate over proxies
- */
- GHashTable *owner_names; /**< Hash to keep track of mapping from
- * base name -> [name,name,...] for proxies which
- * are for names.
- */
- GSList *unassociated_proxies; /**< List of name proxies for which
- * there was no result for
- * GetNameOwner
- */
-};
-
static DBusGProxyManager *dbus_g_proxy_manager_ref (DBusGProxyManager *manager);
static DBusHandlerResult dbus_g_proxy_manager_filter (DBusConnection *connection,
DBusMessage *message,
--- dbus-cvs/dbus/dbus-glib.h 2006-01-03 08:18:49.000000000 +0000
+++ dbus/dbus/dbus-glib.h 2006-01-03 09:51:59.000000000 +0000
@@ -30,7 +30,9 @@
G_BEGIN_DECLS
#define DBUS_INSIDE_DBUS_GLIB_H 1
+#define DBUS_INSIDE_DBUS_H 1
+#include <dbus/dbus-connection.h>
/**
* Convert to DBusConnection with dbus_g_connection_get_connection() in dbus-glib-lowlevel.h
@@ -143,6 +145,8 @@
guint n_types,
const GType* types);
+typedef struct _DBusGProxyManager DBusGProxyManager;
+
typedef struct _DBusGProxy DBusGProxy;
typedef struct _DBusGProxyClass DBusGProxyClass;
@@ -159,6 +163,65 @@
DBusGProxyCall *call_id,
void *user_data);
+/**
+ * Internals of DBusGProxy
+ */
+struct _DBusGProxy
+{
+ GObject parent; /**< Parent instance */
+
+ DBusGProxyManager *manager; /**< Proxy manager */
+ char *name; /**< Name messages go to or NULL */
+ char *path; /**< Path messages go to or NULL */
+ char *interface; /**< Interface messages go to or NULL */
+
+ DBusGProxyCall *name_call; /**< Pending call id to retrieve name owner */
+ guint for_owner : 1; /**< Whether or not this proxy is for a name owner */
+ guint associated : 1; /**< Whether or not this proxy is associated (for name proxies) */
+
+ /* FIXME: make threadsafe? */
+ guint call_id_counter; /**< Integer counter for pending calls */
+
+ GData *signal_signatures; /**< D-BUS signatures for each signal */
+
+ GHashTable *pending_calls; /**< Calls made on this proxy which have not yet returned */
+};
+
+/**
+ * Class struct for DBusGProxy
+ */
+struct _DBusGProxyClass
+{
+ GObjectClass parent_class; /**< Parent class */
+};
+
+/**
+ * DBusGProxyManager's primary task is to route signals to the proxies
+ * those signals are emitted on. In order to do this it also has to
+ * track the owners of the names proxies are bound to.
+ */
+struct _DBusGProxyManager
+{
+ GStaticMutex lock; /**< Thread lock */
+ int refcount; /**< Reference count */
+ DBusConnection *connection; /**< Connection we're associated with. */
+
+ DBusGProxy *bus_proxy; /**< Special internal proxy used to talk to the bus */
+
+ GHashTable *proxy_lists; /**< Hash used to route incoming signals
+ * and iterate over proxies
+ */
+ GHashTable *owner_names; /**< Hash to keep track of mapping from
+ * base name -> [name,name,...] for proxies which
+ * are for names.
+ */
+ GSList *unassociated_proxies; /**< List of name proxies for which
+ * there was no result for
+ * GetNameOwner
+ */
+};
+
+
GType dbus_g_proxy_get_type (void) G_GNUC_CONST;
DBusGProxy* dbus_g_proxy_new_for_name (DBusGConnection *connection,
const char *name,
More information about the dbus
mailing list