ZT_jniutils.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 __ANDROID__
  28. #include <android/log.h>
  29. #define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
  30. #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
  31. #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
  32. #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
  33. #else
  34. #define LOGV(...) fprintf(stdout, __VA_ARGS__)
  35. #define LOGI(...) fprintf(stdout, __VA_ARGS__)
  36. #define LOGD(...) fprintf(stdout, __VA_ARGS__)
  37. #define LOGE(...) fprintf(stdout, __VA_ARGS__)
  38. #endif
  39. jobject createResultObject(JNIEnv *env, ZT_ResultCode code);
  40. jobject createVirtualNetworkStatus(JNIEnv *env, ZT_VirtualNetworkStatus status);
  41. jobject createVirtualNetworkType(JNIEnv *env, ZT_VirtualNetworkType type);
  42. jobject createEvent(JNIEnv *env, ZT_Event event);
  43. jobject createPeerRole(JNIEnv *env, ZT_PeerRole role);
  44. jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT_VirtualNetworkConfigOperation op);
  45. jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr);
  46. jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr);
  47. jobject newMulticastGroup(JNIEnv *env, const ZT_MulticastGroup &mc);
  48. jobject newPeer(JNIEnv *env, const ZT_Peer &peer);
  49. jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp);
  50. jobject newNetworkConfig(JNIEnv *env, const ZT_VirtualNetworkConfig &config);
  51. jobject newVersion(JNIEnv *env, int major, int minor, int rev);
  52. jobject newVirtualNetworkRoute(JNIEnv *env, const ZT_VirtualNetworkRoute &route);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif