fs_android.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. #include <jni.h>
  7. #define ANDROID_STORAGE_FUNCTIONS(V) \
  8. V(OpenContentUri, int, (const std::string& filepath, OpenMode openmode), open_content_uri, \
  9. "openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I")
  10. #define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \
  11. V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J")
  12. namespace Common::FS::Android {
  13. static JavaVM* g_jvm = nullptr;
  14. static jclass native_library = nullptr;
  15. #define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) F(JMethodID)
  16. #define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) F(JMethodID)
  17. #define F(JMethodID) static jmethodID JMethodID = nullptr;
  18. ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
  19. ANDROID_STORAGE_FUNCTIONS(FS)
  20. #undef F
  21. #undef FS
  22. #undef FR
  23. enum class OpenMode {
  24. Read,
  25. Write,
  26. ReadWrite,
  27. WriteAppend,
  28. WriteTruncate,
  29. ReadWriteAppend,
  30. ReadWriteTruncate,
  31. Never
  32. };
  33. void RegisterCallbacks(JNIEnv* env, jclass clazz);
  34. void UnRegisterCallbacks();
  35. bool IsContentUri(const std::string& path);
  36. #define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) \
  37. F(FunctionName, Parameters, ReturnValue)
  38. #define F(FunctionName, Parameters, ReturnValue) ReturnValue FunctionName Parameters;
  39. ANDROID_STORAGE_FUNCTIONS(FS)
  40. #undef F
  41. #undef FS
  42. #define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) \
  43. F(FunctionName, ReturnValue)
  44. #define F(FunctionName, ReturnValue) ReturnValue FunctionName(const std::string& filepath);
  45. ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
  46. #undef F
  47. #undef FR
  48. } // namespace Common::FS::Android