MOre pre vtable changes
parent: tbd commit: 9cfa135
1 | |
2 | |
3 | |
4 | |
5 | use ; |
6 | |
7 | use |
8 | , | OperationError
9 | , |
10 | , |
11 | ; |
12 | use Version; |
13 | |
14 | use ; |
15 | |
16 | use crate:: |
17 | |
18 | OperationHandlerCallback, RuntimeState, SettingChangeCallback, SettingGetterCallback, |
19 | ValueChangeCallback, ValueGetterCallback, |
20 | , |
21 | , | RuntimeFuture
22 | , | PluginHandle
23 | |
24 | IntoRuntimeVtable, ObjectVtable, OperationVTable, RuntimeVTable, SettingVtable, ValueVTable, |
25 | , |
26 | AnyFailure, AnySuccess, |
27 | ; |
28 | |
29 | use OperationHandlerRules; |
30 | |
31 | ; |
32 | |
33 | |
34 | type Target = S; |
35 | |
36 | |
37 | &self.0 |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | pub objects: , |
44 | pub operations: , |
45 | pub settings: , |
46 | pub values: , |
47 | |
48 | |
49 | |
50 | pub unsafe |
51 | get_type_metadata_reference |
52 | . |
53 | .as_ref |
54 | |
55 | |
56 | |
57 | trace!; |
58 | |
59 | self.objects.insert; |
60 | |
61 | |
62 | |
63 | &mut self, |
64 | object_kind: &'static str, |
65 | operation_name: &'static str, |
66 | vtable: OperationVTable, |
67 | |
68 | trace! |
69 | "Registering operation metadata for {}::{}", |
70 | object_kind, |
71 | operation_name |
72 | ; |
73 | |
74 | self.operations.insert |
75 | ObjectOperationPair |
76 | object_kind, |
77 | operation_name, |
78 | , |
79 | vtable, |
80 | ; |
81 | |
82 | |
83 | |
84 | &mut self, |
85 | object_kind: &'static str, |
86 | setting_name: &'static str, |
87 | vtable: SettingVtable, |
88 | |
89 | trace!; |
90 | |
91 | self.settings.insert |
92 | ObjectSettingPair |
93 | object_kind, |
94 | setting_name, |
95 | , |
96 | vtable, |
97 | ; |
98 | |
99 | |
100 | |
101 | &mut self, |
102 | object_kind: &'static str, |
103 | value_name: &'static str, |
104 | vtable: ValueVTable, |
105 | |
106 | trace!; |
107 | |
108 | self.values.insert |
109 | ObjectValuePair |
110 | object_kind, |
111 | value_name, |
112 | , |
113 | vtable, |
114 | ; |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | pub object_kind: &'s str, |
121 | pub operation_name: &'s str, |
122 | |
123 | |
124 | |
125 | |
126 | Self |
127 | object_kind, |
128 | operation_name, |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | pub object_kind: &'s str, |
136 | pub setting_name: &'s str, |
137 | |
138 | |
139 | |
140 | |
141 | Self |
142 | object_kind, |
143 | setting_name, |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | pub object_kind: &'s str, |
151 | pub value_name: &'s str, |
152 | |
153 | |
154 | |
155 | |
156 | Self |
157 | object_kind, |
158 | value_name, |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | pub inner: *mut (), |
167 | |
168 | |
169 | unsafe |
170 | unsafe |
171 | |
172 | |
173 | pub unsafe |
174 | Box from_raw |
175 | |
176 | |
177 | pub unsafe |
178 | let ptr: *const T = transmute; |
179 | |
180 | ptr.as_ref .unwrap |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | Self |
187 | inner: Box into_raw as *mut _, |
188 | |
189 | |
190 | |
191 | pub unsafe |
192 | Self |
193 | inner: Box into_raw as *mut _, |
194 | |
195 | |
196 | |
197 | pub unsafe |
198 | Self |
199 | inner: raw as *mut , |
200 | |
201 | |
202 | |
203 | |
204 | Self |
205 | |
206 | |
207 | |
208 | |
209 | plugins: , |
210 | handlers: RuntimeHandlers, |
211 | |
212 | |
213 | |
214 | runtime: PluginState, |
215 | |
216 | |
217 | |
218 | unsafe extern "C" |
219 | _this: PluginState, |
220 | _object_kind: , |
221 | _operation_name: , |
222 | _object: , |
223 | _operation_payload: , |
224 | _operation_state: , |
225 | |
226 | todo! |
227 | |
228 | |
229 | unsafe extern "C" |
230 | this: PluginState, |
231 | object_str: &str, |
232 | operation_state: *mut OperationState, |
233 | |
234 | |
235 | let runtime_state = unsafe ; |
236 | |
237 | let type_metada = runtime_state |
238 | .vtable |
239 | .type_metadata |
240 | .as_ref |
241 | .unwrap_or_else |
242 | let runtime = this.; |
243 | |
244 | &runtime |
245 | .plugins |
246 | .first |
247 | .unwrap |
248 | .initialization |
249 | .type_metadata |
250 | ; |
251 | |
252 | for in &type_metada.objects |
253 | if let Ok = |
254 | return Ok; |
255 | |
256 | |
257 | |
258 | Err |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | Box new |
265 | plugins: vec!, |
266 | handlers: default, |
267 | |
268 | |
269 | |
270 | |
271 | RuntimeState |
272 | vtable: RuntimeVTable |
273 | runtime: from, |
274 | handle_fn: handle, |
275 | get_object: get_object, |
276 | type_metadata: unsafe , |
277 | , |
278 | |
279 | |
280 | |
281 | |
282 | let _guard = debug_span! .entered; |
283 | |
284 | for in &plugin.initialization.operation_handlers |
285 | let _guard = |
286 | trace_span! .entered; |
287 | |
288 | if self |
289 | .handlers |
290 | .operation_handlers |
291 | .insert |
292 | .is_some |
293 | |
294 | warn! |
295 | |
296 | |
297 | trace! |
298 | |
299 | |
300 | for in &plugin.initialization.value_getters |
301 | let _guard = |
302 | trace_span! .entered; |
303 | |
304 | if self |
305 | .handlers |
306 | .value_getters |
307 | .insert |
308 | .is_some |
309 | |
310 | warn! |
311 | |
312 | |
313 | trace! |
314 | |
315 | |
316 | for in &plugin.initialization.setting_getters |
317 | let _guard = |
318 | trace_span! .entered; |
319 | |
320 | if self |
321 | .handlers |
322 | .setting_getters |
323 | .insert |
324 | .is_some |
325 | |
326 | warn! |
327 | |
328 | |
329 | trace! |
330 | |
331 | |
332 | self.plugins.push; |
333 | |
334 | |
335 | |
336 | unsafe |
337 | |
338 | |
339 | // pub async fn handle( |
340 | // &self, |
341 | // object_kind: &str, |
342 | // operation_name: &str, |
343 | // object: &str, |
344 | // operation_payload: &[u8], |
345 | // operation_state: &OperationState, |
346 | // ) -> Result<AnySuccess, OperationError<AnyFailure>> { |
347 | // let rules = self.handlers.handle_operation(object_kind, operation_name); |
348 | |
349 | // let state = self.state(operation_state); |
350 | |
351 | // rules.handle(&state, object, operation_payload).await |
352 | // } |
353 | |
354 | |
355 | &self, |
356 | _object: O, |
357 | _operation: D, |
358 | |
359 | todo! |
360 | |
361 | |
362 | |
363 | |
364 | |
365 | operation_handlers: |
366 | , |
367 | value_getters: , |
368 | setting_getters: , |
369 | value_change: , |
370 | setting_change: , |
371 | |
372 | |
373 | unsafe |
374 | unsafe |
375 | |
376 | |
377 | |
378 | &mut self, |
379 | pair: , |
380 | handler: OperationHandlerCallback, |
381 | domain: RuntimeDomain, |
382 | |
383 | trace! |
384 | "Inserting operation handler for {}::{}", |
385 | pair.object_kind, |
386 | pair.operation_name |
387 | ; |
388 | |
389 | // There can only be one handler per operation (at least for now?), send a warning if |
390 | // a newly registered handler overwrites the previous handler. |
391 | if self |
392 | .operation_handlers |
393 | .insert |
394 | .is_some |
395 | |
396 | debug!; |
397 | |
398 | |
399 | |
400 | |
401 | &mut self, |
402 | pair: , |
403 | handler: ValueGetterCallback, |
404 | domain: RuntimeDomain, |
405 | |
406 | trace! |
407 | "Inserting value getter for {}::{}", |
408 | pair.object_kind, |
409 | pair.value_name |
410 | ; |
411 | |
412 | if self.value_getters.insert .is_some |
413 | debug! |
414 | "Warning! A newly inserted value getter for {}::{} overwrites a previous handler.", |
415 | pair.object_kind, pair.value_name |
416 | ; |
417 | |
418 | |
419 | |
420 | |
421 | &mut self, |
422 | pair: , |
423 | handler: SettingGetterCallback, |
424 | domain: RuntimeDomain, |
425 | |
426 | trace! |
427 | "Inserting setting getter for {}::{}", |
428 | pair.object_kind, |
429 | pair.setting_name |
430 | ; |
431 | |
432 | if self |
433 | .setting_getters |
434 | .insert |
435 | .is_some |
436 | |
437 | debug!; |
438 | |
439 | |
440 | |
441 | |
442 | &mut self, |
443 | pair: , |
444 | handler: ValueChangeCallback, |
445 | domain: RuntimeDomain, |
446 | |
447 | trace! |
448 | "Inserting value change handler for {}::{}", |
449 | pair.object_kind, |
450 | pair.value_name |
451 | ; |
452 | |
453 | if self.value_change.insert .is_some |
454 | debug!; |
455 | panic!; |
456 | |
457 | |
458 | |
459 | |
460 | &mut self, |
461 | pair: , |
462 | handler: SettingChangeCallback, |
463 | domain: RuntimeDomain, |
464 | |
465 | trace! |
466 | "Inserting setting change handler for {}::{}", |
467 | pair.object_kind, |
468 | pair.setting_name |
469 | ; |
470 | |
471 | if self |
472 | .setting_change |
473 | .insert |
474 | .is_some |
475 | |
476 | debug!; |
477 | panic!; |
478 | |
479 | |
480 | |
481 | |
482 | |
483 | |
484 | &'o self, |
485 | object_kind: &'o str, |
486 | operation_name: &'o str, |
487 | |
488 | new |
489 | |
490 | |
491 | |
492 | |
493 | plugin: PluginHandle, |
494 | |
495 | |
496 | |
497 | |
498 | Self |
499 | plugin: plugin.clone, |
500 | |
501 | |
502 | |
503 | |
504 | self.plugin |
505 | .initialization |
506 | .type_metadata |
507 | .objects |
508 | .get |
509 | .copied |
510 | |
511 | |
512 | |
513 | &self, |
514 | object_kind: &str, |
515 | operation_name: &str, |
516 | |
517 | self.plugin |
518 | .initialization |
519 | .type_metadata |
520 | .operations |
521 | .get |
522 | .copied |
523 | |
524 | |
525 | |
526 | self.plugin |
527 | .initialization |
528 | .type_metadata |
529 | .settings |
530 | .get |
531 | .copied |
532 | |
533 | |
534 | |
535 | self.plugin |
536 | .initialization |
537 | .type_metadata |
538 | .values |
539 | .get |
540 | .copied |
541 | |
542 | |
543 | |
544 | |
545 | |
546 | pub name: String, |
547 | pub version: Version, |
548 | |
549 | |
550 | |
551 | |
552 | pub name: *const u8, |
553 | pub name_len: usize, |
554 | pub version: *const u8, |
555 | pub version_len: usize, |
556 | |
557 | |
558 | |
559 | handle: PluginHandle, |
560 | type_metadata: , |
561 | |
562 | |
563 | |
564 | |
565 | let meta = unsafe ; |
566 | |
567 | let name = unsafe ; |
568 | let version = unsafe ; |
569 | |
570 | let name = from_utf8 .unwrap; |
571 | let version = from_utf8 .unwrap; |
572 | |
573 | PluginMeta |
574 | name: String from, |
575 | version: parse .unwrap, |
576 | |
577 | |
578 | |
579 |