X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Finc%2Fcatcpinterface.h;h=d6173656543bef4b9ca339ba92732e47ead573d7;hb=1e743d337b66bda0e44a5ca500d4d7178bb599b5;hp=722a1c0b435b4172c3ed23b2b3bb98763dea8493;hpb=a214f7d5b1f3c97e4ba731577e7297f14c5ef8b9;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/inc/catcpinterface.h b/resource/csdk/connectivity/inc/catcpinterface.h index 722a1c0..d617365 100644 --- a/resource/csdk/connectivity/inc/catcpinterface.h +++ b/resource/csdk/connectivity/inc/catcpinterface.h @@ -44,11 +44,12 @@ extern "C" * @param[in] endpoint network endpoint description. * @param[in] data Data received from remote OIC device. * @param[in] dataLength Length of data in bytes. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). * @pre Callback must be registered using CAIPSetPacketReceiveCallback(). */ -typedef void (*CATCPPacketReceivedCallback)(const CASecureEndpoint_t *endpoint, - const void *data, - uint32_t dataLength); +typedef CAResult_t (*CATCPPacketReceivedCallback)(const CASecureEndpoint_t *endpoint, + const void *data, + size_t dataLength); /** * Callback to notify error in the TCP adapter. @@ -60,16 +61,18 @@ typedef void (*CATCPPacketReceivedCallback)(const CASecureEndpoint_t *endpoint, * @pre Callback must be registered using CAIPSetPacketReceiveCallback(). */ typedef void (*CATCPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, CAResult_t result); + size_t dataLength, CAResult_t result); /** * Callback to notify connection information in the TCP adapter. * * @param[in] endpoint network endpoint description. * @param[in] isConnected Whether keepalive message needs to be sent. + * @param[in] isClient Host Mode of Operation. * @see Callback must be registered using CATCPSetKeepAliveCallback(). */ -typedef void (*CATCPConnectionHandleCallback)(const CAEndpoint_t *endpoint, bool isConnected); +typedef void (*CATCPConnectionHandleCallback)(const CAEndpoint_t *endpoint, bool isConnected, + bool isClient); /** * set error callback to notify error in TCP adapter. @@ -94,7 +97,7 @@ void CATCPPullData(); * @param[out] transport TCP Server address. * @param[out] headerlen TCP Server port. */ -void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_type *transport, +void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_t *transport, size_t *headerlen); /** @@ -107,6 +110,7 @@ void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_type *trans size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t size); #else +#ifdef TCP_ADAPTER /** * set keepalive callback to notify connection information in TCP adapter. * @@ -114,6 +118,7 @@ size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t * in the TCP adapter. */ void CATCPSetKeepAliveCallback(CAKeepAliveConnectionCallback keepaliveHandler); +#endif /** * Start TCP server. @@ -141,15 +146,21 @@ void CATCPStopServer(); void CATCPSetPacketReceiveCallback(CATCPPacketReceivedCallback callback); /** + * Set this callback for receiving the changed connection information from peer devices. + * + * @param[in] connHandler Callback to be notified when connection state changes. + */ +void CATCPSetConnectionChangedCallback(CATCPConnectionHandleCallback connHandler); + +/** * API to send unicast TCP data. * * @param[in] endpoint complete network address to send to. * @param[in] data Data to be send. * @param[in] dataLength Length of data in bytes. - * @param[in] isMulticast Whether data needs to be sent to multicast ip. + * @return Sent data length or -1 on error. */ -void CATCPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t dataLength, - bool isMulticast); +ssize_t CATCPSendData(CAEndpoint_t *endpoint, const void *data, size_t dataLength); /** * Get a list of CAInterface_t items. @@ -162,18 +173,17 @@ u_arraylist_t *CATCPGetInterfaceInformation(int desiredIndex); * Connect to TCP Server. * * @param[in] endpoint remote endpoint information. - * @return TCP Session Information structure. + * @return Created socket file descriptor. */ -CATCPSessionInfo_t *CAConnectTCPSession(const CAEndpoint_t *endpoint); +CASocketFd_t CAConnectTCPSession(const CAEndpoint_t *endpoint); /** * Disconnect from TCP Server. * - * @param[in] svritem TCP session information. * @param[in] index current session index in list. * @return ::CA_STATUS_OK or Appropriate error code. */ -CAResult_t CADisconnectTCPSession(CATCPSessionInfo_t *svritem, size_t index); +CAResult_t CADisconnectTCPSession(size_t index); /** * Disconnect all connection from TCP Server. @@ -207,8 +217,111 @@ size_t CAGetTotalLengthFromHeader(const unsigned char *recvBuffer); */ CATCPSessionInfo_t *CAGetSessionInfoFromFD(int fd, size_t *index); +/** + * Get socket file descriptor from remote device information. + * + * @param[in] endpoint Remote Endpoint information (such as ipaddress, + * port, reference uri and transport type) to + * which the unicast data has to be sent. + * @return Created socket file descriptor. + */ +CASocketFd_t CAGetSocketFDFromEndpoint(const CAEndpoint_t *endpoint); + +/** + * Find the session with endpoint info and remove it from list. + * + * @param[in] endpoint Remote Endpoint information (such as ipaddress, + * port, reference uri and transport type) to + * which the unicast data has to be sent. + * @return ::CA_STATUS_OK or Appropriate error code. + */ +CAResult_t CASearchAndDeleteTCPSession(const CAEndpoint_t *endpoint); + + +/** + * Abort TCP sessions which are in progress of connecting with servers. + */ +void CATCPCloseInProgressConnections(); + +/** + * Get total payload length from CoAP over TCP header. + * + * @param[in] data Data to be send. + * @param[in] dlen Total data length. + * @return Payload length + */ +size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen); + +/** + * Construct CoAP header and payload from buffer + * + * @param[in] svritem - used socket, buffer, current received message length and protocol + * @param[in/out] data - data buffer, this value is updated as data is copied to svritem + * @param[in/out] dataLength - length of data, this value decreased as data is copied to svritem + * @return - CA_STATUS_OK or appropriate error code + */ +CAResult_t CAConstructCoAP(CATCPSessionInfo_t *svritem, unsigned char **data, + size_t *dataLength); + +/** + * Clean socket state data + * + * @param[in/out] svritem - socket state data + */ +void CACleanData(CATCPSessionInfo_t *svritem); + +/** + * Create a mutex object. + * + * @return ::CA_STATUS_OK or Appropriate error code. + */ +CAResult_t CATCPCreateMutex(); + +/** + * Close a mutex object. + */ +void CATCPDestroyMutex(); + +/** + * Create a mutex object for send data. + * + * @return ::CA_STATUS_OK or Appropriate error code. + */ +CAResult_t CATCPCreateSendMutex(); + +/** + * Close a mutex object for send data. + */ +void CATCPDestroySendMutex(); + + +/** + * Initialize a condition variable. + * + * @return ::CA_STATUS_OK or Appropriate error code. + */ +CAResult_t CATCPCreateCond(); + +/** + * Destroy condition variable state. + */ +void CATCPDestroyCond(); + +/** + * Initialize a condition variable for send data. + * + * @return ::CA_STATUS_OK or Appropriate error code. + */ +CAResult_t CATCPCreateSendCond(); + +/** + * Destroy condition variable state for send data. + */ +void CATCPDestroySendCond(); + #ifdef __cplusplus } #endif #endif /* CA_TCP_INTERFACE_H_ */ +