Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / catcpadapter.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 contains the APIs for TCP Adapter.
24  */
25 #ifndef CA_TCP_ADAPTER_H_
26 #define CA_TCP_ADAPTER_H_
27
28 #include "cacommon.h"
29 #include "caadapterinterface.h"
30 #include "cathreadpool.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /**
38  * TCP Server Information for IPv4 TCP transport
39  */
40 typedef struct
41 {
42     char addr[MAX_ADDR_STR_SIZE_CA];    /**< TCP Server address */
43     CASocket_t u4tcp;                   /**< TCP Server port */
44 } CATCPServerInfo_t;
45
46 /**
47  * API to initialize TCP Interface.
48  * @param[in] registerCallback      Callback to register TCP interfaces to
49  *                                  Connectivity Abstraction Layer.
50  * @param[in] networkPacketCallback Callback to notify request and
51  *                                  response messages from server(s)
52  *                                  started at Connectivity Abstraction Layer.
53  * @param[in] netCallback           Callback to notify the network additions
54  *                                  to Connectivity Abstraction Layer.
55  * @param[in] errorCallback         Callback to notify the network errors to
56  *                                  Connectivity Abstraction Layer.
57  * @param[in] handle                Threadpool Handle.
58  * @return  ::CA_STATUS_OK or Appropriate error code
59  */
60 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
61                            CANetworkPacketReceivedCallback networkPacketCallback,
62                            CANetworkChangeCallback netCallback,
63                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
64
65 /**
66  * Start TCP Interface adapter.
67  * @return  ::CA_STATUS_OK or Appropriate error code.
68  */
69 CAResult_t CAStartTCP();
70
71 /**
72  * Start listening server for receiving connect requests.
73  * Transport Specific Behavior:
74  * TCP Starts Listening Server on a particular interface and prefixed port
75  * number and as per OIC Specification.
76  * @return  ::CA_STATUS_OK or Appropriate error code.
77  */
78 CAResult_t CAStartTCPListeningServer();
79
80 /**
81  * Stops listening server from receiving connect requests.
82  * Transport Specific Behavior:
83  * TCP Stops Listening Server on a particular interface and prefixed port
84  * number and as per OIC Specification.
85  * @return  ::CA_STATUS_OK or Appropriate error code.
86  */
87 CAResult_t CAStopTCPListeningServer();
88
89 /**
90  * Start discovery servers for receiving advertisements.
91  * Transport Specific Behavior:
92  * TCP Starts Discovery server on a particular interface and prefixed port
93  * number as per OIC Specification.
94  * @return  ::CA_STATUS_OK or Appropriate error code.
95  */
96 CAResult_t CAStartTCPDiscoveryServer();
97
98 /**
99  * Sends data to the endpoint using the adapter connectivity.
100  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
101  *                              port, reference uri and transport type) to
102  *                              which the unicast data has to be sent.
103  * @param[in]   data           Data which is required to be sent.
104  * @param[in]   dataLen        Size of data to be sent.
105  * @note  dataLen must be > 0.
106  * @return  The number of bytes sent on the network, or -1 upon error.
107  */
108 int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
109                              const void *data, uint32_t dataLen);
110
111 /**
112  * Send Multicast data to the endpoint using the TCP connectivity.
113  * @param[in]   endpoint       Remote Endpoint information (like ipaddress,
114  *                              port)
115  * @param[in]   data           Data which is required to be sent.
116  * @param[in]   dataLen        Size of data to be sent.
117  * @note  dataLen must be > 0.
118  * @return  The number of bytes sent on the network, or -1 upon error.
119  */
120 int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
121                                const void *data, uint32_t dataLen);
122
123 /**
124  * Get TCP Connectivity network information.
125  * @param[out]   info        Local connectivity information structures.
126  * @note info is allocated in this API and should be freed by the caller.
127  * @param[out]   size        Number of local connectivity structures.
128  * @return  ::CA_STATUS_OK or Appropriate error code.
129  */
130 CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
131
132 /**
133  * Read Synchronous API callback.
134  * @return  ::CA_STATUS_OK or Appropriate error code.
135  */
136 CAResult_t CAReadTCPData();
137
138 /**
139  * Stops Unicast, servers and close the sockets.
140  * @return  ::CA_STATUS_OK or Appropriate error code.
141  */
142 CAResult_t CAStopTCP();
143
144 /**
145  * Terminate the TCP connectivity adapter.
146  * Configuration information will be deleted from further use.
147  */
148 void CATerminateTCP();
149
150 #ifdef __cplusplus
151 } /* extern "C" */
152 #endif
153
154 #endif  // CA_TCP_ADAPTER_H_