c84836c0567f8a07e50324881c2eb96e87e369d0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / camessagehandler.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  * This file contains message functionality.
24  */
25
26 #ifndef CA_MESSAGE_HANDLER_H_
27 #define CA_MESSAGE_HANDLER_H_
28
29 #include "cacommon.h"
30 #include "coap.h"
31
32 #define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
33 goto memory_error_exit;} }
34
35 typedef enum
36 {
37     SEND_TYPE_MULTICAST = 0,
38     SEND_TYPE_UNICAST
39 } CASendDataType_t;
40
41 typedef enum
42 {
43     CA_REQUEST_DATA = 1,
44     CA_RESPONSE_DATA = 2,
45     CA_ERROR_DATA = 3,
46 } CADataType_t;
47
48 typedef struct
49 {
50     CASendDataType_t type;
51     CAEndpoint_t *remoteEndpoint;
52     CARequestInfo_t *requestInfo;
53     CAResponseInfo_t *responseInfo;
54     CAErrorInfo_t *errorInfo;
55     CADataType_t dataType;
56 } CAData_t;
57
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62
63 /**
64  * Detaches control from the caller for sending unicast request.
65  * @param[in] endpoint    endpoint information where the data has to be sent.
66  * @param[in] request     request that needs to be sent.
67  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
68  */
69 CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
70                                   const CARequestInfo_t *request);
71
72 /**
73  * Detaches control from the caller for sending multicast request.
74  * @param[in] object     Group endpoint information where the data has to be sent.
75  * @param[in] request    request that needs to be sent.
76  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
77  */
78 CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
79                                        const CARequestInfo_t *request);
80
81 /**
82  * Detaches control from the caller for sending response.
83  * @param[in] endpoint    endpoint information where the data has to be sent.
84  * @param[in] response    response that needs to be sent.
85  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
86  */
87 CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
88                                    const CAResponseInfo_t *response);
89
90 /**
91  * Detaches control from the caller for sending request.
92  * @param[in] resourceUri    resource uri that needs to  be sent in the request.
93  * @param[in] token          token information of the request.
94  * @param[in] tokenLength    length of the token.
95  * @param[in] options        header options that need to be append in the request.
96  * @param[in] numOptions     number of options be appended.
97  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
98  */
99 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
100                                       uint8_t tokenLength, const CAHeaderOption_t *options,
101                                       uint8_t numOptions);
102
103 /**
104  * Setting the request and response callbacks for network packets.
105  * @param[in] ReqHandler      callback for receiving the requests.
106  * @param[in] RespHandler     callback for receiving the response.
107  * @param[in] ErrorHandler    callback for receiving error response.
108  */
109 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
110                              CAErrorCallback ErrorHandler);
111
112 /**
113  * Initialize the message handler by starting thread pool and initializing the
114  * send and receive queue.
115  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
116  */
117 CAResult_t CAInitializeMessageHandler();
118
119 /**
120  * Terminate the message handler by stopping  the thread pool and destroying the queues.
121  */
122 void CATerminateMessageHandler();
123
124 /**
125  * Handler for receiving request and response callback in single thread model.
126  */
127 void CAHandleRequestResponseCallbacks();
128
129 /**
130  * To log the PDU data.
131  * @param[in] pdu    pdu data.
132  * @param[in] endpoint  endpoint
133  */
134 void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint);
135
136 #ifdef WITH_BWT
137 /**
138  * Add the data to the send queue thread.
139  * @param[in] data    send data.
140  */
141 void CAAddDataToSendThread(CAData_t *data);
142
143 /**
144  * Add the data to the receive queue thread to notify received data.
145  * @param[in] data    received data.
146  */
147 void CAAddDataToReceiveThread(CAData_t *data);
148 #endif
149
150 #ifdef __cplusplus
151 } /* extern "C" */
152 #endif
153
154 #endif /* CA_MESSAGE_HANDLER_H_ */