diff options
author | samanway <samanway@linux-samanway.sa.corp.samsungelectronics.net> | 2019-11-20 19:28:26 +0530 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2019-11-28 16:28:22 +0900 |
commit | 49515e2825ea7997159ab81308ff3dae771d72b6 (patch) | |
tree | 6cda1f92850098c1985077f4886ebe7cca20925d | |
parent | bee5540a55f6e3416863a016d345bb1d8b328452 (diff) | |
download | iotivity-49515e2825ea7997159ab81308ff3dae771d72b6.tar.gz iotivity-49515e2825ea7997159ab81308ff3dae771d72b6.tar.bz2 iotivity-49515e2825ea7997159ab81308ff3dae771d72b6.zip |
Avoiding code duplications in tizen BLE VD client files.
- Caleclient.c and Caleclient_vd.c two files had duplicate code
- Hence merged them into a single one
- Additionally, Sconscript is modified to enable build flag for VD
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/0622badee7ed2f6d424ac69d6796d443f8949953
(cherry-picked from 0622badee7ed2f6d424ac69d6796d443f8949953)
Change-Id: I24720556a7dce71a0a410da1ab7daf93fb55278e
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
-rw-r--r-- | resource/csdk/connectivity/src/bt_le_adapter/tizen/SConscript | 3 | ||||
-rw-r--r-- | resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c | 86 |
2 files changed, 80 insertions, 9 deletions
diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/SConscript b/resource/csdk/connectivity/src/bt_le_adapter/tizen/SConscript index 2166547ae..7560a783b 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/SConscript +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/SConscript @@ -38,7 +38,8 @@ if 'MCD' in division: 'caleutil.c', 'calenwmonitor.c'] elif 'VD' in division: - src_files = [ 'caleclient_vd.c', + env.AppendUnique(CPPDEFINES = ['TIZEN_VD']) + src_files = [ 'caleclient.c', 'caleserver_vd.c', 'caleutil.c', 'calenwmonitor_vd.c'] diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c index fb5a92073..561e2bf62 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleclient.c @@ -58,6 +58,7 @@ static int g_retrycount = 0; static int retry_flag = 0; uint64_t const TIMEOUT = 30 * MICROSECS_PER_SEC; +#ifndef TIZEN_VD /** * Mutex to call connect only after disconnect during retry */ @@ -67,6 +68,7 @@ static oc_mutex g_isDisconnectedMutex = NULL; * Condition for calling connect during connection retry */ static oc_cond g_LEDisconnectedCond = NULL; +#endif /** * Flag to check if scanning is in progress @@ -288,8 +290,10 @@ CAResult_t CALEGattInitiateConnection(const char *remoteAddress) return CA_STATUS_FAILED; } g_isConnectionInProgress = true; +#ifndef TIZEN_VD // Set gatt connect retry count g_retrycount = RETRY_COUNT; +#endif oc_mutex_unlock(g_isConnectionInProgressMutex); // Pause the scanning @@ -336,6 +340,11 @@ void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress) if (!connected) { OIC_LOG_V(DEBUG, TAG, "DisConnected from [%s] ", remoteAddress); +#ifdef TIZEN_VD + oc_mutex_lock(g_LEServerListMutex); + CARemoveLEServerInfoFromList(&g_LEServerList, remoteAddress); + oc_mutex_unlock(g_LEServerListMutex); +#else if(!retry_flag) { oc_mutex_lock(g_LEServerListMutex); @@ -349,6 +358,7 @@ void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress) oc_mutex_unlock(g_isDisconnectedMutex); } retry_flag = 0; +#endif } else { @@ -363,7 +373,7 @@ void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress) if (CA_STATUS_OK != CAGetLEServerInfo(g_LEServerList, remoteAddress, &serverInfo)) { oc_mutex_unlock(g_LEServerListMutex); - OIC_LOG_V(ERROR, TAG, "Could not get server info!"); + OIC_LOG_V(ERROR, TAG, "Could not get server info for [%s]", remoteAddress); return; } @@ -384,6 +394,7 @@ void CALEGattConnectionStateChanged(bool connected, const char *remoteAddress) OIC_LOG(ERROR, TAG, "addr is NULL"); return; } + CAResult_t ret = ca_thread_pool_add_task(g_LEClientThreadPool, CADiscoverLEServicesThread, addr, NULL); oc_mutex_unlock(g_LEClientThreadPoolMutex); @@ -431,13 +442,19 @@ static bool CALEIsHaveServiceImpl(bt_adapter_le_device_scan_result_info_s *scanI if (result == BT_ERROR_NONE && NULL != man_data) { - char *compare_man_data = OICMalloc((man_data_len*2)+1); int pos =0; + char *compare_man_data = OICCalloc(1, (man_data_len*2)+1); + if (!compare_man_data) + { + OIC_LOG(ERROR, TAG, "Memory allocation failed for compare_man_data"); + OICFree(man_data); + return false; + } + for(int i=0;i<man_data_len;i++){ - pos += sprintf(compare_man_data+pos, "%.2x", man_data[i]); + pos += snprintf(compare_man_data+pos, 2, "%.2x", man_data[i]); } - compare_man_data[(man_data_len*2)+1]='\0'; - OIC_LOG_V(DEBUG, TAG, "Manufacture Id %d Manufacture Data[%s]" ,man_id,compare_man_data); + if (man_id == samsung_code && 0 == strncasecmp(compare_man_data, service_uuid, CUSTOM_UUID_LEN)) { OIC_LOG_V(DEBUG, TAG, "Manufacture Data[%s] Found in %s", @@ -467,7 +484,6 @@ void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s void *userData) { (void)userData; - OIC_LOG(DEBUG, TAG, "IN"); VERIFY_NON_NULL_VOID(scanInfo, TAG, "scanInfo"); @@ -636,12 +652,54 @@ CAResult_t CAStartLEGattClient() oc_mutex_unlock(g_LEClientThreadPoolMutex); return CA_STATUS_FAILED; } + +#ifdef TIZEN_VD + result= ca_thread_pool_add_task(g_LEClientThreadPool, CALEClientScanThread, + NULL, NULL); + if (CA_STATUS_OK != result) + { + OIC_LOG(ERROR, TAG, "ca_thread_pool_add_task failed"); + CATerminateGattClientMutexVariables(); + oc_mutex_unlock(g_LEClientThreadPoolMutex); + return CA_STATUS_FAILED; + } +#endif oc_mutex_unlock(g_LEClientThreadPoolMutex); OIC_LOG(DEBUG, TAG, "OUT"); return CA_STATUS_OK; } +#ifdef TIZEN_VD +void CALEClientScanThread() +{ + oc_mutex_lock(g_scanMutex); + if (!g_isMulticastInProgress && !g_isUnicastScanInProgress) + { + CAResult_t result = CALEGattStartDeviceScanning(); + if (CA_STATUS_OK != result) + { + oc_mutex_unlock(g_scanMutex); + OIC_LOG(ERROR, TAG, "CALEGattStartDeviceScanning failed"); + return ; + } + g_isUnicastScanInProgress = true; + // Start Timer + oc_cond_signal(g_startTimerCond); + } + else + { + g_isUnicastScanInProgress = true; + // Reset Timer + oc_cond_signal(g_scanningTimeCond); + } + oc_mutex_unlock(g_scanMutex); + + OIC_LOG(DEBUG, TAG, "OUT"); + return ; +} +#endif + void CAStartTimerThread(void *data) { (void)data; @@ -883,6 +941,7 @@ CAResult_t CAInitGattClientMutexVariables() } } +#ifndef TIZEN_VD if (NULL == g_isDisconnectedMutex) { g_isDisconnectedMutex = oc_mutex_new(); @@ -902,6 +961,7 @@ CAResult_t CAInitGattClientMutexVariables() return CA_STATUS_FAILED; } } +#endif if (NULL == g_startTimerCond) { @@ -985,11 +1045,13 @@ void CATerminateGattClientMutexVariables() oc_mutex_free(g_threadMTUChangedMutex); g_threadMTUChangedMutex = NULL; +#ifndef TIZEN_VD oc_mutex_free(g_isDisconnectedMutex); g_isDisconnectedMutex = NULL; oc_cond_free(g_LEDisconnectedCond); g_LEDisconnectedCond = NULL; +#endif oc_cond_free(g_startTimerCond); g_startTimerCond = NULL; @@ -1123,7 +1185,11 @@ CAResult_t CALEGattConnect(const char *remoteAddress) oc_mutex_lock(g_LEClientConnectMutex); CAResult_t result = CA_STATUS_OK; +#ifdef TIZEN_VD + int ret = bt_gatt_connect(remoteAddress, true); +#else int ret = bt_gatt_connect(remoteAddress, false); +#endif if (BT_ERROR_NONE != ret) { OIC_LOG_V(ERROR, TAG, "bt_gatt_connect Failed with ret value [%s] ", @@ -1255,6 +1321,7 @@ void CADiscoverLEServicesThread(void *remoteAddress) OIC_LOG(DEBUG, TAG, "OUT"); } +#ifndef TIZEN_VD static int CALEWaittillDisconnect(oc_mutex mutex, oc_cond cv, int wait_seconds) { OIC_LOG(DEBUG, TAG, "Waiting for server to be disconnected..."); @@ -1277,6 +1344,7 @@ static CAResult_t CALEGattConnectionRetry(const char *remoteAddress) OIC_LOG(DEBUG, TAG, "OUT"); return result; } +#endif CAResult_t CALEGattDiscoverServices(const char *remoteAddress) { @@ -1302,6 +1370,9 @@ CAResult_t CALEGattDiscoverServices(const char *remoteAddress) { OIC_LOG_V(ERROR, TAG, "bt_gatt_client_get_service Failed with ret value [%s] ", CALEGetErrorMsg(ret)); +#ifdef TIZEN_VD + goto error_exit; +#else if(g_retrycount) { OIC_LOG(DEBUG, TAG, "Retry will be attempted to connect Gatt Server"); @@ -1321,6 +1392,7 @@ CAResult_t CALEGattDiscoverServices(const char *remoteAddress) return CA_STATUS_FAILED; } } +#endif } retry_flag = 0; @@ -1469,7 +1541,6 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, OIC_LOG(ERROR, TAG, "Device address is NULL"); return CA_STATUS_FAILED; } - serverInfo = (LEServerInfo *)OICCalloc(1, sizeof(LEServerInfo)); if (NULL == serverInfo) { @@ -1478,7 +1549,6 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, OICFree(addr); return CA_STATUS_FAILED; } - serverInfo->remoteAddress = addr; serverInfo->status = LE_STATUS_UNICAST_PENDING; |