int supplicant_stop(struct connman_device *device) { int index = connman_device_get_index(device); struct supplicant_task *task; _DBG_SUPPLICANT("device %p", device); task = find_task_by_index(index); if (task == NULL) return -ENODEV; g_free(task->range); task_list = g_slist_remove(task_list, task); if (task->scan_call != NULL) { dbus_pending_call_cancel(task->scan_call); task->scan_call = NULL; } if (task->result_call != NULL) { dbus_pending_call_cancel(task->result_call); task->result_call = NULL; } if (task->scanning == TRUE) connman_device_set_scanning(task->device, FALSE); remove_network(task); disconnect_network(task); return remove_interface(task); }
void g_dbus_client_unref(GDBusClient *client) { unsigned int i; if (client == NULL) return; if (__sync_sub_and_fetch(&client->ref_count, 1) > 0) return; if (client->pending_call != NULL) { dbus_pending_call_cancel(client->pending_call); dbus_pending_call_unref(client->pending_call); } if (client->get_objects_call != NULL) { dbus_pending_call_cancel(client->get_objects_call); dbus_pending_call_unref(client->get_objects_call); } for (i = 0; i < client->match_rules->len; i++) { modify_match(client->dbus_conn, "RemoveMatch", g_ptr_array_index(client->match_rules, i)); } g_ptr_array_free(client->match_rules, TRUE); dbus_connection_remove_filter(client->dbus_conn, message_filter, client); g_list_free_full(client->proxy_list, proxy_free); /* * Don't call disconn_func twice if disconnection * was previously reported. */ if (client->disconn_func && client->connected) client->disconn_func(client->dbus_conn, client->disconn_data); g_dbus_remove_watch(client->dbus_conn, client->watch); g_dbus_remove_watch(client->dbus_conn, client->added_watch); g_dbus_remove_watch(client->dbus_conn, client->removed_watch); dbus_connection_unref(client->dbus_conn); g_free(client->service_name); g_free(client->base_path); g_free(client->root_path); g_free(client); }
static void finalize_call(DBusPendingCall *call) { if (!dbus_pending_call_get_completed(call)) dbus_pending_call_cancel(call); dbus_pending_call_unref(call); }
static gboolean operation_unref (gpointer data) { GkrOperation *op = data; g_assert (op); if (!g_atomic_int_dec_and_test (&op->refs)) return FALSE; if (op->pending) { dbus_pending_call_cancel (op->pending); dbus_pending_call_unref (op->pending); op->pending = NULL; } operation_clear_callbacks (op); if (op->conn) { dbus_connection_unref (op->conn); op->conn = NULL; } g_slice_free (GkrOperation, op); return TRUE; }
void services_action_cleanup(svc_action_t * op) { #if SUPPORT_DBUS if(op->opaque == NULL) { return; } if(op->opaque->timerid != 0) { crm_trace("Removing timer for call %s to %s", op->action, op->rsc); g_source_remove(op->opaque->timerid); op->opaque->timerid = 0; } if(op->opaque->pending) { crm_trace("Cleaning up pending dbus call %p %s for %s", op->opaque->pending, op->action, op->rsc); if(dbus_pending_call_get_completed(op->opaque->pending)) { crm_warn("Pending dbus call %s for %s did not complete", op->action, op->rsc); } dbus_pending_call_cancel(op->opaque->pending); dbus_pending_call_unref(op->opaque->pending); op->opaque->pending = NULL; } if (op->opaque->stderr_gsource) { mainloop_del_fd(op->opaque->stderr_gsource); op->opaque->stderr_gsource = NULL; } if (op->opaque->stdout_gsource) { mainloop_del_fd(op->opaque->stdout_gsource); op->opaque->stdout_gsource = NULL; } #endif }
/** * @brief Send a DBus message with callbacks * @param conn The DBus connection * @param msg The message to send * @param cb_return A callback function for returns (only used if @a msg is a method-call) * @param timeout A timeout in milliseconds, after which a synthetic error will be generated * @param data custom data to pass in to the callback * @return a DBusPendingCall that can be used to cancel the current call */ EAPI DBusPendingCall * e_dbus_message_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data) { DBusPendingCall *pending; if (!dbus_connection_send_with_reply(conn->conn, msg, &pending, timeout)) return NULL; if (cb_return && pending) { E_DBus_Pending_Call_Data *pdata; pdata = malloc(sizeof(E_DBus_Pending_Call_Data)); pdata->cb_return = cb_return; pdata->data = data; if (!dbus_pending_call_set_notify(pending, cb_pending, pdata, free)) { free(pdata); dbus_message_unref(msg); dbus_pending_call_cancel(pending); return NULL; } } return pending; }
static void send_cancel_request(struct pending_agent_request *req) { DBusMessage *message; char address[18], *ptr = address; message = dbus_message_new_method_call(req->agent->name, req->agent->path, "org.bluez.PasskeyAgent", "Cancel"); if (message == NULL) { error("Couldn't allocate D-Bus message"); return; } ba2str(&req->bda, address); dbus_message_append_args(message, DBUS_TYPE_STRING, &req->path, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID); dbus_message_set_no_reply(message, TRUE); send_message_and_unref(req->agent->conn, message); debug("PasskeyAgent.Request(%s, %s) was canceled", req->path, address); dbus_pending_call_cancel(req->call); dbus_pending_call_unref(req->call); g_free(req->pin); g_free(req->path); g_free(req); }
static int request_fallback(struct agent_request *req, DBusPendingCallNotifyFunction function) { struct btd_adapter *adapter = req->agent->adapter; struct agent *adapter_agent = adapter_get_agent(adapter); DBusMessage *msg; if (req->agent == adapter_agent || adapter_agent == NULL) return -EINVAL; dbus_pending_call_cancel(req->call); msg = dbus_message_copy(req->msg); dbus_message_set_destination(msg, adapter_agent->name); dbus_message_set_path(msg, adapter_agent->path); if (dbus_connection_send_with_reply(connection, msg, &req->call, REQUEST_TIMEOUT) == FALSE) { error("D-Bus send failed"); dbus_message_unref(msg); return -EIO; } req->agent->request = NULL; req->agent = adapter_agent; req->agent->request = req; dbus_message_unref(req->msg); req->msg = msg; dbus_pending_call_set_notify(req->call, function, req, NULL); return 0; }
void _battery_dbus_stop(void) { Ac_Adapter *ac; Battery *bat; if (!e_dbus_conn) return; if (battery_config->dbus.have) { dbus_pending_call_cancel(battery_config->dbus.have); battery_config->dbus.have = NULL; } if (battery_config->dbus.dev_add) { e_dbus_signal_handler_del(e_dbus_conn, battery_config->dbus.dev_add); battery_config->dbus.dev_add = NULL; } if (battery_config->dbus.dev_del) { e_dbus_signal_handler_del(e_dbus_conn, battery_config->dbus.dev_del); battery_config->dbus.dev_del = NULL; } EINA_LIST_FREE(device_ac_adapters, ac) { e_dbus_signal_handler_del(e_dbus_conn, ac->prop_change); eina_stringshare_del(ac->udi); eina_stringshare_del(ac->product); free(ac); }
static void pincode_reply(DBusPendingCall *call, void *user_data) { struct agent_request *req = user_data; struct agent *agent = req->agent; struct btd_adapter *adapter = agent->adapter; agent_pincode_cb cb = req->cb; DBusMessage *message; DBusError err; bdaddr_t sba; size_t len; char *pin; adapter_get_address(adapter, &sba); /* steal_reply will always return non-NULL since the callback * is only called after a reply has been received */ message = dbus_pending_call_steal_reply(call); dbus_error_init(&err); if (dbus_set_error_from_message(&err, message)) { error("Agent %s replied with an error: %s, %s", agent->path, err.name, err.message); cb(agent, &err, NULL, req->user_data); dbus_error_free(&err); goto done; } dbus_error_init(&err); if (!dbus_message_get_args(message, &err, DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID)) { error("Wrong passkey reply signature: %s", err.message); cb(agent, &err, NULL, req->user_data); dbus_error_free(&err); goto done; } len = strlen(pin); dbus_error_init(&err); if (len > 16 || len < 1) { error("Invalid PIN length (%zu) from agent", len); dbus_set_error_const(&err, "org.bluez.Error.InvalidArgs", "Invalid passkey length"); cb(agent, &err, NULL, req->user_data); dbus_error_free(&err); goto done; } cb(agent, NULL, pin, req->user_data); done: if (message) dbus_message_unref(message); dbus_pending_call_cancel(req->call); agent->request = NULL; agent_request_free(req, TRUE); }
static void cleanup_register_call(void) { if (register_call != NULL) { dbus_pending_call_cancel(register_call); dbus_pending_call_unref(register_call); register_call = NULL; } }
QDBusPendingCallPrivate::~QDBusPendingCallPrivate() { if (pending) { dbus_pending_call_cancel(pending); dbus_pending_call_unref(pending); } delete watcherHelper; }
static void pending_req_finalize(struct pending_req *req) { if (!dbus_pending_call_get_completed(req->call)) dbus_pending_call_cancel(req->call); dbus_pending_call_unref(req->call); g_free(req); }
static void launcher_logind_get_active(struct launcher_logind *wl) { DBusPendingCall *pending; DBusMessage *m; bool b; const char *iface, *name; m = dbus_message_new_method_call("org.freedesktop.login1", wl->spath, "org.freedesktop.DBus.Properties", "Get"); if (!m) return; iface = "org.freedesktop.login1.Session"; name = "Active"; b = dbus_message_append_args(m, DBUS_TYPE_STRING, &iface, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); if (!b) goto err_unref; b = dbus_connection_send_with_reply(wl->dbus, m, &pending, -1); if (!b) goto err_unref; b = dbus_pending_call_set_notify(pending, get_active_cb, wl, NULL); if (!b) { dbus_pending_call_cancel(pending); dbus_pending_call_unref(pending); goto err_unref; } if (wl->pending_active) { dbus_pending_call_cancel(wl->pending_active); dbus_pending_call_unref(wl->pending_active); } wl->pending_active = pending; return; err_unref: dbus_message_unref(m); }
static void agent_cancel(struct hf_agent *agent) { if (!agent->call) return; dbus_pending_call_cancel(agent->call); dbus_pending_call_unref(agent->call); agent->call = NULL; }
/* * On success @param msg is unref'd or its ref is stolen by the returned * Eldbus_Pending. */ Eldbus_Pending * _eldbus_connection_send(Eldbus_Connection *conn, Eldbus_Message *msg, Eldbus_Message_Cb cb, const void *cb_data, double timeout) { Eldbus_Pending *pending; Eldbus_Message *error_msg; DBG("conn=%p, msg=%p, cb=%p, cb_data=%p, timeout=%f", conn, msg, cb, cb_data, timeout); if (!cb) { dbus_connection_send(conn->dbus_conn, msg->dbus_msg, NULL); eldbus_message_unref(msg); return NULL; } pending = calloc(1, sizeof(Eldbus_Pending)); EINA_SAFETY_ON_NULL_RETURN_VAL(pending, NULL); pending->cb = cb; pending->cb_data = cb_data; pending->conn = conn; pending->dest = eina_stringshare_add(dbus_message_get_destination(msg->dbus_msg)); pending->interface = eina_stringshare_add(dbus_message_get_interface(msg->dbus_msg)); pending->method = eina_stringshare_add(dbus_message_get_member(msg->dbus_msg)); pending->path = eina_stringshare_add(dbus_message_get_path(msg->dbus_msg)); /* Steal the reference */ pending->msg_sent = msg; EINA_MAGIC_SET(pending, ELDBUS_PENDING_MAGIC); if (!dbus_connection_send_with_reply(conn->dbus_conn, msg->dbus_msg, &pending->dbus_pending, timeout)) { error_msg = _eldbus_message_error_get(msg, "org.enlightenment.DBus.NoConnection", "Eldbus_Connection was closed."); eldbus_pending_dispatch(pending, error_msg); return NULL; } if (!pending->dbus_pending) { error_msg = _eldbus_message_error_get(msg, "org.enlightenment.DBus.Error", "dbus_pending is NULL."); eldbus_pending_dispatch(pending, error_msg); return NULL; } if (dbus_pending_call_set_notify(pending->dbus_pending, cb_pending, pending, NULL)) return pending; dbus_pending_call_cancel(pending->dbus_pending); error_msg = _eldbus_message_error_get(pending->msg_sent, "org.enlightenment.DBus.Error", "Error when try set callback to message."); eldbus_pending_dispatch(pending, error_msg); return NULL; }
static void media_endpoint_cancel(struct endpoint_request *request) { struct media_endpoint *endpoint = request->endpoint; if (request->call) dbus_pending_call_cancel(request->call); endpoint->requests = g_slist_remove(endpoint->requests, request); endpoint_request_free(request); }
static DBusHandlerResult watch_nm_state(DBusConnection *dbus_cnx, DBusMessage *message, void *user_data) { struct connline_context *context = user_data; DBusMessageIter arg; struct nm_dbus *nm; const char *member; unsigned int state; if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; member = dbus_message_get_member(message); if (member == NULL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (strncmp(member, "StateChanged", sizeof("StateChanged")) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; nm = context->backend_data; if (dbus_message_iter_init(message, &arg) == FALSE) goto error; if (connline_dbus_get_basic(&arg, DBUS_TYPE_UINT32, &state) < 0) goto error; if (is_connected(state) == TRUE && state != nm->state) { if (nm->call != NULL) { dbus_pending_call_cancel(nm->call); dbus_pending_call_unref(nm->call); nm->call = NULL; } if (nm_get_devices(context) != 0) goto error; } else { if (is_connected(nm->state) == TRUE) __connline_call_disconnected_callback(context); } nm->state = state; return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; error: nm_backend_data_cleanup(context); __connline_call_error_callback(context, false); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
static void service_free(gpointer data) { struct connman_service *service = data; int i; if (service_if != NULL && service_if->selected_service == service) return; if (service->property_changed_wid != 0) g_dbus_remove_watch(service_if->dbus_cnx, service->property_changed_wid); for (i = 0; i < SERVICE_MAX; i++) { if (service->to_update[i] != 0) g_source_remove(service->to_update[i]); if (service->call_modify[i] != 0) { dbus_pending_call_cancel(service->call_modify[i]); dbus_pending_call_unref(service->call_modify[i]); } if (service->to_error[i] != 0) g_source_remove(service->to_error[i]); } g_free(service->path); g_free(service->error); g_free(service->name); g_free(service->type); g_free(service->security); g_free(service->nameservers); g_free(service->nameservers_conf); g_free(service->timeservers); g_free(service->timeservers_conf); g_free(service->domains); g_free(service->domains_conf); ipv4_free(service->ipv4); ipv4_free(service->ipv4_conf); ipv6_free(service->ipv6); ipv6_free(service->ipv6_conf); proxy_free(service->proxy); proxy_free(service->proxy_conf); provider_free(service->provider); ethernet_free(service->ethernet); g_free(service); }
static void sap_remove(struct ofono_modem *modem) { struct sap_data *data = ofono_modem_get_data(modem); DBG("%p", modem); if (data->call != NULL) dbus_pending_call_cancel(data->call); g_free(data); ofono_modem_set_data(modem, NULL); }
void pa_dbus_pending_free(pa_dbus_pending *p) { pa_assert(p); if (p->pending) { dbus_pending_call_cancel(p->pending); dbus_pending_call_unref(p->pending); } if (p->message) dbus_message_unref(p->message); pa_xfree(p); }
static void passkey_reply(DBusPendingCall *call, void *user_data) { struct agent_request *req = user_data; struct agent *agent = req->agent; agent_passkey_cb cb = req->cb; DBusMessage *message; DBusError err; uint32_t passkey; /* steal_reply will always return non-NULL since the callback * is only called after a reply has been received */ message = dbus_pending_call_steal_reply(call); dbus_error_init(&err); if (dbus_set_error_from_message(&err, message)) { error("Agent replied with an error: %s, %s", err.name, err.message); cb(agent, &err, 0, req->user_data); // +s LGBT_COMMON_TEMPORARY [email protected] 120829 if (dbus_error_has_name(&err, "org.bluez.Error.Canceled")) { DBG("User cancel the pairing"); DBG("->device_set_temporary"); device_set_temporary(((struct authentication_req*) req->user_data)->device, TRUE); } // +e LGBT_COMMON_TEMPORARY dbus_error_free(&err); goto done; } dbus_error_init(&err); if (!dbus_message_get_args(message, &err, DBUS_TYPE_UINT32, &passkey, DBUS_TYPE_INVALID)) { error("Wrong passkey reply signature: %s", err.message); cb(agent, &err, 0, req->user_data); dbus_error_free(&err); goto done; } cb(agent, NULL, passkey, req->user_data); done: if (message) dbus_message_unref(message); dbus_pending_call_cancel(req->call); agent->request = NULL; agent_request_free(req, TRUE); }
static void destroy_device(gpointer user) { struct bluetooth_device *bt = user; DBG("%p", bt); if (bt->call != NULL) dbus_pending_call_cancel(bt->call); g_free(bt->path); g_free(bt->address); g_free(bt); }
static void oob_data_reply(DBusPendingCall *call, void *user_data) { struct agent_request *req = user_data; struct agent *agent = req->agent; agent_oob_data_cb cb = req->cb; DBusMessage *message; DBusError err; uint8_t *hash_ptr, *r_ptr; uint8_t hash_len, r_len; /* steal_reply will always return non-NULL since the callback * is only called after a reply has been received */ message = dbus_pending_call_steal_reply(call); dbus_error_init(&err); if (dbus_set_error_from_message(&err, message)) { if ((g_str_equal(DBUS_ERROR_UNKNOWN_METHOD, err.name) || g_str_equal(DBUS_ERROR_NO_REPLY, err.name)) && request_fallback(req, oob_data_reply) == 0) { dbus_error_free(&err); return; } error("Agent replied with an error: %s, %s", err.name, err.message); cb(agent, &err, 0, 0, req->user_data); dbus_error_free(&err); goto done; } if (!dbus_message_get_args(message, &err, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &hash_ptr, &hash_len, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &r_ptr, &r_len, DBUS_TYPE_INVALID)) { error("Wrong OOB data reply signature: %s", err.message); cb(agent, &err, 0, 0, req->user_data); dbus_error_free(&err); goto done; } cb(agent, NULL, hash_ptr, r_ptr, req->user_data); done: if (message) dbus_message_unref(message); dbus_pending_call_cancel(req->call); agent->request = NULL; agent_request_free(req, TRUE); }
int cras_bt_transport_set_volume(struct cras_bt_transport *transport, uint16_t volume) { const char *key = "Volume"; const char *interface = BLUEZ_INTERFACE_MEDIA_TRANSPORT; DBusMessage *method_call; DBusMessageIter message_iter, variant; DBusPendingCall *pending_call; method_call = dbus_message_new_method_call( BLUEZ_SERVICE, transport->object_path, DBUS_INTERFACE_PROPERTIES, "Set"); if (!method_call) return -ENOMEM; dbus_message_iter_init_append(method_call, &message_iter); dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_STRING, &interface); dbus_message_iter_append_basic(&message_iter, DBUS_TYPE_STRING, &key); dbus_message_iter_open_container(&message_iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &variant); dbus_message_iter_append_basic(&variant, DBUS_TYPE_UINT16, &volume); dbus_message_iter_close_container(&message_iter, &variant); if (!dbus_connection_send_with_reply(transport->conn, method_call, &pending_call, DBUS_TIMEOUT_USE_DEFAULT)) { dbus_message_unref(method_call); return -ENOMEM; } dbus_message_unref(method_call); if (!pending_call) return -EIO; if (!dbus_pending_call_set_notify(pending_call, on_transport_volume_set, NULL, NULL)) { dbus_pending_call_cancel(pending_call); dbus_pending_call_unref(pending_call); return -ENOMEM; } return 0; }
static void agent_data_free(struct connman_agent *data) { if (data == NULL) return; if (data->user_context != NULL) { if (data->driver != NULL && data->driver->context_unref != NULL) data->driver->context_unref(data->user_context); } if (data->msg != NULL) dbus_message_unref(data->msg); if (data->call != NULL) dbus_pending_call_cancel(data->call); g_free(data); }
EAPI void eldbus_pending_cancel(Eldbus_Pending *pending) { Eldbus_Message *error_message; ELDBUS_PENDING_CHECK(pending); EINA_SAFETY_ON_NULL_RETURN(pending->dbus_pending); DBG("pending=%p", pending); dbus_pending_call_cancel(pending->dbus_pending); error_message = eldbus_message_error_new(pending->msg_sent, ELDBUS_ERROR_PENDING_CANCELED, "Canceled by user."); eldbus_pending_dispatch(pending, error_message); }
int agent_cancel(struct agent *agent) { if (!agent->request) return -EINVAL; if (agent->request->call) { dbus_pending_call_cancel(agent->request->call); send_cancel_request(agent->request); } agent_request_free(agent->request, TRUE); agent->request = NULL; return 0; }
static void destroy_provider(struct connection_data *data) { DBG("data %p", data); if (g_str_equal(data->state, "ready") == TRUE || g_str_equal(data->state, "configuration") == TRUE) connman_provider_disconnect(data->provider); if (data->call != NULL) dbus_pending_call_cancel(data->call); connman_provider_put(data->provider); data->provider = NULL; }
/* start the D-Bus command chain to find out the already connected * devices */ static gboolean get_default_adapter(void) { DBusMessage *request = NULL; DBusPendingCall *pending_call = NULL; DBusConnection *connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); if (!connection) { goto error; } if ((request = dbus_message_new_method_call ("org.bluez", "/", "org.bluez.Manager", "DefaultAdapter")) == NULL) { goto error; } if (!dbus_connection_send_with_reply (connection, request, &pending_call, -1)) { goto error; } if (!dbus_pending_call_set_notify (pending_call, get_default_adapter_cb, NULL, NULL)) { dbus_pending_call_cancel (pending_call); goto error; } dbus_message_unref(request); return TRUE; error: if (request) dbus_message_unref(request); return FALSE; }