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_
30 #include <coap/coap.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,
43 CASendDataType_t type;
44 CAEndpoint_t *remoteEndpoint;
45 CARequestInfo_t *requestInfo;
46 CAResponseInfo_t *responseInfo;
47 CAErrorInfo_t *errorInfo;
48 CAConnectEvent_t eventInfo;
49 CADataType_t dataType;
58 * Detaches control from the caller for sending message.
59 * @param[in] endpoint endpoint information where the data has to be sent.
60 * @param[in] sendMsg message that needs to be sent.
61 * @param[in] dataType type of the message(request/response).
62 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
64 CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint,
66 CADataType_t dataType);
69 * Detaches control from the caller for sending message to adapter.
70 * @param[in] endpoint endpoint information where the data has to be sent.
71 * @param[in] event command to request disconect or connect.
72 * @param[in] dataType type of the message(request/response).
73 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
75 CAResult_t CADetachSendNetworkReqMessage(const CAEndpoint_t *endpoint,
76 CAConnectEvent_t event,
77 CADataType_t dataType);
80 * Setting the request and response callbacks for network packets.
81 * @param[in] ReqHandler callback for receiving the requests.
82 * @param[in] RespHandler callback for receiving the response.
83 * @param[in] ErrorHandler callback for receiving error response.
85 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
86 CAErrorCallback ErrorHandler);
89 * Initialize the message handler by starting thread pool and initializing the
90 * send and receive queue.
91 * @param[in] transportType transport type to initialize.
92 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
94 CAResult_t CAInitializeMessageHandler(CATransportAdapter_t transportType);
97 * Clears the message handler queue data.
98 * @param[in] transportType transport type to initialize.
100 void CAClearMessageHandler(CATransportAdapter_t transportType);
103 * Terminate the message handler by stopping the thread pool and destroying the queues.
105 void CATerminateMessageHandler();
108 * Handler for receiving request and response callback in single thread model.
110 void CAHandleRequestResponseCallbacks();
113 * Setting the Callback funtion for network state change callback.
114 * @param[in] nwMonitorHandler callback for network state change.
116 void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler);
120 * Add the data to the send queue thread.
121 * @param[in] data send data.
123 void CAAddDataToSendThread(CAData_t *data);
126 * Add the data to the receive queue thread to notify received data.
127 * @param[in] data received data.
129 void CAAddDataToReceiveThread(CAData_t *data);
136 #endif /* CA_MESSAGE_HANDLER_H_ */