static void setup (Fixture *f, gconstpointer data) { if (!dbus_threads_init_default ()) g_error ("OOM"); f->loop = _dbus_loop_new (); g_assert (f->loop != NULL); dbus_error_init (&f->e); f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e); assert_no_error (&f->e); g_assert (f->server != NULL); if (!dbus_connection_allocate_data_slot (&connection_slot)) g_error ("OOM"); if (!dbus_server_allocate_data_slot (&server_slot)) g_error ("OOM"); if (!dbus_message_allocate_data_slot (&message_slot)) g_error ("OOM"); if (!dbus_pending_call_allocate_data_slot (&pending_call_slot)) g_error ("OOM"); }
/** * dbus_server_setup_with_g_main: * @server: the server * @context: the #GMainContext or #NULL for default * * Sets the watch and timeout functions of a #DBusServer * to integrate the server with the GLib main loop. * In most cases the context argument should be #NULL. * * If called twice for the same context, does nothing the second * time. If called once with context A and once with context B, * context B replaces context A as the context monitoring the * connection. */ void dbus_server_setup (DBusServer *server, GMainContext *context) { ConnectionSetup *old_setup; ConnectionSetup *cs; do { /* FIXME we never free the slot, so its refcount just keeps growing, * which is kind of broken. */ dbus_server_allocate_data_slot (&server_slot); if (server_slot < 0) break; if (context == NULL) context = g_main_context_default (); cs = NULL; old_setup = dbus_server_get_data (server, server_slot); if (old_setup != NULL) { if (old_setup->context == context) return; /* nothing to do */ cs = connection_setup_new_from_old (context, old_setup); /* Nuke the old setup */ dbus_server_set_data (server, server_slot, NULL, NULL); old_setup = NULL; } if (cs == NULL) cs = connection_setup_new (context, NULL); if (!dbus_server_set_data (server, server_slot, cs, (DBusFreeFunction)connection_setup_free)) break; if (!dbus_server_set_watch_functions (server, add_watch, remove_watch, watch_toggled, cs, NULL)) break; if (!dbus_server_set_timeout_functions (server, add_timeout, remove_timeout, timeout_toggled, cs, NULL)) break; return; } while (0); g_error ("Not enough memory to set up DBusServer for use with GLib"); }
static void setup (Fixture *f, gconstpointer data) { if (!dbus_threads_init_default ()) g_error ("OOM"); f->n_threads = N_THREADS; f->n_refs = N_REFS; // wine sets WINESERVERSOCKET for its child processes automatically if (g_getenv ("WINESERVERSOCKET") != NULL) { /* Our reference-counting is really slow under Wine (it involves * IPC to wineserver). Do fewer iterations: enough to demonstrate * that it works, rather than a performance test. */ f->n_threads = 10; f->n_refs = 10; } f->loop = _dbus_loop_new (); g_assert (f->loop != NULL); dbus_error_init (&f->e); f->server = dbus_server_listen ("tcp:host=127.0.0.1", &f->e); assert_no_error (&f->e); g_assert (f->server != NULL); if (!dbus_connection_allocate_data_slot (&connection_slot)) g_error ("OOM"); if (!dbus_server_allocate_data_slot (&server_slot)) g_error ("OOM"); if (!dbus_message_allocate_data_slot (&message_slot)) g_error ("OOM"); if (!dbus_pending_call_allocate_data_slot (&pending_call_slot)) g_error ("OOM"); }
static BusContext* server_get_context (DBusServer *server) { BusContext *context; BusServerData *bd; if (!dbus_server_allocate_data_slot (&server_data_slot)) return NULL; bd = BUS_SERVER_DATA (server); if (bd == NULL) { dbus_server_free_data_slot (&server_data_slot); return NULL; } context = bd->context; dbus_server_free_data_slot (&server_data_slot); return context; }