static void server_setup(context_t *c) { c->dbus = mrp_dbus_connect(c->ml, c->busaddr, NULL); if (c->dbus == NULL) { mrp_log_error("Failed to create D-BUS connection to '%s' bus.", c->busaddr); exit(1); } c->name = mrp_dbus_get_unique_name(c->dbus); mrp_log_info("Our address is %s on the bus...", c->name ? c->name : "unknown"); if (!mrp_dbus_acquire_name(c->dbus, SERVER_NAME, NULL)) { mrp_log_error("Failed to acquire D-BUS name '%s' on bus '%s'.", SERVER_NAME, c->busaddr); exit(1); } if (!mrp_dbus_export_method(c->dbus, SERVER_PATH, SERVER_INTERFACE, PING, ping_handler, c)) { mrp_log_error("Failed to export D-BUS method '%s'.", PING); exit(1); } }
static int dbusif_setup(dbusif_t *bus) { srs_context_t *srs = bus->self->srs; const char *path, *iface, *method; int (*cb)(mrp_dbus_t *, mrp_dbus_msg_t *, void *); mrp_debug("setting up client D-BUS interface (%s)", bus->address); bus->dbus = mrp_dbus_get(srs->ml, bus->address, NULL); if (bus->dbus != NULL) { path = SRS_CLIENT_PATH; iface = SRS_CLIENT_INTERFACE; method = SRS_CLIENT_REGISTER; cb = register_req; if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) { mrp_log_error("Failed to register D-BUS '%s' method.", method); goto fail; } method = SRS_CLIENT_UNREGISTER; cb = unregister_req; if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) { mrp_log_error("Failed to register D-BUS '%s' method.", method); goto fail; } method = SRS_CLIENT_REQUEST_FOCUS; cb = focus_req; if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) { mrp_log_error("Failed to register D-BUS '%s' method.", method); goto fail; } method = SRS_CLIENT_RENDER_VOICE; cb = render_voice_req; if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) { mrp_log_error("Failed to register D-BUS '%s' method.", method); goto fail; } method = SRS_CLIENT_CANCEL_VOICE; cb = cancel_voice_req; if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) { mrp_log_error("Failed to register D-BUS '%s' method.", method); goto fail; } method = SRS_CLIENT_QUERY_VOICES; cb = query_voices_req; if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) { mrp_log_error("Failed to register D-BUS '%s' method.", method); goto fail; } if (!mrp_dbus_acquire_name(bus->dbus, SRS_CLIENT_SERVICE, NULL)) { mrp_log_error("Failed to acquire D-BUS name '%s'.", SRS_CLIENT_SERVICE); goto fail; } } else { mrp_log_error("Failed to connect to D-BUS (%s).", bus->address); goto fail; } return TRUE; fail: dbusif_cleanup(bus); return FALSE; }