Patch for enabling blockwise and bt
[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 camessagehandler.h
23  * @brief 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.h"
31
32 /**
33  * @def VERIFY_NON_NULL
34  * @brief Macro to verify the validity of input argument.
35  */
36 #define VERIFY_NON_NULL(arg, log_tag, log_message) \
37     if (NULL == arg ){ \
38         OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
39         return CA_STATUS_INVALID_PARAM; \
40     } \
41
42 /**
43  * @def VERIFY_NON_NULL_VOID
44  * @brief Macro to verify the validity of input argument.
45  */
46 #define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \
47     if (NULL == arg ){ \
48         OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \
49         return; \
50     } \
51
52 #define CA_MEMORY_ALLOC_CHECK(arg) { if (NULL == arg) {OIC_LOG(ERROR, TAG, "Out of memory"); \
53 goto memory_error_exit;} }
54
55 typedef enum
56 {
57     SEND_TYPE_MULTICAST = 0, SEND_TYPE_UNICAST
58 } CASendDataType_t;
59
60 typedef enum
61 {
62     CA_REQUEST_DATA = 1,
63     CA_RESPONSE_DATA = 2,
64     CA_ERROR_DATA = 3,
65 } CADataType_t;
66
67 typedef struct
68 {
69     CASendDataType_t type;
70     CAEndpoint_t *remoteEndpoint;
71     CARequestInfo_t *requestInfo;
72     CAResponseInfo_t *responseInfo;
73     CAErrorInfo_t *errorInfo;
74     CAHeaderOption_t *options;
75     CADataType_t dataType;
76     uint8_t numOptions;
77 } CAData_t;
78
79 #ifdef __cplusplus
80 extern "C"
81 {
82 #endif
83
84 /**
85  * @brief   Detaches control from the caller for sending unicast request
86  * @param   endpoint       [IN]    endpoint information where the data has to be sent
87  * @param   request        [IN]    request that needs to be sent
88  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
89  */
90 CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
91                                   const CARequestInfo_t *request);
92
93 /**
94  * @brief   Detaches control from the caller for sending multicast request
95  * @param   object         [IN]    Group endpoint information where the data has to be sent
96  * @param   request        [IN]    request that needs to be sent
97  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
98  */
99 CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
100                                        const CARequestInfo_t *request);
101
102 /**
103  * @brief   Detaches control from the caller for sending response
104  * @param   endpoint       [IN]    endpoint information where the data has to be sent
105  * @param   response       [IN]    response that needs to be sent
106  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
107  */
108 CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
109                                    const CAResponseInfo_t *response);
110
111 /**
112  * @brief   Detaches control from the caller for sending request
113  * @param   resourceUri    [IN]    resource uri that needs to  be sent in the request
114  * @param   token          [IN]    token information of the request
115  * @param   tokenLength    [IN]    length of the token
116  * @param   options        [IN]    header options that need to be append in the request
117  * @param   numOptions     [IN]    number of options be appended
118  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
119  */
120 CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token,
121                                       uint8_t tokenLength, const CAHeaderOption_t *options,
122                                       uint8_t numOptions);
123
124 /**
125  * @brief   Setting the request and response callbacks for network packets
126  * @param   ReqHandler     [IN]    callback for receiving the requests
127  * @param   RespHandler    [IN]    callback for receiving the response
128  * @param   ErrorHandler   [IN]    callback for receiving error response
129  * @return  NONE
130  */
131 void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
132                              CAErrorCallback ErrorHandler);
133
134 /**
135  * @brief   Initialize the message handler by starting thread pool and initializing the
136  *          send and receive queue
137  * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h)
138  */
139 CAResult_t CAInitializeMessageHandler();
140
141 /**
142  * @brief   Terminate the message handler by stopping  the thread pool and destroying the queues
143  * @return  NONE
144  */
145 void CATerminateMessageHandler();
146
147 /**
148  * @brief   Handler for receiving request and response callback in single thread model
149  */
150 void CAHandleRequestResponseCallbacks();
151
152 /**
153  * @brief To log the PDU data
154  * @param   pdu            [IN]    pdu data
155  */
156 void CALogPDUInfo(coap_pdu_t *pdu);
157
158 #ifdef __cplusplus
159 } /* extern "C" */
160 #endif
161
162 #endif /* CA_MESSAGE_HANDLER_H_ */
163