diff options
author | Szymon Janc <szymon.janc@tieto.com> | 2014-09-18 14:05:34 +0200 |
---|---|---|
committer | Szymon Janc <szymon.janc@tieto.com> | 2014-09-18 16:36:04 +0200 |
commit | 60092ba350aac5fdb1991ab68383ebe77a972e91 (patch) | |
tree | 95b747ef7e6c1d0dbd6f04e7f56792b26128ed3a /android/main.c | |
parent | 7ff234607a4c4e4b58ea8cc209e00efc6d3ef191 (diff) | |
download | bluez-60092ba350aac5fdb1991ab68383ebe77a972e91.tar.gz |
android: Factor out service unregister to helper
Diffstat (limited to 'android/main.c')
-rw-r--r-- | android/main.c | 73 |
1 files changed, 21 insertions, 52 deletions
diff --git a/android/main.c b/android/main.c index 5652331e2..f1b5ac745 100644 --- a/android/main.c +++ b/android/main.c @@ -170,17 +170,12 @@ failed: status); } -static void service_unregister(const void *buf, uint16_t len) +static bool unregister_service(uint8_t id) { - const struct hal_cmd_unregister_module *m = buf; - uint8_t status; - - if (m->service_id > HAL_SERVICE_ID_MAX || !services[m->service_id]) { - status = HAL_STATUS_FAILED; - goto failed; - } + if (id > HAL_SERVICE_ID_MAX || !services[id]) + return false; - switch (m->service_id) { + switch (id) { case HAL_SERVICE_ID_BLUETOOTH: bt_bluetooth_unregister(); break; @@ -212,17 +207,25 @@ static void service_unregister(const void *buf, uint16_t len) bt_hf_client_unregister(); break; default: - /* - * This would indicate bug in HAL, as unregister should not be - * called in init failed - */ - DBG("service %u not supported", m->service_id); + DBG("service %u not supported", id); + return false; + } + + services[id] = false; + + return true; +} + +static void service_unregister(const void *buf, uint16_t len) +{ + const struct hal_cmd_unregister_module *m = buf; + uint8_t status; + + if (!unregister_service(m->service_id)) { status = HAL_STATUS_FAILED; goto failed; } - services[m->service_id] = false; - status = HAL_STATUS_SUCCESS; info("Service ID=%u unregistered", m->service_id); @@ -393,42 +396,8 @@ static void cleanup_services(void) DBG(""); - for (i = HAL_SERVICE_ID_MAX; i > HAL_SERVICE_ID_CORE; i--) { - if (!services[i]) - continue; - - switch (i) { - case HAL_SERVICE_ID_BLUETOOTH: - bt_bluetooth_unregister(); - break; - case HAL_SERVICE_ID_SOCKET: - bt_socket_unregister(); - break; - case HAL_SERVICE_ID_HIDHOST: - bt_hid_unregister(); - break; - case HAL_SERVICE_ID_A2DP: - bt_a2dp_unregister(); - break; - case HAL_SERVICE_ID_AVRCP: - bt_avrcp_unregister(); - break; - case HAL_SERVICE_ID_PAN: - bt_pan_unregister(); - break; - case HAL_SERVICE_ID_HANDSFREE: - bt_handsfree_unregister(); - break; - case HAL_SERVICE_ID_GATT: - bt_gatt_unregister(); - break; - case HAL_SERVICE_ID_HEALTH: - bt_health_unregister(); - break; - } - - services[i] = false; - } + for (i = HAL_SERVICE_ID_MAX; i > HAL_SERVICE_ID_CORE; i--) + unregister_service(i); } static bool set_capabilities(void) |