Fix data alignment issue in tinydtls session_t
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caretransmission.h
index 43d1bb7..b1a9971 100644 (file)
  * limitations under the License.
  *
  ******************************************************************/
+
 /**
- * @file caretransmission.h
- * @brief
+ * @file
+ * This file contains common function for retransmission messages.
  */
-#ifndef __CA_RETRANSMISSION_H_
-#define __CA_RETRANSMISSION_H_
+
+#ifndef CA_RETRANSMISSION_H_
+#define CA_RETRANSMISSION_H_
 
 #include <stdint.h>
 
-#include "uthreadpool.h"
-#include "umutex.h"
+#include "cathreadpool.h"
+#include "camutex.h"
 #include "uarraylist.h"
 #include "cacommon.h"
 
-/** CA_ETHERNET, CA_WIFI, CA_EDR, CA_LE **/
-#define DEFAULT_RETRANSMISSION_TYPE     ((1<<0)|(1<<1)|(1<<2)|(1<<3))
+/** IP, EDR, LE. **/
+#define DEFAULT_RETRANSMISSION_TYPE (CA_ADAPTER_IP | \
+                                     CA_ADAPTER_RFCOMM_BTEDR | \
+                                     CA_ADAPTER_GATT_BTLE)
 
-/** default ACK time is 2 sec.(CoAP) **/
-#define DEFAULT_ACK_TIMEOUT         2
+/** default ACK time is 2 sec(CoAP). **/
+#define DEFAULT_ACK_TIMEOUT_SEC     2
 
-/** default max retransmission trying count is 4.(CoAP) **/
-#define DEFAULT_MAX_RETRANSMIT      4
+/** default max retransmission trying count is 4(CoAP). **/
+#define DEFAULT_RETRANSMISSION_COUNT      4
 
 /** check period is 1 sec. **/
-#define RETRANSMISSION_CHECK_PERIOD     1000000
+#define RETRANSMISSION_CHECK_PERIOD_SEC     1
 
-/** retransmission data send method type**/
-typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, void *pdu,
-        uint32_t size);
+/** retransmission data send method type. **/
+typedef CAResult_t (*CADataSendMethod_t)(const CAEndpoint_t *endpoint,
+                                         const void *pdu,
+                                         uint32_t size);
 
-/** retransmission timeout callback type**/
-typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, void *pdu, uint32_t size);
+/** retransmission timeout callback type. **/
+typedef void (*CATimeoutCallback_t)(const CAEndpoint_t *endpoint,
+                                    const void *pdu,
+                                    uint32_t size);
 
 typedef struct
 {
-    /** retransmission support connectivity type **/
-    CAConnectivityType_t supportType;
-    /** retransmission trying count **/
+    /** retransmission support transport type. **/
+    CATransportAdapter_t supportType;
+
+    /** retransmission trying count. **/
     uint8_t tryingCount;
 
 } CARetransmissionConfig_t;
 
 typedef struct
 {
-    /** Thread pool of the thread started **/
-    u_thread_pool_t threadPool;
-    /** mutex for synchrnoization **/
-    u_mutex threadMutex;
-    /** conditional mutex for synchrnoization **/
-    u_cond threadCond;
-    /** send method for retransmission data **/
+    /** Thread pool of the thread started. **/
+    ca_thread_pool_t threadPool;
+
+    /** mutex for synchronization. **/
+    ca_mutex threadMutex;
+
+    /** conditional mutex for synchronization. **/
+    ca_cond threadCond;
+
+    /** send method for retransmission data. **/
     CADataSendMethod_t dataSendMethod;
-    /** callback function for retransmit timeout **/
+
+    /** callback function for retransmit timeout. **/
     CATimeoutCallback_t timeoutCallback;
-    /** retransmission configure data **/
+
+    /** retransmission configure data. **/
     CARetransmissionConfig_t config;
-    /** Variable to inform the thread to stop **/
-    CABool_t isStop;
+
+    /** Variable to inform the thread to stop. **/
+    bool isStop;
+
     /** array list on which the thread is operating. **/
     u_arraylist_t *dataList;
+
 } CARetransmission_t;
 
 #ifdef __cplusplus
