55960391355121d7d55a6795eeeb3de641710b74
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / camessagehandler.h
1 /* *****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains message functionality.
24  */
25
26 #ifndef CA_MESSAGE_HANDLER_H_
27 #define CA_MESSAGE_HANDLER_H_
28
29 #include "cacommon.h"
30 #include <coap/coap.h>
31
32 #define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
33 goto memory_error_exit;} }
34
35 typedef enum
36 {
37     SEND_TYPE_MULTICAST = 0,
38     SEND_TYPE_UNICAST
39 } CASendDataType_t;
40
41 typedef struct
42 {
43     CASendDataType_t type;
44     CAEndpoint_t *remoteEndpoint;
45     CARequestInfo_t *requestInfo;
46     CAResponseInfo_t *responseInfo;
47     CAErrorInfo_t *errorInfo;
48     CADataType_t dataType;
49 } CAData_t;
50
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55
56 /**
57  * Detaches control from the caller for sending message.
58  * @param[in] endpoint    endpoint information where the data has to be sent.
59  * @param[in] sendMsg     message that needs to be sent.
60  * @param[in] dataType    type of the message(request/response).
61  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
62  */
63 CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint,
64                                const void *sendMsg,
65                                CADataType_t dataType);
66
67 /**
68  * Setting the request and response callbacks for network packets.
69  * @param[in] ReqHandler      callback for receiving the requests.
70  * @param[in] RespHandler     callback for receiving the response.
71  * @param[in] ErrorHandler    callback for receiving error response.
72  */
73 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
74                              CAErrorCallback ErrorHandler);
75
76 /**
77  * Initialize the message handler by starting thread pool and initializing the
78  * send and receive queue.
79  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
80  */
81 CAResult_t CAInitializeMessageHandler();
82
83 /**
84  * Terminate the message handler by stopping  the thread pool and destroying the queues.
85  */
86 void CATerminateMessageHandler();
87
88 /**
89  * Handler for receiving request and response callback in single thread model.
90  */
91 void CAHandleRequestResponseCallbacks();
92
93 /**
94  * Setting the Callback funtion for network state change callback.
95  * @param[in] nwMonitorHandler    callback for network state change.
96  */
97 void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler);
98
99 /**
100  * To log the PDU data.
101  * @param[in] pdu    pdu data.
102  * @param[in] endpoint  endpoint
103  */
104 void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint);
105
106 #ifdef WITH_BWT
107 /**
108  * Add the data to the send queue thread.
109  * @param[in] data    send data.
110  */
111 void CAAddDataToSendThread(CAData_t *data);
112
113 /**
114  * Add the data to the receive queue thread to notify received data.
115  * @param[in] data    received data.
116  */
117 void CAAddDataToReceiveThread(CAData_t *data);
118 #endif
119
120 #ifdef __cplusplus
121 } /* extern "C" */
122 #endif
123
124 #endif /* CA_MESSAGE_HANDLER_H_ */