index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000005.html
glib
dbus-gmain.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-gmain.c GLib main loop integration
00003
*
00004
* Copyright (C) 2002, 2003 CodeFactory AB
00005
* Copyright (C) 2005 Red Hat, Inc.
00006
*
00007
* Licensed under the Academic Free License version 2.1
00008
*
00009
* This program is free software; you can redistribute it and/or modify
00010
* it under the terms of the GNU General Public License as published by
00011
* the Free Software Foundation; either version 2 of the License, or
00012
* (at your option) any later version.
00013
*
00014
* This program is distributed in the hope that it will be useful,
00015
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00016
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017
* GNU General Public License for more details.
00018
*
00019
* You should have received a copy of the GNU General Public License
00020
* along with this program; if not, write to the Free Software
00021
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022
*
00023
*/
00024
00025
#include <config.h>
00026
#include <dbus/dbus-glib.h>
00027
#include <dbus/dbus-glib-lowlevel.h>
00028
#include "dbus-gtest.h"
00029
#include "dbus-gutils.h"
00030
#include "dbus-gvalue.h"
00031
#include "dbus-gobject.h"
00032
#include "dbus-gvalue-utils.h"
00033
#include <string.h>
00034
00035
#include <libintl.h>
00036
#define _(x) dgettext (GETTEXT_PACKAGE, x)
00037
#define N_(x) x
00038
structDBusGMessageQueue.html
00065
typedef
struct
00066
{
structDBusGMessageQueue.html#o0
00067
GSource source;
structDBusGMessageQueue.html#o1
00068
structDBusConnection.html
DBusConnection
*connection;
00069 }
structDBusGMessageQueue.html
DBusGMessageQueue
;
00070
00071
static
gboolean message_queue_prepare  (GSource     *source,
00072                                         gint        *timeout);
00073
static
gboolean message_queue_check    (GSource     *source);
00074
static
gboolean message_queue_dispatch (GSource     *source,
00075                                         GSourceFunc  callback,
00076                                         gpointer     user_data);
00077
00078
static
GSourceFuncs message_queue_funcs = {
00079   message_queue_prepare,
00080   message_queue_check,
00081   message_queue_dispatch,
00082
group__DBusMacros.html#ga4
NULL
00083 };
00084
00085
static
gboolean
00086 message_queue_prepare (GSource *source,
00087                        gint    *timeout)
00088 {
00089
structDBusConnection.html
DBusConnection
*connection = ((
structDBusGMessageQueue.html
DBusGMessageQueue
*)source)->connection;
00090
00091   *timeout = -1;
00092
00093
return
(
group__DBusConnection.html#ga37
dbus_connection_get_dispatch_status
(connection) == DBUS_DISPATCH_DATA_REMAINS);
00094 }
00095
00096
static
gboolean
00097 message_queue_check (GSource *source)
00098 {
00099
return
group__DBusMacros.html#ga3
FALSE
;
00100 }
00101
00102
static
gboolean
00103 message_queue_dispatch (GSource     *source,
00104                         GSourceFunc  callback,
00105                         gpointer     user_data)
00106 {
00107
structDBusConnection.html
DBusConnection
*connection = ((
structDBusGMessageQueue.html
DBusGMessageQueue
*)source)->connection;
00108
00109
group__DBusConnection.html#ga3
dbus_connection_ref
(connection);
00110
00111
/* Only dispatch once - we don't want to starve other GSource */
00112
group__DBusConnection.html#ga40
dbus_connection_dispatch
(connection);
00113
00114
group__DBusConnection.html#ga5
dbus_connection_unref
(connection);
00115
00116
return
group__DBusMacros.html#ga2
TRUE
;
00117 }
00118
structConnectionSetup.html
00119
typedef
struct
00120
{
structConnectionSetup.html#o0
00121
GMainContext *context;
structConnectionSetup.html#o1
00122
GSList *ios;
structConnectionSetup.html#o2
00123
GSList *timeouts;
structConnectionSetup.html#o3
00124
structDBusConnection.html
DBusConnection
*connection;
structConnectionSetup.html#o4
00125
GSource *message_queue_source;
00126 }
structConnectionSetup.html
ConnectionSetup
;
00127
00128
structIOHandler.html
00129
typedef
struct
00130
{
structIOHandler.html#o0
00131
structConnectionSetup.html
ConnectionSetup
*cs;
structIOHandler.html#o1
00132
GSource *source;
structIOHandler.html#o2
00133
structDBusWatch.html
DBusWatch
*watch;
00134 }
structIOHandler.html
IOHandler
;
00135
structTimeoutHandler.html
00136
typedef
struct
00137
{
structTimeoutHandler.html#o0
00138
structConnectionSetup.html
ConnectionSetup
*cs;
structTimeoutHandler.html#o1
00139
GSource *source;
structTimeoutHandler.html#o2
00140
structDBusTimeout.html
DBusTimeout
*timeout;
00141 }
structTimeoutHandler.html
TimeoutHandler
;
00142
00143
static
group__DBusTypes.html#ga4
dbus_int32_t
connection_slot = -1;
00144
static
group__DBusTypes.html#ga4
dbus_int32_t
server_slot = -1;
00145
00146
static
structConnectionSetup.html
ConnectionSetup
*
00147 connection_setup_new (GMainContext   *context,
00148
structDBusConnection.html
DBusConnection
*connection)
00149 {
00150
structConnectionSetup.html
ConnectionSetup
*cs;
00151
00152   cs = g_new0 (
structConnectionSetup.html
ConnectionSetup
, 1);
00153
00154   g_assert (context !=
group__DBusMacros.html#ga4
NULL
);
00155
00156   cs->
structConnectionSetup.html#o0
context
= context;
00157   g_main_context_ref (cs->
structConnectionSetup.html#o0
context
);
00158
00159
if
(connection)
00160     {
00161       cs->
structConnectionSetup.html#o3
connection
= connection;
00162
00163       cs->
structConnectionSetup.html#o4
message_queue_source
= g_source_new (&message_queue_funcs,
00164
sizeof
(
structDBusGMessageQueue.html
DBusGMessageQueue
));
00165       ((DBusGMessageQueue*)cs->
structConnectionSetup.html#o4
message_queue_source
)->connection = connection;
00166       g_source_attach (cs->
structConnectionSetup.html#o4
message_queue_source
, cs->
structConnectionSetup.html#o0
context
);
00167     }
00168
00169
return
cs;
00170 }
00171
00172
static
void
00173 io_handler_source_finalized (gpointer data)
00174 {
00175
structIOHandler.html
IOHandler
*handler;
00176
00177   handler = data;
00178
00179
if
(handler->
structIOHandler.html#o2
watch
)
00180
group__DBusWatch.html#ga3
dbus_watch_set_data
(handler->
structIOHandler.html#o2
watch
,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00181
00182   g_free (handler);
00183 }
00184
00185
static
void
00186 io_handler_destroy_source (
void
*data)
00187 {
00188
structIOHandler.html
IOHandler
*handler;
00189
00190   handler = data;
00191
00192
if
(handler->
structIOHandler.html#o1
source
)
00193     {
00194       GSource *source = handler->
structIOHandler.html#o1
source
;
00195       handler->
structIOHandler.html#o1
source
=
group__DBusMacros.html#ga4
NULL
;
00196       handler->
structIOHandler.html#o0
cs
->
structConnectionSetup.html#o1
ios
= g_slist_remove (handler->
structIOHandler.html#o0
cs
->
structConnectionSetup.html#o1
ios
, handler);
00197       g_source_destroy (source);
00198       g_source_unref (source);
00199     }
00200 }
00201
00202
static
void
00203 io_handler_watch_freed (
void
*data)
00204 {
00205
structIOHandler.html
IOHandler
*handler;
00206
00207   handler = data;
00208
00209   handler->
structIOHandler.html#o2
watch
=
group__DBusMacros.html#ga4
NULL
;
00210
00211   io_handler_destroy_source (handler);
00212 }
00213
00214
static
gboolean
00215 io_handler_dispatch (GIOChannel   *source,
00216                      GIOCondition  condition,
00217                      gpointer      data)
00218 {
00219
structIOHandler.html
IOHandler
*handler;
00220   guint dbus_condition = 0;
00221
structDBusConnection.html
DBusConnection
*connection;
00222
00223   handler = data;
00224
00225   connection = handler->
structIOHandler.html#o0
cs
->
structConnectionSetup.html#o3
connection
;
00226
00227
if
(connection)
00228
group__DBusConnection.html#ga3
dbus_connection_ref
(connection);
00229
00230
if
(condition & G_IO_IN)
00231     dbus_condition |= DBUS_WATCH_READABLE;
00232
if
(condition & G_IO_OUT)
00233     dbus_condition |= DBUS_WATCH_WRITABLE;
00234
if
(condition & G_IO_ERR)
00235     dbus_condition |= DBUS_WATCH_ERROR;
00236
if
(condition & G_IO_HUP)
00237     dbus_condition |= DBUS_WATCH_HANGUP;
00238
00239
/* Note that we don't touch the handler after this, because
00240
* dbus may have disabled the watch and thus killed the
00241
* handler.
00242
*/
00243
group__DBusWatch.html#ga5
dbus_watch_handle
(handler->
structIOHandler.html#o2
watch
, dbus_condition);
00244   handler =
group__DBusMacros.html#ga4
NULL
;
00245
00246
if
(connection)
00247
group__DBusConnection.html#ga5
dbus_connection_unref
(connection);
00248
00249
return
group__DBusMacros.html#ga2
TRUE
;
00250 }
00251
00252
static
void
00253 connection_setup_add_watch (
structConnectionSetup.html
ConnectionSetup
*cs,
00254
structDBusWatch.html
DBusWatch
*watch)
00255 {
00256   guint flags;
00257   GIOCondition condition;
00258   GIOChannel *channel;
00259
structIOHandler.html
IOHandler
*handler;
00260
00261
if
(!
group__DBusWatch.html#ga4
dbus_watch_get_enabled
(watch))
00262
return
;
00263
00264   g_assert (
group__DBusWatch.html#ga2
dbus_watch_get_data
(watch) ==
group__DBusMacros.html#ga4
NULL
);
00265
00266   flags =
group__DBusWatch.html#ga1
dbus_watch_get_flags
(watch);
00267
00268   condition = G_IO_ERR | G_IO_HUP;
00269
if
(flags & DBUS_WATCH_READABLE)
00270     condition |= G_IO_IN;
00271
if
(flags & DBUS_WATCH_WRITABLE)
00272     condition |= G_IO_OUT;
00273
00274   handler = g_new0 (
structIOHandler.html
IOHandler
, 1);
00275   handler->
structIOHandler.html#o0
cs
= cs;
00276   handler->
structIOHandler.html#o2
watch
= watch;
00277
00278   channel = g_io_channel_unix_new (
group__DBusWatch.html#ga0
dbus_watch_get_fd
(watch));
00279
00280   handler->
structIOHandler.html#o1
source
= g_io_create_watch (channel, condition);
00281   g_source_set_callback (handler->
structIOHandler.html#o1
source
, (GSourceFunc) io_handler_dispatch, handler,
00282                          io_handler_source_finalized);
00283   g_source_attach (handler->
structIOHandler.html#o1
source
, cs->
structConnectionSetup.html#o0
context
);
00284
00285   cs->
structConnectionSetup.html#o1
ios
= g_slist_prepend (cs->
structConnectionSetup.html#o1
ios
, handler);
00286
00287
group__DBusWatch.html#ga3
dbus_watch_set_data
(watch, handler, io_handler_watch_freed);
00288 }
00289
00290
static
void
00291 connection_setup_remove_watch (
structConnectionSetup.html
ConnectionSetup
*cs,
00292
structDBusWatch.html
DBusWatch
*watch)
00293 {
00294
structIOHandler.html
IOHandler
*handler;
00295
00296   handler =
group__DBusWatch.html#ga2
dbus_watch_get_data
(watch);
00297
00298
if
(handler ==
group__DBusMacros.html#ga4
NULL
)
00299
return
;
00300
00301   io_handler_destroy_source (handler);
00302 }
00303
00304
static
void
00305 timeout_handler_source_finalized (gpointer data)
00306 {
00307
structTimeoutHandler.html
TimeoutHandler
*handler;
00308
00309   handler = data;
00310
00311
if
(handler->
structTimeoutHandler.html#o2
timeout
)
00312
group__DBusTimeout.html#ga2
dbus_timeout_set_data
(handler->
structTimeoutHandler.html#o2
timeout
,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00313
00314   g_free (handler);
00315 }
00316
00317
static
void
00318 timeout_handler_destroy_source (
void
*data)
00319 {
00320
structTimeoutHandler.html
TimeoutHandler
*handler;
00321
00322   handler = data;
00323
00324
if
(handler->
structTimeoutHandler.html#o1
source
)
00325     {
00326       GSource *source = handler->
structTimeoutHandler.html#o1
source
;
00327       handler->
structTimeoutHandler.html#o1
source
=
group__DBusMacros.html#ga4
NULL
;
00328       handler->
structTimeoutHandler.html#o0
cs
->
structConnectionSetup.html#o2
timeouts
= g_slist_remove (handler->
structTimeoutHandler.html#o0
cs
->
structConnectionSetup.html#o2
timeouts
, handler);
00329       g_source_destroy (source);
00330       g_source_unref (source);
00331     }
00332 }
00333
00334
static
void
00335 timeout_handler_timeout_freed (
void
*data)
00336 {
00337
structTimeoutHandler.html
TimeoutHandler
*handler;
00338
00339   handler = data;
00340
00341   handler->
structTimeoutHandler.html#o2
timeout
=
group__DBusMacros.html#ga4
NULL
;
00342
00343   timeout_handler_destroy_source (handler);
00344 }
00345
00346
static
gboolean
00347 timeout_handler_dispatch (gpointer      data)
00348 {
00349
structTimeoutHandler.html
TimeoutHandler
*handler;
00350
00351   handler = data;
00352
00353
group__DBusTimeout.html#ga3
dbus_timeout_handle
(handler->
structTimeoutHandler.html#o2
timeout
);
00354
00355
return
group__DBusMacros.html#ga2
TRUE
;
00356 }
00357
00358
static
void
00359 connection_setup_add_timeout (
structConnectionSetup.html
ConnectionSetup
*cs,
00360
structDBusTimeout.html
DBusTimeout
*timeout)
00361 {
00362
structTimeoutHandler.html
TimeoutHandler
*handler;
00363
00364
if
(!
group__DBusTimeout.html#ga4
dbus_timeout_get_enabled
(timeout))
00365
return
;
00366
00367   g_assert (
group__DBusTimeout.html#ga1
dbus_timeout_get_data
(timeout) ==
group__DBusMacros.html#ga4
NULL
);
00368
00369   handler = g_new0 (
structTimeoutHandler.html
TimeoutHandler
, 1);
00370   handler->
structTimeoutHandler.html#o0
cs
= cs;
00371   handler->
structTimeoutHandler.html#o2
timeout
= timeout;
00372
00373   handler->
structTimeoutHandler.html#o1
source
= g_timeout_source_new (
group__DBusTimeout.html#ga0
dbus_timeout_get_interval
(timeout));
00374   g_source_set_callback (handler->
structTimeoutHandler.html#o1
source
, timeout_handler_dispatch, handler,
00375                          timeout_handler_source_finalized);
00376   g_source_attach (handler->
structTimeoutHandler.html#o1
source
, handler->
structTimeoutHandler.html#o0
cs
->
structConnectionSetup.html#o0
context
);
00377
00378   cs->
structConnectionSetup.html#o2
timeouts
= g_slist_prepend (cs->
structConnectionSetup.html#o2
timeouts
, handler);
00379
00380
group__DBusTimeout.html#ga2
dbus_timeout_set_data
(timeout, handler, timeout_handler_timeout_freed);
00381 }
00382
00383
static
void
00384 connection_setup_remove_timeout (
structConnectionSetup.html
ConnectionSetup
*cs,
00385
structDBusTimeout.html
DBusTimeout
*timeout)
00386 {
00387
structTimeoutHandler.html
TimeoutHandler
*handler;
00388
00389   handler =
group__DBusTimeout.html#ga1
dbus_timeout_get_data
(timeout);
00390
00391
if
(handler ==
group__DBusMacros.html#ga4
NULL
)
00392
return
;
00393
00394   timeout_handler_destroy_source (handler);
00395 }
00396
00397
static
void
00398 connection_setup_free (
structConnectionSetup.html
ConnectionSetup
*cs)
00399 {
00400
while
(cs->
structConnectionSetup.html#o1
ios
)
00401     io_handler_destroy_source (cs->
structConnectionSetup.html#o1
ios
->data);
00402
00403
while
(cs->
structConnectionSetup.html#o2
timeouts
)
00404     timeout_handler_destroy_source (cs->
structConnectionSetup.html#o2
timeouts
->data);
00405
00406
if
(cs->
structConnectionSetup.html#o4
message_queue_source
)
00407     {
00408       GSource *source;
00409
00410       source = cs->
structConnectionSetup.html#o4
message_queue_source
;
00411       cs->
structConnectionSetup.html#o4
message_queue_source
=
group__DBusMacros.html#ga4
NULL
;
00412
00413       g_source_destroy (source);
00414       g_source_unref (source);
00415     }
00416
00417   g_main_context_unref (cs->
structConnectionSetup.html#o0
context
);
00418   g_free (cs);
00419 }
00420
00421
static
group__DBusTypes.html#ga2
dbus_bool_t
00422 add_watch (
structDBusWatch.html
DBusWatch
*watch,
00423            gpointer   data)
00424 {
00425
structConnectionSetup.html
ConnectionSetup
*cs;
00426
00427   cs = data;
00428
00429   connection_setup_add_watch (cs, watch);
00430
00431
return
group__DBusMacros.html#ga2
TRUE
;
00432 }
00433
00434
static
void
00435 remove_watch (
structDBusWatch.html
DBusWatch
*watch,
00436               gpointer   data)
00437 {
00438
structConnectionSetup.html
ConnectionSetup
*cs;
00439
00440   cs = data;
00441
00442   connection_setup_remove_watch (cs, watch);
00443 }
00444
00445
static
void
00446 watch_toggled (
structDBusWatch.html
DBusWatch
*watch,
00447
void
*data)
00448 {
00449
/* Because we just exit on OOM, enable/disable is
00450
* no different from add/remove
00451
*/
00452
if
(
group__DBusWatch.html#ga4
dbus_watch_get_enabled
(watch))
00453     add_watch (watch, data);
00454
else
00455     remove_watch (watch, data);
00456 }
00457
00458
static
group__DBusTypes.html#ga2
dbus_bool_t
00459 add_timeout (
structDBusTimeout.html
DBusTimeout
*timeout,
00460
void
*data)
00461 {
00462
structConnectionSetup.html
ConnectionSetup
*cs;
00463
00464   cs = data;
00465
00466
if
(!
group__DBusTimeout.html#ga4
dbus_timeout_get_enabled
(timeout))
00467
return
group__DBusMacros.html#ga2
TRUE
;
00468
00469   connection_setup_add_timeout (cs, timeout);
00470
00471
return
group__DBusMacros.html#ga2
TRUE
;
00472 }
00473
00474
static
void
00475 remove_timeout (
structDBusTimeout.html
DBusTimeout
*timeout,
00476
void
*data)
00477 {
00478
structConnectionSetup.html
ConnectionSetup
*cs;
00479
00480   cs = data;
00481
00482   connection_setup_remove_timeout (cs, timeout);
00483 }
00484
00485
static
void
00486 timeout_toggled (
structDBusTimeout.html
DBusTimeout
*timeout,
00487
void
*data)
00488 {
00489
/* Because we just exit on OOM, enable/disable is
00490
* no different from add/remove
00491
*/
00492
if
(
group__DBusTimeout.html#ga4
dbus_timeout_get_enabled
(timeout))
00493     add_timeout (timeout, data);
00494
else
00495     remove_timeout (timeout, data);
00496 }
00497
00498
static
void
00499 wakeup_main (
void
*data)
00500 {
00501
structConnectionSetup.html
ConnectionSetup
*cs = data;
00502
00503   g_main_context_wakeup (cs->
structConnectionSetup.html#o0
context
);
00504 }
00505
00506
00507
/* Move to a new context */
00508
static
structConnectionSetup.html
ConnectionSetup
*
00509 connection_setup_new_from_old (GMainContext    *context,
00510
structConnectionSetup.html
ConnectionSetup
*old)
00511 {
00512   GSList *tmp;
00513
structConnectionSetup.html
ConnectionSetup
*cs;
00514
00515   g_assert (old->
structConnectionSetup.html#o0
context
!= context);
00516
00517   cs = connection_setup_new (context, old->
structConnectionSetup.html#o3
connection
);
00518
00519   tmp = old->
structConnectionSetup.html#o1
ios
;
00520
while
(tmp !=
group__DBusMacros.html#ga4
NULL
)
00521     {
00522
structIOHandler.html
IOHandler
*handler = tmp->data;
00523
00524       connection_setup_add_watch (cs, handler->
structIOHandler.html#o2
watch
);
00525
00526       tmp = tmp->next;
00527     }
00528
00529   tmp = old->
structConnectionSetup.html#o2
timeouts
;
00530
while
(tmp !=
group__DBusMacros.html#ga4
NULL
)
00531     {
00532
structTimeoutHandler.html
TimeoutHandler
*handler = tmp->data;
00533
00534       connection_setup_add_timeout (cs, handler->
structTimeoutHandler.html#o2
timeout
);
00535
00536       tmp = tmp->next;
00537     }
00538
00539
return
cs;
00540 }
00541
/* End of GLib bindings internals */
00543
00562
void
group__DBusGLib.html#ga14
00563
group__DBusGLib.html#ga14
dbus_connection_setup_with_g_main
(
structDBusConnection.html
DBusConnection
*connection,
00564                                    GMainContext   *context)
00565 {
00566
structConnectionSetup.html
ConnectionSetup
*old_setup;
00567
structConnectionSetup.html
ConnectionSetup
*cs;
00568
00569
/* FIXME we never free the slot, so its refcount just keeps growing,
00570
* which is kind of broken.
00571
*/
00572
group__DBusConnection.html#ga56
dbus_connection_allocate_data_slot
(&connection_slot);
00573
if
(connection_slot < 0)
00574
goto
nomem;
00575
00576
if
(context ==
group__DBusMacros.html#ga4
NULL
)
00577     context = g_main_context_default ();
00578
00579   cs =
group__DBusMacros.html#ga4
NULL
;
00580
00581   old_setup =
group__DBusConnection.html#ga59
dbus_connection_get_data
(connection, connection_slot);
00582
if
(old_setup !=
group__DBusMacros.html#ga4
NULL
)
00583     {
00584
if
(old_setup->
structConnectionSetup.html#o0
context
== context)
00585
return
;
/* nothing to do */
00586
00587       cs = connection_setup_new_from_old (context, old_setup);
00588
00589
/* Nuke the old setup */
00590
group__DBusConnection.html#ga58
dbus_connection_set_data
(connection, connection_slot,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00591       old_setup =
group__DBusMacros.html#ga4
NULL
;
00592     }
00593
00594
if
(cs ==
group__DBusMacros.html#ga4
NULL
)
00595     cs = connection_setup_new (context, connection);
00596
00597
if
(!
group__DBusConnection.html#ga58
dbus_connection_set_data
(connection, connection_slot, cs,
00598                                  (
group__DBusMemory.html#ga8
DBusFreeFunction
)connection_setup_free))
00599
goto
nomem;
00600
00601
if
(!
group__DBusConnection.html#ga41
dbus_connection_set_watch_functions
(connection,
00602                                             add_watch,
00603                                             remove_watch,
00604                                             watch_toggled,
00605                                             cs,
group__DBusMacros.html#ga4
NULL
))
00606
goto
nomem;
00607
00608
if
(!
group__DBusConnection.html#ga42
dbus_connection_set_timeout_functions
(connection,
00609                                               add_timeout,
00610                                               remove_timeout,
00611                                               timeout_toggled,
00612                                               cs,
group__DBusMacros.html#ga4
NULL
))
00613
goto
nomem;
00614
00615
group__DBusConnection.html#ga43
dbus_connection_set_wakeup_main_function
(connection,
00616                                             wakeup_main,
00617                                             cs,
group__DBusMacros.html#ga4
NULL
);
00618
00619
return
;
00620
00621  nomem:
00622   g_error (
"Not enough memory to set up DBusConnection for use with GLib"
);
00623 }
00624
00638
void
group__DBusGLib.html#ga15
00639
group__DBusGLib.html#ga15
dbus_server_setup_with_g_main
(
structDBusServer.html
DBusServer
*server,
00640                                GMainContext *context)
00641 {
00642
structConnectionSetup.html
ConnectionSetup
*old_setup;
00643
structConnectionSetup.html
ConnectionSetup
*cs;
00644
00645
/* FIXME we never free the slot, so its refcount just keeps growing,
00646
* which is kind of broken.
00647
*/
00648
group__DBusServer.html#ga13
dbus_server_allocate_data_slot
(&server_slot);
00649
if
(server_slot < 0)
00650
goto
nomem;
00651
00652
if
(context ==
group__DBusMacros.html#ga4
NULL
)
00653     context = g_main_context_default ();
00654
00655   cs =
group__DBusMacros.html#ga4
NULL
;
00656
00657   old_setup =
group__DBusServer.html#ga16
dbus_server_get_data
(server, server_slot);
00658
if
(old_setup !=
group__DBusMacros.html#ga4
NULL
)
00659     {
00660
if
(old_setup->
structConnectionSetup.html#o0
context
== context)
00661
return
;
/* nothing to do */
00662
00663       cs = connection_setup_new_from_old (context, old_setup);
00664
00665
/* Nuke the old setup */
00666
group__DBusServer.html#ga15
dbus_server_set_data
(server, server_slot,
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00667       old_setup =
group__DBusMacros.html#ga4
NULL
;
00668     }
00669
00670
if
(cs ==
group__DBusMacros.html#ga4
NULL
)
00671     cs = connection_setup_new (context,
group__DBusMacros.html#ga4
NULL
);
00672
00673
if
(!
group__DBusServer.html#ga15
dbus_server_set_data
(server, server_slot, cs,
00674                              (
group__DBusMemory.html#ga8
DBusFreeFunction
)connection_setup_free))
00675
goto
nomem;
00676
00677
if
(!
group__DBusServer.html#ga10
dbus_server_set_watch_functions
(server,
00678                                         add_watch,
00679                                         remove_watch,
00680                                         watch_toggled,
00681                                         cs,
group__DBusMacros.html#ga4
NULL
))
00682
goto
nomem;
00683
00684
if
(!
group__DBusServer.html#ga11
dbus_server_set_timeout_functions
(server,
00685                                           add_timeout,
00686                                           remove_timeout,
00687                                           timeout_toggled,
00688                                           cs,
group__DBusMacros.html#ga4
NULL
))
00689
goto
nomem;
00690
00691
return
;
00692
00693  nomem:
00694   g_error (
"Not enough memory to set up DBusServer for use with GLib"
);
00695 }
00696
00708 DBusGConnection*
group__DBusGLib.html#ga16
00709
group__DBusGLib.html#ga16
dbus_g_bus_get
(DBusBusType     type,
00710                 GError        **error)
00711 {
00712
structDBusConnection.html
DBusConnection
*connection;
00713
structDBusError.html
DBusError
derror;
00714
00715   g_return_val_if_fail (error ==
group__DBusMacros.html#ga4
NULL
|| *error ==
group__DBusMacros.html#ga4
NULL
,
group__DBusMacros.html#ga4
NULL
);
00716
00717   dbus_g_value_types_init ();
00718
00719
group__DBusErrors.html#ga0
dbus_error_init
(&derror);
00720
00721   connection =
group__DBusBus.html#ga0
dbus_bus_get
(type, &derror);
00722
if
(connection ==
group__DBusMacros.html#ga4
NULL
)
00723     {
00724
group__DBusGLibInternals.html#ga70
dbus_set_g_error
(error, &derror);
00725
group__DBusErrors.html#ga1
dbus_error_free
(&derror);
00726
return
group__DBusMacros.html#ga4
NULL
;
00727     }
00728
00729
/* does nothing if it's already been done */
00730
group__DBusGLib.html#ga14
dbus_connection_setup_with_g_main
(connection,
group__DBusMacros.html#ga4
NULL
);
00731
00732
return
DBUS_G_CONNECTION_FROM_CONNECTION (connection);
00733 }
00734
/* end of public API */
00736
00737
#ifdef DBUS_BUILD_TESTS
00738
00744 gboolean
00745 _dbus_gmain_test (
const
char
*test_data_dir)
00746 {
00747   GType rectype;
00748   GType gtype;
00749
00750   g_type_init ();
00751   dbus_g_value_types_init ();
00752
00753   rectype = dbus_g_type_get_collection (
"GArray"
, G_TYPE_UINT);
00754   g_assert (rectype != G_TYPE_INVALID);
00755   g_assert (!strcmp (g_type_name (rectype),
"GArray+guint"
));
00756
00757   gtype = dbus_gtype_from_signature (
"au"
,
group__DBusMacros.html#ga2
TRUE
);
00758   g_assert (gtype == rectype);
00759
00760   rectype = dbus_g_type_get_map (
"GHashTable"
, G_TYPE_STRING, G_TYPE_STRING);
00761   g_assert (rectype != G_TYPE_INVALID);
00762   g_assert (!strcmp (g_type_name (rectype),
"GHashTable+gchararray+gchararray"
));
00763
00764   gtype = dbus_gtype_from_signature (
"a{ss}"
,
group__DBusMacros.html#ga2
TRUE
);
00765   g_assert (gtype == rectype);
00766
00767   gtype = dbus_gtype_from_signature (
"o"
,
group__DBusMacros.html#ga3
FALSE
);
00768   g_assert (gtype == DBUS_TYPE_G_OBJECT_PATH);
00769   gtype = dbus_gtype_from_signature (
"o"
,
group__DBusMacros.html#ga2
TRUE
);
00770   g_assert (gtype == DBUS_TYPE_G_OBJECT_PATH);
00771
00772
return
group__DBusMacros.html#ga2
TRUE
;
00773 }
00774
00775
#endif
/* DBUS_BUILD_TESTS */
Generated on Tue Sep 13 01:28:06 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
