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