1 /* *****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
23 * This file contains message functionality.
26 #ifndef CA_MESSAGE_HANDLER_H_
27 #define CA_MESSAGE_HANDLER_H_
32 #define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
33 goto memory_error_exit;} }
37 SEND_TYPE_MULTICAST = 0,
50 CASendDataType_t type;
51 CAEndpoint_t *remoteEndpoint;
52 CARequestInfo_t *requestInfo;
53 CAResponseInfo_t *responseInfo;
54 CAErrorInfo_t *errorInfo;
55 CADataType_t dataType;
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).
69 CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
70 const CARequestInfo_t *request);
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).
78 CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
79 const CARequestInfo_t *request);
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).
87 CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
88 const CAResponseInfo_t *response);
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).
99 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
100 uint8_t tokenLength, const CAHeaderOption_t *options,
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.
109 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
110 CAErrorCallback ErrorHandler);
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).
117 CAResult_t CAInitializeMessageHandler();
120 * Terminate the message handler by stopping the thread pool and destroying the queues.
122 void CATerminateMessageHandler();
125 * Handler for receiving request and response callback in single thread model.
127 void CAHandleRequestResponseCallbacks();
130 * To log the PDU data.
131 * @param[in] pdu pdu data.
133 void CALogPDUInfo(coap_pdu_t *pdu);
137 * Add the data to the send queue thread.
138 * @param[in] data send data.
140 void CAAddDataToSendThread(CAData_t *data);
143 * Add the data to the receive queue thread to notify received data.
144 * @param[in] data received data.
146 void CAAddDataToReceiveThread(CAData_t *data);
153 #endif /* CA_MESSAGE_HANDLER_H_ */