Adding logic for caching MTU in tizen LE Server 63/214463/1
authorKush <kush.agrawal@samsung.com>
Tue, 10 Sep 2019 16:52:41 +0000 (22:22 +0530)
committerSudipto <sudipto.bal@samsung.com>
Mon, 23 Sep 2019 06:37:23 +0000 (12:07 +0530)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/573/commits/6e689edd472e098a873b64549006d026e597c667
(cherry-picked from 6e689edd472e098a873b64549006d026e597c667)

Change-Id: I8a7f8a5eee882894ac27cd98f501fe49345931ca
Signed-off-by: Kush <kush.agrawal@samsung.com>
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c

index cf81f37..a9dbd57 100644 (file)
@@ -1184,7 +1184,16 @@ uint16_t CALEServerGetMtuSize(const char* address)
 
     unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
     int ret = 0;
+    unsigned int cached_mtu;
 
+    oc_mutex_lock(g_LEClientListMutex);
+    cached_mtu  = CAClientInfoGetMTUSize(g_LEClientList, address);
+    if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE)
+    {
+        OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu);
+        oc_mutex_unlock(g_LEClientListMutex);
+        return cached_mtu -CA_BLE_MTU_HEADER_SIZE;
+    }
 #ifdef TIZEN_4
     bt_gatt_client_h client = NULL;
     ret = bt_gatt_client_create(address, &client);
@@ -1192,6 +1201,7 @@ uint16_t CALEServerGetMtuSize(const char* address)
     {
         OIC_LOG_V(ERROR, TAG,
                   "bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret));
+        oc_mutex_unlock(g_LEClientListMutex);
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 
@@ -1200,6 +1210,7 @@ uint16_t CALEServerGetMtuSize(const char* address)
     {
         OIC_LOG_V(ERROR, TAG,
                   "bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
+        oc_mutex_unlock(g_LEClientListMutex);
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 
@@ -1208,6 +1219,7 @@ uint16_t CALEServerGetMtuSize(const char* address)
     {
         OIC_LOG_V(ERROR, TAG,
                   "bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret));
+        oc_mutex_unlock(g_LEClientListMutex);
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 #else
@@ -1219,7 +1231,15 @@ uint16_t CALEServerGetMtuSize(const char* address)
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 #endif // TIZEN_4
+    ret  = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu);
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed");
+        oc_mutex_unlock(g_LEClientListMutex);
+        return CA_DEFAULT_BLE_MTU_SIZE;
+    }
 
+    oc_mutex_unlock(g_LEClientListMutex);
     OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu);
     OIC_LOG(DEBUG, TAG, "OUT");
     return mtu - CA_BLE_MTU_HEADER_SIZE;
index 6a52aed..1e309c1 100644 (file)
@@ -1042,7 +1042,16 @@ uint16_t CALEServerGetMtuSize(const char* address)
 
     unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
     int ret = 0;
+    unsigned int cached_mtu;
 
+    oc_mutex_lock(g_LEClientListMutex);
+    cached_mtu  = CAClientInfoGetMTUSize(g_LEClientList, address);
+    if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE)
+    {
+        OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu);
+        oc_mutex_unlock(g_LEClientListMutex);
+        return cached_mtu -CA_BLE_MTU_HEADER_SIZE;
+    }
 #ifdef TIZEN_4
     bt_gatt_client_h client = NULL;
     ret = bt_gatt_client_create(address, &client);
@@ -1050,6 +1059,7 @@ uint16_t CALEServerGetMtuSize(const char* address)
     {
         OIC_LOG_V(ERROR, TAG,
                   "bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret));
+        oc_mutex_unlock(g_LEClientListMutex);
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 
@@ -1058,6 +1068,7 @@ uint16_t CALEServerGetMtuSize(const char* address)
     {
         OIC_LOG_V(ERROR, TAG,
                   "bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
+        oc_mutex_unlock(g_LEClientListMutex);
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 
@@ -1066,6 +1077,7 @@ uint16_t CALEServerGetMtuSize(const char* address)
     {
         OIC_LOG_V(ERROR, TAG,
                   "bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret));
+        oc_mutex_unlock(g_LEClientListMutex);
         return CA_DEFAULT_BLE_MTU_SIZE;
     }
 #else
@@ -1078,6 +1090,16 @@ uint16_t CALEServerGetMtuSize(const char* address)
     }
 #endif // TIZEN_4
 
+    ret  = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu);
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed");
+        oc_mutex_unlock(g_LEClientListMutex);
+        return CA_DEFAULT_BLE_MTU_SIZE;
+    }
+
+    oc_mutex_unlock(g_LEClientListMutex);
+
     OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu);
     OIC_LOG(DEBUG, TAG, "OUT");
     return mtu - CA_BLE_MTU_HEADER_SIZE;