diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-09-11 17:12:54 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-10-08 15:57:27 +0200 |
commit | e185efc0a2ed5b8d295d29a7afadd84342b80549 (patch) | |
tree | 1ef23e05a76c0d009d45b727b0762bdf6ab0b553 /plugins/lib/bluetooth/hal-bt-data.c | |
parent | 3a7a1127600dd92367609edb02ef74bcb1b55ff8 (diff) |
HalBt plugin keeps list of connected A2DP devices
Hal-Bt plugin only keeps list of connected bluetooth A2DP devices
instead of a list of all connected bluetooth devices.
Change-Id: I6c06be78a927dcac32ed4683d44431514e7daf06
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugins/lib/bluetooth/hal-bt-data.c')
-rw-r--r-- | plugins/lib/bluetooth/hal-bt-data.c | 68 |
1 files changed, 37 insertions, 31 deletions
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; |