~ubuntu-branches/ubuntu/oneiric/dbus-glib/oneiric-updates

« back to all changes in this revision

Viewing changes to dbus/dbus-gobject.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-09-29 23:49:03 UTC
  • mfrom: (1.1.7 upstream) (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090929234903-oaprxcpac2lvd9hs
Tags: 0.82-2
* debian/patches/10_support_duplicate_object_registrations.patch
  - Pull patch from upstream git which allows duplicate object registrations
    and fixes a regression introduced in 0.82.
    (Closes: #540421, #541712, #542513, #544174, #546044)
* Bump Standards-Version to 3.8.3. No further changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
378
378
  return data.info;
379
379
}
380
380
 
381
 
static void
382
 
gobject_unregister_function (DBusConnection  *connection,
383
 
                             void            *user_data)
384
 
{
385
 
  GObject *object;
386
 
 
387
 
  object = G_OBJECT (user_data);
388
 
 
389
 
  /* FIXME */
390
 
 
 
381
typedef struct {
 
382
    DBusGConnection *connection;
 
383
    gchar *object_path;
 
384
    GObject *object;
 
385
} ObjectRegistration;
 
386
 
 
387
static void object_registration_object_died (gpointer user_data, GObject *dead);
 
388
 
 
389
static ObjectRegistration *
 
390
object_registration_new (DBusGConnection *connection,
 
391
                         const gchar *object_path,
 
392
                         GObject *object)
 
393
{
 
394
  ObjectRegistration *o = g_slice_new0 (ObjectRegistration);
 
395
 
 
396
  o->connection = connection;
 
397
  o->object_path = g_strdup (object_path);
 
398
  o->object = object;
 
399
 
 
400
  g_object_weak_ref (o->object, object_registration_object_died, o);
 
401
 
 
402
  return o;
 
403
}
 
404
 
 
405
static void
 
406
object_registration_free (ObjectRegistration *o)
 
407
{
 
408
  if (o->object != NULL)
 
409
    {
 
410
      g_object_weak_unref (o->object, object_registration_object_died, o);
 
411
      g_object_steal_data (o->object, "dbus_glib_object_registration");
 
412
      o->object = NULL;
 
413
    }
 
414
 
 
415
  g_free (o->object_path);
 
416
 
 
417
  g_slice_free (ObjectRegistration, o);
 
418
}
 
419
 
 
420
/* Called when the object falls off the bus (e.g. because connection just
 
421
 * closed) */
 
422
static void
 
423
object_registration_unregistered (DBusConnection *connection,
 
424
                                  void *user_data)
 
425
{
 
426
  object_registration_free (user_data);
391
427
}
392
428
 
393
429
typedef struct
604
640
        }
605
641
 
606
642
      propsig = info->exported_signals;
607
 
      while (*propsig)
 
643
      while (propsig != NULL && *propsig)
608
644
        {
609
645
          const char *iface;
610
646
          const char *signame;
616
652
        }
617
653
 
618
654
      propsig = info->exported_properties;
619
 
      while (*propsig)
 
655
      while (propsig != NULL && *propsig)
620
656
        {
621
657
          const char *iface;
622
658
          const char *propname;
1058
1094
 
1059
1095
static DBusMessage *
1060
1096
gerror_to_dbus_error_message (const DBusGObjectInfo *object_info,
1061
 
                              DBusMessage     *message,
1062
 
                              GError          *error)
 
1097
                              DBusMessage           *message,
 
1098
                              const GError          *error)
1063
1099
{
1064
1100
  DBusMessage *reply;
1065
1101
 
1074
1110
  else
1075
1111
    {
1076
1112
      if (error->domain == DBUS_GERROR)
1077
 
        reply = dbus_message_new_error (message,
1078
 
                                        dbus_g_error_get_name (error),
1079
 
                                        error->message);
 
1113
        {
 
1114
          const gchar *name = DBUS_ERROR_FAILED;
 
1115
 
 
1116
          switch (error->code)
 
1117
            {
 
1118
            case DBUS_GERROR_FAILED:
 
1119
              name = DBUS_ERROR_FAILED;
 
1120
              break;
 
1121
            case DBUS_GERROR_NO_MEMORY:
 
1122
              name = DBUS_ERROR_NO_MEMORY;
 
1123
              break;
 
1124
            case DBUS_GERROR_SERVICE_UNKNOWN:
 
1125
              name = DBUS_ERROR_SERVICE_UNKNOWN;
 
1126
              break;
 
1127
            case DBUS_GERROR_NAME_HAS_NO_OWNER:
 
1128
              name = DBUS_ERROR_NAME_HAS_NO_OWNER;
 
1129
              break;
 
1130
            case DBUS_GERROR_NO_REPLY:
 
1131
              name = DBUS_ERROR_NO_REPLY;
 
1132
              break;
 
1133
            case DBUS_GERROR_IO_ERROR:
 
1134
              name = DBUS_ERROR_IO_ERROR;
 
1135
              break;
 
1136
            case DBUS_GERROR_BAD_ADDRESS:
 
1137
              name = DBUS_ERROR_BAD_ADDRESS;
 
1138
              break;
 
1139
            case DBUS_GERROR_NOT_SUPPORTED:
 
1140
              name = DBUS_ERROR_NOT_SUPPORTED;
 
1141
              break;
 
1142
            case DBUS_GERROR_LIMITS_EXCEEDED:
 
1143
              name = DBUS_ERROR_LIMITS_EXCEEDED;
 
1144
              break;
 
1145
            case DBUS_GERROR_ACCESS_DENIED:
 
1146
              name = DBUS_ERROR_ACCESS_DENIED;
 
1147
              break;
 
1148
            case DBUS_GERROR_AUTH_FAILED:
 
1149
              name = DBUS_ERROR_AUTH_FAILED;
 
1150
              break;
 
1151
            case DBUS_GERROR_NO_SERVER:
 
1152
              name = DBUS_ERROR_NO_SERVER;
 
1153
              break;
 
1154
            case DBUS_GERROR_TIMEOUT:
 
1155
              name = DBUS_ERROR_TIMEOUT;
 
1156
              break;
 
1157
            case DBUS_GERROR_NO_NETWORK:
 
1158
              name = DBUS_ERROR_NO_NETWORK;
 
1159
              break;
 
1160
            case DBUS_GERROR_ADDRESS_IN_USE:
 
1161
              name = DBUS_ERROR_ADDRESS_IN_USE;
 
1162
              break;
 
1163
            case DBUS_GERROR_DISCONNECTED:
 
1164
              name = DBUS_ERROR_DISCONNECTED;
 
1165
              break;
 
1166
            case DBUS_GERROR_INVALID_ARGS:
 
1167
              name = DBUS_ERROR_INVALID_ARGS;
 
1168
              break;
 
1169
            case DBUS_GERROR_FILE_NOT_FOUND:
 
1170
              name = DBUS_ERROR_FILE_NOT_FOUND;
 
1171
              break;
 
1172
            case DBUS_GERROR_REMOTE_EXCEPTION:
 
1173
              name = dbus_g_error_get_name (error);
 
1174
              break;
 
1175
            }
 
1176
 
 
1177
          reply = dbus_message_new_error (message, name, error->message);
 
1178
        }
1080
1179
      else
1081
1180
        {
1082
1181
          char *error_name;
1467
1566
}
1468
1567
 
1469
1568
static DBusHandlerResult
1470
 
gobject_message_function (DBusConnection  *connection,
1471
 
                          DBusMessage     *message,
1472
 
                          void            *user_data)
 
1569
object_registration_message (DBusConnection  *connection,
 
1570
                             DBusMessage     *message,
 
1571
                             void            *user_data)
1473
1572
{
1474
1573
  GParamSpec *pspec;
1475
1574
  GObject *object;
1483
1582
  const DBusGMethodInfo *method;
1484
1583
  const DBusGObjectInfo *object_info;
1485
1584
  DBusMessage *ret;
 
1585
  ObjectRegistration *o;
1486
1586
 
1487
 
  object = G_OBJECT (user_data);
 
1587
  o = user_data;
 
1588
  object = G_OBJECT (o->object);
1488
1589
 
1489
1590
  if (dbus_message_is_method_call (message,
1490
1591
                                   DBUS_INTERFACE_INTROSPECTABLE,
1600
1701
}
1601
1702
 
1602
1703
static const DBusObjectPathVTable gobject_dbus_vtable = {
1603
 
  gobject_unregister_function,
1604
 
  gobject_message_function,
 
1704
  object_registration_unregistered,
 
1705
  object_registration_message,
1605
1706
  NULL
1606
1707
};
1607
1708
 
1963
2064
  g_static_rw_lock_writer_unlock (&globals_lock);
1964
2065
}
1965
2066
 
 
2067
/* Called when the object is destroyed */
1966
2068
static void
1967
 
unregister_gobject (DBusGConnection *connection, GObject *dead)
1968
 
{
1969
 
  char *path;
1970
 
  path = g_object_steal_data (dead, "dbus_glib_object_path");
1971
 
  dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection), path);
1972
 
  g_free (path);
 
2069
object_registration_object_died (gpointer user_data, GObject *dead)
 
2070
{
 
2071
  ObjectRegistration *o = user_data;
 
2072
 
 
2073
  g_assert (dead == o->object);
 
2074
 
 
2075
  /* this prevents the weak unref from taking place, which would cause an
 
2076
   * assertion failure since the object has already gone... */
 
2077
  o->object = NULL;
 
2078
 
 
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);
 
2081
}
 
2082
 
 
2083
/**
 
2084
 * dbus_g_connection_unregister_g_object:
 
2085
 * @connection: the D-BUS connection
 
2086
 * @object: the object
 
2087
 *
 
2088
 * Removes @object from the bus. Properties, methods, and signals
 
2089
 * of the object can no longer be accessed remotely.
 
2090
 */
 
2091
void
 
2092
dbus_g_connection_unregister_g_object (DBusGConnection *connection,
 
2093
                                       GObject *object)
 
2094
{
 
2095
  ObjectRegistration *o;
 
2096
 
 
2097
  o = g_object_get_data (object, "dbus_glib_object_registration");
 
2098
 
 
2099
  g_return_if_fail (o != NULL);
 
2100
 
 
2101
  dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (o->connection),
 
2102
      o->object_path);
1973
2103
}
1974
2104
 
1975
2105
/**
1984
2114
 * with dbus_g_object_type_install_info().
1985
2115
 *
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()
 
2118
 * is used.
1988
2119
 */
1989
2120
void
1990
2121
dbus_g_connection_register_g_object (DBusGConnection       *connection,
1992
2123
                                     GObject               *object)
1993
2124
{
1994
2125
  GList *info_list;
 
2126
  ObjectRegistration *o;
 
2127
 
1995
2128
  g_return_if_fail (connection != NULL);
1996
2129
  g_return_if_fail (at_path != NULL);
1997
2130
  g_return_if_fail (G_IS_OBJECT (object));
2004
2137
      return;
2005
2138
    }
2006
2139
 
 
2140
  o = g_object_get_data (object, "dbus_glib_object_registration");
 
2141
 
 
2142
  if (o != NULL)
 
2143
    {
 
2144
      g_warning ("Object already registered at %s, can't re-register at %s",
 
2145
          o->object_path, at_path);
 
2146
      return;
 
2147
    }
 
2148
 
 
2149
  o = object_registration_new (connection, at_path, object);
 
2150
 
2007
2151
  if (!dbus_connection_register_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection),
2008
2152
                                             at_path,
2009
2153
                                             &gobject_dbus_vtable,
2010
 
                                             object))
 
