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 and the |
45 | // `JNISingleton` registration occurs in |
46 | // `platform/android/java_godot_lib_jni.cpp#Java_org_godotengine_godot_GodotLib_setup` |
47 | java_class_wrapper = memnew(JavaClassWrapper); // Dummy |
48 | GDREGISTER_CLASS(JNISingleton); |
49 | #endif |
50 | |
51 | GDREGISTER_CLASS(JavaClass); |
52 | GDREGISTER_CLASS(JavaClassWrapper); |
53 | Engine::get_singleton()->add_singleton(Engine::Singleton("JavaClassWrapper" , JavaClassWrapper::get_singleton())); |
54 | } |
55 | |
56 | void unregister_android_api() { |
57 | #if !defined(ANDROID_ENABLED) |
58 | memdelete(java_class_wrapper); |
59 | #endif |
60 | } |
61 | |
62 | void JavaClassWrapper::_bind_methods() { |
63 | ClassDB::bind_method(D_METHOD("wrap" , "name" ), &JavaClassWrapper::wrap); |
64 | } |
65 | |
66 | #if !defined(ANDROID_ENABLED) |
67 | |
68 | Variant JavaClass::callp(const StringName &, const Variant **, int, Callable::CallError &) { |
69 | return Variant(); |
70 | } |
71 | |
72 | JavaClass::JavaClass() { |
73 | } |
74 | |
75 | Variant JavaObject::callp(const StringName &, const Variant **, int, Callable::CallError &) { |
76 | return Variant(); |
77 | } |
78 | |
79 | JavaClassWrapper *JavaClassWrapper::singleton = nullptr; |
80 | |
81 | Ref<JavaClass> JavaClassWrapper::wrap(const String &) { |
82 | return Ref<JavaClass>(); |
83 | } |
84 | |
85 | JavaClassWrapper::JavaClassWrapper() { |
86 | singleton = this; |
87 | } |
88 | |
89 | #endif |
90 | |