Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caretransmission_singlethread.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 caretransmission_singlethread.h
23  * @brief This file contains common function for retransmission messages.
24  */
25
26 #ifndef CA_RETRANSMISSION_SINGLETHREAD_H_
27 #define CA_RETRANSMISSION_SINGLETHREAD_H_
28
29 #include <stdint.h>
30
31 #include "uarraylist.h"
32 #include "cacommon.h"
33
34 /** CA_IPV4, CA_LE **/
35 #define DEFAULT_RETRANSMISSION_TYPE     (CA_IPV4 | CA_LE)
36
37 /** default retransmission trying count is 4. **/
38 #define DEFAULT_RETRANSMISSION_COUNT    4
39
40 /** check period is 1 sec. **/
41 #define RETRANSMISSION_CHECK_PERIOD_SEC     1
42
43 /** retransmission data send method type**/
44 typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
45                                          uint32_t size);
46
47 /** retransmission timeout callback type**/
48 typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu,
49                                     uint32_t size);
50
51 typedef struct
52 {
53     /** retransmission support transport type **/
54     CATransportType_t supportType;
55
56     /** retransmission trying count **/
57     uint8_t tryingCount;
58
59 } CARetransmissionConfig_t;
60
61 typedef struct
62 {
63     /** send method for retransmission data **/
64     CADataSendMethod_t dataSendMethod;
65
66     /** callback function for retransmit timeout **/
67     CATimeoutCallback_t timeoutCallback;
68
69     /** retransmission configure data **/
70     CARetransmissionConfig_t config;
71
72     /** Variable to inform the thread to stop **/
73     bool isStop;
74
75     /** array list on which the thread is operating. **/
76     u_arraylist_t *dataList;
77
78 } CARetransmission_t;
79
80 #ifdef __cplusplus
81 extern "C"
82 {
83 #endif
84
85 /**
86  * @brief   Initializes the retransmission context
87  * @param   context                   [IN]    context for retransmission
88  * @param   retransmissionSendMethod  [IN]    function to be called for retransmission
89  * @param   timeoutCallback           [IN]    callback for retransmit timeout
90  * @param   config                    [IN]    configuration for retransmission.
91  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
92  */
93 CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
94                                       CADataSendMethod_t retransmissionSendMethod,
95                                       CATimeoutCallback_t timeoutCallback,
96                                       CARetransmissionConfig_t *config);
97
98 /**
99  * @brief   Pass the sent pdu data. if retransmission process need, internal thread will wake up
100  *          and process the retransmission data.
101  * @param   context     [IN]    context for retransmission
102  * @param   endpoint    [IN]    endpoint information
103  * @param   pdu         [IN]    sent pdu binary data
104  * @param   size        [IN]    sent pdu binary data size
105  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
106  */
107 CAResult_t CARetransmissionSentData(CARetransmission_t *context,
108                                     const CARemoteEndpoint_t *endpoint,
109                                     const void *pdu, uint32_t size);
110
111 /**
112  * @brief   Paas the received pdu data. if received pdu is ACK data for the retransmission CON data,
113  *          the specified CON data will remove on retransmission list.
114  * @param   context             [IN]    context for retransmission
115  * @param   endpoint            [IN]    endpoint information
116  * @param   pdu                 [IN]    received pdu binary data
117  * @param   size                [IN]    received pdu binary data size
118  * @param   retransmissionPdu   [OUT]   pdu data of the request for reset and ack
119  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
120  */
121 CAResult_t CARetransmissionReceivedData(CARetransmission_t *context,
122                                         const CARemoteEndpoint_t *endpoint, const void *pdu,
123                                         uint32_t size, void **retransmissionPdu);
124
125 /**
126  * @brief   Stopping the retransmission context
127  * @param   context     [IN]    context for retransmission
128  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
129  */
130 CAResult_t CARetransmissionStop(CARetransmission_t *context);
131
132 /**
133  * @brief   Terminating the retransmission context
134  * @param   context     [IN]    context for retransmission
135  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
136  */
137 CAResult_t CARetransmissionDestroy(CARetransmission_t *context);
138
139 /**
140  * @brief   Retransmitting the request/response for CONFIRMABLE type
141  */
142 void CACheckRetransmissionList();
143
144 /**
145  * @brief   Invoke Retransmission according to TimedAction Response
146  * @param   threadValue [IN]    context for retransmission
147  */
148 void CARetransmissionBaseRoutine(void *threadValue);
149
150 #ifdef __cplusplus
151 } /* extern "C" */
152 #endif
153
154 #endif  /* CA_RETRANSMISSION_SINGLETHREAD_H_ */
155