2154
                                             o))
2011
2155
    {
2012
2156
      g_error ("Failed to register GObject with DBusConnection");
 
2157
      object_registration_free (o);
2013
2158
      return;
2014
2159
    }
2015
2160
 
2016
2161
  export_signals (connection, info_list, object);
2017
2162
  g_list_free (info_list);
2018
 
 
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);
2021
2164
}
2022
2165
 
2023
2166
/**
2033
2176
dbus_g_connection_lookup_g_object (DBusGConnection       *connection,
2034
2177
                                   const char            *at_path)
2035
2178
{
2036
 
  gpointer ret;
2037
 
  if (!dbus_connection_get_object_path_data (DBUS_CONNECTION_FROM_G_CONNECTION (connection), at_path, &ret))
2038
 
    return NULL;
2039
 
  return ret;
 
2179
  gpointer p;
 
2180
  ObjectRegistration *o;
 
2181
 
 
2182
  if (!dbus_connection_get_object_path_data (DBUS_CONNECTION_FROM_G_CONNECTION (connection), at_path, &p))
 
2183
    return NULL;
 
2184
 
 
2185
  if (p == NULL)
 
2186
    return NULL;
 
2187
 
 
2188
  o = p;
 
2189
  return G_OBJECT (o->object);
2040
2190
}
2041
2191
 
2042
2192
typedef struct {
2267
2417
  const gchar *sender;
2268
2418
 
2269
2419
  sender = dbus_message_get_sender (dbus_g_message_get_message (context->message));
2270
 
 
2271
 
  if (sender == NULL)
2272
 
    return NULL;
2273
 
    
2274
 
  return strdup (sender);
 
2420
  return g_strdup (sender);
2275
2421
}
2276
2422
 
2277
2423
/**
2350
2496
      G_VALUE_COLLECT (&value, args, G_VALUE_NOCOPY_CONTENTS, &error);
2351
2497
      if (error)
2352
2498
        {
2353
 
          g_warning(error);
 
2499
          g_warning("%s", error);
2354
2500
          g_free (error);
2355
2501
        }
2356
2502
      _dbus_gvalue_marshal (&iter, &value);
2376
2522
 * This function also frees the sending context.
2377
2523
 */
2378
2524
void
2379
 
dbus_g_method_return_error (DBusGMethodInvocation *context, GError *error)
 
2525
dbus_g_method_return_error (DBusGMethodInvocation *context, const GError *error)
2380
2526
{
2381
2527
  DBusMessage *reply;
2382
2528
  
2395
2541
 
2396
2542
const char * _dbus_gobject_get_path (GObject *obj)
2397
2543
{
2398
 
  return g_object_get_data (obj, "dbus_glib_object_path");
 
2544
  ObjectRegistration *o;
 
2545
 
 
2546
  o = g_object_get_data (obj, "dbus_glib_object_registration");
 
2547
 
 
2548
  if (o == NULL)
 
2549
    return NULL;
 
2550
 
 
2551
  return o->object_path;
2399
2552
}
2400
2553
 
2401
2554
#ifdef DBUS_BUILD_TESTS