static int weston_dbus_bind(struct wl_event_loop *loop, DBusConnection *c, struct wl_event_source **ctx_out) { bool b; int r, fd; /* Idle events cannot reschedule themselves, therefore we use a dummy * event-fd and mark it for post-dispatch. Hence, the dbus * dispatcher is called after every dispatch-round. * This is required as dbus doesn't allow dispatching events from * within its own event sources. */ fd = eventfd(0, EFD_CLOEXEC); if (fd < 0) return -errno; *ctx_out = wl_event_loop_add_fd(loop, fd, 0, weston_dbus_dispatch, c); close(fd); if (!*ctx_out) return -ENOMEM; wl_event_source_check(*ctx_out); b = dbus_connection_set_watch_functions(c, weston_dbus_add_watch, weston_dbus_remove_watch, weston_dbus_toggle_watch, loop, NULL); if (!b) { r = -ENOMEM; goto error; } b = dbus_connection_set_timeout_functions(c, weston_dbus_add_timeout, weston_dbus_remove_timeout, weston_dbus_toggle_timeout, loop, NULL); if (!b) { r = -ENOMEM; goto error; } dbus_connection_ref(c); return 0; error: dbus_connection_set_timeout_functions(c, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_watch_functions(c, NULL, NULL, NULL, NULL, NULL); wl_event_source_remove(*ctx_out); *ctx_out = NULL; return r; }
dbus_bool_t test_connection_setup (DBusLoop *loop, DBusConnection *connection) { CData *cd; cd = NULL; dbus_connection_set_dispatch_status_function (connection, dispatch_status_function, loop, NULL); cd = cdata_new (loop, connection); if (cd == NULL) goto nomem; if (!dbus_connection_set_watch_functions (connection, add_watch, remove_watch, toggle_watch, cd, cdata_free)) goto nomem; cd = cdata_new (loop, connection); if (cd == NULL) goto nomem; if (!dbus_connection_set_timeout_functions (connection, add_timeout, remove_timeout, NULL, cd, cdata_free)) goto nomem; if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE) { if (!_dbus_loop_queue_dispatch (loop, connection)) goto nomem; } return TRUE; nomem: if (cd) cdata_free (cd); dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL); return FALSE; }
static int ldbus_connection_set_timeout_functions(lua_State *L) { ldbus_timeout_udata *data; DBusConnection *connection = check_DBusConnection(L, 1); lua_settop(L, 4); /* Place a table below the 3 callback argument */ lua_createtable(L, 0, 3); lua_insert(L, 2); /* Insert in reverse order */ lua_rawseti(L, 2, DBUS_LUA_FUNC_TOGGLE); lua_rawseti(L, 2, DBUS_LUA_FUNC_REMOVE); lua_rawseti(L, 2, DBUS_LUA_FUNC_ADD); /* make sure ldbus.watch has been loaded */ luaL_requiref(L, "ldbus.timeout", lua_open_ldbus_timeout, FALSE); lua_pop(L, 1); if ((data = malloc(sizeof(ldbus_timeout_udata))) == NULL) return luaL_error(L, LDBUS_NO_MEMORY); data->L = L; data->ref = luaL_ref(L, LUA_REGISTRYINDEX); if (!dbus_connection_set_timeout_functions(connection, ldbus_timeout_add_function, ldbus_timeout_remove_function, ldbus_timeout_toggled_function, (void *)data, ldbus_timeout_free_data_function)) { free(data); return luaL_error(L, LDBUS_NO_MEMORY); }; lua_pushboolean(L, TRUE); return 1; }
void egg_dbus_connect_with_mainloop (DBusConnection *connection, GMainContext *context) { ConnectionSetup *cs; if (context == NULL) context = g_main_context_default (); cs = connection_setup_new (context, connection); the_setup = cs; if (!dbus_connection_set_watch_functions (connection, add_watch, remove_watch, watch_toggled, cs, NULL)) goto nomem; if (!dbus_connection_set_timeout_functions (connection, add_timeout, remove_timeout, timeout_toggled, cs, NULL)) goto nomem; dbus_connection_set_wakeup_main_function (connection, wakeup_main, cs, NULL); return; nomem: g_error ("Not enough memory to set up DBusConnection for use with GLib"); }
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, pa_bool_t use_rtclock, DBusBusType type, DBusError *error) { DBusConnection *conn; pa_dbus_wrap_connection *pconn; char *id; pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER); if (!(conn = dbus_bus_get_private(type, error))) return NULL; pconn = pa_xnew(pa_dbus_wrap_connection, 1); pconn->mainloop = m; pconn->connection = conn; pconn->use_rtclock = use_rtclock; dbus_connection_set_exit_on_disconnect(conn, FALSE); dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL); dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, pconn, NULL); dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, pconn, NULL); dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL); pconn->dispatch_event = pconn->mainloop->defer_new(pconn->mainloop, dispatch_cb, conn); pa_log_debug("Successfully connected to D-Bus %s bus %s as %s", type == DBUS_BUS_SYSTEM ? "system" : (type == DBUS_BUS_SESSION ? "session" : "starter"), pa_strnull((id = dbus_connection_get_server_id(conn))), pa_strnull(dbus_bus_get_unique_name(conn))); dbus_free(id); return pconn; }
/** * integrate_with_eloop - Register our mainloop integration with dbus * @connection: connection to the system message bus * @iface: a dbus control interface data structure * Returns: 0 on success, -1 on failure * * We register our mainloop integration functions with dbus here. */ static int integrate_with_eloop(DBusConnection *connection, struct ctrl_iface_dbus_priv *iface) { if (!dbus_connection_set_watch_functions(connection, add_watch, remove_watch, watch_toggled, iface, NULL)) { perror("dbus_connection_set_watch_functions[dbus]"); wpa_printf(MSG_ERROR, "Not enough memory to set up dbus."); return -1; } if (!dbus_connection_set_timeout_functions(connection, add_timeout, remove_timeout, timeout_toggled, iface, NULL)) { perror("dbus_connection_set_timeout_functions[dbus]"); wpa_printf(MSG_ERROR, "Not enough memory to set up dbus."); return -1; } if (connection_setup_wakeup_main(iface) < 0) { perror("connection_setup_wakeup_main[dbus]"); wpa_printf(MSG_ERROR, "Could not setup main wakeup function."); return -1; } return 0; }
void pcb_dbus_connection_finish_with_mainloop (DBusConnection * connection) { //ConnectionSetup *cs; //cs = dbus_connection_get_data (connection, connection_slot ); // Replace the stored data with NULL, thus freeing the old data // DBus will call the function connection_setup_free() which we registered earlier //dbus_connection_set_data (connection, connection_slot, NULL, NULL ); //dbus_connection_free_data_slot( &connection_slot ); if (!dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL)) { goto nomem; } if (!dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL)) { goto nomem; } dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); return; nomem: fprintf (stderr, "Not enough memory when cleaning up DBusConnection mainloop integration\n"); }
static void weston_dbus_unbind(DBusConnection *c, struct wl_event_source *ctx) { dbus_connection_set_timeout_functions(c, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_watch_functions(c, NULL, NULL, NULL, NULL, NULL); dbus_connection_unref(c); wl_event_source_remove(ctx); }
void pcmk_dbus_connection_setup_with_select(DBusConnection *c){ dbus_connection_set_exit_on_disconnect (c, FALSE); dbus_connection_set_timeout_functions( c, pcmk_dbus_timeout_add, pcmk_dbus_timeout_remove, pcmk_dbus_timeout_toggle, NULL, NULL); dbus_connection_set_watch_functions(c, pcmk_dbus_watch_add, pcmk_dbus_watch_remove, pcmk_dbus_watch_toggle, NULL, NULL); dbus_connection_set_dispatch_status_function(c, pcmk_dbus_connection_dispatch, NULL, NULL); pcmk_dbus_connection_dispatch(c, dbus_connection_get_dispatch_status(c), NULL); }
/* * Initialization. Works as follows: * * we have a DBusConnection* (say, obtained with dbus_bus_get) * we call dbus_connection_set_watch_functions * libdbus calls back add_watch(watch:0x2341090, data), this watch is for writing * we call toggled_watch, but it finds that watch is not to be enabled yet * libdbus calls back add_watch(watch:0x23410e0, data), this watch is for reading * we call toggled_watch, it adds watch's fd to glib main loop with POLLIN * (note: these watches are different objects, but they have the same fd) * we call dbus_connection_set_timeout_functions * we call dbus_connection_register_object_path * * Note: if user will later call dbus_bus_request_name(conn, ...): * libdbus calls back add_timeout() * libdbus calls back remove_timeout() * note - no callback to timeout_toggled()! * (therefore there is no code yet in timeout_toggled (see above), it's not used) */ void attach_dbus_conn_to_glib_main_loop(DBusConnection* conn, const char* object_path, DBusHandlerResult (*message_received_func)(DBusConnection *conn, DBusMessage *msg, void* data) ) { if (g_dbus_conn) error_msg_and_die("Internal bug: can't connect to more than one dbus"); g_dbus_conn = conn; //do we need this? why? //log("dbus_connection_set_dispatch_status_function"); // dbus_connection_set_dispatch_status_function(conn, // dispatch, /* void dispatch(DBusConnection *conn, DBusDispatchStatus new_status, void* data) */ // NULL, /* data */ // NULL /* free_data_function */ // ) log_debug("dbus_connection_set_watch_functions"); if (!dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggled_watch, NULL, /* data */ NULL /* free_data_function */ ) ) { die_out_of_memory(); } log_debug("dbus_connection_set_timeout_functions"); if (!dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, timeout_toggled, NULL, /* data */ NULL /* free_data_function */ ) ) { die_out_of_memory(); } if (object_path && message_received_func) { /* Table */ const DBusObjectPathVTable vtable = { /* .unregister_function = */ unregister_vtable, /* .message_function = */ message_received_func, }; log_debug("dbus_connection_register_object_path"); if (!dbus_connection_register_object_path(conn, object_path, &vtable, NULL /* data */ ) ) { die_out_of_memory(); } } }
void pcb_dbus_connection_finish_with_mainloop( DBusConnection *connection ) { if ( dbus_connection_set_watch_functions( &connection, 0, 0, 0, 0, 0 ) && dbus_connection_set_timeout_functions( &connection, 0, 0, 0, 0, 0 ) ) { dbus_connection_set_dispatch_status_function( &connection, 0, 0, 0 ); return; } __fprintf_chk( stderr, 1, "Not enough memory when cleaning up DBusConnection mainloop integration\n" ); return; }
static inline void setup_dbus_with_main_loop(DBusConnection *conn) { dbus_connection_set_watch_functions(conn, add_watch, remove_watch, watch_toggled, conn, NULL); dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, timeout_toggled, NULL, NULL); dbus_connection_set_dispatch_status_function(conn, dispatch_status, NULL, NULL); }
static void wpas_dbus_deinit_common(struct wpas_dbus_priv *priv) { if (priv->con) { eloop_cancel_timeout(dispatch_initial_dbus_messages, priv->con, NULL); dbus_connection_set_watch_functions(priv->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions(priv->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_unref(priv->con); } os_free(priv); }
void EdbusConnection::setup_listener_with_fltk(void) { if(!dc || !dc->conn) return; setup_filter(); /* allocate our watch list */ dc->watch_list = new WatchList; dbus_connection_set_watch_functions(dc->conn, edbus_add_watch, edbus_remove_watch, edbus_toggle_watch, dc, 0); dbus_connection_set_timeout_functions(dc->conn, edbus_add_timeout, edbus_remove_timeout, edbus_toggle_timeout, dc, 0); dbus_connection_set_wakeup_main_function(dc->conn, edbus_wakeup_main, 0, 0); }
/** * Sets the watch and timeout functions of a #DBusConnection * to integrate the connection with the GUI HID's main loop. * * @param connection the connection */ void pcb_dbus_connection_setup_with_mainloop (DBusConnection * connection) { //ConnectionSetup *cs; hidval temp; /* FIXME we never free the slot, so its refcount just keeps growing, * which is kind of broken. */ //dbus_connection_allocate_data_slot (&connection_slot); //if (connection_slot < 0) // goto nomem; #if 0 cs = connection_setup_new (connection); if (!dbus_connection_set_data (connection, connection_slot, cs, (DBusFreeFunction) connection_setup_free)) { goto nomem; } #endif if (!dbus_connection_set_watch_functions (connection, watch_add, watch_remove, watch_toggled, NULL, NULL)) // cs, NULL)) { goto nomem; } if (!dbus_connection_set_timeout_functions (connection, timeout_add, timeout_remove, timeout_toggled, NULL, NULL)) // cs, NULL)) { goto nomem; } dbus_connection_set_dispatch_status_function (connection, dispatch_status_changed, NULL, NULL); // cs, NULL); /* Register a new mainloop hook to mop up any unfinished IO. */ temp.ptr = (void *)connection; gui->add_block_hook (block_hook_cb, temp); return; nomem: fprintf (stderr, "Not enough memory to set up DBusConnection for use with PCB\n"); }
/** * wpa_supplicant_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface * @iface: Pointer to dbus private data from * wpa_supplicant_dbus_ctrl_iface_init() * * Deinitialize the dbus control interface that was initialized with * wpa_supplicant_dbus_ctrl_iface_init(). */ void wpa_supplicant_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_priv *iface) { if (iface == NULL) return; if (iface->con) { dbus_connection_set_watch_functions(iface->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions(iface->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_close(iface->con); } memset(iface, 0, sizeof(struct ctrl_iface_dbus_priv)); free(iface); }
void connline_plugin_cleanup_event_loop(DBusConnection *dbus_cnx) { if (triggers_table != NULL) eina_hash_free(triggers_table); triggers_table = NULL; if (dbus_cnx == NULL) return; dbus_connection_set_watch_functions(dbus_cnx, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions(dbus_cnx, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_dispatch_status_function(dbus_cnx, NULL, NULL, NULL); }
int bus_loop_open(DBusConnection *c) { int fd; assert(c); fd = epoll_create1(EPOLL_CLOEXEC); if (fd < 0) return -errno; if (!dbus_connection_set_watch_functions(c, add_watch, remove_watch, toggle_watch, INT_TO_PTR(fd), NULL) || !dbus_connection_set_timeout_functions(c, add_timeout, remove_timeout, toggle_timeout, INT_TO_PTR(fd), NULL)) { close_nointr_nofail(fd); return -ENOMEM; } return fd; }
/** * wpa_supplicant_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface * @iface: Pointer to dbus private data from * wpa_supplicant_dbus_ctrl_iface_init() * * Deinitialize the dbus control interface that was initialized with * wpa_supplicant_dbus_ctrl_iface_init(). */ void wpa_supplicant_dbus_ctrl_iface_deinit(struct ctrl_iface_dbus_priv *iface) { if (iface == NULL) return; if (iface->con) { eloop_cancel_timeout(dispatch_initial_dbus_messages, iface->con, NULL); dbus_connection_set_watch_functions(iface->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions(iface->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_unref(iface->con); } memset(iface, 0, sizeof(struct ctrl_iface_dbus_priv)); free(iface); }
static void wpas_dbus_deinit_common(struct wpas_dbus_priv *priv) { if (priv->con) { eloop_cancel_timeout(dispatch_initial_dbus_messages, priv->con, NULL); eloop_cancel_timeout(process_timeout, priv, ELOOP_ALL_CTX); dbus_connection_set_watch_functions(priv->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions(priv->con, NULL, NULL, NULL, NULL, NULL); dbus_connection_remove_filter(priv->con, disconnect_filter, priv); dbus_connection_unref(priv->con); } os_free(priv); }
Integrator::Integrator( DBusConnection *conn, QObject *parent ) : QObject( parent ), m_connection( conn ) { m_timeouts.setAutoDelete( true ); dbus_connection_set_watch_functions( m_connection, dbusAddWatch, dbusRemoveWatch, dbusToggleWatch, this, 0 ); dbus_connection_set_timeout_functions( m_connection, dbusAddTimeout, dbusRemoveTimeout, dbusToggleTimeout, this, 0 ); dbus_connection_set_wakeup_main_function( m_connection, dbusWakeupMain, this, 0 ); }
void test_connection_shutdown (DBusLoop *loop, DBusConnection *connection) { if (!dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL)) _dbus_assert_not_reached ("setting watch functions to NULL failed"); if (!dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL)) _dbus_assert_not_reached ("setting timeout functions to NULL failed"); dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); }
/** * integrate_with_eloop - Register our mainloop integration with dbus * @connection: connection to the system message bus * @priv: a dbus control interface data structure * Returns: 0 on success, -1 on failure */ static int integrate_with_eloop(struct wpas_dbus_priv *priv) { if (!dbus_connection_set_watch_functions(priv->con, add_watch, remove_watch, watch_toggled, priv, NULL) || !dbus_connection_set_timeout_functions(priv->con, add_timeout, remove_timeout, timeout_toggled, priv, NULL)) { wpa_printf(MSG_ERROR, "dbus: Failed to set callback functions"); return -1; } if (eloop_register_signal(SIGPOLL, process_wakeup_main, priv)) return -1; dbus_connection_set_wakeup_main_function(priv->con, wakeup_main, priv, NULL); return 0; }
int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) { ConnectionData *d = NULL; assert(c); assert(poll_api); if (!(d = avahi_new(ConnectionData, 1))) goto fail;; d->poll_api = poll_api; d->connection = c; d->ref = 1; if (!(d->dispatch_timeout = poll_api->timeout_new(poll_api, NULL, dispatch_timeout_callback, d))) goto fail; if (!(dbus_connection_set_watch_functions(c, add_watch, remove_watch, watch_toggled, connection_data_ref(d), (DBusFreeFunction)connection_data_unref))) goto fail; if (!(dbus_connection_set_timeout_functions(c, add_timeout, remove_timeout, timeout_toggled, connection_data_ref(d), (DBusFreeFunction)connection_data_unref))) goto fail; dbus_connection_set_dispatch_status_function(c, dispatch_status, connection_data_ref(d), (DBusFreeFunction)connection_data_unref); if (dbus_connection_get_dispatch_status(c) == DBUS_DISPATCH_DATA_REMAINS) request_dispatch(d, 1); connection_data_unref(d); return 0; fail: if (d) { d->poll_api->timeout_free(d->dispatch_timeout); avahi_free(d); } return -1; }
void dbus_a_cleanup_connection(DBusConnection* connection) { struct ConnectionData* c; kprintf("CleanupAmigaConnection\n"); kprintf("Slot X: %ld\n", Slot); c = dbus_connection_get_data(connection, Slot); if (c != NULL) { dbus_connection_set_data(connection, Slot, NULL, NULL); dbus_connection_free_data_slot(&Slot); kprintf("Slot Y: %ld\n", Slot); } dbus_connection_set_dispatch_status_function(connection, NULL, NULL, NULL); dbus_connection_set_wakeup_main_function(connection, NULL, NULL, NULL); dbus_connection_set_watch_functions(connection, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions(connection, NULL, NULL, NULL, NULL, NULL); kprintf("Slot X: %ld\n", Slot); }
Bool asdbus_init () { /* return connection unix fd */ char *tmp; #ifdef ASDBUS_DISPATCH if (!ASDBus.dispatches) ASDBus.dispatches = create_asbidirlist(asdbus_dispatch_destroy); #endif if (!ASDBus.session_conn) { ASDBus.session_conn = _asdbus_get_session_connection(); if (!dbus_connection_set_watch_functions(ASDBus.session_conn, add_watch, remove_watch, toggle_watch, ASDBus.session_conn, NULL)) { show_error("dbus_connection_set_watch_functions() failed"); } _asdbus_add_match (ASDBus.session_conn, SESSIONMANAGER_INTERFACE, NULL); //_asdbus_add_match (ASDBus.session_conn, IFACE_SESSION_PRIVATE, "QueryEndSession"); //_asdbus_add_match (ASDBus.session_conn, IFACE_SESSION_PRIVATE, "EndSession"); //_asdbus_add_match (ASDBus.session_conn, IFACE_SESSION_PRIVATE, "Stop"); dbus_connection_set_timeout_functions(ASDBus.session_conn, add_timeout, remove_timeout, toggle_timeout, NULL, NULL); #ifdef ASDBUS_DISPATCH dbus_connection_set_dispatch_status_function(ASDBus.session_conn, queue_dispatch, NULL, NULL); queue_dispatch(ASDBus.session_conn, dbus_connection_get_dispatch_status(ASDBus.session_conn), NULL); #endif } if (!ASDBus.system_conn){ ASDBus.system_conn = _asdbus_get_system_connection(); /*if (!dbus_connection_set_watch_functions(ASDBus.system_conn, add_watch, remove_watch, toggle_watch, ASDBus.system_conn, NULL)) { show_error("dbus_connection_set_watch_functions() failed"); }*/ } /*if (ASDBus.session_conn && ASDBus.watchFds == NULL){ //dbus_connection_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd)); //dbus_whatch_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd)); }*/ if ((tmp = getenv ("KDE_SESSION_VERSION")) != NULL) ASDBus.kdeSessionVersion = atoi(tmp); return (ASDBus.session_conn != NULL); }
static dbus_bool_t setup_dbus_in_efl_mainloop(DBusConnection *dbus_cnx) { DBusDispatchStatus status; if (dbus_connection_set_watch_functions(dbus_cnx, efl_dbus_watch_add, efl_dbus_watch_remove, efl_dbus_watch_toggled, dbus_cnx, NULL) == FALSE) return FALSE; if (dbus_connection_set_timeout_functions(dbus_cnx, efl_dbus_timeout_add, efl_dbus_timeout_remove, efl_dbus_timeout_toggled, dbus_cnx, NULL) == FALSE) return FALSE; dbus_connection_set_dispatch_status_function(dbus_cnx, efl_dbus_dispatch_status, dbus_cnx, NULL); status = dbus_connection_get_dispatch_status(dbus_cnx); if (status == DBUS_DISPATCH_DATA_REMAINS) ecore_timer_add(0, efl_dispatch_dbus, dbus_cnx); return TRUE; }
dbus_bool_t dbus_a_setup_connection(DBusConnection* connection) { struct ConnectionData* c; c = CreateConnectionData(connection); if (c != NULL) { dbus_connection_set_watch_functions(connection, AddWatchFunction, RemoveWatchFunction, WatchToggledFunction, c, NULL); dbus_connection_set_timeout_functions(connection, AddTimeoutFunction, RemoveTimeoutFunction, TimeoutToggledFunction, c, NULL); dbus_connection_set_dispatch_status_function(connection, DispatchStatusFunction, c, NULL); dbus_connection_set_wakeup_main_function(connection, WakeupMainFunction, c, NULL); kprintf("Slot A: %ld\n", Slot); if (dbus_connection_allocate_data_slot(&Slot)) { kprintf("Slot B: %ld\n", Slot); if (dbus_connection_set_data(connection, Slot, c, DeleteConnectionData)) { kprintf("Slot C: %ld\n", Slot); return TRUE; } } } DeleteConnectionData(c); return FALSE; }
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing( pa_mainloop_api *m, pa_bool_t use_rtclock, DBusConnection *conn) { pa_dbus_wrap_connection *pconn; pa_assert(m); pa_assert(conn); pconn = pa_xnew(pa_dbus_wrap_connection, 1); pconn->mainloop = m; pconn->connection = dbus_connection_ref(conn); pconn->use_rtclock = use_rtclock; dbus_connection_set_exit_on_disconnect(conn, FALSE); dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL); dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, pconn, NULL); dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, pconn, NULL); dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL); pconn->dispatch_event = pconn->mainloop->defer_new(pconn->mainloop, dispatch_cb, conn); return pconn; }
/** * Initialize D-Bus connection. */ bool cdbus_init(session_t *ps) { DBusError err = { }; // Initialize dbus_error_init(&err); // Connect to D-Bus // Use dbus_bus_get_private() so we can fully recycle it ourselves ps->dbus_conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); if (dbus_error_is_set(&err)) { printf_errf("(): D-Bus connection failed (%s).", err.message); dbus_error_free(&err); return false; } if (!ps->dbus_conn) { printf_errf("(): D-Bus connection failed for unknown reason."); return false; } // Avoid exiting on disconnect dbus_connection_set_exit_on_disconnect(ps->dbus_conn, false); // Request service name { // Get display name char *display = DisplayString(ps->dpy); if (!display) display = "unknown"; display = mstrcpy(display); // Convert all special characters in display name to underscore { char *pdisp = display; while (*pdisp) { if (!isalnum(*pdisp)) *pdisp = '_'; ++pdisp; } } // Build service name char *service = mstrjoin3(CDBUS_SERVICE_NAME, ".", display); ps->dbus_service = service; free(display); display = NULL; // Request for the name int ret = dbus_bus_request_name(ps->dbus_conn, service, DBUS_NAME_FLAG_DO_NOT_QUEUE, &err); if (dbus_error_is_set(&err)) { printf_errf("(): Failed to obtain D-Bus name (%s).", err.message); dbus_error_free(&err); } if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret && DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER != ret) { printf_errf("(): Failed to become the primary owner of requested " "D-Bus name (%d).", ret); } } // Add watch handlers if (!dbus_connection_set_watch_functions(ps->dbus_conn, cdbus_callback_add_watch, cdbus_callback_remove_watch, cdbus_callback_watch_toggled, ps, NULL)) { printf_errf("(): Failed to add D-Bus watch functions."); return false; } // Add timeout handlers if (!dbus_connection_set_timeout_functions(ps->dbus_conn, cdbus_callback_add_timeout, cdbus_callback_remove_timeout, cdbus_callback_timeout_toggled, ps, NULL)) { printf_errf("(): Failed to add D-Bus timeout functions."); return false; } // Add match dbus_bus_add_match(ps->dbus_conn, "type='method_call',interface='" CDBUS_INTERFACE_NAME "'", &err); if (dbus_error_is_set(&err)) { printf_errf("(): Failed to add D-Bus match."); dbus_error_free(&err); return false; } return true; }