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