1 /* ****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
23 * This file contains the APIs for TCP Adapter.
25 #ifndef CA_TCP_ADAPTER_H_
26 #define CA_TCP_ADAPTER_H_
29 #include "caadapterinterface.h"
30 #include "cathreadpool.h"
38 * TCP Session Information for IPv4 TCP transport
42 CAEndpoint_t endpoint; /**< endpoint information */
43 int fd; /**< file descriptor info */
44 void *recvData; /**< received data from remote device*/
45 size_t recvDataLen; /**< received data length */
46 size_t totalDataLen; /**< total data length */
50 * API to initialize TCP Interface.
51 * @param[in] registerCallback Callback to register TCP interfaces to
52 * Connectivity Abstraction Layer.
53 * @param[in] networkPacketCallback Callback to notify request and
54 * response messages from server(s)
55 * started at Connectivity Abstraction Layer.
56 * @param[in] netCallback Callback to notify the network additions
57 * to Connectivity Abstraction Layer.
58 * @param[in] errorCallback Callback to notify the network errors to
59 * Connectivity Abstraction Layer.
60 * @param[in] handle Threadpool Handle.
61 * @return ::CA_STATUS_OK or Appropriate error code
63 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
64 CANetworkPacketReceivedCallback networkPacketCallback,
65 CANetworkChangeCallback netCallback,
66 CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
69 * Start TCP Interface adapter.
70 * @return ::CA_STATUS_OK or Appropriate error code.
72 CAResult_t CAStartTCP();
75 * Start listening server for receiving connect requests.
76 * Transport Specific Behavior:
77 * TCP Starts Listening Server on a particular interface and prefixed port
78 * number and as per OIC Specification.
79 * @return ::CA_STATUS_OK or Appropriate error code.
81 CAResult_t CAStartTCPListeningServer();
84 * Stops listening server from receiving connect requests.
85 * Transport Specific Behavior:
86 * TCP Stops Listening Server on a particular interface and prefixed port
87 * number and as per OIC Specification.
88 * @return ::CA_STATUS_OK or Appropriate error code.
90 CAResult_t CAStopTCPListeningServer();
93 * Start discovery servers for receiving advertisements.
94 * Transport Specific Behavior:
95 * TCP Starts Discovery server on a particular interface and prefixed port
96 * number as per OIC Specification.
97 * @return ::CA_STATUS_OK or Appropriate error code.
99 CAResult_t CAStartTCPDiscoveryServer();
102 * Sends data to the endpoint using the adapter connectivity.
103 * @param[in] endpoint Remote Endpoint information (like ipaddress,
104 * port, reference uri and transport type) to
105 * which the unicast data has to be sent.
106 * @param[in] data Data which is required to be sent.
107 * @param[in] dataLen Size of data to be sent.
108 * @note dataLen must be > 0.
109 * @return The number of bytes sent on the network, or -1 upon error.
111 int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
112 const void *data, uint32_t dataLen);
115 * Send Multicast data to the endpoint using the TCP connectivity.
116 * @param[in] endpoint Remote Endpoint information (like ipaddress,
118 * @param[in] data Data which is required to be sent.
119 * @param[in] dataLen Size of data to be sent.
120 * @note dataLen must be > 0.
121 * @return The number of bytes sent on the network, or -1 upon error.
123 int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
124 const void *data, uint32_t dataLen);
127 * Get TCP Connectivity network information.
128 * @param[out] info Local connectivity information structures.
129 * @note info is allocated in this API and should be freed by the caller.
130 * @param[out] size Number of local connectivity structures.
131 * @return ::CA_STATUS_OK or Appropriate error code.
133 CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
136 * Read Synchronous API callback.
137 * @return ::CA_STATUS_OK or Appropriate error code.
139 CAResult_t CAReadTCPData();
142 * Stops Unicast, servers and close the sockets.
143 * @return ::CA_STATUS_OK or Appropriate error code.
145 CAResult_t CAStopTCP();
148 * Terminate the TCP connectivity adapter.
149 * Configuration information will be deleted from further use.
151 void CATerminateTCP();
157 #endif // CA_TCP_ADAPTER_H_