ZT_jniutils.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <stdio.h>
  21. #include <jni.h>
  22. #include <ZeroTierOne.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #define LOG_TAG "ZeroTierOneJNI"
  27. #if defined(__ANDROID__)
  28. #include <android/log.h>
  29. #if !defined(NDEBUG)
  30. #define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
  31. #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
  32. #else
  33. #define LOGV(...)
  34. #define LOGD(...)
  35. #endif
  36. #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
  37. #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
  38. #else
  39. #if !defined(NDEBUG)
  40. #define LOGV(...) fprintf(stdout, __VA_ARGS__)
  41. #define LOGD(...) fprintf(stdout, __VA_ARGS__)
  42. #else
  43. #define LOGV(...)
  44. #define LOGD(...)
  45. #endif
  46. #define LOGI(...) fprintf(stdout, __VA_ARGS__)
  47. #define LOGE(...) fprintf(stdout, __VA_ARGS__)
  48. #endif
  49. jobject createResultObject(JNIEnv *env, ZT_ResultCode code);
  50. jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status);
  51. jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type);
  52. jobject createEvent(JNIEnv *env, ZT_Event event);
  53. jobject createPeerRole(JNIEnv *env, ZT_PeerRole role);
  54. jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT_VirtualNetworkConfigOperation op);
  55. jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr);
  56. jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr);
  57. jobject newMulticastGroup(JNIEnv *env, const ZT_MulticastGroup &mc);
  58. jobject newPeer(JNIEnv *env, const ZT_Peer &peer);
  59. jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp);
  60. jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &config);
  61. jobject newVersion(JNIEnv *env, int major, int minor, int rev);
  62. jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route);
  63. jobject newVirtualNetworkDNS(JNIEnv *env, const ZT_VirtualNetworkDNS &dns);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif