| 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 | |
| 31 | #include "api.h" |
| 32 | |
| 33 | #include "java_class_wrapper.h" |
| 34 | #include "jni_singleton.h" |
| 35 | |
| 36 | #include "core/config/engine.h" |
| 37 | |
| 38 | #if !defined(ANDROID_ENABLED) |
| 39 | static JavaClassWrapper *java_class_wrapper = nullptr; |
| 40 | #endif |
| 41 | |
| 42 | void register_android_api() { |
| 43 | #if !defined(ANDROID_ENABLED) |
| 44 | // On Android platforms, the `java_class_wrapper` instantiation occurs in |
| 45 | // `platform/android/java_godot_lib_jni.cpp#Java_org_godotengine_godot_GodotLib_setup` |
| 46 | java_class_wrapper = memnew(JavaClassWrapper); |
| 47 | #endif |
| 48 | GDREGISTER_CLASS(JNISingleton); |
| 49 | GDREGISTER_CLASS(JavaClass); |
| 50 | GDREGISTER_CLASS(JavaObject); |
| 51 | GDREGISTER_CLASS(JavaClassWrapper); |
| 52 | Engine::get_singleton()->add_singleton(Engine::Singleton("JavaClassWrapper", JavaClassWrapper::get_singleton())); |
| 53 | } |
| 54 | |
| 55 | void unregister_android_api() { |
| 56 | #if !defined(ANDROID_ENABLED) |
| 57 | memdelete(java_class_wrapper); |
| 58 | #endif |
| 59 | } |
| 60 | |
| 61 | void JavaClass::_bind_methods() { |
| 62 | ClassDB::bind_method(D_METHOD("get_java_class_name"), &JavaClass::get_java_class_name); |
| 63 | ClassDB::bind_method(D_METHOD("get_java_method_list"), &JavaClass::get_java_method_list); |
| 64 | ClassDB::bind_method(D_METHOD("get_java_parent_class"), &JavaClass::get_java_parent_class); |
| 65 | ClassDB::bind_method(D_METHOD("has_java_method", "method"), &JavaClass::has_java_method); |
| 66 | } |
| 67 | |
| 68 | void JavaObject::_bind_methods() { |
| 69 | ClassDB::bind_method(D_METHOD("get_java_class"), &JavaObject::get_java_class); |
| 70 | ClassDB::bind_method(D_METHOD("has_java_method", "method"), &JavaObject::has_java_method); |
| 71 | } |
| 72 | |
| 73 | void JavaClassWrapper::_bind_methods() { |
| 74 | ClassDB::bind_method(D_METHOD("wrap", "name"), &JavaClassWrapper::wrap); |
| 75 | ClassDB::bind_method(D_METHOD("get_exception"), &JavaClassWrapper::get_exception); |
| 76 | } |
| 77 | |
| 78 | #if !defined(ANDROID_ENABLED) |
| 79 | bool JavaClass::_get(const StringName &p_name, Variant &r_ret) const { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | Variant JavaClass::callp(const StringName &, const Variant **, int, Callable::CallError &) { |
| 84 | return Variant(); |
| 85 | } |
| 86 | |
| 87 | String JavaClass::get_java_class_name() const { |
| 88 | return ""; |
| 89 | } |
| 90 | |
| 91 | TypedArray<Dictionary> JavaClass::get_java_method_list() const { |
| 92 | return TypedArray<Dictionary>(); |
| 93 | } |
| 94 | |
| 95 | Ref<JavaClass> JavaClass::get_java_parent_class() const { |
| 96 | return Ref<JavaClass>(); |
| 97 | } |
| 98 | |
| 99 | bool JavaClass::has_java_method(const StringName &) const { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | JavaClass::JavaClass() { |
| 104 | } |
| 105 | |
| 106 | JavaClass::~JavaClass() { |
| 107 | } |
| 108 | |
| 109 | Variant JavaObject::callp(const StringName &, const Variant **, int, Callable::CallError &) { |
| 110 | return Variant(); |
| 111 | } |
| 112 | |
| 113 | Ref<JavaClass> JavaObject::get_java_class() const { |
| 114 | return Ref<JavaClass>(); |
| 115 | } |
| 116 | |
| 117 | bool JavaObject::has_java_method(const StringName &) const { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | JavaClassWrapper *JavaClassWrapper::singleton = nullptr; |
| 122 | |
| 123 | Ref<JavaClass> JavaClassWrapper::_wrap(const String &, bool) { |
| 124 | return Ref<JavaClass>(); |
| 125 | } |
| 126 | |
| 127 | JavaClassWrapper::JavaClassWrapper() { |
| 128 | singleton = this; |
| 129 | } |
| 130 | |
| 131 | #endif |