From: Atul Rai Date: Fri, 1 Jul 2016 06:43:21 +0000 (+0900) Subject: [Adapt] Implement is_service_used API X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a78e4f8fe43ea0335481da95bbf73b9291531bd;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git [Adapt] Implement is_service_used API This patch implements is_service_used() API to check if user specified service is enabled for local adapter. Change-Id: Ic29fce509cf49ecea2074ad2437c3ff300b05572 Signed-off-by: Atul Rai --- diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c index 6e6c0e6..731fd6e 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c @@ -938,6 +938,118 @@ int _bt_hal_dbus_get_local_address(void) return BT_STATUS_SUCCESS; } +/* Get Local services API and callback */ +static gboolean __bt_adapter_service_uuids_cb(gpointer user_data) +{ + GVariant *result = user_data; + GVariant *temp; + GVariantIter *iter = NULL; + gchar *uuid_str; + + /* Buffer and propety count management */ + uint8_t buf[BT_MAX_PROPERTY_BUF_SIZE]; + struct hal_ev_adapter_props_changed *ev = (void*) buf; + size_t size = 0; + + /* UUID collection */ + uint8_t uuids[HAL_UUID_LEN * MAX_UUID_COUNT]; + int uuid_count = 0; + + memset(buf, 0, sizeof(buf)); + size = sizeof(*ev); + ev->num_props = 0; + ev->status = BT_STATUS_SUCCESS; + + g_variant_get(result, "(v)", &temp); + g_variant_get(temp, "as", &iter); + if (iter == NULL) { + ERR("Failed to get UUIDs"); + goto fail; + } + + while (g_variant_iter_loop(iter, "s", &uuid_str)) { + uint8_t uuid[HAL_UUID_LEN]; + + DBG("UUID string [%s]\n", uuid_str); + _bt_convert_uuid_string_to_type(uuid, uuid_str); + memcpy(uuids + uuid_count * HAL_UUID_LEN, uuid, HAL_UUID_LEN); + uuid_count++; + } + + size += __bt_insert_hal_properties(buf + size, + HAL_PROP_ADAPTER_UUIDS, + (HAL_UUID_LEN * uuid_count), + uuids); + ev->num_props++; + + if (size > 2) { + DBG("Send Adapter properties changed event to HAL user," + " Num Prop [%d] total size [%d]", ev->num_props, size); + event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size); + } + + g_variant_iter_free(iter); + g_variant_unref(result); + g_variant_unref(temp); + return FALSE; + +fail: + ev->status = BT_STATUS_FAIL; + ev->num_props = 0; + DBG("Send Adapter properties changed event to HAL user," + " Num Prop [%d] total size [%d]", ev->num_props, size); + event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size); + + g_variant_unref(result); + return FALSE; +} + +int _bt_hal_dbus_get_adapter_supported_uuids(void) +{ + GDBusProxy *proxy; + GError *error = NULL; + GVariant *result; + + DBG("+"); + + proxy = _bt_get_adapter_properties_proxy(); + + if (!proxy) { + DBG("_bt_hal_dbus_get_local_name: Adapter Properties proxy get failed!!!"); + return BT_STATUS_FAIL; + } + + result = g_dbus_proxy_call_sync(proxy, + "Get", + g_variant_new("(ss)", BT_ADAPTER_INTERFACE, + "UUIDs"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (!result) { + if (error != NULL) { + ERR("Failed to get UUIDs (Error: %s)", error->message); + g_clear_error(&error); + } else + ERR("Failed to get UUIDs"); + return BT_STATUS_FAIL; + } + + + DBG("Got All Adaptr service UUID's from Bluez Stack!!, time to start parsing"); + + /* + * As we need to provide async callback to user from HAL, simply schedule a + * callback method which will carry actual result + */ + g_idle_add(__bt_adapter_service_uuids_cb, (gpointer)result); + + DBG("-"); + return BT_STATUS_SUCCESS; +} + int _bt_hal_dbus_get_adapter_property(bt_property_type_t property_type) { DBG("+"); @@ -958,7 +1070,7 @@ int _bt_hal_dbus_get_adapter_property(bt_property_type_t property_type) case BT_PROPERTY_CLASS_OF_DEVICE: return BT_STATUS_UNSUPPORTED; case BT_PROPERTY_UUIDS: - return BT_STATUS_UNSUPPORTED; + return _bt_hal_dbus_get_adapter_supported_uuids(); case BT_PROPERTY_ADAPTER_BONDED_DEVICES: return BT_STATUS_UNSUPPORTED; default: diff --git a/bt-oal/include/oal-adapter-mgr.h b/bt-oal/include/oal-adapter-mgr.h index b0a0ffc..4873a1d 100755 --- a/bt-oal/include/oal-adapter-mgr.h +++ b/bt-oal/include/oal-adapter-mgr.h @@ -116,6 +116,18 @@ oal_status_t adapter_is_connectable(int *p_connectable); */ oal_status_t adapter_get_discoverable_timeout(int *p_timeout); +/** + * @brief Get List of UUIDs for services supported + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + * + * @see OAL_EVENT_ADAPTER_PROPERTY_SERVICES + */ +oal_status_t adapter_get_service_uuids(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index 33bd6d2..b263c4c 100755 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -237,6 +237,23 @@ oal_status_t adapter_get_discoverable_timeout(int *p_timeout) return OAL_STATUS_SUCCESS; } +oal_status_t adapter_get_service_uuids(void) +{ + int ret; + + CHECK_OAL_INITIALIZED(); + + API_TRACE(); + + ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS); + if (ret != BT_STATUS_SUCCESS) { + BT_ERR("get_adapter_property failed: [%s]", status2string(ret)); + return convert_to_oal_status(ret); + } + + return OAL_STATUS_SUCCESS; +} + static void cb_adapter_properties (bt_status_t status, int num_properties, bt_property_t *properties) diff --git a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c index d2efaca..83e8997 100644 --- a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c +++ b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c @@ -188,6 +188,24 @@ int _bt_get_discoverable_mode(int *mode) return BLUETOOTH_ERROR_NONE; } +int _bt_is_service_used(void) +{ + int result; + + BT_DBG("+"); + + result = adapter_get_service_uuids(); + if (result != OAL_STATUS_SUCCESS) { + BT_ERR("adapter_get_service_uuids failed: %d", result); + result = BLUETOOTH_ERROR_INTERNAL; + } else { + result = BLUETOOTH_ERROR_NONE; + } + + BT_DBG("-"); + return result; +} + static void __bt_adapter_event_handler(int event_type, gpointer event_data) { BT_DBG("+"); @@ -262,6 +280,16 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data) BT_INFO("Discoverable timeout: [%d]", *timeout); break; } + case OAL_EVENT_ADAPTER_PROPERTY_SERVICES: { + int count; + service_uuid_t *service_list; + event_adapter_services_t *list = event_data; + + count = list->num; + service_list = list->service_list; + __bt_adapter_handle_pending_requests(BT_IS_SERVICE_USED, service_list, count); + break; + } default: BT_ERR("Unhandled event.."); break; @@ -326,6 +354,29 @@ static void __bt_adapter_handle_pending_requests(int service_function, void *use case BT_GET_LOCAL_VERSION: g_array_append_vals(out_param, user_data, size); break; + case BT_IS_SERVICE_USED: { + int i; + gboolean used = FALSE; + unsigned char *uuid; + char uuid_str[BT_UUID_STRING_SIZE]; + char *request_uuid = req_info->user_data; + service_uuid_t *service_list = user_data; + + BT_INFO("Check for service uuid: %s", request_uuid); + for (i = 0; i < size; i++) { + uuid = service_list[i].uuid; + _bt_service_convert_uuid_type_to_string(uuid_str, uuid); + BT_INFO("Adapter Service: [%s]", uuid_str); + if (strcasecmp(uuid_str, request_uuid) == 0) { + BT_INFO("UUID matched!!"); + used = TRUE; + break; + } + } + + g_array_append_vals(out_param, &used, sizeof(gboolean)); + break; + } default: BT_ERR("Unknown service function[%d]", service_function); } diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index ea19c68..d047552 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -414,6 +414,21 @@ int __bt_bluez_request(int function_name, g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int)); break; } + case BT_IS_SERVICE_USED: { + char *uuid = NULL; + + uuid = (char *)g_variant_get_data(in_param1); + BT_INFO("UUID to be searched [%s]", uuid); + result = _bt_is_service_used(); + + /* Save invocation */ + if (result == BLUETOOTH_ERROR_NONE) { + sender = (char*)g_dbus_method_invocation_get_sender(context); + _bt_save_invocation_context(context, result, sender, + function_name, (gpointer)uuid); + } + break; + } default: BT_INFO("UnSupported function [%d]", function_name); result = BLUETOOTH_ERROR_NOT_SUPPORT; diff --git a/bt-service-adaptation/services/bt-service-util.c b/bt-service-adaptation/services/bt-service-util.c index 635f428..6454b6a 100755 --- a/bt-service-adaptation/services/bt-service-util.c +++ b/bt-service-adaptation/services/bt-service-util.c @@ -146,3 +146,13 @@ void _bt_clear_request_list(void) } } +void _bt_service_convert_uuid_type_to_string(char *str, const unsigned char *uuid) +{ + ret_if(str == NULL); + ret_if(uuid == NULL); + + g_snprintf(str, BT_UUID_STRING_SIZE, + "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", + uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); +} diff --git a/bt-service-adaptation/services/include/bt-service-core-adapter.h b/bt-service-adaptation/services/include/bt-service-core-adapter.h index 06c35b9..7151216 100755 --- a/bt-service-adaptation/services/include/bt-service-core-adapter.h +++ b/bt-service-adaptation/services/include/bt-service-core-adapter.h @@ -55,6 +55,8 @@ int _bt_get_local_name(void); int _bt_get_discoverable_mode(int *mode); +int _bt_is_service_used(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-service-adaptation/services/include/bt-service-util.h b/bt-service-adaptation/services/include/bt-service-util.h index edb42b4..75df082 100755 --- a/bt-service-adaptation/services/include/bt-service-util.h +++ b/bt-service-adaptation/services/include/bt-service-util.h @@ -27,6 +27,7 @@ extern "C" { #endif /* __cplusplus */ #define BT_NODE_NAME_LEN 50 +#define BT_UUID_STRING_SIZE 37 typedef struct { int req_id; @@ -54,6 +55,8 @@ request_info_t *_bt_get_request_info(int req_id); void _bt_clear_request_list(void); +void _bt_service_convert_uuid_type_to_string(char *str, const unsigned char *uuid); + #ifdef __cplusplus } #endif /* __cplusplus */