Unified stack refactor clean up
Clean up obsolete code and some warnings
parent: tbd commit: 356f714
1 | use ; |
2 | |
3 | use |
4 | , | AuthenticatedPayload
5 | , | OperationError
6 | , | GiteratedMessage
7 | , |
8 | , | ObjectBackend
9 | , |
10 | , |
11 | , |
12 | ; |
13 | use trace; |
14 | |
15 | use crate:: |
16 | GiteratedOperationHandler, ObjectMeta, ObjectOperationPair, ObjectValuePair, OperationMeta, |
17 | OperationWrapper, SettingMeta, StackOperationState, ValueMeta, |
18 | ; |
19 | |
20 | /// Temporary name for the next generation of Giterated stack |
21 | |
22 | |
23 | operation_handlers: , |
24 | value_getters: , |
25 | setting_getters: , |
26 | metadata: RuntimeMetadata, |
27 | |
28 | |
29 | |
30 | |
31 | &mut self, |
32 | builder: , |
33 | |
34 | for in builder.operation_handlers |
35 | let tree = self.get_or_create_tree; |
36 | |
37 | tree.push; |
38 | |
39 | |
40 | for in builder.value_getters |
41 | assert!; |
42 | |
43 | |
44 | for in builder.setting_getters |
45 | assert!; |
46 | |
47 | |
48 | self.metadata.append; |
49 | |
50 | self |
51 | |
52 | |
53 | |
54 | if self.operation_handlers.contains_key |
55 | self.operation_handlers.get_mut .unwrap |
56 | else |
57 | self.operation_handlers |
58 | .insert; |
59 | |
60 | self.operation_handlers.get_mut .unwrap |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | elements: , |
67 | |
68 | |
69 | |
70 | |
71 | Self |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | self.elements.push; |
78 | |
79 | |
80 | |
81 | &self, |
82 | _object: &dyn Any, |
83 | _operation: , |
84 | _operation_state: &StackOperationState, |
85 | |
86 | todo! |
87 | |
88 | |
89 | |
90 | /// Stores runtime metadata for all in-use Giterated protocol types. |
91 | |
92 | |
93 | objects: , |
94 | operations: , |
95 | values: , |
96 | settings: , |
97 | |
98 | |
99 | /// Defines a type that is a valid Giterated runtime state. |
100 | /// |
101 | /// This allows for extraction of state in handlers, based on a |
102 | /// [`FromOperationState<S>`] impl on (what is in this case) [`Self`]. |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | operation_handlers: , |
109 | value_getters: , |
110 | setting_getters: , |
111 | metadata: RuntimeMetadata, |
112 | state: S, |
113 | |
114 | |
115 | |
116 | |
117 | todo! |
118 | |
119 | |
120 | |
121 | |
122 | /// Insert an operation handler into the runtime builder. |
123 | /// |
124 | /// # Type Registration |
125 | /// Inserting the handler will automatically, if required, register the operation type of the |
126 | /// handler. It will **not** register the object type automatically. |
127 | |
128 | |
129 | O: GiteratedObject + 'static, |
130 | D: + 'static, |
131 | H: + 'static + Clone, |
132 | |
133 | let object_name = handler.object_name .to_string; |
134 | let operation_name = handler.operation_name .to_string; |
135 | |
136 | let wrapped = new; |
137 | |
138 | let pair = ObjectOperationPair |
139 | object_name, |
140 | operation_name, |
141 | ; |
142 | |
143 | assert!; |
144 | |
145 | self.metadata.; |
146 | |
147 | self |
148 | |
149 | |
150 | /// Register a [`GiteratedObject`] type with the runtime. |
151 | /// |
152 | /// # Type Registration |
153 | /// This will register the provided object type. |
154 | |
155 | self.metadata.; |
156 | |
157 | self |
158 | |
159 | |
160 | /// Register a [`Setting`] type with the runtime. |
161 | /// |
162 | /// # Type Registration |
163 | /// This will register the provided setting type. |
164 | |
165 | self.metadata.; |
166 | |
167 | self |
168 | |
169 | |
170 | /// Register a [`GiteratedObjectValue<O>`] type with the runtime, providing |
171 | /// its associated handler for [`GetValue`]. |
172 | /// |
173 | /// # Type Registration |
174 | /// This will register the provided [`GiteratedObjectValue`] type for its matching / specified |
175 | /// object type. It will **not** register the object type automatically. |
176 | |
177 | |
178 | O: GiteratedObject + 'static, |
179 | V: + 'static, |
180 | F: + Clone + 'static, |
181 | |
182 | let object_name = handler.object_name .to_string; |
183 | let value_name = value_name .to_string; |
184 | |
185 | let wrapped = new; |
186 | |
187 | assert! |
188 | .value_getters |
189 | .insert |
190 | ObjectValuePair |
191 | object_kind: object_name, |
192 | value_kind: value_name |
193 | , |
194 | wrapped |
195 | |
196 | .is_none; |
197 | |
198 | self.metadata.; |
199 | |
200 | self |
201 | |
202 | |
203 | /// Register a handler for [`GetSetting`] for it's associated object type. |
204 | |
205 | |
206 | O: GiteratedObject + 'static, |
207 | F: + Clone + 'static, |
208 | |
209 | let object_name = handler.object_name .to_string; |
210 | |
211 | let wrapped = new; |
212 | |
213 | assert!; |
214 | |
215 | self |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | let object_name = object_name .to_string; |
222 | |
223 | let object_meta = ObjectMeta |
224 | name: object_name.clone, |
225 | from_str: Box new, |
226 | any_is_same: Box new, |
227 | ; |
228 | |
229 | if self.objects.insert .is_some |
230 | trace! |
231 | "Registration of object {} overwrote previous registration.", |
232 | object_name |
233 | ; |
234 | else |
235 | trace! |
236 | |
237 | |
238 | |
239 | |
240 | &mut self, |
241 | |
242 | let object_name = object_name .to_string; |
243 | let operation_name = operation_name .to_string; |
244 | |
245 | if self |
246 | .operations |
247 | .insert |
248 | ObjectOperationPair |
249 | object_name: object_name.clone, |
250 | operation_name: operation_name.clone, |
251 | , |
252 | OperationMeta |
253 | name: operation_name, |
254 | object_kind: object_name, |
255 | deserialize: Box new |
256 | Ok |
257 | as |
258 | , |
259 | any_is_same: Box new, |
260 | serialize_success: Box new |
261 | let to_serialize = any. .unwrap; |
262 | to_vec |
263 | , |
264 | serialize_error: Box new |
265 | let to_serialize = any. .unwrap; |
266 | to_vec |
267 | , |
268 | , |
269 | |
270 | .is_some |
271 | |
272 | trace! |
273 | "Registration of object operation {}<{}> overwrote previous registration.", |
274 | , | operation_name
275 | object_name |
276 | ; |
277 | else |
278 | trace! |
279 | "Registration of object operation {}<{}>.", |
280 | , | operation_name
281 | object_name |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | O: GiteratedObject + 'static, |
288 | V: + 'static, |
289 | > |
290 | &mut self, |
291 | |
292 | let object_name = object_name .to_string; |
293 | let value_name = value_name .to_string; |
294 | |
295 | if self |
296 | .values |
297 | .insert |
298 | ObjectValuePair |
299 | object_kind: object_name.clone, |
300 | value_kind: value_name.clone, |
301 | , |
302 | ValueMeta |
303 | name: value_name, |
304 | deserialize: Box new, |
305 | , |
306 | |
307 | .is_some |
308 | |
309 | trace! |
310 | "Registration of value <{}>::{} overwrote previous registration.", |
311 | , | object_name
312 | value_name |
313 | ; |
314 | else |
315 | trace! |
316 | "Registration of value <{}>::{}.", |
317 | , | object_name
318 | value_name |
319 | ; |
320 | |
321 | |
322 | |
323 | |
324 | let setting_name = name .to_string; |
325 | |
326 | if self |
327 | .settings |
328 | .insert |
329 | setting_name.clone, |
330 | SettingMeta |
331 | name: setting_name, |
332 | deserialize: Box new, |
333 | , |
334 | |
335 | .is_some |
336 | |
337 | trace! |
338 | "Registration of setting {} overwrote previous registration.", |
339 | name |
340 | ; |
341 | else |
342 | trace!; |
343 | |
344 | |
345 | |
346 | |
347 | self.objects.extend; |
348 | self.operations.extend; |
349 | self.values.extend; |
350 | self.settings.extend; |
351 | |
352 | |
353 | |
354 | |
355 | |
356 | |
357 | O: GiteratedObject + 'static, |
358 | D: + 'static, |
359 | S: GiteratedRuntimeState + 'static, |
360 | |
361 | |
362 | operation_name |
363 | |
364 | |
365 | |
366 | object_name |
367 | |
368 | |
369 | async |
370 | &self, |
371 | object: &O, |
372 | operation: D, |
373 | _state: S, |
374 | operation_state: &StackOperationState, |
375 | |
376 | // Erase object and operation types. |
377 | let object = object as &dyn Any; |
378 | let operation = Box new as ; |
379 | |
380 | // We need to determine the type of the object, iterate through all known |
381 | // object types and check if the &dyn Any we have is the same type as the |
382 | // object type. |
383 | let object_type = |
384 | let mut object_type = None; |
385 | |
386 | for in self.metadata.objects.iter |
387 | if |
388 | object_type = Some; |
389 | break; |
390 | |
391 | |
392 | |
393 | object_type |
394 | |
395 | .ok_or_else?; |
396 | |
397 | // We need to hijack get_value, set_setting, and get_setting. |
398 | if operation. |
399 | todo! |
400 | else if operation. |
401 | todo! |
402 | else if operation. |
403 | todo! |
404 | |
405 | |
406 | // Resolve the operation from the known operations table. |
407 | let operation_type = |
408 | let mut operation_type = None; |
409 | |
410 | for in self.metadata.operations.iter |
411 | // Skip elements that we know will not match |
412 | if target.object_name != object_type |
413 | continue; |
414 | |
415 | |
416 | if |
417 | operation_type = Some; |
418 | break; |
419 | |
420 | |
421 | |
422 | operation_type |
423 | |
424 | .ok_or_else?; |
425 | |
426 | // Resolve the handler from our handler tree |
427 | let handler_tree = self |
428 | .operation_handlers |
429 | .get |
430 | .ok_or_else?; |
431 | |
432 | let raw_result = handler_tree.handle; |
433 | |
434 | // Convert the dynamic result back into its concrete type |
435 | match raw_result |
436 | Ok => Ok, |
437 | Err => Err |
438 | => Internal, | Internal
439 | => | Operation
440 | Operation |
441 | |
442 | => Unhandled, | Unhandled
443 | , |
444 | |
445 | |
446 | |
447 | |
448 | |
449 | /// Handles a giterated network message, returning either a raw success |
450 | /// payload or a serialized error payload. |
451 | pub async |
452 | &self, |
453 | message: AuthenticatedPayload, |
454 | _state: &S, |
455 | operation_state: &StackOperationState, |
456 | |
457 | let message: = message.into_message_v2; |
458 | |
459 | // Deserialize the object, also getting the object type's name |
460 | let = |
461 | let mut result = None; |
462 | |
463 | for in self.metadata.objects.iter |
464 | if let Ok = |
465 | result = Some; |
466 | break; |
467 | |
468 | |
469 | |
470 | result |
471 | |
472 | .ok_or_else?; |
473 | |
474 | let target = ObjectOperationPair |
475 | object_name: object_type, |
476 | operation_name: message.operation, |
477 | ; |
478 | |
479 | // Resolve the target operations from the handlers table |
480 | let handler = self |
481 | .operation_handlers |
482 | .get |
483 | .ok_or_else?; |
484 | |
485 | // Deserialize the operation |
486 | let meta = self |
487 | .metadata |
488 | .operations |
489 | .get |
490 | .ok_or_else?; |
491 | |
492 | let operation = |
493 | map_err?; | .
494 | |
495 | // Get the raw result of the operation, where the return values are boxed. |
496 | let raw_result = handler.handle; |
497 | |
498 | // Deserialize the raw result for the network |
499 | match raw_result |
500 | Ok => Ok |
501 | .map_err?, |
502 | Err => Err |
503 | => Operation | Operation
504 | |
505 | .map_err?, |
506 | , |
507 | => Internal, | Internal
508 | => Unhandled, | Unhandled
509 | , |
510 | |
511 | |
512 | |
513 | |
514 | use Debug; |
515 | |
516 | |
517 | |
518 | async |
519 | &self, |
520 | _object: O, |
521 | _operation: &str, |
522 | _payload: D, |
523 | _operation_state: &StackOperationState, |
524 | |
525 | |
526 | O: GiteratedObject + Debug + 'static, |
527 | D: + Debug, |
528 | |
529 | todo! |
530 | |
531 | |
532 | async |
533 | &self, |
534 | _object_str: &str, |
535 | _operation_state: &StackOperationState, |
536 | |
537 | todo! |
538 | |
539 | |
540 |