Corrected @file tags and restored 'Files' section.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caretransmission.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  *
24  *
25  */
26
27 #ifndef __CA_RETRANSMISSION_H_
28 #define __CA_RETRANSMISSION_H_
29
30 #include <stdint.h>
31
32 #include "uthreadpool.h"
33 #include "umutex.h"
34 #include "uarraylist.h"
35 #include "cacommon.h"
36
37 /** CA_ETHERNET, CA_WIFI, CA_EDR, CA_LE **/
38 #define DEFAULT_RETRANSMISSION_TYPE     (CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE)
39
40 /** default ACK time is 2 sec.(CoAP) **/
41 #define DEFAULT_ACK_TIMEOUT_SEC     2
42
43 /** default max retransmission trying count is 4.(CoAP) **/
44 #define DEFAULT_MAX_RETRANSMIT      4
45
46 /** check period is 1 sec. **/
47 #define RETRANSMISSION_CHECK_PERIOD_SEC     1
48
49 /** retransmission data send method type**/
50 typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
51         uint32_t size);
52
53 /** retransmission timeout callback type**/
54 typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size);
55
56 typedef struct
57 {
58     /** retransmission support connectivity type **/
59     CAConnectivityType_t supportType;
60     /** retransmission trying count **/
61     uint8_t tryingCount;
62
63 } CARetransmissionConfig_t;
64
65 typedef struct
66 {
67     /** Thread pool of the thread started **/
68     u_thread_pool_t threadPool;
69     /** mutex for synchrnoization **/
70     u_mutex threadMutex;
71     /** conditional mutex for synchrnoization **/
72     u_cond threadCond;
73     /** send method for retransmission data **/
74     CADataSendMethod_t dataSendMethod;
75     /** callback function for retransmit timeout **/
76     CATimeoutCallback_t timeoutCallback;
77     /** retransmission configure data **/
78     CARetransmissionConfig_t config;
79     /** Variable to inform the thread to stop **/
80     bool isStop;
81     /** array list on which the thread is operating. **/
82     u_arraylist_t *dataList;
83 } CARetransmission_t;
84
85 #ifdef __cplusplus
86 extern "C"
87 {
88 #endif
89
90 /**
91  * @brief   Initializes the retransmission context
92  * @param   context     [IN] context for retransmission
93  * @param   handle      [IN] thread pool handle
94  * @param   retransmissionSendMethod    [IN] function to be called for retransmission
95  * @param   timeoutCallback [IN] callback for retransmit timeout
96  * @param   config      [IN] configuration for retransmission.
97  *                           if NULL is coming, it will set default values.
98  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
99  */
100 CAResult_t CARetransmissionInitialize(CARetransmission_t *context, u_thread_pool_t handle,
101                                     CADataSendMethod_t retransmissionSendMethod,
102                                     CATimeoutCallback_t timeoutCallback,
103                                     CARetransmissionConfig_t* config);
104
105 /**
106  * @brief   Starting the retransmission context
107  * @param   context     [IN] context for retransmission
108  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
109  */
110 CAResult_t CARetransmissionStart(CARetransmission_t *context);
111
112 /**
113  * @brief   Pass the sent pdu data. if retransmission process need, internal thread will wake up and
114  *          process the retransmission data.
115  * @param   context     [IN] context for retransmission
116  * @param   endpoint    [IN] endpoint information
117  * @param   pdu         [IN] sent pdu binary data
118  * @param   size        [IN] sent pdu binary data size
119  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
120  */
121 CAResult_t CARetransmissionSentData(CARetransmission_t* context,
122                                     const CARemoteEndpoint_t* endpoint,const void* pdu,
123                                     uint32_t size);
124
125 /**
126  * @brief   Pass the received pdu data. if received pdu is ACK data for the retransmission CON data,
127  *          the specified CON data will remove on retransmission list.
128  * @param   context     [IN] context for retransmission
129  * @param   endpoint    [IN] endpoint information
130  * @param   pdu         [IN] received pdu binary data
131  * @param   size        [IN] received pdu binary data size
132  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
133  */
134 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
135                                         const CARemoteEndpoint_t *endpoint, const void *pdu,
136                                         uint32_t size);
137
138 /**
139  * @brief   Stopping the retransmission context
140  * @param   context     [IN] context for retransmission
141  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
142  */
143 CAResult_t CARetransmissionStop(CARetransmission_t *context);
144
145 /**
146  * @brief   Terminating the retransmission context
147  * @param   context     [IN] context for retransmission
148  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
149  */
150 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
151
152 #ifdef __cplusplus
153 } /* extern "C" */
154 #endif
155
156 #endif  // __CA_RETRANSMISSION_H_
157