static void connection_created_cb (GObject *source_object, GAsyncResult *result, MainData *data) { guint i; GError *error = NULL; /* Finish connecting to D-Bus. */ data->connection = g_dbus_connection_new_finish (result, &error); if (error != NULL) { g_printerr (_("Error connecting to D-Bus using address ‘%s’: %s"), data->dbus_address, error->message); g_printerr ("\n"); g_error_free (error); data->exit_status = STATUS_DBUS_ERROR; g_main_loop_quit (data->main_loop); return; } /* Connect to closed notifications, so we know if the bus disappears. */ g_signal_connect (data->connection, "closed", (GCallback) connection_closed_cb, data); /* Hold an outstanding callback while we loop over the objects, so that we don't spawn the program under test before we've finished * registering all the objects (e.g. if their callbacks are called very quickly). */ data->outstanding_registration_callbacks++; /* Register our DfsmObjects on the bus. */ for (i = 0; i < data->simulated_objects->len; i++) { DfsmObject *simulated_object; simulated_object = g_ptr_array_index (data->simulated_objects, i); /* Register the object. We keep a count of all the outstanding callbacks and only spawn the program under test once all are complete. */ data->outstanding_registration_callbacks++; g_signal_connect (simulated_object, "notify::dbus-activity-count", (GCallback) simulated_object_dbus_activity_count_notify_cb, data); dfsm_object_register_on_bus (simulated_object, data->connection, (GAsyncReadyCallback) object_registered_cb, data); } /* Release our outstanding callback and spawn the test program if it hasn't been spawned already. */ data->outstanding_registration_callbacks--; if (data->outstanding_registration_callbacks == 0) { start_simulation (data); } }
static void on_peer_acquired (GObject *source, GAsyncResult *result, gpointer user_data) { GDBusConnection *connection; GError *error = NULL; connection = g_dbus_connection_new_finish (result, &error); if (error != NULL) { g_warning ("Couldn't connect to peer: %s", error->message); g_main_loop_quit (loop); g_error_free (error); } else { g_debug ("connected to peer"); start_daemon (connection); } }