From: Pekka Pessi pekka.pe...@nokia.com
Use call_ofono() wrapper.
---
plugins/ofono.c | 267 ---
1 files changed, 75 insertions(+), 192 deletions(-)
diff --git a/plugins/ofono.c b/plugins/ofono.c
index e5d4187..9ad8708 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -79,6 +79,56 @@ static void modem_remove(struct connman_device *device)
DBG(device %p, device);
}
+static int call_ofono(const char *path,
+ const char *interface, const char *method,
+ DBusPendingCallNotifyFunction notify, void *user_data,
+ DBusFreeFunction free_function,
+ int type, ...)
+{
+ DBusMessage *message;
+ DBusPendingCall *call;
+ dbus_bool_t ok;
+ va_list va;
+
+ DBG(path %s %s.%s, path, interface, method);
+
+ if (path == NULL)
+ return -EINVAL;
+
+ message = dbus_message_new_method_call(OFONO_SERVICE, path,
+ interface, method);
+ if (message == NULL)
+ return -ENOMEM;
+
+ dbus_message_set_auto_start(message, FALSE);
+
+ va_start(va, type);
+ ok = dbus_message_append_args_valist(message, type, va);
+ va_end(va);
+
+ if (!ok)
+ return -ENOMEM;
+
+ if (dbus_connection_send_with_reply(connection, message,
+ call, TIMEOUT) == FALSE) {
+ connman_error(Failed to call %s.%s, interface, method);
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ if (call == NULL) {
+ connman_error(D-Bus connection not available);
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ dbus_pending_call_set_notify(call, notify, user_data, free_function);
+
+ dbus_message_unref(message);
+
+ return -EINPROGRESS;
+}
+
static void set_property_reply(DBusPendingCall *call, void *user_data)
{
DBusMessage *reply;
@@ -289,8 +339,6 @@ done:
static void set_network_name(struct connman_network *network)
{
struct connman_device *device;
- DBusMessage *message;
- DBusPendingCall *call;
const char *path;
device = connman_network_get_device(network);
@@ -301,29 +349,9 @@ static void set_network_name(struct connman_network
*network)
DBG(path %s, path);
- message = dbus_message_new_method_call(OFONO_SERVICE, path,
- OFONO_REGISTRATION_INTERFACE, GET_PROPERTIES);
- if (message == NULL)
- return;
-
- dbus_message_set_auto_start(message, FALSE);
-
- if (dbus_connection_send_with_reply(connection, message,
- call, TIMEOUT) == FALSE) {
- connman_error(Failed to get operator name);
- goto done;
- }
-
- if (call == NULL) {
- connman_error(D-Bus connection not available);
- goto done;
- }
-
- dbus_pending_call_set_notify(call, set_network_name_reply,
- (void *)network, NULL);
-
-done:
- dbus_message_unref(message);
+ call_ofono(path, OFONO_REGISTRATION_INTERFACE, GET_PROPERTIES,
+ set_network_name_reply, network, NULL,
+ DBUS_TYPE_INVALID);
}
static void config_network_reply(DBusPendingCall *call, void *user_data)
@@ -384,34 +412,11 @@ done:
static void config_network(struct connman_network *network, const char *path)
{
- DBusMessage *message;
- DBusPendingCall *call;
-
DBG(path %s, path);
- message = dbus_message_new_method_call(OFONO_SERVICE, path,
- OFONO_PRI_CONTEXT_INTERFACE, GET_PROPERTIES);
- if (message == NULL)
- return;
-
- dbus_message_set_auto_start(message, FALSE);
-
- if (dbus_connection_send_with_reply(connection, message,
- call, TIMEOUT) == FALSE) {
- connman_error(Failed to get Primary Context);
- goto done;
- }
-
- if (call == NULL) {
- connman_error(D-Bus connection not available);
- goto done;
- }
-
- dbus_pending_call_set_notify(call, config_network_reply,
- (void *)network, NULL);
-
-done:
- dbus_message_unref(message);
+ ofono_call(path, OFONO_PRI_CONTEXT_INTERFACE, GET_PROPERTIES,
+ config_network_reply, network, NULL,
+ DBUS_TYPE_INVALID);
}
static gboolean registration_changed(DBusConnection *connection,
@@ -740,33 +745,11 @@ static void add_default_context(DBusMessageIter *array,
DBG(path %s, name %s, type %s, path, name, type);
- message =