23
23
#include " JFunc_void_std__shared_ptr_ArrayBuffer_.hpp"
24
24
#include " JHybridWebSocketManagerSpec.hpp"
25
25
#include < NitroModules/JNISharedPtr.hpp>
26
+ #include < NitroModules/DefaultConstructableObject.hpp>
26
27
#include " HybridCompressorFactory.hpp"
27
28
28
29
namespace margelo ::nitro::fastio {
@@ -52,63 +53,35 @@ int initialize(JavaVM* vm) {
52
53
HybridObjectRegistry::registerHybridObjectConstructor (
53
54
" WebSocketManager" ,
54
55
[]() -> std::shared_ptr<HybridObject> {
55
- static auto javaClass = jni::findClassStatic (" com/margelo/nitro/fastio/HybridWebSocketManager" );
56
- static auto defaultConstructor = javaClass->getConstructor <JHybridWebSocketManagerSpec::javaobject ()>();
57
-
58
- auto instance = javaClass->newObject (defaultConstructor);
59
- #ifdef NITRO_DEBUG
60
- if (instance == nullptr ) [[unlikely]] {
61
- throw std::runtime_error (" Failed to create an instance of \" JHybridWebSocketManagerSpec\" - the constructor returned null!" );
62
- }
63
- #endif
56
+ static DefaultConstructableObject<JHybridWebSocketManagerSpec::javaobject> object (" com/margelo/nitro/fastio/HybridWebSocketManager" );
57
+ auto instance = object.create ();
64
58
auto globalRef = jni::make_global (instance);
65
59
return JNISharedPtr::make_shared_from_jni<JHybridWebSocketManagerSpec>(globalRef);
66
60
}
67
61
);
68
62
HybridObjectRegistry::registerHybridObjectConstructor (
69
63
" FileSystem" ,
70
64
[]() -> std::shared_ptr<HybridObject> {
71
- static auto javaClass = jni::findClassStatic (" com/margelo/nitro/fastio/HybridFileSystem" );
72
- static auto defaultConstructor = javaClass->getConstructor <JHybridFileSystemSpec::javaobject ()>();
73
-
74
- auto instance = javaClass->newObject (defaultConstructor);
75
- #ifdef NITRO_DEBUG
76
- if (instance == nullptr ) [[unlikely]] {
77
- throw std::runtime_error (" Failed to create an instance of \" JHybridFileSystemSpec\" - the constructor returned null!" );
78
- }
79
- #endif
65
+ static DefaultConstructableObject<JHybridFileSystemSpec::javaobject> object (" com/margelo/nitro/fastio/HybridFileSystem" );
66
+ auto instance = object.create ();
80
67
auto globalRef = jni::make_global (instance);
81
68
return JNISharedPtr::make_shared_from_jni<JHybridFileSystemSpec>(globalRef);
82
69
}
83
70
);
84
71
HybridObjectRegistry::registerHybridObjectConstructor (
85
72
" Network" ,
86
73
[]() -> std::shared_ptr<HybridObject> {
87
- static auto javaClass = jni::findClassStatic (" com/margelo/nitro/fastio/HybridNetwork" );
88
- static auto defaultConstructor = javaClass->getConstructor <JHybridNetworkSpec::javaobject ()>();
89
-
90
- auto instance = javaClass->newObject (defaultConstructor);
91
- #ifdef NITRO_DEBUG
92
- if (instance == nullptr ) [[unlikely]] {
93
- throw std::runtime_error (" Failed to create an instance of \" JHybridNetworkSpec\" - the constructor returned null!" );
94
- }
95
- #endif
74
+ static DefaultConstructableObject<JHybridNetworkSpec::javaobject> object (" com/margelo/nitro/fastio/HybridNetwork" );
75
+ auto instance = object.create ();
96
76
auto globalRef = jni::make_global (instance);
97
77
return JNISharedPtr::make_shared_from_jni<JHybridNetworkSpec>(globalRef);
98
78
}
99
79
);
100
80
HybridObjectRegistry::registerHybridObjectConstructor (
101
81
" DuplexStream" ,
102
82
[]() -> std::shared_ptr<HybridObject> {
103
- static auto javaClass = jni::findClassStatic (" com/margelo/nitro/fastio/HybridDuplexStream" );
104
- static auto defaultConstructor = javaClass->getConstructor <JHybridDuplexStreamSpec::javaobject ()>();
105
-
106
- auto instance = javaClass->newObject (defaultConstructor);
107
- #ifdef NITRO_DEBUG
108
- if (instance == nullptr ) [[unlikely]] {
109
- throw std::runtime_error (" Failed to create an instance of \" JHybridDuplexStreamSpec\" - the constructor returned null!" );
110
- }
111
- #endif
83
+ static DefaultConstructableObject<JHybridDuplexStreamSpec::javaobject> object (" com/margelo/nitro/fastio/HybridDuplexStream" );
84
+ auto instance = object.create ();
112
85
auto globalRef = jni::make_global (instance);
113
86
return JNISharedPtr::make_shared_from_jni<JHybridDuplexStreamSpec>(globalRef);
114
87
}
@@ -125,15 +98,8 @@ int initialize(JavaVM* vm) {
125
98
HybridObjectRegistry::registerHybridObjectConstructor (
126
99
" StreamFactory" ,
127
100
[]() -> std::shared_ptr<HybridObject> {
128
- static auto javaClass = jni::findClassStatic (" com/margelo/nitro/fastio/HybridStreamFactory" );
129
- static auto defaultConstructor = javaClass->getConstructor <JHybridStreamFactorySpec::javaobject ()>();
130
-
131
- auto instance = javaClass->newObject (defaultConstructor);
132
- #ifdef NITRO_DEBUG
133
- if (instance == nullptr ) [[unlikely]] {
134
- throw std::runtime_error (" Failed to create an instance of \" JHybridStreamFactorySpec\" - the constructor returned null!" );
135
- }
136
- #endif
101
+ static DefaultConstructableObject<JHybridStreamFactorySpec::javaobject> object (" com/margelo/nitro/fastio/HybridStreamFactory" );
102
+ auto instance = object.create ();
137
103
auto globalRef = jni::make_global (instance);
138
104
return JNISharedPtr::make_shared_from_jni<JHybridStreamFactorySpec>(globalRef);
139
105
}
0 commit comments