remove warning issue fragmentation and rdclient
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 12 Sep 2016 07:59:29 +0000 (16:59 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Thu, 20 Oct 2016 07:52:56 +0000 (07:52 +0000)
this warning was came from analysis tool
- remove unreachable code.
- apply to check return value in rdclient example.

Change-Id: I2466e15e56f11344ffbc2712527d12c7ae326a0a
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11673
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/inc/cafragmentation.h
resource/csdk/connectivity/src/adapter_util/cafragmentation.c
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/resource-directory/samples/rdclient.cpp

index 0aff468..3dd8a9b 100644 (file)
 #define CA_BLE_LENGTH_HEADER_SIZE 4
 
 /**
+ * The length payload size of the normal data segment (after first segment) for ble fragmentation.
+ */
+#define CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE  CA_SUPPORTED_BLE_MTU_SIZE \
+    - CA_BLE_HEADER_SIZE
+
+/**
+ * The length payload size of the first data segment for ble fragmentation.
+ */
+#define CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE \
+    - CA_BLE_LENGTH_HEADER_SIZE
+
+/**
  * Current Header version.
  */
 #define HEADER_VERSION 1
@@ -214,16 +226,17 @@ CAResult_t CAMakeFirstDataSegment(uint8_t *dataSegment,
  * to maintain the fragmentation logic. start data segment is included
  * 2 bytes header and transmit data.
  *
- * @param[out]  dataSegment    Pointer to the octet array that will
- *                             contain the generated data packet.
- * @param[in]   data           Data to the octet array that required
- *                             transmittin to remote device. it will
- *                             be embedded in 7th byte to data length.
- * @param[in]   dataLength     The length of data size.
- * @param[in]   index          Index to determine whether some of the
- *                             total data
- * @param[in]   dataHeader     Pointer to the octet array that contain
- *                             data header.
+ * @param[out]  dataSegment            Pointer to the octet array that will
+ *                                     contain the generated data packet.
+ * @param[in]   segmentPayloadLength   The length of data segment payload.
+ * @param[in]   sourceData             Data to the octet array that required
+ *                                     transmission to remote device. it will
+ *                                     be embedded in 7th byte to data length.
+ * @param[in]   sourceDataLength       The length of total data.
+ * @param[in]   segmentNum             Index to determine whether some of the
+ *                                     total data
+ * @param[in]   dataHeader             Pointer to the octet array that contain
+ *                                     data header.
  *
  * @return ::CA_STATUS_OK on success. One of the CA_STATUS_FAILED
  *           or other error values on error.
@@ -232,9 +245,10 @@ CAResult_t CAMakeFirstDataSegment(uint8_t *dataSegment,
  * @retval ::CA_STATUS_FAILED         Operation failed
  */
 CAResult_t CAMakeRemainDataSegment(uint8_t *dataSegment,
-                                   const uint8_t *data,
-                                   const uint32_t dataLength,
-                                   const uint32_t index,
+                                   const uint32_t segmentPayloadLength,
+                                   const uint8_t *sourceData,
+                                   const uint32_t sourceDataLength,
+                                   const uint32_t segmentNum,
                                    const uint8_t *dataHeader);
 
 /**
index dc51dd4..40ac3a9 100644 (file)
@@ -185,9 +185,10 @@ CAResult_t CAMakeFirstDataSegment(uint8_t *dataSegment,
 }
 
 CAResult_t CAMakeRemainDataSegment(uint8_t *dataSegment,
-                                   const uint8_t *data,
-                                   const uint32_t dataLength,
-                                   const uint32_t index,
+                                   const uint32_t segmentPayloadLength,
+                                   const uint8_t *sourceData,
+                                   const uint32_t sourceDataLength,
+                                   const uint32_t segmentNum,
                                    const uint8_t *dataHeader)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -195,17 +196,16 @@ CAResult_t CAMakeRemainDataSegment(uint8_t *dataSegment,
     VERIFY_NON_NULL(dataSegment, TAG, "dataSegment is NULL");
     VERIFY_NON_NULL(dataHeader, TAG, "dataHeader is NULL");
 
-    const uint8_t *cur_pos = data +
-        (CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE +
-         (index * (CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE)));
-    if (NULL == cur_pos)
+    uint32_t index = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE +
+            (segmentNum * CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE);
+    if (sourceDataLength < index + segmentPayloadLength)
     {
-        OIC_LOG(ERROR, TAG, "data is NULL");
+        OIC_LOG(DEBUG, TAG, "dataSegment will exceed");
         return CA_STATUS_FAILED;
     }
 
     memcpy(dataSegment, dataHeader, CA_BLE_HEADER_SIZE);
-    memcpy(dataSegment + CA_BLE_HEADER_SIZE, cur_pos, dataLength);
+    memcpy(dataSegment + CA_BLE_HEADER_SIZE, sourceData + index, segmentPayloadLength);
 
     OIC_LOG(DEBUG, TAG, "OUT");
 
index abce764..6fa4f46 100644 (file)
@@ -48,8 +48,7 @@
 /**
  * Stores information of all the senders.
  *
- * This structure will be used to track and defragment all incoming
- * data packet.
+ * This structure will be used to track and defragment all incoming data packet.
  */
 typedef struct
 {
@@ -1111,7 +1110,7 @@ static void CALEServerSendDataThread(void *threadData)
     else
     {
         length = CA_SUPPORTED_BLE_MTU_SIZE;
-        dataLen = CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
+        dataLen = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE;
     }
 
     result = CAMakeFirstDataSegment(dataSegment,
@@ -1179,8 +1178,9 @@ static void CALEServerSendDataThread(void *threadData)
                       index);
 
             result = CAMakeRemainDataSegment(dataSegment,
+                                             CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
                                              bleData->data,
-                                             CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1216,8 +1216,9 @@ static void CALEServerSendDataThread(void *threadData)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
 
             result = CAMakeRemainDataSegment(dataSegment,
-                                             bleData->data,
                                              remainingLen,
+                                             bleData->data,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1283,8 +1284,9 @@ static void CALEServerSendDataThread(void *threadData)
             OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
 
             result = CAMakeRemainDataSegment(dataSegment,
+                                             CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
                                              bleData->data,
-                                             CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1317,8 +1319,9 @@ static void CALEServerSendDataThread(void *threadData)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
 
             result = CAMakeRemainDataSegment(dataSegment,
-                                             bleData->data,
                                              remainingLen,
+                                             bleData->data,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1436,7 +1439,7 @@ static void CALEClientSendDataThread(void *threadData)
     else
     {
         length = CA_SUPPORTED_BLE_MTU_SIZE;
-        dataLen = CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
+        dataLen = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE;
     }
 
     result = CAMakeFirstDataSegment(dataSegment,
@@ -1500,8 +1503,9 @@ static void CALEClientSendDataThread(void *threadData)
         for (index = 0; index < iter; index++)
         {
             result = CAMakeRemainDataSegment(dataSegment,
+                                             CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
                                              bleData->data,
-                                             CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1540,8 +1544,9 @@ static void CALEClientSendDataThread(void *threadData)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
 
             result = CAMakeRemainDataSegment(dataSegment,
-                                             bleData->data,
                                              remainingLen,
+                                             bleData->data,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1603,8 +1608,9 @@ static void CALEClientSendDataThread(void *threadData)
         for (index = 0; index < iter; index++)
         {
             result = CAMakeRemainDataSegment(dataSegment,
+                                             CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
                                              bleData->data,
-                                             CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1638,8 +1644,9 @@ static void CALEClientSendDataThread(void *threadData)
             OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
 
             result = CAMakeRemainDataSegment(dataSegment,
-                                             bleData->data,
                                              remainingLen,
+                                             bleData->data,
+                                             bleData->dataLen,
                                              index,
                                              dataHeader);
 
@@ -1916,7 +1923,7 @@ static CAResult_t CALEServerSendDataSingleThread(const uint8_t *data,
     else
     {
         length = CA_SUPPORTED_BLE_MTU_SIZE;
-        dataOnlyLen = CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
+        dataOnlyLen = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE;
     }
 
     result = CAMakeFirstDataSegment(dataSegment,
@@ -1960,8 +1967,9 @@ static CAResult_t CALEServerSendDataSingleThread(const uint8_t *data,
     for (uint32_t iter = 0; iter < dataLimit; iter++)
     {
         result = CAMakeRemainDataSegment(dataSegment,
+                                         CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
                                          data,
-                                         CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+                                         dataLen,
                                          iter,
                                          dataHeader);
 
@@ -1991,8 +1999,9 @@ static CAResult_t CALEServerSendDataSingleThread(const uint8_t *data,
         OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
 
         result = CAMakeRemainDataSegment(dataSegment,
-                                         data,
                                          remainingLen,
+                                         data,
+                                         dataLen,
                                          dataLimit,
                                          dataHeader);
 
index ef6a0c3..107ba6f 100644 (file)
@@ -61,10 +61,18 @@ public:
 
         m_resourceUri = resourceURI;
 
-        OCPlatform::registerResource(m_resourceHandle, resourceURI, resourceTypeName,
-                                     resourceInterface,
-                                     nullptr,
-                                     OC_DISCOVERABLE);
+        OCStackResult ret = OCPlatform::registerResource(m_resourceHandle,
+                                                         resourceURI,
+                                                         resourceTypeName,
+                                                         resourceInterface,
+                                                         nullptr,
+                                                         OC_DISCOVERABLE);
+
+        if (OC_STACK_OK != ret)
+        {
+            cout << "Resource creation was unsuccessful\n";
+            return;
+        }
 
         m_publishedResourceHandles.push_back(m_resourceHandle);
         cout << "registerResource is called." << endl;