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; }
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) {} } }
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; }
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"); }
static DBusConnection *virDBusBusInit(DBusBusType type, DBusError *dbuserr) { DBusConnection *bus; /* Allocate and initialize a new HAL context */ dbus_connection_set_change_sigpipe(FALSE); dbus_threads_init_default(); dbus_error_init(dbuserr); bus = sharedBus ? dbus_bus_get(type, dbuserr) : dbus_bus_get_private(type, dbuserr); if (!bus) return NULL; dbus_connection_set_exit_on_disconnect(bus, FALSE); /* Register dbus watch callbacks */ if (!dbus_connection_set_watch_functions(bus, virDBusAddWatch, virDBusRemoveWatch, virDBusToggleWatch, bus, NULL)) { return NULL; } return bus; }
bool DBusThread::Init() { if (pipe(m_wakeup_pipe) == -1) { // Just to be sure m_wakeup_pipe[0] = -1; m_wakeup_pipe[1] = -1; return false; } if (Create() != wxTHREAD_NO_ERROR) return false; int res; do { res = fcntl(m_wakeup_pipe[0], F_SETFL, O_NONBLOCK); } while( res == -1 && errno == EINTR ); m_parent_id = pthread_self(); dbus_connection_set_watch_functions(m_connection, add_watch, remove_watch, toggle_watch, (void *)this, NULL); Run(); return true; }
/** * 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 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(); }
/* returns NULL or error message, may fail silently if dbus daemon not yet up. */ char *dbus_init(void) { DBusConnection *connection = NULL; DBusObjectPathVTable dnsmasq_vtable = {NULL, &message_handler, NULL, NULL, NULL, NULL }; DBusError dbus_error; DBusMessage *message; dbus_error_init (&dbus_error); if (!(connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error))) return NULL; dbus_connection_set_exit_on_disconnect(connection, FALSE); dbus_connection_set_watch_functions(connection, add_watch, remove_watch, NULL, NULL, NULL); dbus_error_init (&dbus_error); dbus_bus_request_name (connection, daemon->dbus_name, 0, &dbus_error); if (dbus_error_is_set (&dbus_error)) return (char *)dbus_error.message; if (!dbus_connection_register_object_path(connection, DNSMASQ_PATH, &dnsmasq_vtable, NULL)) return _("could not register a DBus message handler"); daemon->dbus = connection; if ((message = dbus_message_new_signal(DNSMASQ_PATH, daemon->dbus_name, "Up"))) { dbus_connection_send(connection, message, NULL); dbus_message_unref(message); } return NULL; }
static int ldbus_connection_set_watch_functions(lua_State *L) { ldbus_watch_udata *data; DBusConnection *connection = check_DBusConnection(L, 1); int has_toggle = lua_isnil(L, 4); 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.watch", luaopen_ldbus_watch, FALSE); lua_pop(L, 1); if ((data = malloc(sizeof(ldbus_watch_udata))) == NULL) return luaL_error(L, LDBUS_NO_MEMORY); data->L = L; data->ref = luaL_ref(L, LUA_REGISTRYINDEX); if (!dbus_connection_set_watch_functions(connection, ldbus_watch_add_function, ldbus_watch_remove_function, has_toggle ? NULL : ldbus_watch_toggled_function, (void *)data, ldbus_watch_free_data_function)) { free(data); return luaL_error(L, LDBUS_NO_MEMORY); }; lua_pushboolean(L, TRUE); return 1; }
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"); }
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; }
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); }
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); }
/* * 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); }
void pcb_dbus_connection_setup_with_mainloop( DBusConnection *connection ) { if ( dbus_connection_set_watch_functions( &connection, &watch_add, &watch_remove, &watch_toggled, 0, 0 ) && dbus_connection_set_timeout_functions( &connection, &timeout_add, &timeout_remove, &timeout_toggled, 0, 0 ) ) { dbus_connection_set_dispatch_status_function( &connection, &dispatch_status_changed, 0, 0 ); gui->add_block_hook( ebp_12, block_hook_cb, connection ); return; } __fprintf_chk( stderr, 1, "Not enough memory to set up DBusConnection for use with PCB\n" ); return; }
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; }
void Run() { MOZ_ASSERT(!NS_IsMainThread()); dbus_bool_t success = dbus_connection_set_watch_functions(mConnection->GetConnection(), DBusWatcher::AddWatchFunction, DBusWatcher::RemoveWatchFunction, DBusWatcher::ToggleWatchFunction, mConnection, nullptr); NS_ENSURE_TRUE_VOID(success == TRUE); }
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"); }
DBusThread::DBusThread(wxThreadKind kind, wxDBusConnection * parent, int ID, DBusConnection * connection): wxThread(kind) { m_ID = ID; m_connection = connection; m_parent = parent; m_exit = false; m_thread_holds_lock = false; pipe(m_wakeup_pipe); fcntl(m_wakeup_pipe[0], F_SETFL, O_NONBLOCK); m_parent_id = pthread_self(); dbus_connection_set_watch_functions(m_connection, add_watch, remove_watch, toggle_watch, (void *)this, NULL); }
/** * 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; }
JoyDBus * joy_dbus_new(JoyApplication *app, const gchar *address, GError **error) { joy_return_error_if_fail(JOY_IS_APPLICATION(app), NULL, error); joy_return_error_if_fail(address, NULL, error); DBusError dbus_error; dbus_error_init(&dbus_error); DBusConnection *connection = dbus_connection_open_private(address, &dbus_error); if (!connection) { g_set_error(error, JOY_ERROR, JOY_ERROR_DBUS, "%s", dbus_error.message); goto error; } if (!dbus_bus_register(connection, &dbus_error)) { g_set_error(error, JOY_ERROR, JOY_ERROR_DBUS, "%s", dbus_error.message); goto error; } JoyDBus *self = g_object_new(JOY_TYPE_DBUS, "application", app, "connection", connection, NULL); if (!self) { g_set_error_literal(error, JOY_ERROR, JOY_ERROR_NO_MEMORY, Q_("out of memory")); goto error; } if (!dbus_connection_set_watch_functions(connection, add, remove, toggled, self, NULL)) { g_set_error_literal(error, JOY_ERROR, JOY_ERROR_NO_MEMORY, Q_("out of memory")); goto error; } return self; error: dbus_error_free(&dbus_error); if (connection) { if (dbus_connection_get_is_connected(connection)) { dbus_connection_close(connection); } dbus_connection_unref(connection); } return NULL; }
/** * 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); }