bool wxDBusConnection::SendWithReply(DBusMessage *message, int timeout_milliseconds) { DBusPendingCall * pcall = NULL; m_thread->EnterCriticalSection(); bool result = (bool) dbus_connection_send_with_reply(m_connection, message, &pcall, timeout_milliseconds); dbus_pending_call_set_notify(pcall, response_notify, (void *) this, NULL); m_thread->LeaveCriticalSection(); m_thread->Wakeup(); return result; }
int supplicant_dbus_property_get(const char *path, const char *interface, const char *method, supplicant_dbus_property_function function, void *user_data) { struct property_get_data *data; DBusMessage *message; DBusPendingCall *call; if (connection == NULL) return -EINVAL; if (path == NULL || interface == NULL || method == NULL) return -EINVAL; data = dbus_malloc0(sizeof(*data)); if (data == NULL) return -ENOMEM; message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path, DBUS_INTERFACE_PROPERTIES, "Get"); if (message == NULL) { dbus_free(data); return -ENOMEM; } dbus_message_set_auto_start(message, FALSE); dbus_message_append_args(message, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &method, NULL); if (dbus_connection_send_with_reply(connection, message, &call, TIMEOUT) == FALSE) { dbus_message_unref(message); dbus_free(data); return -EIO; } if (call == NULL) { dbus_message_unref(message); dbus_free(data); return -EIO; } data->function = function; data->user_data = user_data; dbus_pending_call_set_notify(call, property_get_reply, data, dbus_free); dbus_message_unref(message); return 0; }
gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method, GDBusSetupFunction setup, GDBusReturnFunction function, void *user_data, GDBusDestroyFunction destroy) { struct method_call_data *data; GDBusClient *client; DBusMessage *msg; DBusPendingCall *call; if (proxy == NULL || method == NULL) return FALSE; client = proxy->client; if (client == NULL) return FALSE; msg = dbus_message_new_method_call(client->service_name, proxy->obj_path, proxy->interface, method); if (msg == NULL) return FALSE; if (setup) { DBusMessageIter iter; dbus_message_iter_init_append(msg, &iter); setup(&iter, user_data); } if (!function) return g_dbus_send_message(client->dbus_conn, msg); data = g_try_new0(struct method_call_data, 1); if (data == NULL) return FALSE; data->function = function; data->user_data = user_data; data->destroy = destroy; if (g_dbus_send_message_with_reply(client->dbus_conn, msg, &call, METHOD_CALL_TIMEOUT) == FALSE) { dbus_message_unref(msg); g_free(data); return FALSE; } dbus_pending_call_set_notify(call, method_call_reply, data, g_free); dbus_pending_call_unref(call); dbus_message_unref(msg); return TRUE; }
/** Initiate asynchronous connman property change D-Bus method call * * @param key property name * @param val value to set * * @return TRUE if the method call was initiated, or FALSE in case of errors */ static gboolean xconnman_set_property_bool(const char *key, gboolean val) { gboolean res = FALSE; DBusMessage *req = 0; DBusPendingCall *pc = 0; dbus_bool_t dta = val; DBusMessageIter miter, viter; mce_log(LL_DEBUG, "%s = %s", key, val ? "true" : "false"); if( !(req = dbus_message_new_method_call(CONNMAN_SERVICE, CONNMAN_OBJECT_PATH, CONNMAN_INTERFACE, CONNMAN_SET_PROPERTY_REQ)) ) goto EXIT; dbus_message_iter_init_append(req, &miter); dbus_message_iter_append_basic(&miter, DBUS_TYPE_STRING, &key); if( !dbus_message_iter_open_container(&miter, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &viter) ) { mce_log(LL_WARN, "container open failed"); goto EXIT; } dbus_message_iter_append_basic(&viter, DBUS_TYPE_BOOLEAN, &dta); if( !dbus_message_iter_close_container(&miter, &viter) ) { mce_log(LL_WARN, "container close failed"); goto EXIT; } if( !dbus_connection_send_with_reply(connman_bus, req, &pc, -1) ) goto EXIT; if( !pc ) goto EXIT; mce_dbus_pending_call_blocks_suspend(pc); if( !dbus_pending_call_set_notify(pc, xconnman_set_property_cb, 0, 0) ) goto EXIT; // success res = TRUE; EXIT: if( pc ) dbus_pending_call_unref(pc); if( req ) dbus_message_unref(req); return res; }
static DBusHandlerResult handle_run_hello_from_self (DBusConnection *connection, DBusMessage *message) { DBusError error; DBusMessage *reply, *self_message; DBusPendingCall *pcall; char *s; _dbus_verbose ("sending reply to Echo method\n"); dbus_error_init (&error); if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID)) { reply = dbus_message_new_error (message, error.name, error.message); if (reply == NULL) die ("No memory\n"); if (!dbus_connection_send (connection, reply, NULL)) die ("No memory\n"); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } printf ("Sending HelloFromSelf\n"); _dbus_verbose ("*** Sending message to self\n"); self_message = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService", "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "HelloFromSelf"); if (self_message == NULL) die ("No memory"); if (!dbus_connection_send_with_reply (connection, self_message, &pcall, -1)) die("No memory"); dbus_message_ref (message); if (!dbus_pending_call_set_notify (pcall, check_hello_from_self_reply, (void *)message, NULL)) die("No memory"); printf ("Sent HelloFromSelf\n"); return DBUS_HANDLER_RESULT_HANDLED; }
/* * 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_new(msg, "org.enlightenment.DBus.NoConnection", "Eldbus_Connection was closed."); 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_new(pending->msg_sent, "org.enlightenment.DBus.Error", "Error when try set callback to message."); eldbus_pending_dispatch(pending, error_msg); return NULL; }
static void test_uae (Fixture *f, gconstpointer context) { const Config *config = context; DBusMessage *m; DBusPendingCall *pc; DBusMessageIter args_iter; DBusMessageIter arr_iter; if (f->skip) return; m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment"); if (m == NULL) g_error ("OOM"); dbus_message_iter_init_append (m, &args_iter); /* Append an empty a{ss} (string => string dictionary). */ if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY, "{ss}", &arr_iter) || !dbus_message_iter_close_container (&args_iter, &arr_iter)) g_error ("OOM"); if (!dbus_connection_send_with_reply (f->conn, m, &pc, DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL) g_error ("OOM"); dbus_message_unref (m); m = NULL; if (dbus_pending_call_get_completed (pc)) test_pending_call_store_reply (pc, &m); else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply, &m, NULL)) g_error ("OOM"); while (m == NULL) test_main_context_iterate (f->ctx, TRUE); if (config->expect_success) { /* it succeeds */ g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_METHOD_RETURN); }
/* Run a helper program using the commandline, with input as infomation on * stdin */ void hald_runner_run_method(HalDevice *device, const gchar *command_line, char **extra_env, gchar *input, gboolean error_on_stderr, guint32 timeout, HalRunTerminatedCB cb, gpointer data1, gpointer data2) { DBusMessage *msg; DBusMessageIter iter; DBusPendingCall *call; HelperData *hd = NULL; msg = dbus_message_new_method_call("org.freedesktop.HalRunner", "/org/freedesktop/HalRunner", "org.freedesktop.HalRunner", "Run"); if (msg == NULL) DIE(("No memory")); dbus_message_iter_init_append(msg, &iter); if (!add_first_part(&iter, device, command_line, extra_env)) goto error; dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &input); dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &error_on_stderr); dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &timeout); if (!dbus_connection_send_with_reply(runner_connection, msg, &call, INT_MAX)) DIE (("No memory")); /* the connection was disconnected */ if (call == NULL) goto error; hd = malloc(sizeof(HelperData)); hd->d = device; hd->cb = cb; hd->data1 = data1; hd->data2 = data2; g_object_ref (device); dbus_pending_call_set_notify(call, call_notify, hd, free); dbus_message_unref(msg); return; error: dbus_message_unref(msg); free(hd); cb(device, HALD_RUN_FAILED, 0, NULL, data1, data2); }
static int add_interface(struct supplicant_task *task) { const char *driver = connman_option_get_string("wifi"); DBusMessage *message; DBusMessageIter array, dict; DBusPendingCall *call; _DBG_SUPPLICANT("task %p", task); message = dbus_message_new_method_call(SUPPLICANT_NAME, SUPPLICANT_PATH, SUPPLICANT_INTF, "addInterface"); if (message == NULL) return -ENOMEM; dbus_message_set_auto_start(message, FALSE); dbus_message_iter_init_append(message, &array); dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &task->ifname); dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); connman_dbus_dict_append_variant(&dict, "driver", DBUS_TYPE_STRING, &driver); dbus_message_iter_close_container(&array, &dict); if (dbus_connection_send_with_reply(connection, message, &call, TIMEOUT) == FALSE) { connman_error("Failed to add interface"); dbus_message_unref(message); return -EIO; } if (call == NULL) { connman_error("D-Bus connection not available"); dbus_message_unref(message); return -EIO; } dbus_pending_call_set_notify(call, add_interface_reply, task, NULL); dbus_message_unref(message); return -EINPROGRESS; }
static void test_echo (Fixture *f, gconstpointer context G_GNUC_UNUSED) { guint count = 2000; guint sent; guint received = 0; double elapsed; if (g_test_perf ()) count = 100000; add_echo_filter (f); g_test_timer_start (); for (sent = 0; sent < count; sent++) { DBusMessage *m = dbus_message_new_method_call ( dbus_bus_get_unique_name (f->right_conn), "/", "com.example", "Spam"); DBusPendingCall *pc; if (m == NULL) g_error ("OOM"); if (!dbus_connection_send_with_reply (f->left_conn, m, &pc, DBUS_TIMEOUT_INFINITE) || pc == NULL) g_error ("OOM"); if (dbus_pending_call_get_completed (pc)) pc_count (pc, &received); else if (!dbus_pending_call_set_notify (pc, pc_count, &received, NULL)) g_error ("OOM"); dbus_pending_call_unref (pc); dbus_message_unref (m); } while (received < count) g_main_context_iteration (NULL, TRUE); elapsed = g_test_timer_elapsed (); g_test_maximized_result (count / elapsed, "%u messages / %f seconds", count, elapsed); }
DBusHandlerResult handle_authorize_request(DBusConnection *conn, DBusMessage *msg, struct service *service, const char *address, const char *uuid) { struct auth_agent_req *req; char adapter_path[PATH_MAX]; bdaddr_t bdaddr; int adapter_id; debug("handle_authorize_request"); if (!default_auth_agent) { debug("no default agent"); return error_auth_agent_does_not_exist(conn, msg); } str2ba(address, &bdaddr); adapter_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); if (adapter_id < 0) return error_not_connected(conn, msg); debug("Found %s connected to hci%d", address, adapter_id); snprintf(adapter_path, sizeof(adapter_path), "/org/bluez/hci%d", adapter_id); req = auth_agent_req_new(msg, default_auth_agent, adapter_path, address, service->object_path, uuid); req->call = auth_agent_call_authorize(default_auth_agent, adapter_path, service->object_path, address, uuid); if (!req->call) { auth_agent_req_free(req); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_pending_call_set_notify(req->call, auth_agent_req_reply, req, NULL); default_auth_agent->pending_requests = g_slist_append(default_auth_agent->pending_requests, req); debug("authorize request was forwarded"); return DBUS_HANDLER_RESULT_HANDLED; }
/** Verify that a client exists via an asynchronous GetNameOwner method call * * @param name the dbus name who's owner we wish to know * * @return TRUE if the method call was initiated, or FALSE in case of errors */ static gboolean cka_clients_verify_name(const char *name) { gboolean res = FALSE; DBusMessage *req = 0; DBusPendingCall *pc = 0; gchar *key = 0; if( !(req = cka_dbusutil_create_GetNameOwner_req(name)) ) { goto EXIT; } if( !dbus_connection_send_with_reply(cka_dbus_systembus, req, &pc, -1) ) { goto EXIT; } if( !pc ) { goto EXIT; } mce_dbus_pending_call_blocks_suspend(pc); key = g_strdup(name); if( !dbus_pending_call_set_notify(pc, cka_clients_verify_name_cb, key, g_free) ) { goto EXIT; } // key string is owned by pending call key = 0; // success res = TRUE; EXIT: g_free(key); if( pc ) dbus_pending_call_unref(pc); if( req ) dbus_message_unref(req); return res; }
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; }
gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name) { struct refresh_property_data *data; GDBusClient *client; DBusMessage *msg; DBusMessageIter iter; DBusPendingCall *call; if (proxy == NULL || name == NULL) return FALSE; client = proxy->client; if (client == NULL) return FALSE; data = g_try_new0(struct refresh_property_data, 1); if (data == NULL) return FALSE; data->proxy = proxy; data->name = g_strdup(name); msg = dbus_message_new_method_call(client->service_name, proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Get"); if (msg == NULL) { refresh_property_free(data); return FALSE; } dbus_message_iter_init_append(msg, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &proxy->interface); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name); if (g_dbus_send_message_with_reply(client->dbus_conn, msg, &call, -1) == FALSE) { dbus_message_unref(msg); refresh_property_free(data); return FALSE; } dbus_pending_call_set_notify(call, refresh_property_reply, data, refresh_property_free); dbus_pending_call_unref(call); dbus_message_unref(msg); return TRUE; }
static void get_properties(struct supplicant_task *task) { DBusMessage *message; char *path; path = g_slist_nth_data(task->scan_results, 0); if (path == NULL) goto noscan; message = dbus_message_new_method_call(SUPPLICANT_NAME, path, SUPPLICANT_INTF ".BSSID", "properties"); task->scan_results = g_slist_remove(task->scan_results, path); g_free(path); if (message == NULL) goto noscan; dbus_message_set_auto_start(message, FALSE); if (dbus_connection_send_with_reply(connection, message, &task->result_call, TIMEOUT) == FALSE) { connman_error("Failed to get network properties"); dbus_message_unref(message); goto noscan; } if (task->result_call == NULL) { connman_error("D-Bus connection not available"); dbus_message_unref(message); goto noscan; } dbus_pending_call_set_notify(task->result_call, properties_reply, task, NULL); dbus_message_unref(message); return; noscan: task->result_call = NULL; if (task->scanning == TRUE) { connman_device_set_scanning(task->device, FALSE); task->scanning = FALSE; } }
static struct pending_req *send_method_call(DBusConnection *connection, const char *dest, const char *path, const char *interface, const char *method, DBusPendingCallNotifyFunction cb, void *user_data, int type, ...) { DBusMessage *msg; DBusPendingCall *call; va_list args; struct pending_req *req; msg = dbus_message_new_method_call(dest, path, interface, method); if (!msg) { error("Unable to allocate new D-Bus %s message", method); return NULL; } va_start(args, type); if (!dbus_message_append_args_valist(msg, type, args)) { dbus_message_unref(msg); va_end(args); return NULL; } va_end(args); if (!cb) { g_dbus_send_message(connection, msg); return 0; } if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) { error("Sending %s failed", method); dbus_message_unref(msg); return NULL; } dbus_pending_call_set_notify(call, cb, user_data, NULL); req = g_new0(struct pending_req, 1); req->call = call; req->user_data = user_data; dbus_message_unref(msg); return req; }
static void _libnm_glib_get_nm_state (libnm_glib_ctx *ctx) { DBusMessage * message; DBusPendingCall * pcall = NULL; g_return_if_fail (ctx != NULL); if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"))) { dbus_connection_send_with_reply (ctx->dbus_con, message, &pcall, -1); if (pcall) dbus_pending_call_set_notify (pcall, _libnm_glib_nm_state_cb, ctx, NULL); dbus_message_unref (message); } }
static int provider_remove(struct connman_provider *provider) { DBusPendingCall *call; DBusMessage *message; struct connection_data *data; data = connman_provider_get_data(provider); DBG("provider %p data %p", provider, data); /* * When provider.c:provider_remove() calls this function, * it will remove the provider itself after the call. * This means that we cannot use the provider pointer later * as it is no longer valid. */ data->provider = NULL; message = dbus_message_new_method_call(VPN_SERVICE, "/", VPN_MANAGER_INTERFACE, VPN_REMOVE); if (message == NULL) return -ENOMEM; dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &data->path, NULL); if (dbus_connection_send_with_reply(connection, message, &call, DBUS_TIMEOUT) == FALSE) { connman_error("Unable to call %s.%s()", VPN_MANAGER_INTERFACE, VPN_REMOVE); dbus_message_unref(message); return -EINVAL; } if (call == NULL) { dbus_message_unref(message); return -EINVAL; } dbus_pending_call_set_notify(call, remove_connection_reply, NULL, NULL); dbus_message_unref(message); return 0; }
static gboolean get_device_list(gchar *adapter_path) { 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", adapter_path, "org.bluez.Adapter", "ListDevices")) == 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_device_list_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; }
/* 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; }
/* As per: http://www.freedesktop.org/wiki/Software/systemd/inhibit */ static void virNetDaemonCallInhibit(virNetDaemonPtr dmn, const char *what, const char *who, const char *why, const char *mode) { DBusMessage *message; DBusPendingCall *pendingReply; DBusConnection *systemBus; VIR_DEBUG("dmn=%p what=%s who=%s why=%s mode=%s", dmn, NULLSTR(what), NULLSTR(who), NULLSTR(why), NULLSTR(mode)); if (!(systemBus = virDBusGetSystemBus())) return; /* Only one outstanding call at a time */ if (dmn->autoShutdownCallingInhibit) return; message = dbus_message_new_method_call("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Inhibit"); if (message == NULL) return; dbus_message_append_args(message, DBUS_TYPE_STRING, &what, DBUS_TYPE_STRING, &who, DBUS_TYPE_STRING, &why, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID); pendingReply = NULL; if (dbus_connection_send_with_reply(systemBus, message, &pendingReply, 25*1000)) { dbus_pending_call_set_notify(pendingReply, virNetDaemonGotInhibitReply, dmn, NULL); dmn->autoShutdownCallingInhibit = true; } dbus_message_unref(message); }
static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_backend *backend, DBusMessage *m, DBusPendingCallNotifyFunction func, void *call_data) { pa_dbus_pending *p; DBusPendingCall *call; pa_assert(backend); pa_assert(m); pa_assert_se(dbus_connection_send_with_reply(pa_dbus_connection_get(backend->connection), m, &call, -1)); p = pa_dbus_pending_new(pa_dbus_connection_get(backend->connection), m, call, backend, call_data); PA_LLIST_PREPEND(pa_dbus_pending, backend->pending, p); dbus_pending_call_set_notify(call, func, p, NULL); return p; }
/* Helper function to check if this module is needed */ static void check_loader_needed(void) { DBusError err = DBUS_ERROR_INIT; DBusPendingCall *pc = 0; DBusConnection *conn = 0; DBusMessage *req = NULL; const char *unit = WLAN_SYSTEMD_UNIT; if (!(conn = dsme_dbus_get_connection(&err))) { dsme_log(LOG_ERR, "wlanloader: system bus connect: %s: %s", err.name, err.message); goto cleanup; } req = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "GetUnit"); if (!req) goto cleanup; if (!dbus_message_append_args(req, DBUS_TYPE_STRING, &unit, DBUS_TYPE_INVALID)) { goto cleanup; } if (!dbus_connection_send_with_reply(conn, req, &pc, -1)) goto cleanup; if (!pc) { dsme_log(LOG_WARNING, "wlanloader: null pending call received"); goto cleanup; } if (!dbus_pending_call_set_notify(pc, loader_needed_cb, 0, 0)) goto cleanup; cleanup: if (pc) dbus_pending_call_unref(pc); if (req) dbus_message_unref(req); if (conn) dbus_connection_unref(conn); dbus_error_free(&err); }
static bool xdbus_async_call_va(const char *srv, const char *obj, const char *ifc, const char *fun, DBusPendingCallNotifyFunction cb, void *aptr, DBusFreeFunction free_cb, int type, va_list va) { bool res = false; DBusMessage *req = 0; DBusPendingCall *pc = 0; if( !xdbus_con ) goto EXIT; if( !(req = dbus_message_new_method_call(srv, obj, ifc, fun)) ) goto EXIT; if( !dbus_message_append_args_valist(req, type, va) ) goto EXIT; if( !cb ) { dbus_message_set_no_reply(req, true); if( !dbus_connection_send(xdbus_con, req, 0) ) goto EXIT; } else { if( !dbus_connection_send_with_reply(xdbus_con, req, &pc, -1) ) goto EXIT; if( !dbus_pending_call_set_notify(pc, cb, aptr, free_cb) ) goto EXIT; } res = true; EXIT: if( !res ) log_error("%s.%s: failed to initiate query", ifc, fun); if( pc ) dbus_pending_call_unref(pc); if( req ) dbus_message_unref(req); return res; }
static void check_network (DBusConnection *connection, gpointer user_data) { DBusMessage *message; DBusPendingCall *reply; message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"); if (dbus_connection_send_with_reply (connection, message, &reply, -1)) { dbus_pending_call_set_notify (reply, state_notify, user_data, NULL); dbus_pending_call_unref (reply); } dbus_message_unref (message); }
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); }
/** Verify that a client exists via an asynchronous GetNameOwner method call * * @param name the dbus name who's owner we wish to know * * @return TRUE if the method call was initiated, or FALSE in case of errors */ static gboolean cpu_keepalive_verify_name(const char *name) { gboolean res = FALSE; DBusMessage *req = 0; DBusPendingCall *pc = 0; gchar *key = 0; if( !(req = cpu_keepalive_create_GetNameOwner_req(name)) ) { goto EXIT; } if( !dbus_connection_send_with_reply(systembus, req, &pc, -1) ) { goto EXIT; } key = g_strdup(name); if( !dbus_pending_call_set_notify(pc, cpu_keepalive_verify_name_cb, key, g_free) ) { goto EXIT; } // pending call should not be cancelled pc = 0; // key string is owned by pending call key = 0; // success res = TRUE; EXIT: g_free(key); if( pc ) dbus_pending_call_cancel(pc); if( req ) dbus_message_unref(req); return res; }
static int send_method_call(struct bluetooth_session *session, const char *path, const char *interface, const char *method, DBusPendingCallNotifyFunction cb, int type, ...) { DBusMessage *msg; DBusPendingCall *call; va_list args; msg = dbus_message_new_method_call(BT_BUS_NAME, path, interface, method); if (!msg) { error("Unable to allocate new D-Bus %s message", method); return -ENOMEM; } va_start(args, type); if (!dbus_message_append_args_valist(msg, type, args)) { dbus_message_unref(msg); va_end(args); return -EINVAL; } va_end(args); if (!cb) { g_dbus_send_message(session->conn, msg); return 0; } if (!dbus_connection_send_with_reply(session->conn, msg, &call, -1)) { error("Sending %s failed", method); dbus_message_unref(msg); return -EIO; } dbus_pending_call_set_notify(call, cb, session, NULL); session->pending_calls = g_slist_prepend(session->pending_calls, call); return 0; }
static DBusMessage * send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error) { DBusPendingCall *pending; DBusMessage *reply = NULL; if (!dbus_connection_send_with_reply (bus, message, &pending, -1)) { return NULL; } dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL); while (!reply) { if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL; } return reply; }
static void FcitxNotifyGetCapabilities(FcitxNotify *notify) { DBusMessage* message = dbus_message_new_method_call(NOTIFICATIONS_SERVICE_NAME, NOTIFICATIONS_PATH, NOTIFICATIONS_INTERFACE_NAME, "GetCapabilities"); DBusPendingCall *call = NULL; dbus_bool_t reply = dbus_connection_send_with_reply(notify->conn, message, &call, DBUS_TIMEOUT_USE_DEFAULT); if (reply == TRUE) { dbus_pending_call_set_notify(call, FcitxNotifyGetCapabilitiesCallback, notify, NULL); dbus_pending_call_unref(call); } }