本文整理汇总了C++中dbus_message_new_error函数的典型用法代码示例。如果您正苦于以下问题:C++ dbus_message_new_error函数的具体用法?C++ dbus_message_new_error怎么用?C++ dbus_message_new_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dbus_message_new_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: properties_handler
static DBusMessage * properties_handler(DBusMessage *message,
struct wpa_dbus_object_desc *obj_dsc)
{
DBusMessageIter iter;
char *interface;
const char *method;
method = dbus_message_get_member(message);
dbus_message_iter_init(message, &iter);
if (!os_strncmp(WPA_DBUS_PROPERTIES_GET, method,
WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) ||
!os_strncmp(WPA_DBUS_PROPERTIES_SET, method,
WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) ||
!os_strncmp(WPA_DBUS_PROPERTIES_GETALL, method,
WPAS_DBUS_METHOD_SIGNAL_PROP_MAX)) {
/* First argument: interface name (DBUS_TYPE_STRING) */
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
{
return dbus_message_new_error(message,
DBUS_ERROR_INVALID_ARGS,
NULL);
}
dbus_message_iter_get_basic(&iter, &interface);
if (!os_strncmp(WPA_DBUS_PROPERTIES_GETALL, method,
WPAS_DBUS_METHOD_SIGNAL_PROP_MAX)) {
/* GetAll */
return properties_get_all(message, interface, obj_dsc);
}
/* Get or Set */
return properties_get_or_set(message, &iter, interface,
obj_dsc);
}
return dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD,
NULL);
}
示例2: handle_run_hello_from_self
static DBusHandlerResult
handle_run_hello_from_self (DBusConnection *connection,
DBusMessage *message)
{
DBusError error;
DBusMessage *reply, *self_message;
DBusPendingCall *pcall;
char *s;
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");
self_message = dbus_message_new_method_call ("org.freedesktop.DBus.GLib.TestEchoService",
"/org/freedesktop/DBus/GLib/TestSuite",
"org.freedesktop.DBus.GLib.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;
}
示例3: handle_echo
static DBusHandlerResult
handle_echo (DBusConnection *connection,
DBusMessage *message)
{
DBusError error;
DBusMessage *reply;
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;
}
reply = dbus_message_new_method_return (message);
if (reply == NULL)
die ("No memory\n");
if (!dbus_message_append_args (reply,
DBUS_TYPE_STRING, &s,
DBUS_TYPE_INVALID))
die ("No memory");
if (!dbus_connection_send (connection, reply, NULL))
die ("No memory\n");
fprintf (stderr, "Echo service echoed string: \"%s\"\n", s);
dbus_message_unref (reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
示例4: wpas_dbus_new_invalid_opts_error
/**
* wpas_dbus_new_invalid_opts_error - Return a new invalid options error message
* @message: Pointer to incoming dbus message this error refers to
* Returns: a dbus error message
*
* Convenience function to create and return an invalid options error
*/
DBusMessage * wpas_dbus_new_invalid_opts_error(DBusMessage *message,
const char *arg)
{
DBusMessage *reply;
reply = dbus_message_new_error(message, WPAS_ERROR_INVALID_OPTS,
"Did not receive correct message "
"arguments.");
if (arg != NULL)
dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
DBUS_TYPE_INVALID);
return reply;
}
示例5: wpas_dbus_iface_wps_pin
/**
* wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
* @message: Pointer to incoming dbus message
* @wpa_s: %wpa_supplicant data structure
* Returns: A dbus message containing a UINT32 indicating success (1) or
* failure (0)
*
* Handler function for "wpsPin" method call
*/
DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
struct wpa_supplicant *wpa_s)
{
DBusMessage *reply = NULL;
char *arg_bssid;
char *pin = NULL;
u8 bssid[ETH_ALEN], *_bssid = NULL;
int ret = 0;
if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
return wpas_dbus_new_invalid_opts_error(message, NULL);
if (!os_strcmp(arg_bssid, "any"))
_bssid = NULL;
else if (!hwaddr_aton(arg_bssid, bssid))
_bssid = bssid;
else {
return wpas_dbus_new_invalid_opts_error(message,
"Invalid BSSID");
}
if (os_strlen(pin) > 0)
ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
DEV_PW_DEFAULT);
else
ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0,
DEV_PW_DEFAULT);
if (ret < 0) {
return dbus_message_new_error(message,
WPAS_ERROR_WPS_PIN_ERROR,
"Could not init PIN");
}
reply = dbus_message_new_method_return(message);
if (reply == NULL)
return NULL;
if (ret == 0) {
dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
DBUS_TYPE_INVALID);
} else {
char npin[9];
os_snprintf(npin, sizeof(npin), "%08d", ret);
dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
DBUS_TYPE_INVALID);
}
return reply;
}
示例6: error_unknown_method
DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg)
{
char error[128];
const char *signature = dbus_message_get_signature(msg);
const char *method = dbus_message_get_member(msg);
const char *interface = dbus_message_get_interface(msg);
snprintf(error, 128, "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist",
method, signature, interface);
return send_message_and_unref(conn,
dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownMethod",
error));
}
示例7: message_reply
static int
message_reply(lua_State *T)
{
DBusConnection *conn = bus_unbox(T, lua_upvalueindex(1));
struct message_object *m;
DBusMessage *msg;
DBusMessage *reply;
if (conn == NULL) /* connection closed */
return 0;
m = lua_touserdata(T, lua_upvalueindex(2));
msg = m->msg;
if (msg == NULL)
return luaL_error(T, "send reply called twice");
m->msg = NULL;
/* check if the method returned an error */
if (lua_gettop(T) > 0 && lua_isnil(T, 1)) {
const char *name = luaL_checkstring(T, 2);
const char *message = luaL_optstring(T, 3, NULL);
if (message && message[0] == '\0')
message = NULL;
reply = dbus_message_new_error(msg, name, message);
dbus_message_unref(msg);
if (reply == NULL)
return 0;
} else {
const char *signature = luaL_optstring(T, 1, NULL);
reply = dbus_message_new_method_return(msg);
dbus_message_unref(msg);
if (reply == NULL)
return 0;
if (signature && signature[0] != '\0' &&
lem_dbus_add_arguments(T, 2, signature, reply)) {
dbus_message_unref(reply);
/* add_arguments() pushes its own error message */
return luaL_error(T, "%s", lua_tostring(T, -1));
}
}
dbus_connection_send(conn, reply, NULL);
dbus_message_unref(reply);
return 0;
}
示例8: properties_set
static DBusMessage * properties_set(DBusMessage *message,
const struct wpa_dbus_property_desc *dsc,
void *user_data)
{
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
if (os_strcmp(dbus_message_get_signature(message), "ssv")) {
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
NULL);
}
if (dsc->setter == NULL) {
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
"Property is read-only");
}
dbus_message_iter_init(message, &iter);
/* Skip the interface name and the property name */
dbus_message_iter_next(&iter);
dbus_message_iter_next(&iter);
/* Iter will now point to the property's new value */
dbus_error_init(&error);
if (dsc->setter(&iter, &error, user_data) == TRUE) {
/* Success */
reply = dbus_message_new_method_return(message);
} else {
reply = wpas_dbus_reply_new_from_error(
message, &error, DBUS_ERROR_FAILED,
"Failed to set property");
dbus_error_free(&error);
}
return reply;
}
示例9: msg_method_handler
static DBusMessage * msg_method_handler(DBusMessage *message,
struct wpa_dbus_object_desc *obj_dsc)
{
const struct wpa_dbus_method_desc *method_dsc = obj_dsc->methods;
const char *method;
const char *msg_interface;
method = dbus_message_get_member(message);
msg_interface = dbus_message_get_interface(message);
/* try match call to any registered method */
while (method_dsc && method_dsc->dbus_method) {
/* compare method names and interfaces */
if (!os_strncmp(method_dsc->dbus_method, method,
WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) &&
!os_strncmp(method_dsc->dbus_interface, msg_interface,
WPAS_DBUS_INTERFACE_MAX))
break;
method_dsc++;
}
if (method_dsc == NULL || method_dsc->dbus_method == NULL) {
wpa_printf(MSG_DEBUG, "no method handler for %s.%s on %s",
msg_interface, method,
dbus_message_get_path(message));
return dbus_message_new_error(message,
DBUS_ERROR_UNKNOWN_METHOD, NULL);
}
if (!is_signature_correct(message, method_dsc)) {
return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
NULL);
}
return method_dsc->method_handler(message,
obj_dsc->user_data);
}
示例10: handle_get
static DBusHandlerResult handle_get(DBusConnection *conn, DBusMessage *msg, pa_dbusobj_server_lookup *sl) {
DBusHandlerResult r = DBUS_HANDLER_RESULT_HANDLED;
const char* interface;
const char* property;
DBusMessage *reply = NULL;
pa_assert(conn);
pa_assert(msg);
pa_assert(sl);
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
if (!(reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, "Invalid arguments"))) {
r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
goto finish;
}
if (!dbus_connection_send(conn, reply, NULL)) {
r = DBUS_HANDLER_RESULT_NEED_MEMORY;
goto finish;
}
r = DBUS_HANDLER_RESULT_HANDLED;
goto finish;
}
if (*interface && !pa_streq(interface, INTERFACE)) {
r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
goto finish;
}
if (!pa_streq(property, "Address")) {
if (!(reply = dbus_message_new_error_printf(msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s: No such property", property))) {
r = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
goto finish;
}
if (!dbus_connection_send(conn, reply, NULL)) {
r = DBUS_HANDLER_RESULT_NEED_MEMORY;
goto finish;
}
r = DBUS_HANDLER_RESULT_HANDLED;
goto finish;
}
r = handle_get_address(conn, msg, sl);
finish:
if (reply)
dbus_message_unref(reply);
return r;
}
示例11: service_method_unlock_with_master_password
static DBusMessage*
service_method_unlock_with_master_password (GkdSecretService *self, DBusMessage *message)
{
DBusError derr = DBUS_ERROR_INIT;
GkdSecretSecret *master;
GError *error = NULL;
GckObject *collection;
DBusMessageIter iter;
DBusMessage *reply;
const gchar *path;
/* Parse the incoming message */
if (!dbus_message_has_signature (message, "o(oayays)"))
return NULL;
if (!dbus_message_iter_init (message, &iter))
g_return_val_if_reached (NULL);
dbus_message_iter_get_basic (&iter, &path);
dbus_message_iter_next (&iter);
master = gkd_secret_secret_parse (self, message, &iter, &derr);
if (master == NULL)
return gkd_secret_error_to_reply (message, &derr);
/* Make sure we have such a collection */
collection = gkd_secret_objects_lookup_collection (self->objects,
dbus_message_get_sender (message),
path);
/* No such collection */
if (collection == NULL) {
reply = dbus_message_new_error (message, SECRET_ERROR_NO_SUCH_OBJECT,
"The collection does not exist");
/* Success */
} else if (gkd_secret_unlock_with_secret (collection, master, &error)) {
reply = dbus_message_new_method_return (message);
gkd_secret_objects_emit_collection_locked (self->objects, collection);
/* Failure */
} else {
reply = gkd_secret_propagate_error (message, "Couldn't unlock collection", error);
}
gkd_secret_secret_free (master);
if (collection)
g_object_unref (collection);
return reply;
}
示例12: g_dbus_send_error_valist
gboolean g_dbus_send_error_valist(DBusConnection *connection,
DBusMessage *message, const char *name,
const char *format, va_list args)
{
DBusMessage *error;
char str[1024];
vsnprintf(str, sizeof(str), format, args);
error = dbus_message_new_error(message, name, str);
if (error == NULL)
return FALSE;
return g_dbus_send_message(connection, error);
}
示例13:
/**
* Create a new D-Bus error message, with proper error checking
* will exit the mainloop if an error occurs
*
* @param message The DBusMessage that caused the error message to be sent
* @param error The message to send
* @return A new DBusMessage
*/
static DBusMessage *dbus_new_error(DBusMessage *const message,
const gchar *const error)
{
DBusMessage *error_msg;
if ((error_msg = dbus_message_new_error(message, error,
NULL)) == NULL) {
mce_log(LL_CRIT, "No memory for new D-Bus error message!");
// FIXME: this is not how one should exit from mainloop
mce_quit_mainloop();
exit(EXIT_FAILURE);
}
return error_msg;
}
示例14: handle_forget
static DBusMessage*
handle_forget (void *object,
DBusMessage *message,
DBusError *error)
{
const char *notification_path;
const char *resource_id;
DBusMessageIter iter;
dbus_message_iter_init (message, &iter);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) {
return dbus_message_new_error(message,
DBUS_ERROR_INVALID_ARGS,
_("First argument should be an object path (notification_path)"));
}
dbus_message_iter_get_basic(&iter, ¬ification_path);
dbus_message_iter_next (&iter);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
return dbus_message_new_error(message,
DBUS_ERROR_INVALID_ARGS,
_("Second argument should be a string (resource_id)"));
}
dbus_message_iter_get_basic(&iter, &resource_id);
dbus_message_iter_next (&iter);
if (dbus_message_iter_has_next(&iter))
return dbus_message_new_error(message,
DBUS_ERROR_INVALID_ARGS,
_("Too many arguments"));
/* FIXME: Do the forget; change the NULL return to an ACK if we aren't doing something async */
return NULL;
}
示例15: service_method_create_with_master_password
static DBusMessage*
service_method_create_with_master_password (GkdSecretService *self, DBusMessage *message)
{
GckBuilder builder = GCK_BUILDER_INIT;
DBusError derr = DBUS_ERROR_INIT;
DBusMessageIter iter, array;
DBusMessage *reply = NULL;
GkdSecretSecret *secret = NULL;
GckAttributes *attrs = NULL;
GError *error = NULL;
gchar *path;
/* Parse the incoming message */
if (!dbus_message_has_signature (message, "a{sv}(oayays)"))
return NULL;
if (!dbus_message_iter_init (message, &iter))
g_return_val_if_reached (NULL);
dbus_message_iter_recurse (&iter, &array);
if (!gkd_secret_property_parse_all (&array, SECRET_COLLECTION_INTERFACE, &builder)) {
gck_builder_clear (&builder);
return dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS,
"Invalid properties argument");
}
dbus_message_iter_next (&iter);
secret = gkd_secret_secret_parse (self, message, &iter, &derr);
if (secret == NULL) {
gck_builder_clear (&builder);
return gkd_secret_error_to_reply (message, &derr);
}
gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE);
attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
path = gkd_secret_create_with_secret (attrs, secret, &error);
gck_attributes_unref (attrs);
gkd_secret_secret_free (secret);
if (path == NULL)
return gkd_secret_propagate_error (message, "Couldn't create collection", error);
/* Notify the callers that a collection was created */
gkd_secret_service_emit_collection_created (self, path);
reply = dbus_message_new_method_return (message);
dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
g_free (path);
return reply;
}