static dbus_bool_t bus_driver_handle_acquire_service (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, DBusError *error) { DBusMessage *reply; DBusString service_name; const char *name; dbus_uint32_t service_reply; dbus_uint32_t flags; dbus_bool_t retval; BusRegistry *registry; _DBUS_ASSERT_ERROR_IS_CLEAR (error); registry = bus_connection_get_registry (connection); if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID)) return FALSE; _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags); retval = FALSE; reply = NULL; _dbus_string_init_const (&service_name, name); if (!bus_registry_acquire_service (registry, connection, &service_name, flags, &service_reply, transaction, error)) goto out; reply = dbus_message_new_method_return (message); if (reply == NULL) { BUS_SET_OOM (error); goto out; } if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID)) { BUS_SET_OOM (error); goto out; } if (!bus_transaction_send_from_driver (transaction, connection, reply)) { BUS_SET_OOM (error); goto out; } retval = TRUE; out: if (reply) dbus_message_unref (reply); return retval; }
int main(int argc, const char* argv[]) { DBusConnection* session; #if 0 dbus_uint32_t result; #endif static const DBusObjectPathVTable vtable = { .unregister_function = ping_object_unregistered_cb, .message_function = ping_object_message_handler_cb }; if (argc > 2) { usage(); return 1; } if (argc == 2) { if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { usage(); return 1; } else { s_report = (unsigned)atoi(argv[1]); if (s_report <= 0) { fprintf(stderr, "DPONG: ERROR: invalid reporting period. Quitting!\n"); return 1; } } } g_type_init(); s_server = server_new(); set_base_time(); printf ("DPONG: server starting with PID %u ...\n", (unsigned) getpid()); printf ("DPONG: reporting period is set to %u messages.\n", s_report); printf ("DPONG: base test time set to %ld seconds.\n", base_time); dbus_error_init (&s_error) ; /* Setup main loop */ s_server->context = g_main_context_new(); s_server->loop = g_main_loop_new(s_server->context, FALSE) ; session = dbus_bus_get(DBUS_SERVER_TYPE, &s_error); if (check_dbus_error(&s_error) || NULL == session ) { fatal("DPONG: ERROR: dbus_bus_get() failure.\n"); } dbus_connection_setup_with_g_main (session, s_server->context) ; dbus_bus_request_name (session, SERVICE, DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &s_error); if ( check_dbus_error(&s_error) ) { fatal("DPONG: ERROR: Unable to use service name " SERVICE "."); } #if 0 /* Create registry */ registry = bus_registry_new(BusContext*); if ( !registry ) { fatal("unable to create registry"); } if ( bus_registry_acquire_service(registry, session, SERVICE, 0, &result, transaction, &s_error) ) { fprintf (stderr, "bus_registry_acquire_service --> %u + %u\n", result, s_error); fatal("unable to acquire service"); } #endif if ( !dbus_connection_register_object_path(session, OBJECT, &vtable, NULL) ) { fatal("DPONG: ERROR: dbus_connection_register_object_path() failure."); } fprintf (stderr, "DPONG: server base service is \"%s\".\n", dbus_bus_get_unique_name(session)); fprintf (stderr, "DPONG: server is ready to accept calls!\n"); g_main_loop_run (s_server->loop) ; dbus_connection_close (session); server_delete(s_server); return 0; } /* main */