void DBusThread::CleanUp() { MOZ_ASSERT(!NS_IsMainThread()); dbus_connection_set_wakeup_main_function(mConnection, nullptr, nullptr, nullptr); dbus_bool_t success = dbus_connection_set_watch_functions(mConnection, nullptr, nullptr, nullptr, nullptr, nullptr); if (success != TRUE) { NS_WARNING("dbus_connection_set_watch_functions failed"); } #ifdef DEBUG LOG("Removing DBus Sockets\n"); #endif if (mControlFdW.get()) { mControlFdW.dispose(); } if (mControlFdR.get()) { mControlFdR.dispose(); } mPollData.Clear(); // DBusWatch pointers are maintained by DBus, so we won't leak by // clearing. mWatchData.Clear(); }
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; }
/** * connection_setup_wakeup_main - Tell dbus about our wakeup_main function * @iface: dbus control interface private data * Returns: 0 on success, -1 on failure * * Register our wakeup_main handler with dbus */ static int connection_setup_wakeup_main(struct ctrl_iface_dbus_priv *iface) { if (eloop_register_signal(SIGPOLL, process_wakeup_main, iface)) return -1; dbus_connection_set_wakeup_main_function(iface->con, wakeup_main, iface, NULL); return 0; }
void DBusThread::EventLoop() { dbus_connection_set_watch_functions(mConnection, AddWatch, RemoveWatch, ToggleWatch, this, NULL); dbus_connection_set_wakeup_main_function(mConnection, DBusWakeup, this, NULL); #ifdef DEBUG LOG("DBus Event Loop Starting\n"); #endif while (1) { poll(mPollData.Elements(), mPollData.Length(), -1); for (uint32_t i = 0; i < mPollData.Length(); i++) { if (!mPollData[i].revents) { continue; } if (mPollData[i].fd == mControlFdR.get()) { char data; while (recv(mControlFdR.get(), &data, sizeof(char), MSG_DONTWAIT) != -1) { switch (data) { case DBUS_EVENT_LOOP_EXIT: #ifdef DEBUG LOG("DBus Event Loop Exiting\n"); #endif dbus_connection_set_watch_functions(mConnection, NULL, NULL, NULL, NULL, NULL); return; case DBUS_EVENT_LOOP_ADD: HandleWatchAdd(this); break; case DBUS_EVENT_LOOP_REMOVE: HandleWatchRemove(this); break; case DBUS_EVENT_LOOP_WAKEUP: // noop break; } } } else { short events = mPollData[i].revents; unsigned int flags = UnixEventsToDBusFlags(events); dbus_watch_handle(mWatchData[i], flags); mPollData[i].revents = 0; // Break at this point since we don't know if the operation // was destructive break; } } while (dbus_connection_dispatch(mConnection) == DBUS_DISPATCH_DATA_REMAINS) {} } }
bool DBusWatcher::SetUp() { MOZ_ASSERT(!NS_IsMainThread()); // If we already have a connection, exit if (mConnection) { return false; } // socketpair opens two sockets for the process to communicate on. // This is how android's implementation of the dbus event loop // communicates with itself in relation to IPC signals. These // sockets are contained sequentially in the same struct in the // android code, but we break them out into class members here. // Therefore we read into a local array and then copy. int sockets[2]; if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockets) < 0) { return false; } mControlFdR.rwget() = sockets[0]; mControlFdW.rwget() = sockets[1]; pollfd* p = mPollData.AppendElement(); p->fd = mControlFdR.get(); p->events = POLLIN; p->revents = 0; // Due to the fact that mPollData and mWatchData have to match, we // push a null to the front of mWatchData since it has the control // fd in the first slot of mPollData. mWatchData.AppendElement(static_cast<DBusWatch*>(nullptr)); // If we can't establish a connection to dbus, nothing else will work nsresult rv = EstablishDBusConnection(); if (NS_FAILED(rv)) { NS_WARNING("Cannot create DBus Connection for DBus Thread!"); return false; } dbus_bool_t success = dbus_connection_set_watch_functions(mConnection, AddWatchFunction, RemoveWatchFunction, ToggleWatchFunction, this, nullptr); NS_ENSURE_TRUE(success == TRUE, false); dbus_connection_set_wakeup_main_function(mConnection, DBusWakeupFunction, this, nullptr); return true; }
static int ldbus_connection_set_wakeup_main_function(lua_State *L) { DBusConnection *connection = check_DBusConnection(L, 1); ldbus_callback_udata *data; luaL_checktype(L, 2, LUA_TFUNCTION); lua_settop(L, 2); if ((data = malloc(sizeof(ldbus_callback_udata))) == NULL) { return luaL_error(L, LDBUS_NO_MEMORY); } data->L = L; data->ref = luaL_ref(L, LUA_REGISTRYINDEX); dbus_connection_set_wakeup_main_function(connection, wakeup_main_function, data, free_data_function); lua_pushboolean(L, 1); return 1; }
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); }
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 ); }
/** * 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; }
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); }
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; }
/** * dbus_connection_setup_with_g_main: * @connection: the connection * @context: the #GMainContext or #NULL for default context * * Sets the watch and timeout functions of a #DBusConnection * to integrate the connection with the GLib main loop. * Pass in #NULL for the #GMainContext unless you're * doing something specialized. * * 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_connection_setup (DBusConnection *connection, 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_connection_allocate_data_slot (&_dbus_gmain_connection_slot); if (_dbus_gmain_connection_slot < 0) break; if (context == NULL) context = g_main_context_default (); cs = NULL; old_setup = dbus_connection_get_data (connection, _dbus_gmain_connection_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_connection_set_data (connection, _dbus_gmain_connection_slot, NULL, NULL); old_setup = NULL; } if (cs == NULL) cs = connection_setup_new (context, connection); if (!dbus_connection_set_data (connection, _dbus_gmain_connection_slot, cs, (DBusFreeFunction)connection_setup_free)) break; if (!dbus_connection_set_watch_functions (connection, add_watch, remove_watch, watch_toggled, cs, NULL)) break; if (!dbus_connection_set_timeout_functions (connection, add_timeout, remove_timeout, timeout_toggled, cs, NULL)) break; dbus_connection_set_wakeup_main_function (connection, wakeup_main, cs, NULL); return; } while (0); g_error ("Not enough memory to set up DBusConnection for use with GLib"); }