378
378
return data.info;
382
gobject_unregister_function (DBusConnection *connection,
387
object = G_OBJECT (user_data);
382
DBusGConnection *connection;
385
} ObjectRegistration;
387
static void object_registration_object_died (gpointer user_data, GObject *dead);
389
static ObjectRegistration *
390
object_registration_new (DBusGConnection *connection,
391
const gchar *object_path,
394
ObjectRegistration *o = g_slice_new0 (ObjectRegistration);
396
o->connection = connection;
397
o->object_path = g_strdup (object_path);
400
g_object_weak_ref (o->object, object_registration_object_died, o);
406
object_registration_free (ObjectRegistration *o)
408
if (o->object != NULL)
410
g_object_weak_unref (o->object, object_registration_object_died, o);
411
g_object_steal_data (o->object, "dbus_glib_object_registration");
415
g_free (o->object_path);
417
g_slice_free (ObjectRegistration, o);
420
/* Called when the object falls off the bus (e.g. because connection just
423
object_registration_unregistered (DBusConnection *connection,
426
object_registration_free (user_data);
1076
1112
if (error->domain == DBUS_GERROR)
1077
reply = dbus_message_new_error (message,
1078
dbus_g_error_get_name (error),
1114
const gchar *name = DBUS_ERROR_FAILED;
1116
switch (error->code)
1118
case DBUS_GERROR_FAILED:
1119
name = DBUS_ERROR_FAILED;
1121
case DBUS_GERROR_NO_MEMORY:
1122
name = DBUS_ERROR_NO_MEMORY;
1124
case DBUS_GERROR_SERVICE_UNKNOWN:
1125
name = DBUS_ERROR_SERVICE_UNKNOWN;
1127
case DBUS_GERROR_NAME_HAS_NO_OWNER:
1128
name = DBUS_ERROR_NAME_HAS_NO_OWNER;
1130
case DBUS_GERROR_NO_REPLY:
1131
name = DBUS_ERROR_NO_REPLY;
1133
case DBUS_GERROR_IO_ERROR:
1134
name = DBUS_ERROR_IO_ERROR;
1136
case DBUS_GERROR_BAD_ADDRESS:
1137
name = DBUS_ERROR_BAD_ADDRESS;
1139
case DBUS_GERROR_NOT_SUPPORTED:
1140
name = DBUS_ERROR_NOT_SUPPORTED;
1142
case DBUS_GERROR_LIMITS_EXCEEDED:
1143
name = DBUS_ERROR_LIMITS_EXCEEDED;
1145
case DBUS_GERROR_ACCESS_DENIED:
1146
name = DBUS_ERROR_ACCESS_DENIED;
1148
case DBUS_GERROR_AUTH_FAILED:
1149
name = DBUS_ERROR_AUTH_FAILED;
1151
case DBUS_GERROR_NO_SERVER:
1152
name = DBUS_ERROR_NO_SERVER;
1154
case DBUS_GERROR_TIMEOUT:
1155
name = DBUS_ERROR_TIMEOUT;
1157
case DBUS_GERROR_NO_NETWORK:
1158
name = DBUS_ERROR_NO_NETWORK;
1160
case DBUS_GERROR_ADDRESS_IN_USE:
1161
name = DBUS_ERROR_ADDRESS_IN_USE;
1163
case DBUS_GERROR_DISCONNECTED:
1164
name = DBUS_ERROR_DISCONNECTED;
1166
case DBUS_GERROR_INVALID_ARGS:
1167
name = DBUS_ERROR_INVALID_ARGS;
1169
case DBUS_GERROR_FILE_NOT_FOUND:
1170
name = DBUS_ERROR_FILE_NOT_FOUND;
1172
case DBUS_GERROR_REMOTE_EXCEPTION:
1173
name = dbus_g_error_get_name (error);
1177
reply = dbus_message_new_error (message, name, error->message);
1082
1181
char *error_name;
1483
1582
const DBusGMethodInfo *method;
1484
1583
const DBusGObjectInfo *object_info;
1485
1584
DBusMessage *ret;
1585
ObjectRegistration *o;
1487
object = G_OBJECT (user_data);
1588
object = G_OBJECT (o->object);
1489
1590
if (dbus_message_is_method_call (message,
1490
1591
DBUS_INTERFACE_INTROSPECTABLE,
1602
1703
static const DBusObjectPathVTable gobject_dbus_vtable = {
1603
gobject_unregister_function,
1604
gobject_message_function,
1704
object_registration_unregistered,
1705
object_registration_message,
1963
2064
g_static_rw_lock_writer_unlock (&globals_lock);
2067
/* Called when the object is destroyed */
1967
unregister_gobject (DBusGConnection *connection, GObject *dead)
1970
path = g_object_steal_data (dead, "dbus_glib_object_path");
1971
dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection), path);
2069
object_registration_object_died (gpointer user_data, GObject *dead)
2071
ObjectRegistration *o = user_data;
2073
g_assert (dead == o->object);
2075
/* this prevents the weak unref from taking place, which would cause an
2076
* assertion failure since the object has already gone... */
2079
/* ... while this results in a call to object_registration_unregistered */
2080
dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (o->connection), o->object_path);
2084
* dbus_g_connection_unregister_g_object:
2085
* @connection: the D-BUS connection
2086
* @object: the object
2088
* Removes @object from the bus. Properties, methods, and signals
2089
* of the object can no longer be accessed remotely.
2092
dbus_g_connection_unregister_g_object (DBusGConnection *connection,
2095
ObjectRegistration *o;
2097
o = g_object_get_data (object, "dbus_glib_object_registration");
2099
g_return_if_fail (o != NULL);
2101
dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (o->connection),
1984
2114
* with dbus_g_object_type_install_info().
1986
2116
* The registration will be cancelled if either the #DBusConnection or
1987
* the #GObject gets finalized.
2117
* the #GObject gets finalized, or if dbus_g_connection_unregister_g_object()
1990
2121
dbus_g_connection_register_g_object (DBusGConnection *connection,
2140
o = g_object_get_data (object, "dbus_glib_object_registration");
2144
g_warning ("Object already registered at %s, can't re-register at %s",
2145
o->object_path, at_path);
2149
o = object_registration_new (connection, at_path, object);
2007
2151
if (!dbus_connection_register_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection),
2009
2153
&gobject_dbus_vtable,
2012
2156
g_error ("Failed to register GObject with DBusConnection");
2157
object_registration_free (o);
2016
2161
export_signals (connection, info_list, object);
2017
2162
g_list_free (info_list);
2019
g_object_set_data (object, "dbus_glib_object_path", g_strdup (at_path));
2020
g_object_weak_ref (object, (GWeakNotify)unregister_gobject, connection);
2163
g_object_set_data (object, "dbus_glib_object_registration", o);
2033
2176
dbus_g_connection_lookup_g_object (DBusGConnection *connection,
2034
2177
const char *at_path)
2037
if (!dbus_connection_get_object_path_data (DBUS_CONNECTION_FROM_G_CONNECTION (connection), at_path, &ret))
2180
ObjectRegistration *o;
2182
if (!dbus_connection_get_object_path_data (DBUS_CONNECTION_FROM_G_CONNECTION (connection), at_path, &p))
2189
return G_OBJECT (o->object);
2042
2192
typedef struct {