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 * @brief This file contains message functionality.
26 #ifndef CA_MESSAGE_HANDLER_H_
27 #define CA_MESSAGE_HANDLER_H_
33 * @def VERIFY_NON_NULL
34 * @brief Macro to verify the validity of input argument.
36 #define VERIFY_NON_NULL(arg, log_tag, log_message) \
38 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
39 return CA_STATUS_INVALID_PARAM; \
43 * @def VERIFY_NON_NULL_VOID
44 * @brief Macro to verify the validity of input argument.
46 #define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \
48 OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
52 #define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
53 goto memory_error_exit;} }
61 * @brief Detaches control from the caller for sending unicast request
62 * @param endpoint [IN] endpoint information where the data has to be sent
63 * @param request [IN] request that needs to be sent
64 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
66 CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
67 const CARequestInfo_t *request);
70 * @brief Detaches control from the caller for sending multicast request
71 * @param object [IN] Group endpoint information where the data has to be sent
72 * @param request [IN] request that needs to be sent
73 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
75 CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
76 const CARequestInfo_t *request);
79 * @brief Detaches control from the caller for sending response
80 * @param endpoint [IN] endpoint information where the data has to be sent
81 * @param response [IN] response that needs to be sent
82 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
84 CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
85 const CAResponseInfo_t *response);
88 * @brief Detaches control from the caller for sending request
89 * @param resourceUri [IN] resource uri that needs to be sent in the request
90 * @param token [IN] token information of the request
91 * @param tokenLength [IN] length of the token
92 * @param options [IN] header options that need to be append in the request
93 * @param numOptions [IN] number of options be appended
94 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
96 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
97 uint8_t tokenLength, const CAHeaderOption_t *options,
101 * @brief Setting the request and response callbacks for network packets
102 * @param ReqHandler [IN] callback for receiving the requests
103 * @param RespHandler [IN] callback for receiving the response
104 * @param ErrorHandler [IN] callback for receiving error response
107 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
108 CAErrorCallback ErrorHandler);
111 * @brief Initialize the message handler by starting thread pool and initializing the
112 * send and receive queue
113 * @return CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
115 CAResult_t CAInitializeMessageHandler();
118 * @brief Terminate the message handler by stopping the thread pool and destroying the queues
121 void CATerminateMessageHandler();
124 * @brief Handler for receiving request and response callback in single thread model
126 void CAHandleRequestResponseCallbacks();
129 * @brief To log the PDU data
130 * @param pdu [IN] pdu data
132 void CALogPDUInfo(coap_pdu_t *pdu);
138 #endif /* CA_MESSAGE_HANDLER_H_ */