1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ofdbus/dbus-glib/dbus/dbus-glib.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,508 @@
1.4 +/* -*- mode: C; c-file-style: "gnu" -*- */
1.5 +/* dbus-glib.c General GLib binding stuff
1.6 + *
1.7 + * Copyright (C) 2004 Red Hat, Inc.
1.8 + * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.9 + * Licensed under the Academic Free License version 2.1
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + *
1.21 + * You should have received a copy of the GNU General Public License
1.22 + * along with this program; if not, write to the Free Software
1.23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.24 + *
1.25 + */
1.26 +
1.27 +#ifndef __SYMBIAN32__
1.28 +#include <config.h>
1.29 +#else
1.30 +#include "config.h"
1.31 +#endif //__SYMBIAN32__
1.32 +#include "dbus-glib.h"
1.33 +#include "dbus-glib-lowlevel.h"
1.34 +#include "dbus-gtest.h"
1.35 +#include "dbus-gutils.h"
1.36 +#include "dbus-gobject.h"
1.37 +#include <string.h>
1.38 +
1.39 +#ifndef __SYMBIAN32__
1.40 +#include <libintl.h>
1.41 +#define _(x) dgettext (GETTEXT_PACKAGE, x)
1.42 +#define N_(x) x
1.43 +#else
1.44 +
1.45 +#define _(x) x
1.46 +#define N_(x) x
1.47 +#endif
1.48 +
1.49 +#ifdef __SYMBIAN32__
1.50 +#include "libdbus_glib_wsd_solution.h"
1.51 +#endif
1.52 +
1.53 +/**
1.54 + * SECTION:dbus-gconnection
1.55 + * @short_description: DBus Connection
1.56 + * @see_also: #DBusConnection
1.57 + * @stability: Stable
1.58 + *
1.59 + * A #DBusGConnection is a boxed type abstracting a DBusConnection.
1.60 + */
1.61 +
1.62 +/**
1.63 + * dbus_g_connection_flush:
1.64 + * @connection: the #DBusGConnection to flush
1.65 + *
1.66 + * Blocks until outgoing calls and signal emissions have been sent.
1.67 + */
1.68 + #ifdef __SYMBIAN32__
1.69 +EXPORT_C
1.70 +#endif
1.71 +void
1.72 +dbus_g_connection_flush (DBusGConnection *connection)
1.73 +{
1.74 + dbus_connection_flush (DBUS_CONNECTION_FROM_G_CONNECTION (connection));
1.75 +}
1.76 +
1.77 +/**
1.78 + * dbus_g_connection_ref:
1.79 + * @gconnection the #DBusGConnection to ref
1.80 + *
1.81 + * Increment refcount on a #DBusGConnection
1.82 + *
1.83 + * Returns: the connection that was ref'd
1.84 + */
1.85 + #ifdef __SYMBIAN32__
1.86 + EXPORT_C
1.87 + #endif
1.88 +DBusGConnection*
1.89 +dbus_g_connection_ref (DBusGConnection *gconnection)
1.90 +{
1.91 + DBusConnection *c;
1.92 +
1.93 + c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
1.94 + dbus_connection_ref (c);
1.95 + return gconnection;
1.96 +}
1.97 +
1.98 +
1.99 +/**
1.100 + * dbus_g_connection_unref:
1.101 + * @gconnection: the connection to unref
1.102 + *
1.103 + * Decrement refcount on a #DBusGConnection
1.104 + */
1.105 + #ifdef __SYMBIAN32__
1.106 + EXPORT_C
1.107 + #endif
1.108 +void
1.109 +dbus_g_connection_unref (DBusGConnection *gconnection)
1.110 +{
1.111 + DBusConnection *c;
1.112 +
1.113 + c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
1.114 + dbus_connection_unref (c);
1.115 +}
1.116 +
1.117 +
1.118 +/**
1.119 + * SECTION:dbus-gmessage
1.120 + * @short_description: DBus Message
1.121 + * @see_also: #DBusMessage
1.122 + * @stability: Stable
1.123 + *
1.124 + * A #DBusGConnection is a boxed type abstracting a DBusMessage.
1.125 + */
1.126 +
1.127 +/**
1.128 + * dbus_g_message_ref:
1.129 + * @gmessage: the message to ref
1.130 + *
1.131 + * Increment refcount on a #DBusGMessage
1.132 + *
1.133 + * Returns: the message that was ref'd
1.134 + */
1.135 + #ifdef __SYMBIAN32__
1.136 + EXPORT_C
1.137 + #endif
1.138 +DBusGMessage*
1.139 +dbus_g_message_ref (DBusGMessage *gmessage)
1.140 +{
1.141 + DBusMessage *c;
1.142 +
1.143 + c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
1.144 + dbus_message_ref (c);
1.145 + return gmessage;
1.146 +}
1.147 +
1.148 +/**
1.149 + * dbus_g_message_unref:
1.150 + * @gmessage: the message to unref
1.151 + *
1.152 + * Decrement refcount on a #DBusGMessage
1.153 + */
1.154 + #ifdef __SYMBIAN32__
1.155 + EXPORT_C
1.156 + #endif
1.157 +void
1.158 +dbus_g_message_unref (DBusGMessage *gmessage)
1.159 +{
1.160 + DBusMessage *c;
1.161 +
1.162 + c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
1.163 + dbus_message_unref (c);
1.164 +}
1.165 +
1.166 +/**
1.167 + * SECTION:dbus-gerror
1.168 + * @short_description: DBus GError
1.169 + * @see_also: #GError
1.170 + * @stability: Stable
1.171 + *
1.172 + * #DBusGError is the #GError used by DBus.
1.173 + */
1.174 +
1.175 +/**
1.176 + * dbus_g_error_quark:
1.177 + *
1.178 + * The implementation of #DBUS_GERROR error domain. See documentation
1.179 + * for #GError in GLib reference manual.
1.180 + *
1.181 + * Returns: the error domain quark for use with #GError
1.182 + */
1.183 +
1.184 + #if EMULATOR
1.185 +GET_STATIC_VAR_FROM_TLS(quark,dbus_glib,GQuark )
1.186 +#define quark (*GET_DBUS_WSD_VAR_NAME(quark,dbus_glib,s)())
1.187 +
1.188 +#endif
1.189 + #ifdef __SYMBIAN32__
1.190 + EXPORT_C
1.191 + #endif
1.192 +GQuark
1.193 +dbus_g_error_quark (void)
1.194 +{
1.195 +#ifndef EMULATOR
1.196 + static GQuark quark=0;
1.197 +#endif
1.198 + if (quark == 0)
1.199 + quark = g_quark_from_static_string ("dbus-glib-error-quark");
1.200 + return quark;
1.201 +}
1.202 +
1.203 +/**
1.204 + * dbus_g_error_has_name:
1.205 + * @error: the GError given from the remote method
1.206 + * @name: the D-BUS error name
1.207 + * @msg: the D-BUS error detailed message
1.208 + *
1.209 + * Determine whether D-BUS error name for a remote exception matches
1.210 + * the given name. This function is intended to be invoked on a
1.211 + * GError returned from an invocation of a remote method, e.g. via
1.212 + * dbus_g_proxy_end_call. It will silently return FALSE for errors
1.213 + * which are not remote D-BUS exceptions (i.e. with a domain other
1.214 + * than DBUS_GERROR or a code other than
1.215 + * DBUS_GERROR_REMOTE_EXCEPTION).
1.216 + *
1.217 + * Returns: TRUE iff the remote error has the given name
1.218 + */
1.219 + #ifdef __SYMBIAN32__
1.220 + EXPORT_C
1.221 + #endif
1.222 +gboolean
1.223 +dbus_g_error_has_name (GError *error, const char *name)
1.224 +{
1.225 + g_return_val_if_fail (error != NULL, FALSE);
1.226 +
1.227 + if (error->domain != DBUS_GERROR
1.228 + || error->code != DBUS_GERROR_REMOTE_EXCEPTION)
1.229 + return FALSE;
1.230 +
1.231 + return !strcmp (dbus_g_error_get_name (error), name);
1.232 +}
1.233 +
1.234 +/**
1.235 + * dbus_g_error_get_name:
1.236 + * @error: the #GError given from the remote method
1.237 + * @name: the D-BUS error name
1.238 + * @msg: the D-BUS error detailed message
1.239 + *
1.240 + * This function may only be invoked on a #GError returned from an
1.241 + * invocation of a remote method, e.g. via dbus_g_proxy_end_call.
1.242 + * Moreover, you must ensure that the error's domain is #DBUS_GERROR,
1.243 + * and the code is #DBUS_GERROR_REMOTE_EXCEPTION.
1.244 + *
1.245 + * Returns: the D-BUS name for a remote exception.
1.246 + */
1.247 + #ifdef __SYMBIAN32__
1.248 + EXPORT_C
1.249 + #endif
1.250 +const char *
1.251 +dbus_g_error_get_name (GError *error)
1.252 +{
1.253 + g_return_val_if_fail (error != NULL, NULL);
1.254 + g_return_val_if_fail (error->domain == DBUS_GERROR, NULL);
1.255 + g_return_val_if_fail (error->code == DBUS_GERROR_REMOTE_EXCEPTION, NULL);
1.256 +
1.257 + return error->message + strlen (error->message) + 1;
1.258 +}
1.259 +
1.260 +/**
1.261 + * dbus_connection_get_g_type:
1.262 + * Get the GLib type ID for a #DBusConnection boxed type.
1.263 + *
1.264 + * Returns: the GLib type
1.265 + */
1.266 + /*
1.267 +#if EMULATOR
1.268 +GET_STATIC_VAR_FROM_TLS(our_type,dbus_glib,GType )
1.269 +#define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_glib,p)())
1.270 +#endif
1.271 +*/
1.272 +
1.273 +#ifdef __SYMBIAN32__
1.274 +EXPORT_C
1.275 +#endif
1.276 +GType
1.277 +dbus_connection_get_g_type (void)
1.278 +{
1.279 + #ifndef EMULATOR
1.280 +
1.281 + static GType our_type = 0;
1.282 + #else
1.283 + // RETURN_WSD_VAR(our_type,dbus_glib,p) //(libdbus_glib_ImpurePtr()->GET_DBUS_WSD_VAR_NAME(var,filename,prefix))
1.284 + // #define GET_DBUS_WSD_VAR_NAME(var,filename,prefix) _##prefix##_##filename##_##var
1.285 + #ifdef our_type
1.286 + #undef our_type
1.287 + #endif
1.288 + #define our_type RETURN_WSD_VAR(our_type,dbus_glib,p)
1.289 + // #define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_glib,p)()) //(*_p_dbus_glib_our_type())
1.290 +
1.291 +
1.292 +#endif
1.293 +
1.294 +
1.295 +
1.296 + if (our_type == 0)
1.297 + our_type = g_boxed_type_register_static ("DBusConnection",
1.298 + (GBoxedCopyFunc) dbus_connection_ref,
1.299 + (GBoxedFreeFunc) dbus_connection_unref);
1.300 +
1.301 + return our_type;
1.302 +
1.303 +}
1.304 +
1.305 +/**
1.306 + * dbus_message_get_g_type:
1.307 + * Get the GLib type ID for a #DBusMessage boxed type.
1.308 + *
1.309 + * Returns: the GLib type
1.310 + */
1.311 +
1.312 + /*
1.313 + #if EMULATOR
1.314 +GET_STATIC_VAR_FROM_TLS(out_type,dbus_glib,GType )
1.315 +#define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_glib,q)())
1.316 +#endif*/
1.317 +
1.318 + #ifdef __SYMBIAN32__
1.319 + EXPORT_C
1.320 + #endif
1.321 +GType
1.322 +dbus_message_get_g_type (void)
1.323 +{
1.324 +
1.325 + #ifndef EMULATOR
1.326 + static GType our_type = 0;
1.327 + #else
1.328 + #ifdef our_type
1.329 + #undef our_type
1.330 + #endif
1.331 + #define our_type RETURN_WSD_VAR(our_type,dbus_glib,q)
1.332 +#endif
1.333 +
1.334 +
1.335 + if (our_type == 0)
1.336 + our_type = g_boxed_type_register_static ("DBusMessage",
1.337 + (GBoxedCopyFunc) dbus_message_ref,
1.338 + (GBoxedFreeFunc) dbus_message_unref);
1.339 +
1.340 + return our_type;
1.341 +}
1.342 +
1.343 +/**
1.344 + * dbus_g_connection_get_g_type:
1.345 + * Get the GLib type ID for a DBusGConnection boxed type.
1.346 + *
1.347 + * Returns: the GLib type
1.348 + */
1.349 +
1.350 +
1.351 + #ifdef __SYMBIAN32__
1.352 +EXPORT_C
1.353 +#endif
1.354 +GType
1.355 +dbus_g_connection_get_g_type (void)
1.356 +{
1.357 + #ifndef EMULATOR
1.358 + static GType our_type = 0;
1.359 + #else
1.360 + #ifdef our_type
1.361 + #undef our_type
1.362 + #endif
1.363 + #define our_type RETURN_WSD_VAR(our_type,dbus_glib,r)
1.364 +#endif
1.365 +
1.366 +
1.367 + if (our_type == 0)
1.368 + our_type = g_boxed_type_register_static ("DBusGConnection",
1.369 + (GBoxedCopyFunc) dbus_g_connection_ref,
1.370 + (GBoxedFreeFunc) dbus_g_connection_unref);
1.371 +
1.372 + return our_type;
1.373 +}
1.374 +
1.375 +/**
1.376 + * dbus_g_message_get_g_type:
1.377 + * Get the GLib type ID for a #DBusGMessage boxed type.
1.378 + *
1.379 + * Returns: the GLib type
1.380 + */
1.381 + #ifdef __SYMBIAN32__
1.382 + EXPORT_C
1.383 + #endif
1.384 +GType
1.385 +dbus_g_message_get_g_type (void)
1.386 +{
1.387 + #ifndef EMULATOR
1.388 + static GType our_type = 0;
1.389 + #else
1.390 + #ifdef our_type
1.391 + #undef our_type
1.392 + #endif
1.393 + #define our_type RETURN_WSD_VAR(our_type,dbus_glib,s)
1.394 +
1.395 + #endif
1.396 +
1.397 + if (our_type == 0)
1.398 + our_type = g_boxed_type_register_static ("DBusGMessage",
1.399 + (GBoxedCopyFunc) dbus_g_message_ref,
1.400 + (GBoxedFreeFunc) dbus_g_message_unref);
1.401 +
1.402 + return our_type;
1.403 +}
1.404 +
1.405 +/**
1.406 + * SECTION:dbus-glib-lowlevel
1.407 + * @short_description: DBus lower level functions
1.408 + * @stability: Unstable
1.409 + *
1.410 + * These functions can be used to access lower level of DBus.
1.411 + */
1.412 +
1.413 +/**
1.414 + * dbus_g_connection_get_connection:
1.415 + * @gconnection: a #DBusGConnection
1.416 + *
1.417 + * Get the #DBusConnection corresponding to this #DBusGConnection.
1.418 + * The return value does not have its refcount incremented.
1.419 + *
1.420 + * Returns: #DBusConnection
1.421 + */
1.422 + #ifdef __SYMBIAN32__
1.423 +EXPORT_C
1.424 +#endif
1.425 +DBusConnection*
1.426 +dbus_g_connection_get_connection (DBusGConnection *gconnection)
1.427 +{
1.428 + g_return_val_if_fail (gconnection, NULL);
1.429 + return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection);
1.430 +}
1.431 +
1.432 +#if EMULATOR
1.433 +dbus_int32_t GET_DBUS_WSD_VAR_NAME(_dbus_gmain_connection_slot,dbus_gmain,dbus_int32_t)();
1.434 +#define _dbus_gmain_connection_slot (GET_DBUS_WSD_VAR_NAME(_dbus_gmain_connection_slot,dbus_gmain,g)())
1.435 +#else
1.436 +extern dbus_int32_t _dbus_gmain_connection_slot;
1.437 +#endif
1.438 +/**
1.439 + * dbus_connection_get_g_connection:
1.440 + * @connection: a #DBusConnection
1.441 + *
1.442 + * Get the #DBusGConnection corresponding to this #DBusConnection. This only
1.443 + * makes sense if the #DBusConnection was originally a #DBusGConnection that was
1.444 + * registered with the GLib main loop. The return value does not have its
1.445 + * refcount incremented.
1.446 + *
1.447 + * Returns: #DBusGConnection
1.448 + */
1.449 + #ifdef __SYMBIAN32__
1.450 +EXPORT_C
1.451 +#endif
1.452 +DBusGConnection*
1.453 +dbus_connection_get_g_connection (DBusConnection *connection)
1.454 +{
1.455 + g_return_val_if_fail (connection, NULL);
1.456 + g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL);
1.457 +
1.458 + return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
1.459 +}
1.460 +
1.461 +
1.462 +/**
1.463 + * dbus_g_message_get_message:
1.464 + * @gmessage: a #DBusGMessage
1.465 + *
1.466 + * Get the #DBusMessage corresponding to this #DBusGMessage.
1.467 + * The return value does not have its refcount incremented.
1.468 + *
1.469 + * Returns: #DBusMessage
1.470 + */
1.471 + #ifdef __SYMBIAN32__
1.472 + EXPORT_C
1.473 + #endif
1.474 +DBusMessage*
1.475 +dbus_g_message_get_message (DBusGMessage *gmessage)
1.476 +{
1.477 + return DBUS_MESSAGE_FROM_G_MESSAGE (gmessage);
1.478 +}
1.479 +
1.480 +#ifdef DBUS_BUILD_TESTS
1.481 +
1.482 +/**
1.483 + * @ingroup DBusGLibInternals
1.484 + * Unit test for general glib stuff
1.485 + * Returns: #TRUE on success.
1.486 + */
1.487 + #ifdef __SYMBIAN32__
1.488 + EXPORT_C
1.489 + #endif
1.490 +gboolean
1.491 +_dbus_glib_test (const char *test_data_dir)
1.492 +{
1.493 + DBusError err;
1.494 + GError *gerror = NULL;
1.495 +
1.496 + dbus_error_init (&err);
1.497 + dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!");
1.498 +
1.499 + dbus_set_g_error (&gerror, &err);
1.500 + g_assert (gerror != NULL);
1.501 + g_assert (gerror->domain == DBUS_GERROR);
1.502 + g_assert (gerror->code == DBUS_GERROR_NO_MEMORY);
1.503 + g_assert (!strcmp (gerror->message, "Out of memory!"));
1.504 +
1.505 + dbus_error_init (&err);
1.506 + g_clear_error (&gerror);
1.507 +
1.508 + return TRUE;
1.509 +}
1.510 +
1.511 +#endif /* DBUS_BUILD_TESTS */