replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caadapterutils.h
index c1e17c7..cb9692f 100644 (file)
 #ifndef CA_ADAPTER_UTILS_H_
 #define CA_ADAPTER_UTILS_H_
 
+#include "iotivity_config.h"
+
 #include <stdbool.h>
 #ifdef __ANDROID__
 #include <jni.h>
 #endif
 
-#ifndef WITH_ARDUINO
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#if defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H)
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
 
 #include "cacommon.h"
 #include "logger.h"
-#include "pdu.h"
+#include <coap/pdu.h>
 #include "uarraylist.h"
+#include "cacommonutil.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -47,30 +58,6 @@ extern "C"
 #endif
 
 /**
- * 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; \
-    } \
-
-/**
- * Macro to verify the validity of input argument.
- */
-#define VERIFY_NON_NULL(arg, log_tag, log_message) \
-    VERIFY_NON_NULL_RET((arg), (log_tag), (log_message), CA_STATUS_INVALID_PARAM)
-
-/**
- * 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; \
-    } \
-
-/**
  * Length of network interface name.
  */
 #define CA_INTERFACE_NAME_SIZE 16
@@ -107,11 +94,6 @@ typedef struct
 } CAServerInfo_t;
 
 /**
- * To log the PDU data.
- */
-void CALogPDUData(coap_pdu_t *pdu);
-
-/**
  * To parse the IP address and port from "ipaddress:port".
  * @param[in]   ipAddrStr       IP address to be parsed.
  * @param[out]  ipAddr          Parsed IP address.
@@ -217,13 +199,16 @@ void CAClearNetInterfaceInfoList(u_arraylist_t *infoList);
  */
 void CAClearServerInfoList(u_arraylist_t *serverInfoList);
 
+#ifndef WITH_ARDUINO
 /**
  * Convert address from binary to string.
- * @param[in]    ipaddr   IP address info.
- * @param[out]   host     address string (must be CA_IPADDR_SIZE).
- * @param[out]   port     host order port number.
+ * @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, char *host, uint16_t *port);
+void CAConvertAddrToName(const struct sockaddr_storage *sockAddr, socklen_t sockAddrLen,
+                         char *host, uint16_t *port);
 
 /**
  * Convert address from string to binary.
@@ -232,6 +217,7 @@ void CAConvertAddrToName(const struct sockaddr_storage *sockaddr, char *host, ui
  * @param[out]  ipaddr    IP address info.
  */
 void CAConvertNameToAddr(const char *host, uint16_t port, struct sockaddr_storage *sockaddr);
+#endif /* WITH_ARDUINO */
 
 #ifdef __ANDROID__
 /**
@@ -262,6 +248,75 @@ jobject CANativeJNIGetContext();
  * @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