From 7f5e9f73abe64c790d75e92b775eb7f040a8ffe3 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Thu, 2 Dec 2010 16:09:14 +0200 Subject: [PATCH] agent: Agent API ReportError method call The __connman_agent_report_error function creates and sends a ReportError method call to the registered agent. The agent can reply with D-Bus error org.moblin.connman.Agent.Error.Retry if the same service is to be retried. --- src/agent.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/connman.h | 7 ++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/agent.c b/src/agent.c index 2fadf63..d000a56 100644 --- a/src/agent.c +++ b/src/agent.c @@ -215,6 +215,91 @@ int __connman_agent_request_input(struct connman_service *service, return -EIO; } +struct report_error_data { + struct connman_service *service; + report_error_cb_t callback; + void *user_data; +}; + +static void report_error_reply(DBusPendingCall *call, void *user_data) +{ + struct report_error_data *report_error = user_data; + DBusMessage *reply = dbus_pending_call_steal_reply(call); + gboolean retry = FALSE; + const char *dbus_err; + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + dbus_err = dbus_message_get_error_name(reply); + if (dbus_err != NULL && + strcmp(dbus_err, + CONNMAN_AGENT_INTERFACE ".Error.Retry") == 0) + retry = TRUE; + } + + report_error->callback(report_error->service, retry, + report_error->user_data); + connman_service_unref(report_error->service); + g_free(report_error); + dbus_message_unref(reply); +} + +int __connman_agent_report_error(struct connman_service *service, + const char *error, + report_error_cb_t callback, void *user_data) +{ + DBusMessage *message; + DBusMessageIter iter; + const char *path; + struct report_error_data *report_error; + DBusPendingCall *call; + + if (service == NULL || agent_path == NULL || error == NULL || + callback == NULL) + return -ESRCH; + + message = dbus_message_new_method_call(agent_sender, agent_path, + CONNMAN_AGENT_INTERFACE, + "ReportError"); + if (message == NULL) + return -ENOMEM; + + dbus_message_iter_init_append(message, &iter); + + path = __connman_service_get_path(service); + dbus_message_iter_append_basic(&iter, + DBUS_TYPE_OBJECT_PATH, &path); + dbus_message_iter_append_basic(&iter, + DBUS_TYPE_STRING, &error); + + report_error = g_try_new0(struct report_error_data, 1); + if (report_error == NULL) { + dbus_message_unref(message); + return -ENOMEM; + } + + if (dbus_connection_send_with_reply(connection, message, + &call, -1) == FALSE) { + dbus_message_unref(message); + g_free(report_error); + return -ESRCH; + } + + if (call == NULL) { + dbus_message_unref(message); + g_free(report_error); + return -ESRCH; + } + + report_error->service = connman_service_ref(service); + report_error->callback = callback; + report_error->user_data = user_data; + dbus_pending_call_set_notify(call, report_error_reply, + report_error, NULL); + dbus_message_unref(message); + + return -EIO; +} + int __connman_agent_init(void) { DBG(""); diff --git a/src/connman.h b/src/connman.h index a2ffe10..6e2105a 100644 --- a/src/connman.h +++ b/src/connman.h @@ -79,9 +79,14 @@ struct connman_service *service; typedef void (* passphrase_cb_t) (struct connman_service *service, const char *passphrase, void *user_data); - +typedef void (* report_error_cb_t) (struct connman_service *service, + gboolean retry, void *user_data); int __connman_agent_request_input(struct connman_service *service, passphrase_cb_t callback, void *user_data); +int __connman_agent_report_error(struct connman_service *service, + const char *error, + report_error_cb_t callback, void *user_data); + #include -- 2.7.4