1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 * @file caretransmission.h
23 * @brief This file contains common function for retransmission messages.
26 #ifndef CA_RETRANSMISSION_H_
27 #define CA_RETRANSMISSION_H_
31 #include "cathreadpool.h"
33 #include "uarraylist.h"
37 #define DEFAULT_RETRANSMISSION_TYPE (CA_ADAPTER_IP | \
38 CA_ADAPTER_RFCOMM_BTEDR | \
41 /** default ACK time is 2 sec.(CoAP) **/
42 #define DEFAULT_ACK_TIMEOUT_SEC 2
44 /** default max retransmission trying count is 4.(CoAP) **/
45 #define DEFAULT_RETRANSMISSION_COUNT 4
47 /** check period is 1 sec. **/
48 #define RETRANSMISSION_CHECK_PERIOD_SEC 1
50 /** retransmission data send method type**/
51 typedef CAResult_t (*CADataSendMethod_t)(const CAEndpoint_t *endpoint,
55 /** retransmission timeout callback type**/
56 typedef void (*CATimeoutCallback_t)(const CAEndpoint_t *endpoint,
62 /** retransmission support transport type **/
63 CATransportAdapter_t supportType;
65 /** retransmission trying count **/
68 } CARetransmissionConfig_t;
72 /** Thread pool of the thread started **/
73 ca_thread_pool_t threadPool;
75 /** mutex for synchronization **/
78 /** conditional mutex for synchronization **/
81 /** send method for retransmission data **/
82 CADataSendMethod_t dataSendMethod;
84 /** callback function for retransmit timeout **/
85 CATimeoutCallback_t timeoutCallback;
87 /** retransmission configure data **/
88 CARetransmissionConfig_t config;
90 /** Variable to inform the thread to stop **/
93 /** array list on which the thread is operating. **/
94 u_arraylist_t *dataList;
104 * @brief Initializes the retransmission context
105 * @param context [IN] context for retransmission
106 * @param handle [IN] thread pool handle
107 * @param retransmissionSendMethod [IN] function to be called for retransmission
108 * @param timeoutCallback [IN] callback for retransmit timeout
109 * @param config [IN] configuration for retransmission.
110 * if NULL is coming, it will set default values.
111 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
113 CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
114 ca_thread_pool_t handle,
115 CADataSendMethod_t retransmissionSendMethod,
116 CATimeoutCallback_t timeoutCallback,
117 CARetransmissionConfig_t* config);
120 * @brief Starting the retransmission context
121 * @param context [IN] context for retransmission
122 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
124 CAResult_t CARetransmissionStart(CARetransmission_t *context);
127 * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up and
128 * process the retransmission data
129 * @param context [IN] context for retransmission
130 * @param endpoint [IN] endpoint information
131 * @param pdu [IN] sent pdu binary data
132 * @param size [IN] sent pdu binary data size
133 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
135 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
136 const CAEndpoint_t* endpoint,
137 const void* pdu, uint32_t size);
140 * @brief Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
141 * the specified CON data will remove on retransmission list.
142 * @param context [IN] context for retransmission
143 * @param endpoint [IN] endpoint information
144 * @param pdu [IN] received pdu binary data
145 * @param size [IN] received pdu binary data size
146 * @param retransmissionPdu [OUT] pdu data of the request for reset and ack
147 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
149 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
150 const CAEndpoint_t *endpoint, const void *pdu,
151 uint32_t size, void **retransmissionPdu);
154 * @brief Stopping the retransmission context
155 * @param context [IN] context for retransmission
156 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
158 CAResult_t CARetransmissionStop(CARetransmission_t *context);
161 * @brief Terminating the retransmission context
162 * @param context [IN] context for retransmission
163 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
165 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
168 * @brief Invoke Retransmission according to TimedAction Response
169 * @param threadValue [IN] context for retransmission
171 void CARetransmissionBaseRoutine(void *threadValue);
177 #endif /* CA_RETRANSMISSION_H_ */