OSDN Git Service

android: Fix bt_adapter_init
authorSzymon Janc <szymon.janc@gmail.com>
Thu, 24 Oct 2013 09:54:21 +0000 (11:54 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 24 Oct 2013 15:31:33 +0000 (18:31 +0300)
Make bt_adapter_init return void and use ready callback for error
reporting. This also fix returning incorrect status and invalid
mgmt_if unref (mgmt_send return 0 on error or >0 on success).

android/adapter.c
android/adapter.h

index 88ac19f..160623a 100644 (file)
@@ -277,24 +277,22 @@ failed:
        adapter->ready(NULL, err);
 }
 
-bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
-                                               bt_adapter_ready ready)
+void bt_adapter_init(uint16_t index, struct mgmt *mgmt, bt_adapter_ready cb)
 {
        struct bt_adapter *adapter;
 
        adapter = g_new0(struct bt_adapter, 1);
 
-       adapter->mgmt = mgmt_ref(mgmt_if);
+       adapter->mgmt = mgmt_ref(mgmt);
        adapter->index = index;
-       adapter->ready = ready;
+       adapter->ready = cb;
 
-       if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
-                               read_info_complete, adapter, NULL) > 0) {
-               mgmt_unref(mgmt_if);
-               return false;
-       }
+       if (mgmt_send(mgmt, MGMT_OP_READ_INFO, index, 0, NULL,
+                               read_info_complete, adapter, NULL) > 0)
+               return;
 
-       return adapter;
+       mgmt_unref(mgmt);
+       adapter->ready(adapter, -EIO);
 }
 
 static void set_mode_complete(uint8_t status, uint16_t length,
index b8d0a58..236f10a 100644 (file)
@@ -32,8 +32,8 @@ struct bt_adapter;
 
 typedef void (*bt_adapter_ready)(struct bt_adapter *adapter, int err);
 
-bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
-                                               bt_adapter_ready func);
+void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
+                                                       bt_adapter_ready cb);
 
 void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
                                                                uint16_t len);