Merge tag 'upstream/1.40' into tizen.
[platform/upstream/connman.git] / src / device.c
index d0825ce..5116900 100755 (executable)
@@ -76,7 +76,10 @@ struct connman_device {
        time_t last_user_selection_time;
        char *last_user_selection_ident;
        char *last_connected_ident;
-       DBusMessage *pending_reply;
+       GList *pending_reply_list; /* List of DBusMessage* for async reply to multiple
+                                   * device power dbus calls, which are made before
+                                   * connman_device_set_powered().
+                                   */
        int max_scan_ssids;
        bool is_5_0_ghz_supported;
        unsigned int mac_policy;
@@ -85,12 +88,21 @@ struct connman_device {
 #endif
 };
 
+#if defined TIZEN_EXT
+static void __clear_pending_trigger(gpointer data, gpointer user_data)
+{
+       DBusMessage *msg = (DBusMessage *)data;
+       dbus_message_unref(msg);
+}
+#endif
+
 static void clear_pending_trigger(struct connman_device *device)
 {
 #if defined TIZEN_EXT
-       if (device->pending_reply) {
-               dbus_message_unref(device->pending_reply);
-               device->pending_reply = NULL;
+       if (device->pending_reply_list) {
+               g_list_foreach(device->pending_reply_list, __clear_pending_trigger, NULL);
+               g_list_free(device->pending_reply_list);
+               device->pending_reply_list = NULL;
        }
 #endif
        if (device->pending_timeout > 0) {
@@ -200,6 +212,20 @@ static bool device_has_service_type(struct connman_device *device,
        return service_type == device_service_type;
 }
 
+#if defined TIZEN_EXT
+static void __device_pending_reset(gpointer data, gpointer user_data)
+{
+       DBusMessage *msg = (DBusMessage *)data;
+       DBusMessage *reply;
+
+       reply = __connman_error_failed(msg, ETIMEDOUT);
+       if (reply)
+               g_dbus_send_message(connection, reply);
+
+       dbus_message_unref(msg);
+}
+#endif
+
 static gboolean device_pending_reset(gpointer user_data)
 {
        struct connman_device *device = user_data;
@@ -207,16 +233,11 @@ static gboolean device_pending_reset(gpointer user_data)
        DBG("device %p", device);
 
 #if defined TIZEN_EXT
-       DBusMessage *reply;
-
        /* Power request timed out, send ETIMEDOUT. */
-       if (device->pending_reply) {
-               reply = __connman_error_failed(device->pending_reply, ETIMEDOUT);
-               if (reply)
-                       g_dbus_send_message(connection, reply);
-
-               dbus_message_unref(device->pending_reply);
-               device->pending_reply = NULL;
+       if (device->pending_reply_list) {
+               g_list_foreach(device->pending_reply_list, __device_pending_reset, NULL);
+               g_list_free(device->pending_reply_list);
+               device->pending_reply_list = NULL;
        }
 #endif
        /* Power request timedout, reset power pending state. */
@@ -277,11 +298,11 @@ int __connman_device_enable(struct connman_device *device)
        }
        /*
         * if err == -EINPROGRESS, then the DBus call to the respective daemon
-        * was successful. We set a 10 sec timeout so if the daemon never
+        * was successful. We set a 4 sec timeout so if the daemon never
         * returns a reply, we would reset the pending request.
         */
        if (err == -EINPROGRESS)
-               device->pending_timeout = g_timeout_add_seconds(10,
+               device->pending_timeout = g_timeout_add_seconds(4,
                                        device_pending_reset, device);
 done:
        return err;
@@ -506,13 +527,19 @@ static void device_send_changed(const char *ifname, enum connman_service_type ty
        dbus_message_unref(signal);
 }
 
+static void __device_send_reply(gpointer data, gpointer user_data)
+{
+       DBusMessage *msg = (DBusMessage *)data;
+       g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
+       dbus_message_unref(msg);
+}
+
 static void device_send_reply(struct connman_device *device)
 {
-       if (device->pending_reply) {
-               g_dbus_send_reply(connection,
-                               device->pending_reply, DBUS_TYPE_INVALID);
-               dbus_message_unref(device->pending_reply);
-               device->pending_reply = NULL;
+       if (device->pending_reply_list) {
+               g_list_foreach(device->pending_reply_list, __device_send_reply, NULL);
+               g_list_free(device->pending_reply_list);
+               device->pending_reply_list = NULL;
        }
 }
 #endif
@@ -853,7 +880,9 @@ const char *connman_device_get_last_connected_ident(struct connman_device *devic
 {
        return device->last_connected_ident;
 }
+#endif
 
+#if defined TIZEN_EXT && defined TIZEN_EXT_INS
 void connman_device_save_last_user_selection(struct connman_device *device)
 {
        GKeyFile *keyfile;
@@ -987,7 +1016,7 @@ void connman_device_load_last_connected(struct connman_device *device)
 
        g_key_file_free(keyfile);
 }
-#endif
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
 
 static void mark_network_available(gpointer key, gpointer value,
                                                        gpointer user_data)
@@ -1220,7 +1249,7 @@ struct connman_network *connman_device_get_default_network(
 void connman_device_set_pending_reply(struct connman_device *device,
                                                        DBusMessage *msg)
 {
-       device->pending_reply = dbus_message_ref(msg);
+       device->pending_reply_list = g_list_prepend(device->pending_reply_list, dbus_message_ref(msg));
 }
 
 void connman_device_send_connected_signal(struct connman_device *device,
@@ -2021,10 +2050,10 @@ struct connman_device *connman_device_create_from_index(int index)
 
        connman_device_set_index(device, index);
        connman_device_set_interface(device, devname);
-#if defined TIZEN_EXT
+#if defined TIZEN_EXT && defined TIZEN_EXT_INS
        connman_device_load_last_connected(device);
        connman_device_load_last_user_selection(device);
-#endif
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
 
        if (ident) {
                connman_device_set_ident(device, ident);