ZT_jniutils.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ZT_jniutils_h_
  19. #define ZT_jniutils_h_
  20. #include <jni.h>
  21. #include <ZeroTierOne.h>
  22. #define LOG_TAG "ZeroTierOneJNI"
  23. #if defined(__ANDROID__)
  24. #include <android/log.h>
  25. #if !defined(NDEBUG)
  26. #define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
  27. #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
  28. #else
  29. #define LOGV(...)
  30. #define LOGD(...)
  31. #endif
  32. #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
  33. #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
  34. #else
  35. #if !defined(NDEBUG)
  36. #define LOGV(...) fprintf(stdout, __VA_ARGS__)
  37. #define LOGD(...) fprintf(stdout, __VA_ARGS__)
  38. #else
  39. #define LOGV(...)
  40. #define LOGD(...)
  41. #endif
  42. #define LOGI(...) fprintf(stdout, __VA_ARGS__)
  43. #define LOGE(...) fprintf(stdout, __VA_ARGS__)
  44. #endif
  45. jobject createResultObject(JNIEnv *env, ZT_ResultCode code);
  46. jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status);
  47. jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type);
  48. jobject createEvent(JNIEnv *env, ZT_Event event);
  49. jobject createPeerRole(JNIEnv *env, ZT_PeerRole role);
  50. jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT_VirtualNetworkConfigOperation op);
  51. jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr);
  52. jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr);
  53. jobject newPeer(JNIEnv *env, const ZT_Peer &peer);
  54. jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp);
  55. jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &config);
  56. jobject newVersion(JNIEnv *env, int major, int minor, int rev);
  57. jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route);
  58. jobject newVirtualNetworkDNS(JNIEnv *env, const ZT_VirtualNetworkDNS &dns);
  59. #endif // ZT_jniutils_h_