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 Server Information for IPv4 TCP transport
42 char addr[MAX_ADDR_STR_SIZE_CA]; /**< TCP Server address */
43 CASocket_t u4tcp; /**< TCP Server port */
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
60 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
61 CANetworkPacketReceivedCallback networkPacketCallback,
62 CANetworkChangeCallback netCallback,
63 CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
66 * Start TCP Interface adapter.
67 * @return ::CA_STATUS_OK or Appropriate error code.
69 CAResult_t CAStartTCP();
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.
78 CAResult_t CAStartTCPListeningServer();
81 * Start discovery servers for receiving advertisements.
82 * Transport Specific Behavior:
83 * TCP Starts Discovery server on a particular interface and prefixed port
84 * number as per OIC Specification.
85 * @return ::CA_STATUS_OK or Appropriate error code.
87 CAResult_t CAStartTCPDiscoveryServer();
90 * Sends data to the endpoint using the adapter connectivity.
91 * @param[in] endpoint Remote Endpoint information (like ipaddress,
92 * port, reference uri and transport type) to
93 * which the unicast data has to be sent.
94 * @param[in] data Data which is required to be sent.
95 * @param[in] dataLen Size of data to be sent.
96 * @note dataLen must be > 0.
97 * @return The number of bytes sent on the network, or -1 upon error.
99 int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
100 const void *data, uint32_t dataLen);
103 * Send Multicast data to the endpoint using the TCP connectivity.
104 * @param[in] endpoint Remote Endpoint information (like ipaddress,
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 CASendTCPMulticastData(const CAEndpoint_t *endpoint,
112 const void *data, uint32_t dataLen);
115 * Get TCP Connectivity network information.
116 * @param[out] info Local connectivity information structures.
117 * @note info is allocated in this API and should be freed by the caller.
118 * @param[out] size Number of local connectivity structures.
119 * @return ::CA_STATUS_OK or Appropriate error code.
121 CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
124 * Read Synchronous API callback.
125 * @return ::CA_STATUS_OK or Appropriate error code.
127 CAResult_t CAReadTCPData();
130 * Stops Unicast, servers and close the sockets.
131 * @return ::CA_STATUS_OK or Appropriate error code.
133 CAResult_t CAStopTCP();
136 * Terminate the TCP connectivity adapter.
137 * Configuration information will be deleted from further use.
139 void CATerminateTCP();
145 #endif // CA_TCP_ADAPTER_H_