replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / util / inc / caconnectionmanager.h
1 /* *****************************************************************
2  *
3  * Copyright 2016 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 common function for connection manager
24  */
25
26 #ifndef CA_CONNECTIONMANAGER_H_
27 #define CA_CONNECTIONMANAGER_H_
28
29 #include <stdint.h>
30
31 #include <coap/coap.h>
32 #include "cathreadpool.h"
33 #include "octhread.h"
34 #include "logger.h"
35 #include "uarraylist.h"
36 #include "cacommon.h"
37 #include "caprotocolmessage.h"
38 #include "camessagehandler.h"
39 #include "cautilinterface.h"
40
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45
46 /**
47  * Callback to send replaced data.
48  * @param[in]   data    send data.
49  */
50 typedef void (*CASendThreadFunc)(CAData_t *data);
51
52 /**
53  * Callback to notify received data from the remote endpoint.
54  * @param[in]   data    received data.
55  */
56 typedef void (*CAReceiveThreadFunc)(CAData_t *data);
57
58 /**
59  * Context of connection manager
60  */
61 typedef struct
62 {
63     /** send method for block data. **/
64     CASendThreadFunc sendThreadFunc;
65
66     /** callback function for received message. **/
67     CAReceiveThreadFunc receivedThreadFunc;
68
69     /** array list on which the thread is operating. **/
70     u_arraylist_t *dataList;
71
72     /** data list mutex for synchronization. **/
73     oc_mutex dataListMutex;
74
75     /** sender mutex for synchronization. **/
76     oc_mutex dataSenderMutex;
77 } CAConnectionManagerContext_t;
78
79 /**
80  * Initializes the connection manager context.
81  * @param[in]  CASendThreadFunc    function point to add data in send queue thread.
82  * @param[in]  CAReceiveThreadFunc function point to add data in receive queue thread.
83  * @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
84  */
85 CAResult_t CAInitializeConnectionManager(CASendThreadFunc blockSendMethod,
86                                          CAReceiveThreadFunc receivedDataCallback);
87
88 /**
89  * Terminate the connection manager context.
90  */
91 void CATerminateConnectionManager();
92
93 /**
94  * Initialize mutex.
95  * @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
96  */
97 CAResult_t CAInitConnectionManagerMutexVariables();
98
99 /**
100  * Terminate mutex.
101  */
102 void CATerminateConnectionManagerMutexVariables();
103
104 /**
105  * Get request/response message to send.
106  */
107 CAData_t* CAGetConnectionManagerMessageData(CAData_t *data);
108
109 /**
110  * Start connection manager.
111  */
112 void CAStartConnectionManagerService(CMConfigureInfo_t info);
113
114 #ifdef __cplusplus
115 } /* extern "C" */
116 #endif
117
118 #endif  // CA_CONNECTIONMANAGER_H_