OSDN Git Service

android: Use common exit path for commands in bt_adapter_handle_cmd
authorSzymon Janc <szymon.janc@tieto.com>
Fri, 25 Oct 2013 15:14:58 +0000 (17:14 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Sun, 27 Oct 2013 11:23:35 +0000 (13:23 +0200)
All adapter commands return no parameters so putting error and success
response on common exit path. This will make function easier to follow
when more commands support will be added.

android/adapter.c

index ec90cca..685b00d 100644 (file)
@@ -374,39 +374,37 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
        case HAL_OP_ENABLE:
                if (adapter->current_settings & MGMT_SETTING_POWERED) {
                        status = HAL_STATUS_DONE;
-                       break;
+                       goto error;
                }
 
-               if (set_mode(MGMT_OP_SET_POWERED, 0x01)) {
-                       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
-                                                                       -1);
-                       return;
-               }
+               if (!set_mode(MGMT_OP_SET_POWERED, 0x01))
+                       goto error;
+
                break;
        case HAL_OP_DISABLE:
                if (!(adapter->current_settings & MGMT_SETTING_POWERED)) {
                        status = HAL_STATUS_DONE;
-                       break;
+                       goto error;
                }
 
-               if (set_mode(MGMT_OP_SET_POWERED, 0x00)) {
-                       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
-                                                                       -1);
-                       return;
-               }
+               if (!set_mode(MGMT_OP_SET_POWERED, 0x00))
+                       goto error;
+
                break;
        case HAL_OP_GET_ADAPTER_PROP:
-               if (get_property(buf, len)) {
-                       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
-                                                                       -1);
-                       return;
-               }
+               if (!get_property(buf, len))
+                       goto error;
+
                break;
        default:
                DBG("Unhandled command, opcode 0x%x", opcode);
-               break;
+               goto error;
        }
 
+       ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL, -1);
+       return;
+
+error:
        ipc_send_rsp(io, HAL_SERVICE_ID_BLUETOOTH, status);
 }