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 message.
65 * @param[in] endpoint endpoint information where the data has to be sent.
66 * @param[in] sendMsg message that needs to be sent.
67 * @param[in] dataType type of the message(request/response).
68 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
70 CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint,
72 CADataType_t dataType);
75 * Setting the request and response callbacks for network packets.
76 * @param[in] ReqHandler callback for receiving the requests.
77 * @param[in] RespHandler callback for receiving the response.
78 * @param[in] ErrorHandler callback for receiving error response.
80 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
81 CAErrorCallback ErrorHandler);
84 * Initialize the message handler by starting thread pool and initializing the
85 * send and receive queue.
86 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
88 CAResult_t CAInitializeMessageHandler();
91 * Terminate the message handler by stopping the thread pool and destroying the queues.
93 void CATerminateMessageHandler();
96 * Handler for receiving request and response callback in single thread model.
98 void CAHandleRequestResponseCallbacks();
101 * Setting the Callback funtion for network state change callback.
102 * @param[in] nwMonitorHandler callback for network state change.
104 void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler);
107 * To log the PDU data.
108 * @param[in] pdu pdu data.
109 * @param[in] endpoint endpoint
111 void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint);
115 * Add the data to the send queue thread.
116 * @param[in] data send data.
118 void CAAddDataToSendThread(CAData_t *data);
121 * Add the data to the receive queue thread to notify received data.
122 * @param[in] data received data.
124 void CAAddDataToReceiveThread(CAData_t *data);
131 #endif /* CA_MESSAGE_HANDLER_H_ */