More restructuring
parent: tbd commit: 10b7b7c
1 | |
2 | |
3 | |
4 | use ; |
5 | |
6 | use Container; |
7 | use |
8 | |
9 | , | OperationHandlerCallback
10 | , |
11 | , |
12 | CallbackPtr, |
13 | , |
14 | , | GiteratedPluginAbi
15 | |
16 | , Plugin, RuntimeHandle, Object, Setting, VTable, | Operation
17 | Value, |
18 | , |
19 | ; |
20 | use TypeMetadata; |
21 | use |
22 | , | OperationError
23 | , |
24 | , | GiteratedOperation
25 | , | ObjectSettingPair
26 | , | ObjectValuePair
27 | ; |
28 | use OperationHandlerRules; |
29 | use PluginInitializationState; |
30 | use ; |
31 | |
32 | |
33 | plugins: , |
34 | handlers: RuntimeHandlers, |
35 | |
36 | |
37 | |
38 | |
39 | vtable: &'static , |
40 | library: , |
41 | |
42 | |
43 | |
44 | |
45 | todo! |
46 | |
47 | |
48 | |
49 | todo! |
50 | |
51 | |
52 | |
53 | todo! |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | Box new |
60 | plugins: vec!, |
61 | handlers: default, |
62 | |
63 | |
64 | |
65 | |
66 | RuntimeHandle |
67 | |
68 | |
69 | |
70 | &mut self, |
71 | mut plugin: RuntimePlugin, |
72 | mut initialization: PluginInitializationState, |
73 | |
74 | let _guard = debug_span! .entered; |
75 | |
76 | for in initialization.operation_handlers.drain |
77 | let _guard = |
78 | trace_span! .entered; |
79 | |
80 | if self |
81 | .handlers |
82 | .operation_handlers |
83 | .insert |
84 | .is_some |
85 | |
86 | warn! |
87 | |
88 | |
89 | trace! |
90 | |
91 | |
92 | for in initialization.value_getters.drain |
93 | let _guard = |
94 | trace_span! .entered; |
95 | |
96 | if self |
97 | .handlers |
98 | .value_getters |
99 | .insert |
100 | .is_some |
101 | |
102 | warn! |
103 | |
104 | |
105 | trace! |
106 | |
107 | |
108 | for in initialization.setting_getters |
109 | let _guard = |
110 | trace_span! .entered; |
111 | |
112 | if self |
113 | .handlers |
114 | .setting_getters |
115 | .insert |
116 | .is_some |
117 | |
118 | warn! |
119 | |
120 | |
121 | trace! |
122 | |
123 | |
124 | self.plugins.push; |
125 | |
126 | |
127 | |
128 | todo! |
129 | // unsafe { giterated_static_runtime::initialize_runtime(Box::into_raw(self).cast::<()>()) } |
130 | |
131 | |
132 | // pub async fn handle( |
133 | // &self, |
134 | // object_kind: &str, |
135 | // operation_name: &str, |
136 | // object: &str, |
137 | // operation_payload: &[u8], |
138 | // operation_state: &OperationState, |
139 | // ) -> Result<AnySuccess, OperationError<AnyFailure>> { |
140 | // let rules = self.handlers.handle_operation(object_kind, operation_name); |
141 | |
142 | // let state = self.state(operation_state); |
143 | |
144 | // rules.handle(&state, object, operation_payload).await |
145 | // } |
146 | |
147 | |
148 | &self, |
149 | _object: O, |
150 | _operation: D, |
151 | |
152 | todo! |
153 | |
154 | |
155 | |
156 | |
157 | plugin: RuntimePlugin, |
158 | |
159 | |
160 | |
161 | |
162 | Self |
163 | plugin: plugin.clone, |
164 | |
165 | |
166 | |
167 | |
168 | self.plugin.metadata .objects.get .copied |
169 | |
170 | |
171 | |
172 | &self, |
173 | object_kind: &str, |
174 | operation_name: &str, |
175 | |
176 | self.plugin |
177 | .metadata |
178 | .operations |
179 | .get |
180 | .copied |
181 | |
182 | |
183 | |
184 | &self, |
185 | object_kind: &str, |
186 | setting_name: &str, |
187 | |
188 | self.plugin |
189 | .metadata |
190 | .settings |
191 | .get |
192 | .copied |
193 | |
194 | |
195 | |
196 | &self, |
197 | object_kind: &str, |
198 | value_name: &str, |
199 | |
200 | self.plugin |
201 | .metadata |
202 | .values |
203 | .get |
204 | .copied |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | pub name: *const u8, |
211 | pub name_len: usize, |
212 | pub version: *const u8, |
213 | pub version_len: usize, |
214 | |
215 | |
216 | // pub struct RuntimePlugin { |
217 | // handle: PluginHandle, |
218 | // type_metadata: Arc<TypeMetadata>, |
219 | // } |
220 | |
221 | |
222 | // pub fn plugin_meta(&self) -> PluginMeta { |
223 | // let meta = unsafe { self.handle.raw.plugin_meta() }; |
224 | |
225 | // let name = unsafe { std::slice::from_raw_parts(meta.name, meta.name_len) }; |
226 | // let version = unsafe { std::slice::from_raw_parts(meta.version, meta.version_len) }; |
227 | |
228 | // let name = std::str::from_utf8(name).unwrap(); |
229 | // let version = std::str::from_utf8(version).unwrap(); |
230 | |
231 | // PluginMeta { |
232 | // name: String::from(name), |
233 | // version: Version::parse(version).unwrap(), |
234 | // } |
235 | // } |
236 | |
237 | |
238 | // #[derive(WrapperApi)] |
239 | // pub struct GiteratedPluginApi { |
240 | // plugin_meta: unsafe extern "C" fn() -> FFIPluginMeta, |
241 | // load_host_vtable: unsafe extern "C" fn(vtable: &HostVTable), |
242 | // load_initialization_vtable: unsafe extern "C" fn(vtable: &'static VTable<Initialization>), |
243 | // initialize: unsafe extern "C" fn(runtime_state: *const RuntimeState) -> PluginState, |
244 | // initialize_registration: unsafe extern "C" fn( |
245 | // init_state: *mut PluginInitializationState, |
246 | // ) -> *mut PluginInitializationState, |
247 | // load_type_metadata: unsafe extern "C" fn(metadata: *mut ()), |
248 | // } |
249 | |
250 | |
251 | operation_handlers: |
252 | , |
253 | (RuntimeDomain, ), |
254 | >, |
255 | value_getters: |
256 | , |
257 | setting_getters: |
258 | , |
259 | value_change: |
260 | , |
261 | setting_change: |
262 | , |
263 | |
264 | |
265 | unsafe |
266 | unsafe |
267 | |
268 | |
269 | |
270 | &mut self, |
271 | pair: , |
272 | handler: , |
273 | domain: RuntimeDomain, |
274 | |
275 | trace! |
276 | "Inserting operation handler for {}::{}", |
277 | pair.object_kind, |
278 | pair.operation_name |
279 | ; |
280 | |
281 | // There can only be one handler per operation (at least for now?), send a warning if |
282 | // a newly registered handler overwrites the previous handler. |
283 | if self |
284 | .operation_handlers |
285 | .insert |
286 | .is_some |
287 | |
288 | debug!; |
289 | |
290 | |
291 | |
292 | |
293 | &mut self, |
294 | pair: , |
295 | handler: , |
296 | domain: RuntimeDomain, |
297 | |
298 | trace! |
299 | "Inserting value getter for {}::{}", |
300 | pair.object_kind, |
301 | pair.value_name |
302 | ; |
303 | |
304 | if self.value_getters.insert .is_some |
305 | debug! |
306 | "Warning! A newly inserted value getter for {}::{} overwrites a previous handler.", |
307 | pair.object_kind, pair.value_name |
308 | ; |
309 | |
310 | |
311 | |
312 | |
313 | &mut self, |
314 | pair: , |
315 | handler: , |
316 | domain: RuntimeDomain, |
317 | |
318 | trace! |
319 | "Inserting setting getter for {}::{}", |
320 | pair.object_kind, |
321 | pair.setting_name |
322 | ; |
323 | |
324 | if self |
325 | .setting_getters |
326 | .insert |
327 | .is_some |
328 | |
329 | debug!; |
330 | |
331 | |
332 | |
333 | |
334 | &mut self, |
335 | pair: , |
336 | handler: , |
337 | domain: RuntimeDomain, |
338 | |
339 | trace! |
340 | "Inserting value change handler for {}::{}", |
341 | pair.object_kind, |
342 | pair.value_name |
343 | ; |
344 | |
345 | if self.value_change.insert .is_some |
346 | debug!; |
347 | panic!; |
348 | |
349 | |
350 | |
351 | |
352 | &mut self, |
353 | pair: , |
354 | handler: , |
355 | domain: RuntimeDomain, |
356 | |
357 | trace! |
358 | "Inserting setting change handler for {}::{}", |
359 | pair.object_kind, |
360 | pair.setting_name |
361 | ; |
362 | |
363 | if self |
364 | .setting_change |
365 | .insert |
366 | .is_some |
367 | |
368 | debug!; |
369 | panic!; |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | &'o self, |
377 | object_kind: &'o str, |
378 | operation_name: &'o str, |
379 | |
380 | new |
381 | |
382 | |
383 |