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 ******************************************************************/
22 * @file camessagehandler.h
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 CAHeaderOption_t *options;
56 CADataType_t dataType;
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)
71 CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
72 const CARequestInfo_t *request);
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)
80 CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
81 const CARequestInfo_t *request);
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)
89 CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
90 const CAResponseInfo_t *response);
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)
101 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
102 uint8_t tokenLength, const CAHeaderOption_t *options,
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
111 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
112 CAErrorCallback ErrorHandler);
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)
119 CAResult_t CAInitializeMessageHandler();
122 * Terminate the message handler by stopping the thread pool and destroying the queues
124 void CATerminateMessageHandler();
127 * Handler for receiving request and response callback in single thread model
129 void CAHandleRequestResponseCallbacks();
132 * To log the PDU data
133 * @param[IN] pdu pdu data
135 void CALogPDUInfo(coap_pdu_t *pdu);
139 * Add the data to the send queue thread
140 * @param[IN] data send data
142 void CAAddDataToSendThread(CAData_t *data);
145 * Add the data to the receive queue thread to notify received data
146 * @param[IN] data received data
148 void CAAddDataToReceiveThread(CAData_t *data);
155 #endif /* CA_MESSAGE_HANDLER_H_ */