diff options
Diffstat (limited to 'plugins/lib')
-rw-r--r-- | plugins/lib/bluetooth/hal-bt-cb.c | 23 | ||||
-rw-r--r-- | plugins/lib/bluetooth/hal-bt-cb.h | 12 | ||||
-rw-r--r-- | plugins/lib/bluetooth/hal-bt-data.c | 68 | ||||
-rw-r--r-- | plugins/lib/bluetooth/hal-bt-data.h | 6 | ||||
-rw-r--r-- | plugins/lib/bluetooth/hal-bt.c | 24 |
5 files changed, 67 insertions, 66 deletions
diff --git a/plugins/lib/bluetooth/hal-bt-cb.c b/plugins/lib/bluetooth/hal-bt-cb.c index dad6aa0..c75830d 100644 --- a/plugins/lib/bluetooth/hal-bt-cb.c +++ b/plugins/lib/bluetooth/hal-bt-cb.c @@ -92,7 +92,7 @@ void HalBtSetStreamingStatus(AFB_ReqT request) AFB_ReqSuccess(request, NULL, "Bluetooth streaming status successfully set"); } -void HalBtGetConnectedBluetoothDevices(AFB_ReqT request) +void HalBtGetA2DPBluetoothDevices(AFB_ReqT request) { struct HalBtPluginData *localHalBtPluginData; struct HalBtDeviceData *currentBtDeviceData; @@ -105,7 +105,7 @@ void HalBtGetConnectedBluetoothDevices(AFB_ReqT request) } if(! (currentBtDeviceData = localHalBtPluginData->first)) { - AFB_ReqSuccess(request, NULL, "No bluetooth device connected"); + AFB_ReqSuccess(request, NULL, "No A2DP bluetooth device connected"); return; } @@ -120,17 +120,16 @@ void HalBtGetConnectedBluetoothDevices(AFB_ReqT request) "{s:s s:s s:s s:b}", "Hci", currentBtDeviceData->hci, "Name", currentBtDeviceData->name, - "Address", currentBtDeviceData->address, - "A2dp", currentBtDeviceData->a2dp); + "Address", currentBtDeviceData->address); json_object_array_add(requestAnswer, currentBtDeviceObjectJ); currentBtDeviceData = currentBtDeviceData->next; } - AFB_ReqSuccess(request, requestAnswer, "Connected bluetooth devices list"); + AFB_ReqSuccess(request, requestAnswer, "Connected A2DP bluetooth devices list"); } -void HalBtGetSelectedBluetoothDevice(AFB_ReqT request) +void HalBtGetSelectedA2DPBluetoothDevice(AFB_ReqT request) { struct HalBtPluginData *localHalBtPluginData; @@ -150,13 +149,12 @@ void HalBtGetSelectedBluetoothDevice(AFB_ReqT request) "{s:s s:s s:s s:b}", "Hci", localHalBtPluginData->selectedBtDevice->hci, "Name", localHalBtPluginData->selectedBtDevice->name, - "Address", localHalBtPluginData->selectedBtDevice->address, - "A2dp", localHalBtPluginData->selectedBtDevice->a2dp); + "Address", localHalBtPluginData->selectedBtDevice->address); AFB_ReqSuccess(request, selectedBtDeviceObject, "Selected Bluetooth device"); } -void HalBtSetSelectedBluetoothDevice(AFB_ReqT request) +void HalBtSetSelectedA2DPBluetoothDevice(AFB_ReqT request) { char *requestedBtDeviceToSelect; @@ -188,12 +186,7 @@ void HalBtSetSelectedBluetoothDevice(AFB_ReqT request) } if(! (selectedBtDeviceData = HalBtDataSearchBtDeviceByAddress(&localHalBtPluginData->first, requestedBtDeviceToSelect))) { - AFB_ReqFail(request, "requested_device_to_select", "Requested bluetooth device to select is not currently connected"); - return; - } - - if(! selectedBtDeviceData->a2dp) { - AFB_ReqFail(request, "requested_device_to_select", "Requested bluetooth device to select is not able to use A2DP profile"); + AFB_ReqFail(request, "requested_device_to_select", "Requested A2DP bluetooth device to select is not currently connected"); return; } diff --git a/plugins/lib/bluetooth/hal-bt-cb.h b/plugins/lib/bluetooth/hal-bt-cb.h index 2d23d26..f0f1052 100644 --- a/plugins/lib/bluetooth/hal-bt-cb.h +++ b/plugins/lib/bluetooth/hal-bt-cb.h @@ -26,15 +26,15 @@ #define HAL_BT_GET_STREAMING_STATUS_VERB "get_bt_streaming_status" #define HAL_BT_SET_STREAMING_STATUS_VERB "set_bt_streaming_status" -#define HAL_BT_GET_CONNECTED_DEVICES_VERB "get_connected_bt_devices" -#define HAL_BT_GET_SELECTED_DEVICE_VERB "get_selected_bt_device" -#define HAL_BT_SET_SELECTED_DEVICE_VERB "set_selected_bt_device" +#define HAL_BT_GET_CONNECTED_A2DP_DEVICES_VERB "get_connected_bt_a2dp_devices" +#define HAL_BT_GET_SELECTED_A2DP_DEVICE_VERB "get_selected_bt_a2dp_device" +#define HAL_BT_SET_SELECTED_A2DP_DEVICE_VERB "set_selected_bt_a2dp_device" // HAL Bluetooth plugin verbs functions void HalBtGetStreamingStatus(AFB_ReqT request); void HalBtSetStreamingStatus(AFB_ReqT request); -void HalBtGetConnectedBluetoothDevices(AFB_ReqT request); -void HalBtGetSelectedBluetoothDevice(AFB_ReqT request); -void HalBtSetSelectedBluetoothDevice(AFB_ReqT request); +void HalBtGetA2DPBluetoothDevices(AFB_ReqT request); +void HalBtGetSelectedA2DPBluetoothDevice(AFB_ReqT request); +void HalBtSetSelectedA2DPBluetoothDevice(AFB_ReqT request); #endif /* _HAL_BT_CB_INCLUDE_ */
\ No newline at end of file diff --git a/plugins/lib/bluetooth/hal-bt-data.c b/plugins/lib/bluetooth/hal-bt-data.c index ff93ab8..a548039 100644 --- a/plugins/lib/bluetooth/hal-bt-data.c +++ b/plugins/lib/bluetooth/hal-bt-data.c @@ -95,11 +95,10 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat } // TODO JAI : get hci device of bt device here - // TODO JAI : check if a2dp profile is supported here if(wrap_json_unpack(currentSingleBtDeviceDataJ, - "{s:s s:s}", - "Name", ¤tBtDeviceName, - "Address", ¤tBtDeviceAddress)) { + "{s:s s:s s:o}", + "Name", ¤tBtDeviceName, + "Address", ¤tBtDeviceAddress)) { HalBtDataRemoveSelectedBtDeviceFromList(firstBtDeviceData, currentBtDeviceData); return NULL; } @@ -125,31 +124,9 @@ struct HalBtDeviceData *HalBtDataAddBtDeviceToBtDeviceList(struct HalBtDeviceDat return NULL; } - // JAI : WARNING : a2dp profile is currently harcoded - currentBtDeviceData->a2dp = 1; - return currentBtDeviceData; } -struct HalBtDeviceData *HalBtDataGetFirstA2dpBtDeviceAvailable(struct HalBtDeviceData **firstBtDeviceData) -{ - struct HalBtDeviceData *currentBtDeviceData; - - if(! firstBtDeviceData) - return NULL; - - currentBtDeviceData = *firstBtDeviceData; - - while(currentBtDeviceData) { - if(currentBtDeviceData->a2dp) - return currentBtDeviceData; - - currentBtDeviceData = currentBtDeviceData->next; - } - - return NULL; -} - int HalBtDataGetNumberOfBtDeviceInList(struct HalBtDeviceData **firstBtDeviceData) { unsigned int btDeviceNb = 0; @@ -190,22 +167,51 @@ struct HalBtDeviceData *HalBtDataSearchBtDeviceByAddress(struct HalBtDeviceData int HalBtDataHandleReceivedSingleBtDeviceData(struct HalBtPluginData *halBtPluginData, json_object *currentSingleBtDeviceDataJ) { - unsigned int currentBtDeviceIsConnected; + int btProfilesCount; + + unsigned int idx = 0, currentBtDeviceIsConnected, currentBtDeviceIsA2DP; char *currentBtDeviceAddress, *currentBtDeviceIsConnectedString; + json_object *currentBtAllProfilesJ, *currentBtCurrentProfileJ; + struct HalBtDeviceData *currentBtDevice; if(! halBtPluginData || ! currentSingleBtDeviceDataJ) return -1; if(wrap_json_unpack(currentSingleBtDeviceDataJ, - "{s:s s:s}", + "{s:s s:s s:s}", "Address", ¤tBtDeviceAddress, - "Connected", ¤tBtDeviceIsConnectedString)) { + "Connected", ¤tBtDeviceIsConnectedString, + "UUIDs", ¤tBtAllProfilesJ)) { return -2; } + if(json_object_is_type(currentBtAllProfilesJ, json_type_array)) { + btProfilesCount = json_object_array_length(currentBtAllProfilesJ); + + while(idx < btProfilesCount) { + currentBtCurrentProfileJ = json_object_array_get_idx(currentBtAllProfilesJ, idx); + + if(json_object_is_type(currentBtCurrentProfileJ, json_type_string) && + ! strncasecmp(json_object_get_string(currentBtCurrentProfileJ), A2DP_AUDIOSOURCE_UUID, sizeof(A2DP_AUDIOSOURCE_UUID))) { + currentBtDeviceIsA2DP = 1; + break; + } + + idx++; + } + } + else if(json_object_is_type(currentBtAllProfilesJ, json_type_string) && + ! strncasecmp(json_object_get_string(currentBtAllProfilesJ), A2DP_AUDIOSOURCE_UUID, sizeof(A2DP_AUDIOSOURCE_UUID))) { + currentBtDeviceIsA2DP = 1; + } + + if(! currentBtDeviceIsA2DP) + return 0; + currentBtDeviceIsConnected = ! strncmp(currentBtDeviceIsConnectedString, "True", strlen(currentBtDeviceIsConnectedString)); + currentBtDevice = HalBtDataSearchBtDeviceByAddress(&halBtPluginData->first, currentBtDeviceAddress); if(currentBtDevice && ! currentBtDeviceIsConnected) { @@ -213,14 +219,14 @@ int HalBtDataHandleReceivedSingleBtDeviceData(struct HalBtPluginData *halBtPlugi return -3; if(halBtPluginData->selectedBtDevice == currentBtDevice) - halBtPluginData->selectedBtDevice = HalBtDataGetFirstA2dpBtDeviceAvailable(&halBtPluginData->first); + halBtPluginData->selectedBtDevice = halBtPluginData->first; } else if(! currentBtDevice && currentBtDeviceIsConnected) { if(! HalBtDataAddBtDeviceToBtDeviceList(&halBtPluginData->first, currentSingleBtDeviceDataJ)) return -4; if(! halBtPluginData->selectedBtDevice) - halBtPluginData->selectedBtDevice = HalBtDataGetFirstA2dpBtDeviceAvailable(&halBtPluginData->first); + halBtPluginData->selectedBtDevice = halBtPluginData->first; } return 0; diff --git a/plugins/lib/bluetooth/hal-bt-data.h b/plugins/lib/bluetooth/hal-bt-data.h index 500654b..e57f02f 100644 --- a/plugins/lib/bluetooth/hal-bt-data.h +++ b/plugins/lib/bluetooth/hal-bt-data.h @@ -26,6 +26,10 @@ #include <4a-hal-utilities-data.h> +#define A2DP_AUDIOSOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb" +#define HSP_GATEAWAY_UUID "00001112-0000-1000-8000-00805f9b34fb" +#define HFP_GATEAWAY_UUID "0000111f-0000-1000-8000-00805f9b34fb" + // Structure to store bluetooth device data struct HalBtDeviceData { char *uid; @@ -34,8 +38,6 @@ struct HalBtDeviceData { char *name; char *address; - unsigned int a2dp; - struct HalBtDeviceData *next; }; diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c index b661def..408b232 100644 --- a/plugins/lib/bluetooth/hal-bt.c +++ b/plugins/lib/bluetooth/hal-bt.c @@ -107,35 +107,35 @@ CTLP_CAPI(init, source, argsJ, queryJ) } if(afb_dynapi_add_verb(source->api, - HAL_BT_GET_CONNECTED_DEVICES_VERB, - "Get connected Bluetooth devices list", - HalBtGetConnectedBluetoothDevices, + HAL_BT_GET_CONNECTED_A2DP_DEVICES_VERB, + "Get connected Bluetooth A2DP devices list", + HalBtGetA2DPBluetoothDevices, (void *) &localHalBtPluginData, NULL, 0)) { - AFB_ApiError(source->api, "%s: error while creating verb for bluetooth plugin : '%s'", __func__, HAL_BT_GET_CONNECTED_DEVICES_VERB); + AFB_ApiError(source->api, "%s: error while creating verb for bluetooth plugin : '%s'", __func__, HAL_BT_GET_CONNECTED_A2DP_DEVICES_VERB); return -3; } if(afb_dynapi_add_verb(source->api, - HAL_BT_GET_SELECTED_DEVICE_VERB, - "Get selected Bluetooth device", - HalBtGetSelectedBluetoothDevice, + HAL_BT_GET_SELECTED_A2DP_DEVICE_VERB, + "Get selected Bluetooth A2DP device", + HalBtGetSelectedA2DPBluetoothDevice, (void *) &localHalBtPluginData, NULL, 0)) { - AFB_ApiError(source->api, "%s: error while creating verb for bluetooth plugin : '%s'", __func__, HAL_BT_GET_SELECTED_DEVICE_VERB); + AFB_ApiError(source->api, "%s: error while creating verb for bluetooth plugin : '%s'", __func__, HAL_BT_GET_SELECTED_A2DP_DEVICE_VERB); return -4; } if(afb_dynapi_add_verb(source->api, - HAL_BT_SET_SELECTED_DEVICE_VERB, - "Set selected Bluetooth device", - HalBtSetSelectedBluetoothDevice, + HAL_BT_SET_SELECTED_A2DP_DEVICE_VERB, + "Set selected Bluetooth A2DP device", + HalBtSetSelectedA2DPBluetoothDevice, (void *) &localHalBtPluginData, NULL, 0)) { - AFB_ApiError(source->api, "%s: error while creating verb for bluetooth plugin : '%s'", __func__, HAL_BT_SET_SELECTED_DEVICE_VERB); + AFB_ApiError(source->api, "%s: error while creating verb for bluetooth plugin : '%s'", __func__, HAL_BT_SET_SELECTED_A2DP_DEVICE_VERB); return -5; } |