[IOT-1671] Fixed base layer terminate logic
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / camessagehandler.h
index 9e58735..5596039 100644 (file)
@@ -1,4 +1,4 @@
-/******************************************************************
+/* *****************************************************************
  *
  * Copyright 2014 Samsung Electronics All Rights Reserved.
  *
  ******************************************************************/
 
 /**
- * @file camessagehandler.h
- * @brief This file contains message functionality.
+ * @file
+ * This file contains message functionality.
  */
 
 #ifndef CA_MESSAGE_HANDLER_H_
 #define CA_MESSAGE_HANDLER_H_
 
 #include "cacommon.h"
-#include "coap.h"
-
-/**
- * @def VERIFY_NON_NULL
- * @brief Macro to verify the validity of input argument.
- */
-#define VERIFY_NON_NULL(arg, log_tag, log_message) \
-    if (NULL == arg ){ \
-        OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
-        return CA_STATUS_INVALID_PARAM; \
-    } \
-
-/**
- * @def VERIFY_NON_NULL_VOID
- * @brief Macro to verify the validity of input argument.
- */
-#define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \
-    if (NULL == arg ){ \
-        OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
-        return; \
-    } \
+#include <coap/coap.h>
 
 #define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
 goto memory_error_exit;} }
 
+typedef enum
+{
+    SEND_TYPE_MULTICAST = 0,
+    SEND_TYPE_UNICAST
+} CASendDataType_t;
+
+typedef struct
+{
+    CASendDataType_t type;
+    CAEndpoint_t *remoteEndpoint;
+    CARequestInfo_t *requestInfo;
+    CAResponseInfo_t *responseInfo;
+    CAErrorInfo_t *errorInfo;
+    CADataType_t dataType;
+} CAData_t;
+
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 /**
- * @brief   Detaches control from the caller for sending unicast request
- * @param   endpoint       [IN]    endpoint information where the data has to be sent
- * @param   request        [IN]    request that needs to be sent
- * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
+ * 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 CADetachRequestMessage(const CAEndpoint_t *endpoint,
-                                  const CARequestInfo_t *request);
+CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint,
+                               const void *sendMsg,
+                               CADataType_t dataType);
 
 /**
- * @brief   Detaches control from the caller for sending multicast request
- * @param   object         [IN]    Group endpoint information where the data has to be sent
- * @param   request        [IN]    request that needs to be sent
- * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
+ * 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.
  */
-CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
-                                       const CARequestInfo_t *request);
+void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
+                             CAErrorCallback ErrorHandler);
 
 /**
- * @brief   Detaches control from the caller for sending response
- * @param   endpoint       [IN]    endpoint information where the data has to be sent
- * @param   response       [IN]    response that needs to be sent
- * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
+ * 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 CADetachResponseMessage(const CAEndpoint_t *endpoint,
-                                   const CAResponseInfo_t *response);
+CAResult_t CAInitializeMessageHandler();
 
 /**
- * @brief   Detaches control from the caller for sending request
- * @param   resourceUri    [IN]    resource uri that needs to  be sent in the request
- * @param   token          [IN]    token information of the request
- * @param   tokenLength    [IN]    length of the token
- * @param   options        [IN]    header options that need to be append in the request
- * @param   numOptions     [IN]    number of options be appended
- * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
+ * Terminate the message handler by stopping  the thread pool and destroying the queues.
  */
-CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
-                                      uint8_t tokenLength, const CAHeaderOption_t *options,
-                                      uint8_t numOptions);
+void CATerminateMessageHandler();
 
 /**
- * @brief   Setting the request and response callbacks for network packets
- * @param   ReqHandler     [IN]    callback for receiving the requests
- * @param   RespHandler    [IN]    callback for receiving the response
- * @param   ErrorHandler   [IN]    callback for receiving error response
- * @return  NONE
+ * Handler for receiving request and response callback in single thread model.
  */
-void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
-                             CAErrorCallback ErrorHandler);
+void CAHandleRequestResponseCallbacks();
 
 /**
- * @brief   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)
+ * Setting the Callback funtion for network state change callback.
+ * @param[in] nwMonitorHandler    callback for network state change.
  */
-CAResult_t CAInitializeMessageHandler();
+void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler);
 
 /**
- * @brief   Terminate the message handler by stopping  the thread pool and destroying the queues
- * @return  NONE
+ * To log the PDU data.
+ * @param[in] pdu    pdu data.
+ * @param[in] endpoint  endpoint
  */
-void CATerminateMessageHandler();
+void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint);
 
+#ifdef WITH_BWT
 /**
- * @brief   Handler for receiving request and response callback in single thread model
+ * Add the data to the send queue thread.
+ * @param[in] data    send data.
  */
-void CAHandleRequestResponseCallbacks();
+void CAAddDataToSendThread(CAData_t *data);
 
 /**
- * @brief To log the PDU data
- * @param   pdu            [IN]    pdu data
+ * Add the data to the receive queue thread to notify received data.
+ * @param[in] data    received data.
  */
-void CALogPDUInfo(coap_pdu_t *pdu);
+void CAAddDataToReceiveThread(CAData_t *data);
+#endif
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
 #endif /* CA_MESSAGE_HANDLER_H_ */
-