modified CA comment for doxygen.
[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     CAHeaderOption_t *options;
56     CADataType_t dataType;
57     uint8_t numOptions;
58 } CAData_t;
59
60 #ifdef __cplusplus
61 extern "C"
62 {
63 #endif
64
65 /**
66  * Detaches control from the caller for sending unicast request.
67  * @param[in] endpoint    endpoint information where the data has to be sent.
68  * @param[in] request     request that needs to be sent.
69  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
70  */
71 CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
72                                   const CARequestInfo_t *request);
73
74 /**
75  * Detaches control from the caller for sending multicast request.
76  * @param[in] object     Group endpoint information where the data has to be sent.
77  * @param[in] request    request that needs to be sent.
78  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
79  */
80 CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
81                                        const CARequestInfo_t *request);
82
83 /**
84  * Detaches control from the caller for sending response.
85  * @param[in] endpoint    endpoint information where the data has to be sent.
86  * @param[in] response    response that needs to be sent.
87  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
88  */
89 CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
90                                    const CAResponseInfo_t *response);
91
92 /**
93  * Detaches control from the caller for sending request.
94  * @param[in] resourceUri    resource uri that needs to  be sent in the request.
95  * @param[in] token          token information of the request.
96  * @param[in] tokenLength    length of the token.
97  * @param[in] options        header options that need to be append in the request.
98  * @param[in] numOptions     number of options be appended.
99  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
100  */
101 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
102                                       uint8_t tokenLength, const CAHeaderOption_t *options,
103                                       uint8_t numOptions);
104
105 /**
106  * Setting the request and response callbacks for network packets.
107  * @param[in] ReqHandler      callback for receiving the requests.
108  * @param[in] RespHandler     callback for receiving the response.
109  * @param[in] ErrorHandler    callback for receiving error response.
110  */
111 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
112                              CAErrorCallback ErrorHandler);
113
114 /**
115  * Initialize the message handler by starting thread pool and initializing the
116  * send and receive queue.
117  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
118  */
119 CAResult_t CAInitializeMessageHandler();
120
121 /**
122  * Terminate the message handler by stopping  the thread pool and destroying the queues.
123  */
124 void CATerminateMessageHandler();
125
126 /**
127  * Handler for receiving request and response callback in single thread model.
128  */
129 void CAHandleRequestResponseCallbacks();
130
131 /**
132  * To log the PDU data.
133  * @param[in] pdu    pdu data.
134  */
135 void CALogPDUInfo(coap_pdu_t *pdu);
136
137 #ifdef WITH_BWT
138 /**
139  * Add the data to the send queue thread.
140  * @param[in] data    send data.
141  */
142 void CAAddDataToSendThread(CAData_t *data);
143
144 /**
145  * Add the data to the receive queue thread to notify received data.
146  * @param[in] data    received data.
147  */
148 void CAAddDataToReceiveThread(CAData_t *data);
149 #endif
150
151 #ifdef __cplusplus
152 } /* extern "C" */
153 #endif
154
155 #endif /* CA_MESSAGE_HANDLER_H_ */