X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Finc%2Fcaadapterutils.h;h=cb9692f541b4243a23e9f652888f43780bfdc0f9;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=f78cebbe4c706d332de1dd4a13699deb150a38fa;hpb=0734f2d4a926a266e8f5a988834e4c25c2d8d11d;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/inc/caadapterutils.h b/resource/csdk/connectivity/inc/caadapterutils.h index f78cebb..cb9692f 100644 --- a/resource/csdk/connectivity/inc/caadapterutils.h +++ b/resource/csdk/connectivity/inc/caadapterutils.h @@ -27,15 +27,30 @@ #ifndef CA_ADAPTER_UTILS_H_ #define CA_ADAPTER_UTILS_H_ +#include "iotivity_config.h" + #include #ifdef __ANDROID__ #include #endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#if defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H) +#include +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + #include "cacommon.h" #include "logger.h" -#include "pdu.h" +#include #include "uarraylist.h" +#include "cacommonutil.h" #ifdef __cplusplus extern "C" @@ -43,144 +58,68 @@ extern "C" #endif /** - * @def VERIFY_NON_NULL - * @brief Macro to verify the validity of input argument - */ -#define VERIFY_NON_NULL(arg, log_tag, log_message) \ - if (NULL == arg ){ \ - OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \ - return CA_STATUS_INVALID_PARAM; \ - } \ - -/** - * @def VERIFY_NON_NULL_RET - * @brief Macro to verify the validity of input argument - */ -#define VERIFY_NON_NULL_RET(arg, log_tag, log_message,ret) \ - if (NULL == arg ){ \ - OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \ - return ret; \ - } \ - -/** - * @def VERIFY_NON_NULL_VOID - * @brief Macro to verify the validity of input argument - */ -#define VERIFY_NON_NULL_VOID(arg, log_tag, log_message) \ - if (NULL == arg ){ \ - OIC_LOG_V(ERROR, log_tag, "Invalid input:%s", log_message); \ - return; \ - } \ - -/** - * @brief Length of network interface name. + * Length of network interface name. */ #define CA_INTERFACE_NAME_SIZE 16 /** - * @def IPV4_ADDR_ONE_OCTECT_LEN - * @brief Macro to allocate memory for ipv4 address in the form of uint8_t. + * Macro to allocate memory for ipv4 address in the form of uint8_t. */ #define IPV4_ADDR_ONE_OCTECT_LEN 4 +#ifdef SINGLE_THREAD /** - * @brief Network Interface Information. + * Network Interface Information. Only needed for Arduino. */ typedef struct { - char ipAddress[CA_IPADDR_SIZE]; /**< Address of the interface **/ - char subnetMask[CA_IPADDR_SIZE]; /**< Maintains interface subnetmask **/ - char interfaceName[CA_INTERFACE_NAME_SIZE]; /**< Interface name**/ + char ipAddress[CA_IPADDR_SIZE]; /**< Address of the interface. **/ + char subnetMask[CA_IPADDR_SIZE]; /**< Maintains interface subnetmask. **/ + char interfaceName[CA_INTERFACE_NAME_SIZE]; /**< Interface name. **/ } CANetInfo_t; +#endif /** - * @brief unicast and multicast server information. + * unicast and multicast server information. */ typedef struct { - int socketFd; /**< Socket decriptor **/ - char ipAddress[CA_IPADDR_SIZE]; /**< Address of the ip **/ - uint16_t port; /**< Server port number **/ - bool isSecured; /**< Indicates secured server **/ - bool isServerStarted; /**< Indicates server started **/ - bool isMulticastServer; /**< Indicates multicast server **/ - char ifAddr[CA_IPADDR_SIZE]; /**< Address of the multicast interface **/ - char interfaceName[CA_INTERFACE_NAME_SIZE]; /**< Interface Name **/ - char subNetMask[CA_IPADDR_SIZE]; /**< Subnet Mask **/ + int socketFd; /**< Socket descriptor. **/ + CAEndpoint_t endpoint; /**< endpoint description. **/ + bool isServerStarted; /**< Indicates server started. **/ + bool isMulticastServer; /**< Indicates multicast server. **/ + char ifAddr[CA_IPADDR_SIZE]; /**< Address of the multicast interface. **/ + char interfaceName[CA_INTERFACE_NAME_SIZE]; /**< Interface Name. **/ + char subNetMask[CA_IPADDR_SIZE]; /**< Subnet Mask. **/ } CAServerInfo_t; /** - * @brief To log the PDU data - */ -void CALogPDUData(coap_pdu_t *pdu); - -/** - * @fn CAAdapterCreateLocalEndpoint - * @brief Create CALocalConnectivity_t instance. - */ -CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CATransportType_t type, const char *address); - -/** - * @fn CAAdapterCopyLocalEndpoint - * @brief Create CALocalConnectivity_t duplicate instance. - */ -CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(const CALocalConnectivity_t *connectivity); - -/** - * @fn CAAdapterFreeLocalEndpoint - * @brief Deallocate CALocalConnectivity_t instance. - */ -void CAAdapterFreeLocalEndpoint(CALocalConnectivity_t *localEndPoint); - -/** - * @fn CAAdapterCreateRemoteEndpoint - * @brief Allocate CARemoteEndpoint_t instance. - */ -CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CATransportType_t type, const char *address, - const char *resourceUri); - -/** - * @fn CAAdapterCopyRemoteEndpoint - * @brief Create CARemoteEndpoint_t duplicate instance. - */ -CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint( - const CARemoteEndpoint_t *remoteEndpoint); - -/** - * @fn CAAdapterFreeRemoteEndpoint - * @brief Deallocate CARemoteEndpoint_t instance. - */ -void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint); - -/** - * @fn CAParseIPv4AddressInternal - * @brief To parse the IP address and port from "ipaddress:port" - * @param ipAddrStr [IN] IP address to be parsed - * @param ipAddr [OUT] Parsed IP address - * @param ipAddr [IN] Buffer length for parsed IP address - * @param port [OUT] Parsed Port number - * @return #CA_STATUS_OK or Appropriate error code + * To parse the IP address and port from "ipaddress:port". + * @param[in] ipAddrStr IP address to be parsed. + * @param[out] ipAddr Parsed IP address. + * @param[in] ipAddr Buffer length for parsed IP address. + * @param[out] port Parsed Port number. + * @return ::CA_STATUS_OK or Appropriate error code. */ CAResult_t CAParseIPv4AddressInternal(const char *ipAddrStr, uint8_t *ipAddr, size_t ipAddrLen, uint16_t *port); /** - * @fn CAAdapterIsSameSubnet - * @brief Check if two ip address belong to same subnet. - * @param ipAddress1 [IN] IP address to be checked - * @param ipAddress2 [IN] IP address to be checked - * @param netMask [IN] Subnet mask - * @return true if same subnet and false if not same subnet + * Check if two ip address belong to same subnet. + * @param[in] ipAddress1 IP address to be checked. + * @param[in] ipAddress2 IP address to be checked. + * @param[in] netMask Subnet mask. + * @return true if same subnet and false if not same subnet. */ bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2, const char *netMask); /** - * @brief Used to check the multicast server is running or not. + * Used to check the multicast server is running or not. * - * @param serverInfoList [IN] Server information list. - * @param ipAddress [IN] Interface address of the server. - * @param multicastAddress [IN] Multicast address of the server. - * @param port [IN] Port number of the server. + * @param[in] serverInfoList Server information list. + * @param[in] ipAddress Interface address of the server. + * @param[in] multicastAddress Multicast address of the server. + * @param[in] port Port number of the server. * * @return true or false. */ @@ -188,11 +127,11 @@ bool CAIsMulticastServerStarted(const u_arraylist_t *serverInfoList, const char const char *multicastAddress, uint16_t port); /** - * @brief Used to check the unicast server is running or not. + * Used to check the unicast server is running or not. * - * @param serverInfoList [IN] Server information list. - * @param ipAddress [IN] Ip address of the server. - * @param port [IN] Port number of the server. + * @param[in] serverInfoList Server information list. + * @param[in] ipAddress Ip address of the server. + * @param[in] port Port number of the server. * * @return true or false. */ @@ -200,11 +139,11 @@ bool CAIsUnicastServerStarted(const u_arraylist_t *serverInfoList, const char *i uint16_t port); /** - * @brief Used to get the port number based on given information. + * Used to get the port number based on given information. * - * @param serverInfoList [IN] Server information list. - * @param ipAddress [IN] Ip address of the server. - * @param isSecured [IN] specifies whether to get secured or normal unicast server port. + * @param[in] serverInfoList Server information list. + * @param[in] ipAddress Ip address of the server. + * @param[in] isSecured specifies whether to get secured or normal unicast server port. * * @return positive value on success and 0 on error. */ @@ -212,97 +151,172 @@ uint16_t CAGetServerPort(const u_arraylist_t *serverInfoList, const char *ipAddr bool isSecured); /** - * @brief Used to get the socket fd for given server information. + * Used to get the socket fd for given server information. * - * @param serverInfoList [IN] Server information list. - * @param ipAddress [IN] Ip address of the server. - * @param isSecured [IN] To check whether it is secured server or not. - * @param isMulticast [IN] To check whether it is multicast server or not. - * @param type [IN] CA_IPV4, CA_IPV6 etc. + * @param[in] serverInfoList Server information list. + * @param[in] isMulticast To check whether it is multicast server or not. + * @param[in] endpoint network address * @return positive value on success and -1 on error. */ -int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList, const char *ipAddress, - bool isSecured, bool isMulticast, CATransportType_t type); +int CAGetSocketFdForUnicastServer(const u_arraylist_t *serverInfoList, + bool isMulticast, const CAEndpoint_t *endpoint); /** - * @brief Used to add the server information into serverinfo list + * Used to add the server information into serverinfo list. * - * @param serverInfoList [INOUT] server information list. - * @param info [IN] server informations like ip, port. + * @param[in/out] serverInfoList server information list. + * @param[in] info server informations like ip, port. * - * @return #CA_STATUS_OK or Appropriate error code - * @retval #CA_STATUS_OK Successful - * @retval #CA_STATUS_INVALID_PARAM Invalid input data - * @retval #CA_STATUS_FAILED Initialization failed + * @return ::CA_STATUS_OK or Appropriate error code. + * @retval ::CA_STATUS_OK Successful. + * @retval ::CA_STATUS_INVALID_PARAM Invalid input data. + * @retval ::CA_STATUS_FAILED Initialization failed. */ CAResult_t CAAddServerInfo(u_arraylist_t *serverInfoList, CAServerInfo_t *info); /** - * @brief Used to remove the server information based on socket fd from server info list. - * - * @param serverInfoList [INOUT] server information list. - * @param sockFd [IN] Socket descriptor. + * Used to remove the server information based on socket fd from server info list. * - * @return None + * @param[in/out] serverInfoList server information list. + * @param[in] sockFd Socket descriptor. */ void CARemoveServerInfo(u_arraylist_t *serverInfoList, int sockFd); /** - * @brief Used to clear the memory of network inteface list - * Memory pointed by infoList will become invalid after this function call. - * - * @param infoList [IN] Network interface list. + * Used to clear the memory of network interface list. + * Memory pointed by infoList will become invalid after this function call. * - * @return None + * @param[in] infoList Network interface list. */ void CAClearNetInterfaceInfoList(u_arraylist_t *infoList); /** - * @brief Used to clear the memory of server info list. - * Memory pointed by serverInfoList will become invalid after this function call. + * Used to clear the memory of server info list. + * Memory pointed by serverInfoList will become invalid after this function call. * - * @param infoList [IN] Server information list. - * - * @return None + * @param[in] infoList Server information list. */ void CAClearServerInfoList(u_arraylist_t *serverInfoList); +#ifndef WITH_ARDUINO +/** + * Convert address from binary to string. + * @param[in] sockAddr IP address info. + * @param[in] sockAddrLen size of sockAddr. + * @param[out] host address string (must be CA_IPADDR_SIZE). + * @param[out] port host order port number. + */ +void CAConvertAddrToName(const struct sockaddr_storage *sockAddr, socklen_t sockAddrLen, + char *host, uint16_t *port); + +/** + * Convert address from string to binary. + * @param[in] host address string. + * @param[in] port host order port number. + * @param[out] ipaddr IP address info. + */ +void CAConvertNameToAddr(const char *host, uint16_t port, struct sockaddr_storage *sockaddr); +#endif /* WITH_ARDUINO */ + #ifdef __ANDROID__ /** - * @fn CANativeJNISetContext - * @brief To set context of JNI Application - * This must be called by the Android API before CA Initialization - * @param env [IN] JNI interface pointer - * @param context [IN] context object - * @return None + * To set context of JNI Application. + * This must be called by the Android API before CA Initialization. + * @param[in] env JNI interface pointer. + * @param[in] context context object. */ void CANativeJNISetContext(JNIEnv *env, jobject context); /** - * @fn CANativeJNISetJavaVM - * @brief To set jvm object - * This must be called by the Android API before CA Initialization - * @param jvm [IN] jvm object - * @return None + * To set jvm object. + * This must be called by the Android API before CA Initialization. + * @param[in] jvm jvm object. */ void CANativeJNISetJavaVM(JavaVM *jvm); /** - * @fn CANativeJNISetContext - * @brief To get context - * Called by adapters to get Application context - * @return context object + * To get context. + * Called by adapters to get Application context. + * @return context object. */ jobject CANativeJNIGetContext(); /** - * @fn CANativeJNIGetJavaVM - * @brief To get JVM object - * Called from adapters to get JavaVM object - * @return JVM object + * To get JVM object. + * Called from adapters to get JavaVM object. + * @return JVM object. */ JavaVM *CANativeJNIGetJavaVM(); + +/** + * To set Activity to JNI. + * This must be called by the Android API before CA Initialization. + * @param[in] env JNI Environment pointer. + * @param[in] activity Activity object. + */ +void CANativeSetActivity(JNIEnv *env, jobject activity); + +/** + * To get Activity. + * Called from adapters to get Activity. + * @return Activity object. + */ +jobject *CANativeGetActivity(); + +/** + * get method ID for method Name and class + * @param[in] env JNI interface pointer. + * @param[in] className android class. + * @param[in] methodName android method name. + * @param[in] methodFormat method type of methodName. + * @return jmethodID iD of the method. + */ +jmethodID CAGetJNIMethodID(JNIEnv *env, const char* className, + const char* methodName, + const char* methodFormat); + +/** + * check JNI exception occurrence + * @param[in] env JNI interface pointer. + * @return true(occurrence) or false(no occurrence). + */ +bool CACheckJNIException(JNIEnv *env); + +/** + * To Delete other Global References + * Called during CATerminate to remove global references + */ +void CADeleteGlobalReferences(); + +#endif + +#ifndef WITH_ARDUINO +/** + * print send state in the adapter. + * @param[in] adapter transport adapter type. + * @param[in] addr remote address. + * @param[in] port port. + * @param[in] sentLen sent data length. + * @param[in] isSuccess sent state. + * @param[in] message detailed message. + */ +void CALogSendStateInfo(CATransportAdapter_t adapter, + const char *addr, uint16_t port, ssize_t sentLen, + bool isSuccess, const char* message); + +/** + * print adapter state in the adapter. + * @param[in] adapter transport adapter type. + * @param[in] state adapter state. + */ +void CALogAdapterStateInfo(CATransportAdapter_t adapter, CANetworkStatus_t state); + +/** + * print adapter type name in the adapter. + * @param[in] adapter transport adapter type. + */ +void CALogAdapterTypeInfo(CATransportAdapter_t adapter); #endif #ifdef __cplusplus