@@ -85,67 +101,77 @@ extern "C"
 #endif
 
 /**
- * @brief   Initializes the retransmission context
- * @param   context [IN]context for retransmission
- * @param   handle  [IN]thread pool handle
- * @param   retransmissionSendMethod    [IN]function to be called for retransmission
- * @param   timeoutCallback [IN]callback for retransmit timeout
- * @param   config  [IN]configuration for retransmission. if NULL is coming, it will set default values.
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Initializes the retransmission context.
+ * @param[in]   context                      context for retransmission.
+ * @param[in]   handle                       thread pool handle.
+ * @param[in]   retransmissionSendMethod     function to be called for retransmission.
+ * @param[in]   timeoutCallback              callback for retransmit timeout.
+ * @param[in]   config                       configuration for retransmission.
+ *                                           if NULL is coming, it will set default values.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CARetransmissionInitialize(CARetransmission_t *context, u_thread_pool_t handle,
-        CADataSendMethod_t retransmissionSendMethod, CATimeoutCallback_t timeoutCallback,
-        CARetransmissionConfig_t* config);
+CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
+                                      ca_thread_pool_t handle,
+                                      CADataSendMethod_t retransmissionSendMethod,
+                                      CATimeoutCallback_t timeoutCallback,
+                                      CARetransmissionConfig_t* config);
 
 /**
- * @brief   Starting the retransmission context
- * @param   context [IN]context for retransmission
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Starting the retransmission context.
+ * @param[in]   context      context for retransmission.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CARetransmissionStart(CARetransmission_t *context);
 
 /**
- * @brief   Pass the sent pdu data. if retransmission process need, internal thread will wake up and
- *             process the retransmission data.
- * @param   context     [IN]context for retransmission
- * @param   endpoint    [IN]endpoint information
- * @param   pdu         [IN]sent pdu binary data
- * @param   size        [IN]sent pdu binary data size
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Pass the sent pdu data. if retransmission process need, internal thread will wake up and
+ * process the retransmission data.
+ * @param[in]   context      context for retransmission.
+ * @param[in]   endpoint     endpoint information.
+ * @param[in]   pdu          sent pdu binary data.
+ * @param[in]   size         sent pdu binary data size.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
-                        const CARemoteEndpoint_t* endpoint,const void* pdu, uint32_t size);
+                                    const CAEndpoint_t* endpoint,
+                                    const void* pdu, uint32_t size);
 
 /**
- * @brief   Paas the received pdu data. if received pdu is ACK data for the retransmission CON data,
- *             the specified CON data will remove on retransmission list.
- * @param   context     [IN]context for retransmission
- * @param   endpoint    [IN]endpoint information
- * @param   pdu         [IN]received pdu binary data
- * @param   size        [IN]received pdu binary data size
- * @param   void        [OUT] pdu data of the request for reset and ack
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
+ * the specified CON data will remove on retransmission list.
+ * @param[in]   context              context for retransmission.
+ * @param[in]   endpoint             endpoint information.
+ * @param[in]   pdu                  received pdu binary data.
+ * @param[in]   size                 received pdu binary data size.
+ * @param[out]  retransmissionPdu    pdu data of the request for reset and ack.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
-                                        const CARemoteEndpoint_t *endpoint, const void *pdu,
+                                        const CAEndpoint_t *endpoint, const void *pdu,
                                         uint32_t size, void **retransmissionPdu);
 
 /**
- * @brief   Stopping the retransmission context
- * @param   context [IN]context for retransmission
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Stopping the retransmission context.
+ * @param[in]   context         context for retransmission.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CARetransmissionStop(CARetransmission_t *context);
 
 /**
- * @brief   Terminating the retransmission context
- * @param   context [IN]context for retransmission
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Terminating the retransmission context.
+ * @param[in]   context         context for retransmission.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
 
+/**
+ * Invoke Retransmission according to TimedAction Response.
+ * @param[in]   threadValue     context for retransmission.
+ */
+void CARetransmissionBaseRoutine(void *threadValue);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
-#endif  // __CA_RETRANSMISSION_H_
+#endif  /* CA_RETRANSMISSION_H_ */