Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/android/api/api.cpp
10278 views
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
}
66
67
void JavaObject::_bind_methods() {
68
ClassDB::bind_method(D_METHOD("get_java_class"), &JavaObject::get_java_class);
69
}
70
71
void JavaClassWrapper::_bind_methods() {
72
ClassDB::bind_method(D_METHOD("wrap", "name"), &JavaClassWrapper::wrap);
73
ClassDB::bind_method(D_METHOD("get_exception"), &JavaClassWrapper::get_exception);
74
}
75
76
#if !defined(ANDROID_ENABLED)
77
bool JavaClass::_get(const StringName &p_name, Variant &r_ret) const {
78
return false;
79
}
80
81
Variant JavaClass::callp(const StringName &, const Variant **, int, Callable::CallError &) {
82
return Variant();
83
}
84
85
String JavaClass::get_java_class_name() const {
86
return "";
87
}
88
89
TypedArray<Dictionary> JavaClass::get_java_method_list() const {
90
return TypedArray<Dictionary>();
91
}
92
93
Ref<JavaClass> JavaClass::get_java_parent_class() const {
94
return Ref<JavaClass>();
95
}
96
97
JavaClass::JavaClass() {
98
}
99
100
JavaClass::~JavaClass() {
101
}
102
103
Variant JavaObject::callp(const StringName &, const Variant **, int, Callable::CallError &) {
104
return Variant();
105
}
106
107
Ref<JavaClass> JavaObject::get_java_class() const {
108
return Ref<JavaClass>();
109
}
110
111
JavaClassWrapper *JavaClassWrapper::singleton = nullptr;
112
113
Ref<JavaClass> JavaClassWrapper::_wrap(const String &, bool) {
114
return Ref<JavaClass>();
115
}
116
117
JavaClassWrapper::JavaClassWrapper() {
118
singleton = this;
119
}
120
121
#endif
122
123