Merge branch 'master' into easysetup
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / catcpinterface.h
1 /* *****************************************************************
2  *
3  * Copyright 2015 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 provides APIs TCP client/server/network monitor modules.
24  */
25
26 #ifndef CA_TCP_INTERFACE_H_
27 #define CA_TCP_INTERFACE_H_
28
29 #include <stdbool.h>
30
31 #include "cacommon.h"
32 #include "catcpadapter.h"
33 #include "cathreadpool.h"
34 #include "uarraylist.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 /**
42  * Callback to be notified on reception of any data from remote OIC devices.
43  *
44  * @param[in]  endpoint      network endpoint description.
45  * @param[in]  data          Data received from remote OIC device.
46  * @param[in]  dataLength    Length of data in bytes.
47  * @pre  Callback must be registered using CAIPSetPacketReceiveCallback().
48  */
49 typedef void (*CATCPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
50                                            const void *data,
51                                            uint32_t dataLength);
52
53 /**
54   * Callback to notify error in the TCP adapter.
55   *
56   * @param[in]  endpoint      network endpoint description.
57   * @param[in]  data          Data sent/received.
58   * @param[in]  dataLength    Length of data in bytes.
59   * @param[in]  result        result of request from R.I.
60   * @pre  Callback must be registered using CAIPSetPacketReceiveCallback().
61  */
62 typedef void (*CATCPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data,
63                                         uint32_t dataLength, CAResult_t result);
64
65 /**
66  * set error callback to notify error in TCP adapter.
67  *
68  * @param[in]  errorHandleCallback Callback function to notify the error
69  * in the TCP adapter.
70  */
71 void CATCPSetErrorHandler(CATCPErrorHandleCallback errorHandleCallback);
72
73 /**
74  * Start TCP server.
75  *
76  * @param   threadPool   Thread pool for managing Unicast server threads.
77  * @return ::CA_STATUS_OK or Appropriate error code.
78  * @retval ::CA_STATUS_OK  Successful.
79  * @retval ::CA_STATUS_INVALID_PARAM Invalid input data.
80  * @retval ::CA_STATUS_FAILED Initialization failed.
81  */
82 CAResult_t CATCPStartServer(const ca_thread_pool_t threadPool);
83
84 /**
85  * Stop TCP server.
86  */
87 void CATCPStopServer();
88
89 /**
90  * Set this callback for receiving data packets from peer devices.
91  *
92  * @param[in]  callback    Callback to be notified on reception of unicast data packets.
93  */
94 void CATCPSetPacketReceiveCallback(CATCPPacketReceivedCallback callback);
95
96 /**
97  * API to send unicast TCP data.
98  *
99  * @param[in]  endpoint          complete network address to send to.
100  * @param[in]  data              Data to be send.
101  * @param[in]  dataLength        Length of data in bytes.
102  * @param[in]  isMulticast       Whether data needs to be sent to multicast ip.
103  */
104 void CATCPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t dataLength,
105                    bool isMulticast);
106
107 /**
108  * Get a list of CAInterface_t items.
109  *
110  * @return  List of CAInterface_t items.
111  */
112 u_arraylist_t *CATCPGetInterfaceInformation(int desiredIndex);
113
114 /**
115  * Connect to TCP Server.
116  * @param[in]   TCPServerInfo   TCP Server information.
117  * @return  TCP Server Information structure.
118  */
119 CATCPServerInfo_t *CAConnectToTCPServer(const CAEndpoint_t *TCPServerInfo);
120
121 /**
122  * Disconnect from TCP Server.
123  * @param[in]   TCPServerInfo   TCP Server information.
124  * @return  ::CA_STATUS_OK or Appropriate error code.
125  */
126 CAResult_t CADisconnectFromTCPServer(const CAEndpoint_t *TCPServerInfo);
127
128 /**
129  * Get TCP Connection Information from list.
130  * @param[in]   addr    TCP Server address.
131  * @param[in]   port    TCP Server port.
132  * @param[out]  index   index of array list.
133  * @return  TCP Server Information structure.
134  */
135 CATCPServerInfo_t *CAGetTCPServerInfoFromList(const char *addr, const uint16_t port,
136                                             uint32_t *index);
137
138 #ifdef __cplusplus
139 }
140 #endif
141
142 #endif /* CA_TCP_INTERFACE_H_ */