From: Marcel Holtmann Date: Sun, 30 Aug 2009 05:50:54 +0000 (-0700) Subject: Add support for handling errors from agent registration X-Git-Tag: 0.40~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2afb01c31fad5b0e814eb13389ded499dcd8d88b;p=platform%2Fupstream%2Fconnman.git Add support for handling errors from agent registration --- diff --git a/src/agent.c b/src/agent.c index 42a126e..82f6146 100644 --- a/src/agent.c +++ b/src/agent.c @@ -75,7 +75,7 @@ int __connman_agent_unregister(const char *sender, const char *path) DBG("sender %s path %s", sender, path); if (agent_path == NULL) - return -ENOENT; + return -ESRCH; if (agent_watch > 0) g_dbus_remove_watch(connection, agent_watch); diff --git a/src/connman.h b/src/connman.h index af11c29..81343dd 100644 --- a/src/connman.h +++ b/src/connman.h @@ -36,6 +36,7 @@ DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum); DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg); DBusMessage *__connman_error_permission_denied(DBusMessage *msg); DBusMessage *__connman_error_passphrase_required(DBusMessage *msg); +DBusMessage *__connman_error_not_registered(DBusMessage *msg); DBusMessage *__connman_error_not_supported(DBusMessage *msg); DBusMessage *__connman_error_not_implemented(DBusMessage *msg); DBusMessage *__connman_error_not_found(DBusMessage *msg); diff --git a/src/error.c b/src/error.c index 4217091..6021f4c 100644 --- a/src/error.c +++ b/src/error.c @@ -35,6 +35,8 @@ DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum) const char *str = strerror(errnum); switch (errnum) { + case ESRCH: + return __connman_error_not_registered(msg); case ENXIO: return __connman_error_not_found(msg); case EACCES: @@ -85,6 +87,12 @@ DBusMessage *__connman_error_passphrase_required(DBusMessage *msg) ".PassphraseRequired", "Passphrase required"); } +DBusMessage *__connman_error_not_registered(DBusMessage *msg) +{ + return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE + ".NotRegistered", "Not registered"); +} + DBusMessage *__connman_error_not_supported(DBusMessage *msg) { return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE diff --git a/src/manager.c b/src/manager.c index 8acb317..e761ce8 100644 --- a/src/manager.c +++ b/src/manager.c @@ -579,8 +579,8 @@ static DBusMessage *connect_service(DBusConnection *conn, static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *path; + int err; DBG("conn %p", conn); @@ -589,22 +589,18 @@ static DBusMessage *register_agent(DBusConnection *conn, dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - __connman_agent_register(sender, path); + err = __connman_agent_register(sender, path); + if (err < 0) + return __connman_error_failed(msg, -err); - return reply; + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } static DBusMessage *unregister_agent(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *path; + int err; DBG("conn %p", conn); @@ -613,15 +609,11 @@ static DBusMessage *unregister_agent(DBusConnection *conn, dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - __connman_agent_unregister(sender, path); + err = __connman_agent_unregister(sender, path); + if (err < 0) + return __connman_error_failed(msg, -err); - return reply; + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } static GDBusMethodTable manager_methods[] = {