api.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**************************************************************************/
  2. /* api.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "api.h"
  31. #include "core/engine.h"
  32. #include "java_class_wrapper.h"
  33. #include "jni_singleton.h"
  34. #if !defined(ANDROID_ENABLED)
  35. static JavaClassWrapper *java_class_wrapper = nullptr;
  36. #endif
  37. void register_android_api() {
  38. #if !defined(ANDROID_ENABLED)
  39. // On Android platforms, the `java_class_wrapper` instantiation and the
  40. // `JNISingleton` registration occurs in
  41. // `platform/android/java_godot_lib_jni.cpp#Java_org_godotengine_godot_GodotLib_setup`
  42. java_class_wrapper = memnew(JavaClassWrapper); // Dummy
  43. ClassDB::register_class<JNISingleton>();
  44. #endif
  45. ClassDB::register_class<JavaClass>();
  46. ClassDB::register_class<JavaClassWrapper>();
  47. Engine::get_singleton()->add_singleton(Engine::Singleton("JavaClassWrapper", JavaClassWrapper::get_singleton()));
  48. }
  49. void unregister_android_api() {
  50. #if !defined(ANDROID_ENABLED)
  51. memdelete(java_class_wrapper);
  52. #endif
  53. }
  54. void JavaClassWrapper::_bind_methods() {
  55. ClassDB::bind_method(D_METHOD("wrap", "name"), &JavaClassWrapper::wrap);
  56. }
  57. #if !defined(ANDROID_ENABLED)
  58. Variant JavaClass::call(const StringName &, const Variant **, int, Variant::CallError &) {
  59. return Variant();
  60. }
  61. JavaClass::JavaClass() {
  62. }
  63. Variant JavaObject::call(const StringName &, const Variant **, int, Variant::CallError &) {
  64. return Variant();
  65. }
  66. JavaClassWrapper *JavaClassWrapper::singleton = nullptr;
  67. Ref<JavaClass> JavaClassWrapper::wrap(const String &) {
  68. return Ref<JavaClass>();
  69. }
  70. JavaClassWrapper::JavaClassWrapper() {
  71. singleton = this;
  72. }
  73. #endif