[IOT-1671] Fixed base layer terminate logic
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / camessagehandler.h
index 597da7b..5596039 100644 (file)
@@ -1,4 +1,4 @@
-/******************************************************************
+/* *****************************************************************
  *
  * 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;
-
-typedef void (*CAMessageHandlerCallback)(int32_t id, CADetachErrorCode code);
+    SEND_TYPE_MULTICAST = 0,
+    SEND_TYPE_UNICAST
+} CASendDataType_t;
 
-int32_t CADetachRequestMessage(const CARemoteEndpoint_t* object, const CARequestInfo_t* request);
-
-int32_t CADetachResponseMessage(const CARemoteEndpoint_t* object, const CAResponseInfo_t* response);
+typedef struct
+{
+    CASendDataType_t type;
+    CAEndpoint_t *remoteEndpoint;
+    CARequestInfo_t *requestInfo;
+    CAResponseInfo_t *responseInfo;
+    CAErrorInfo_t *errorInfo;
+    CADataType_t dataType;
+} CAData_t;
 
-int32_t CADetachMessageResourceUri(const CAURI_t resourceUri);
+#ifdef __cplusplus
+extern "C"
+{
+#endif
 
-void CASetMessageHandlerCallback(CAMessageHandlerCallback callback);
+/**
+ * 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);
 
-void CASetRequestResponseCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
+/**
+ * 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);
 
+/**
+ * Initialize the message handler by starting thread pool and initializing the
+ * send and receive queue.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
 CAResult_t CAInitializeMessageHandler();
 
+/**
+ * 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);
+
+/**
+ * To log the PDU data.
+ * @param[in] pdu    pdu data.
+ * @param[in] endpoint  endpoint
+ */
+void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint);
+
+#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_ */