int dbusif_send_signal(struct tonegend *tonegend, const char *intf, const char *name, int first_arg_type, ...) { struct dbusif *dbusif = tonegend->dbus_ctx; DBusMessage *msg; va_list ap; dbus_bool_t success = FALSE; if (name == NULL) { N_ERROR(LOG_CAT "%s(): Called with invalid argument", __FUNCTION__); errno = EINVAL; return -1; } if (intf == NULL) intf = TELEPHONY_TONES_SERVICE; if ((msg = dbus_message_new_signal(TELEPHONY_TONES_PATH, intf, name)) == NULL) { errno = ENOMEM; return -1; } va_start(ap, first_arg_type); if (dbus_message_append_args_valist(msg, first_arg_type, ap)) { success = dbus_connection_send(dbusif->conn, msg, NULL); } va_end(ap); dbus_message_unref(msg); return success ? 0 : -1; }
static DBusMessage * client_make_method_message(const char *method, int dbus_type, ...) { DBusMessage *msg = 0; va_list va; va_start(va, dbus_type); if( !(msg = dbus_message_new_method_call(ALARMD_SERVICE, ALARMD_PATH, ALARMD_INTERFACE, method)) ) { log_error("%s\n", "dbus_message_new_method_call"); goto cleanup; } if( !dbus_message_append_args_valist(msg, dbus_type, va) ) { log_error("%s\n", "dbus_message_append_args_valist"); dbus_message_unref(msg), msg = 0; goto cleanup; } cleanup: va_end(va); return msg; }
static dbus_bool_t dbus_func_args_async_valist(DBusConnection *conn, int timeout_ms, void (*user_cb)(DBusMessage*, void*), void *user, const char *path, const char *ifc, const char *func, int first_arg_type, va_list args) { DBusMessage *msg = NULL; /* Compose the command */ msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, path, ifc, func); if (msg == NULL) { LOG("Could not allocate D-Bus message object!"); goto done; } /* append arguments */ if (!dbus_message_append_args_valist(msg, first_arg_type, args)) { LOG("Could not append argument to method call!"); goto done; } return dbus_func_send_async(conn, msg, timeout_ms, user_cb, user); done: if (msg) dbus_message_unref(msg); return FALSE; }
void cdbus_method_return_new_valist(struct cdbus_method_call * call_ptr, int type, ...) { if (!call_ptr) { log_error("Call pointer is NULL"); return; } if (type == DBUS_TYPE_INVALID) { log_error("No argument(s) supplied"); return; } va_list argp; call_ptr->reply = dbus_message_new_method_return(call_ptr->message); if (!call_ptr->reply) goto fail_no_mem; va_start(argp, type); if (dbus_message_append_args_valist(call_ptr->reply, type, argp)) { va_end(argp); return; } va_end(argp); dbus_message_unref(call_ptr->reply); call_ptr->reply = NULL; fail_no_mem: log_error("Ran out of memory trying to construct method return"); }
gboolean g_dbus_emit_signal_valist(DBusConnection *connection, const char *path, const char *interface, const char *name, int type, va_list args) { DBusMessage *signal; dbus_bool_t ret; const GDBusArgInfo *args_info; if (!check_signal(connection, path, interface, name, &args_info)) return FALSE; signal = dbus_message_new_signal(path, interface, name); if (signal == NULL) { error("Unable to allocate new %s.%s signal", interface, name); return FALSE; } ret = dbus_message_append_args_valist(signal, type, args); if (!ret) goto fail; if (g_dbus_args_have_signature(args_info, signal) == FALSE) { error("%s.%s: got unexpected signature '%s'", interface, name, dbus_message_get_signature(signal)); ret = FALSE; goto fail; } return g_dbus_send_message(connection, signal); fail: dbus_message_unref(signal); return ret; }
static DBusMessage * client_make_method_message(const char *method, int dbus_type, ...) { DBusMessage *msg = 0; va_list va; va_start(va, dbus_type); if( !(msg = dbus_message_new_method_call(PROFILED_SERVICE, PROFILED_PATH, PROFILED_INTERFACE, method)) ) { log_err_F("could not create method call message\n"); goto cleanup; } if( !dbus_message_append_args_valist(msg, dbus_type, va) ) { log_err_F("could not add args to method call message\n"); goto cleanup; } cleanup: va_end(va); return msg; }
static sss_sifp_error sss_sifp_ifp_call(sss_sifp_ctx *ctx, const char *method, int first_arg_type, va_list ap, DBusMessage **_reply) { DBusMessage *msg = NULL; sss_sifp_error ret; msg = sss_sifp_create_message(SSS_SIFP_PATH_IFP, SSS_SIFP_IFACE_IFP, method); if (msg == NULL) { ret = SSS_SIFP_OUT_OF_MEMORY; goto done; } if (first_arg_type != DBUS_TYPE_INVALID) { dbus_message_append_args_valist(msg, first_arg_type, ap); } ret = sss_sifp_send_message(ctx, msg, _reply); done: if (msg != NULL) { dbus_message_unref(msg); } return ret; }
static dbus_bool_t dbus_func_args_async_valist(JNIEnv *env, DBusConnection *conn, int timeout_ms, void (*user_cb)(DBusMessage *, void *, void*), void *user, void *nat, const char *path, const char *ifc, const char *func, int first_arg_type, va_list args) { DBusMessage *msg = NULL; const char *name; dbus_async_call_t *pending; dbus_bool_t reply = FALSE; /* Compose the command */ msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, path, ifc, func); if (msg == NULL) { LOGE("Could not allocate D-Bus message object!"); goto done; } /* append arguments */ if (!dbus_message_append_args_valist(msg, first_arg_type, args)) { LOGE("Could not append argument to method call!"); goto done; } /* Make the call. */ pending = (dbus_async_call_t *)malloc(sizeof(dbus_async_call_t)); if (pending) { DBusPendingCall *call; pending->env = env; pending->user_cb = user_cb; pending->user = user; pending->nat = nat; //pending->method = msg; reply = dbus_connection_send_with_reply(conn, msg, &call, timeout_ms); if (reply == TRUE) { dbus_pending_call_set_notify(call, dbus_func_args_async_callback, pending, NULL); } } done: if (msg) dbus_message_unref(msg); return reply; }
/** * Generic function to send D-Bus messages and signals * to send a signal, call dbus_send with service == NULL * * @todo Make it possible to send D-Bus replies as well * * @param service D-Bus service; for signals, set to NULL * @param path D-Bus path * @param interface D-Bus interface * @param name The D-Bus method or signal name to send to * @param callback A reply callback, or NULL to set no reply; * for signals, this is unused, but please use NULL * for consistency * @param first_arg_type The DBUS_TYPE of the first argument in the list * @param ... The arguments to append to the D-Bus message; * terminate with DBUS_TYPE_INVALID * Note: the arguments MUST be passed by reference * @return TRUE on success, FALSE on failure */ gboolean dbus_send(const gchar *const service, const gchar *const path, const gchar *const interface, const gchar *const name, DBusPendingCallNotifyFunction callback, int first_arg_type, ...) { DBusMessage *msg; gboolean status = FALSE; va_list var_args; if (service != NULL) { msg = dbus_new_method_call(service, path, interface, name); if (callback == NULL) dbus_message_set_no_reply(msg, TRUE); } else { if (callback != NULL) { mce_log(LL_ERR, "Programmer snafu! " "dbus_send() called with a DBusPending " "callback for a signal. Whoopsie!"); callback = NULL; } msg = dbus_new_signal(path, interface, name); } /* Append the arguments, if any */ va_start(var_args, first_arg_type); if (first_arg_type != DBUS_TYPE_INVALID) { if (dbus_message_append_args_valist(msg, first_arg_type, var_args) == FALSE) { mce_log(LL_CRIT, "Failed to append arguments to D-Bus message " "for %s.%s", interface, name); dbus_message_unref(msg); goto EXIT; } } /* Send the signal / call the method */ if (callback == NULL) { status = dbus_send_message(msg); } else { status = dbus_send_message_with_reply_handler(msg, callback); } EXIT: va_end(var_args); return status; }
void spi_dbus_emit_valist(DBusConnection *bus, const char *path, const char *interface, const char *name, int first_arg_type, va_list args) { DBusMessage *sig; sig = dbus_message_new_signal(path, interface, name); if (first_arg_type != DBUS_TYPE_INVALID) { dbus_message_append_args_valist(sig, first_arg_type, args); } dbus_connection_send(bus, sig, NULL); dbus_message_unref(sig); }
DBusMessage *rtdbus_append_args_valist(DBusMessage *message, int first_arg_type, va_list ap) { if (first_arg_type == DBUS_TYPE_INVALID) return message; if (!dbus_message_append_args_valist(message, first_arg_type, ap)) { UNREF_LOG(dbus_message_unref(message)); message = NULL; g_critical(_("Unable to append arguments to D-BUS message")); } return message; }
/** * Generic function to send D-Bus messages, blocking version * * @param service D-Bus service * @param path D-Bus path * @param interface D-Bus interface * @param name The D-Bus method to send to * @param timeout The reply timeout in milliseconds to use * @param first_arg_type The DBUS_TYPE of the first argument in the list * @param ... The arguments to append to the D-Bus message; * terminate with DBUS_TYPE_INVALID * Note: the arguments MUST be passed by reference * @return A new DBusMessage with the reply on success, NULL on failure */ DBusMessage *dbus_send_with_block(const gchar *const service, const gchar *const path, const gchar *const interface, const gchar *const name, gint timeout, int first_arg_type, ...) { DBusMessage *reply = NULL; DBusMessage *msg = NULL; va_list var_args; DBusError error; /* Register error channel */ dbus_error_init(&error); msg = dbus_new_method_call(service, path, interface, name); /* Append the arguments, if any */ va_start(var_args, first_arg_type); if (first_arg_type != DBUS_TYPE_INVALID) { if (dbus_message_append_args_valist(msg, first_arg_type, var_args) == FALSE) { mce_log(LL_CRIT, "Failed to append arguments to D-Bus message " "for %s.%s", interface, name); dbus_message_unref(msg); goto EXIT; } } /* Call the method */ reply = dbus_connection_send_with_reply_and_block(dbus_connection, msg, timeout, &error); dbus_message_unref(msg); if (dbus_error_is_set(&error) == TRUE) { mce_log(LL_ERR, "Error sending with reply to %s.%s: %s", interface, name, error.message); dbus_error_free(&error); reply = NULL; } EXIT: va_end(var_args); return reply; }
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; }
gboolean g_dbus_send_reply_valist(DBusConnection *connection, DBusMessage *message, int type, va_list args) { DBusMessage *reply; reply = dbus_message_new_method_return(message); if (reply == NULL) return FALSE; if (dbus_message_append_args_valist(reply, type, args) == FALSE) { dbus_message_unref(reply); return FALSE; } return g_dbus_send_message(connection, reply); }
DBusMessage *g_dbus_create_reply_valist(DBusMessage *message, int type, va_list args) { DBusMessage *reply; reply = dbus_message_new_method_return(message); if (reply == NULL) return NULL; if (dbus_message_append_args_valist(reply, type, args) == FALSE) { dbus_message_unref(reply); return NULL; } return reply; }
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; }
// If err is NULL, then any errors will be LOGE'd, and free'd and the reply // will be NULL. // If err is not NULL, then it is assumed that dbus_error_init was already // called, and error's will be returned to the caller without logging. The // return value is NULL iff an error was set. The client must free the error if // set. DBusMessage * dbus_func_args_timeout_valist(JNIEnv *env, DBusConnection *conn, int timeout_ms, DBusError *err, const char *path, const char *ifc, const char *func, int first_arg_type, va_list args) { DBusMessage *msg = NULL, *reply = NULL; const char *name; bool return_error = (err != NULL); if (!return_error) { err = (DBusError*)malloc(sizeof(DBusError)); dbus_error_init(err); } /* Compose the command */ msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, path, ifc, func); if (msg == NULL) { LOGE("Could not allocate D-Bus message object!"); goto done; } /* append arguments */ if (!dbus_message_append_args_valist(msg, first_arg_type, args)) { LOGE("Could not append argument to method call!"); goto done; } /* Make the call. */ reply = dbus_connection_send_with_reply_and_block(conn, msg, timeout_ms, err); if (!return_error && dbus_error_is_set(err)) { LOG_AND_FREE_DBUS_ERROR_WITH_MSG(err, msg); } done: if (!return_error) { free(err); } if (msg) dbus_message_unref(msg); return reply; }
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 void gnss_agent_send_noreply(struct gnss_agent *agent, const char *method, int type, ...) { DBusConnection *conn = ofono_dbus_get_connection(); DBusMessage *message; va_list args; message = dbus_message_new_method_call(agent->bus, agent->path, OFONO_GNSS_POSR_AGENT_INTERFACE, method); va_start(args, type); dbus_message_append_args_valist(message, type, args); va_end(args); dbus_message_set_no_reply(message, TRUE); g_dbus_send_message(conn, message); }
int sbus_request_return_and_finish(struct sbus_request *dbus_req, int first_arg_type, ...) { DBusMessage *reply; DBusError error = DBUS_ERROR_INIT; dbus_bool_t dbret; va_list va; int ret; va_start(va, first_arg_type); ret = sbus_request_valist_check(va, first_arg_type); if (ret != EOK) { va_end(va); dbus_set_error_const(&error, DBUS_ERROR_INVALID_ARGS, INTERNAL_ERROR); return sbus_request_fail_and_finish(dbus_req, &error); } reply = dbus_message_new_method_return(dbus_req->message); if (!reply) { va_end(va); DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory allocating DBus message\n"); sbus_request_finish(dbus_req, NULL); return ENOMEM; } dbret = dbus_message_append_args_valist(reply, first_arg_type, va); va_end(va); if (dbret) { ret = sbus_request_finish(dbus_req, reply); } else { DEBUG(SSSDBG_CRIT_FAILURE, "Couldn't build DBus message\n"); sbus_request_finish(dbus_req, NULL); ret = EINVAL; } dbus_message_unref(reply); return ret; }
DBusMessage * test_dbus_call_sync(DBusConnection *conn, const char *object_path, const char *interface, const char *method, DBusError *error, int first_arg_type, ...) { DBusMessage *message; DBusMessage *reply; va_list va; message = dbus_message_new_method_call(NULL, object_path, interface, method); verify_neq(message, NULL); va_start(va, first_arg_type); verify_eq(dbus_message_append_args_valist(message, first_arg_type, va), TRUE); va_end(va); reply = dbus_connection_send_with_reply_and_block(conn, message, -1, error); dbus_message_unref(message); return reply; }
static dbus_bool_t emit_signal_valist(DBusConnection *conn, const char *path, const char *interface, const char *name, int first, va_list var_args) { DBusMessage *signal; dbus_bool_t ret; const char *signature, *args; if (!check_signal(conn, path, interface, name, &args)) return FALSE; signal = dbus_message_new_signal(path, interface, name); if (signal == NULL) { error("Unable to allocate new %s.%s signal", interface, name); return FALSE; } ret = dbus_message_append_args_valist(signal, first, var_args); if (!ret) goto fail; signature = dbus_message_get_signature(signal); if (strcmp(args, signature) != 0) { error("%s.%s: expected signature'%s' but got '%s'", interface, name, args, signature); ret = FALSE; goto fail; } ret = dbus_connection_send(conn, signal, NULL); fail: dbus_message_unref(signal); return ret; }
static gboolean send_dbus_signal(const char *name, int first_arg_type, ...) { DBusMessage * msg; gboolean result = FALSE; va_list va; va_start(va, first_arg_type); msg = dbus_message_new_signal("/com/nokia/bme/signal", "com.nokia.bme.signal", name); if (msg && dbus_message_append_args_valist(msg, first_arg_type, va) && dbus_connection_send(system_dbus, msg, 0)) { dbus_connection_flush(system_dbus); result = TRUE; } if (msg) dbus_message_unref(msg); return result; }
int dbusif_send_signal(struct tonegend *tonegend, char *intf, char *name, int first_arg_type, ...) { struct dbusif *dbusif = tonegend->dbus_ctx; DBusMessage *msg; va_list ap; int success; do { /* not a loop */ success = FALSE; if (name == NULL) { LOG_ERROR("%s(): Called with invalid argument", __FUNCTION__); errno = EINVAL; break; } if (intf == NULL) intf = service; if ((msg = dbus_message_new_signal(path, intf, name)) == NULL) { errno = ENOMEM; break; } va_start(ap, first_arg_type); if (dbus_message_append_args_valist(msg, first_arg_type, ap)) { success = dbus_connection_send(dbusif->conn, msg, NULL); } va_end(ap); dbus_message_unref(msg); } while(FALSE); return success ? 0 : -1; }
static sss_sifp_error sss_sifp_ifp_call(sss_sifp_ctx *ctx, const char *object_path, const char *interface, const char *method, int first_arg_type, va_list ap, DBusMessage **_reply) { DBusMessage *msg = NULL; sss_sifp_error ret; dbus_bool_t bret; if (object_path == NULL || interface == NULL || method == NULL) { return SSS_SIFP_INVALID_ARGUMENT; } msg = sss_sifp_create_message(object_path, interface, method); if (msg == NULL) { ret = SSS_SIFP_OUT_OF_MEMORY; goto done; } if (first_arg_type != DBUS_TYPE_INVALID) { bret = dbus_message_append_args_valist(msg, first_arg_type, ap); if (!bret) { ret = SSS_SIFP_IO_ERROR; goto done; } } ret = sss_sifp_send_message(ctx, msg, _reply); done: if (msg != NULL) { dbus_message_unref(msg); } return ret; }
static DBusMessage * server_make_reply(DBusMessage *msg, int type, ...) { DBusMessage *rsp = 0; va_list va; va_start(va, type); if( (rsp = dbus_message_new_method_return(msg)) != 0 ) { if( !dbus_message_append_args_valist(rsp, type, va) ) { dbus_message_unref(rsp), rsp = 0; } } va_end(va); return rsp; }
uint8_t dbus_svc_send_va ( DBusConnectionState *cs, dbus_svc_MessageType type, int32_t reply_serial, uint32_t *new_serial, const char *destination, const char *path, const char *interface, const char *member, dbus_svc_DataType firstType, va_list va ) { DBusMessageIter iter; char *e; DBusMessage *msg = dbus_svc_new_message ( cs, type, reply_serial, destination, path, interface, member ); if(msg == 0L) { if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_svc_new_message failed"); return 0; } if( type != DBUS_MESSAGE_TYPE_ERROR ) { if( !dbus_message_append_args_valist( msg, firstType, va ) ) { if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_append_args_valist failed"); return 0; } }else { if( firstType == DBUS_TYPE_STRING ) { e = 0L; e = va_arg( va, char* ); if( (e == 0L) || !dbus_message_set_error_name( msg, e ) ) { if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_set_error_name failed"); return 0; } firstType = va_arg(va, int); if( firstType == DBUS_TYPE_STRING ) { e = 0L; e = va_arg( va, char* ); if( e == 0L ) { if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: NULL error message"); return 0; } dbus_message_iter_init_append (msg, &iter); if( !dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &e) ) { if( cs->eh != 0L ) (*(cs->eh))("dbus_svc_send: dbus_message_iter_append_basic failed"); return 0; } } }else