-/******************************************************************
+/* *****************************************************************
*
* Copyright 2014 Samsung Electronics All Rights Reserved.
*
* limitations under the License.
*
******************************************************************/
-#ifndef __CA_MESSAGE_HANDLER_H_
-#define __CA_MESSAGE_HANDLER_H_
-#include <stdint.h>
+/**
+ * @file
+ * This file contains message functionality.
+ */
+
+#ifndef CA_MESSAGE_HANDLER_H_
+#define CA_MESSAGE_HANDLER_H_
+
#include "cacommon.h"
+#include <coap/coap.h>
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+#define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
+goto memory_error_exit;} }
typedef enum
{
- SUCCESS = 0, NETWORK_ERROR, FAIL
-} CADetachErrorCode;
+ SEND_TYPE_MULTICAST = 0,
+ SEND_TYPE_UNICAST
+} CASendDataType_t;
-typedef void (*CAMessageHandlerCallback)(int32_t id, CADetachErrorCode code);
+typedef struct
+{
+ CASendDataType_t type;
+ CAEndpoint_t *remoteEndpoint;
+ CARequestInfo_t *requestInfo;
+ CAResponseInfo_t *responseInfo;
+ CAErrorInfo_t *errorInfo;
+ CAConnectEvent_t eventInfo;
+ CADataType_t dataType;
+} CAData_t;
-int32_t CADetachRequestMessage(const CARemoteEndpoint_t* object, const CARequestInfo_t* request);
+#ifdef __cplusplus
+extern "C"
+{
+#endif
-int32_t CADetachResponseMessage(const CARemoteEndpoint_t* object, const CAResponseInfo_t* response);
+/**
+ * Detaches control from the caller for sending message.
+ * @param[in] endpoint endpoint information where the data has to be sent.
+ * @param[in] sendMsg message that needs to be sent.
+ * @param[in] dataType type of the message(request/response).
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint,
+ const void *sendMsg,
+ CADataType_t dataType);
-int32_t CADetachMessageResourceUri(const CAURI_t resourceUri);
+/**
+ * Detaches control from the caller for sending message to adapter.
+ * @param[in] endpoint endpoint information where the data has to be sent.
+ * @param[in] event command to request disconect or connect.
+ * @param[in] dataType type of the message(request/response).
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CADetachSendNetworkReqMessage(const CAEndpoint_t *endpoint,
+ CAConnectEvent_t event,
+ CADataType_t dataType);
-void CASetMessageHandlerCallback(CAMessageHandlerCallback callback);
+/**
+ * Setting the request and response callbacks for network packets.
+ * @param[in] ReqHandler callback for receiving the requests.
+ * @param[in] RespHandler callback for receiving the response.
+ * @param[in] ErrorHandler callback for receiving error response.
+ */
+void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
+ CAErrorCallback ErrorHandler);
-void CASetRequestResponseCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
+/**
+ * Initialize the message handler by starting thread pool and initializing the
+ * send and receive queue.
+ * @param[in] transportType transport type to initialize.
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAInitializeMessageHandler(CATransportAdapter_t transportType);
-CAResult_t CAInitializeMessageHandler();
+/**
+ * Clears the message handler queue data.
+ * @param[in] transportType transport type to initialize.
+ */
+void CAClearMessageHandler(CATransportAdapter_t transportType);
+/**
+ * Terminate the message handler by stopping the thread pool and destroying the queues.
+ */
void CATerminateMessageHandler();
+/**
+ * Handler for receiving request and response callback in single thread model.
+ */
void CAHandleRequestResponseCallbacks();
+/**
+ * Setting the Callback funtion for network state change callback.
+ * @param[in] nwMonitorHandler callback for network state change.
+ */
+void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler);
+
+#ifdef WITH_BWT
+/**
+ * Add the data to the send queue thread.
+ * @param[in] data send data.
+ */
+void CAAddDataToSendThread(CAData_t *data);
+
+/**
+ * Add the data to the receive queue thread to notify received data.
+ * @param[in] data received data.
+ */
+void CAAddDataToReceiveThread(CAData_t *data);
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif
-#endif //#ifndef __CA_MESSAGE_HANDLER_H_
+#endif /* CA_MESSAGE_HANDLER_H_ */