Huge refactor to prep for moving the daemon over to the plugin architecture
parent: tbd commit: 5df753c
1 | |
2 | |
3 | |
4 | use |
5 | , HashMap, Debug, transmute, null_mut, Arc, | type_name
6 | ; |
7 | |
8 | use |
9 | , Instance, GiteratedObject, | OperationError
10 | , | GiteratedOperation
11 | ; |
12 | use Version; |
13 | use ; |
14 | |
15 | use crate:: |
16 | |
17 | OperationHandlerCallback, SettingChangeCallback, SettingGetterCallback, |
18 | ValueChangeCallback, ValueGetterCallback, |
19 | , |
20 | , |
21 | , |
22 | ; |
23 | |
24 | use OperationHandlerRules; |
25 | |
26 | ; |
27 | |
28 | |
29 | type Target = S; |
30 | |
31 | |
32 | &self.0 |
33 | |
34 | |
35 | |
36 | |
37 | pub our_instance: Instance, |
38 | |
39 | |
40 | |
41 | |
42 | pub objects: , |
43 | pub operations: , |
44 | pub settings: , |
45 | pub values: , |
46 | |
47 | |
48 | |
49 | |
50 | trace!; |
51 | |
52 | self.objects.insert; |
53 | |
54 | |
55 | |
56 | &mut self, |
57 | object_kind: &'static str, |
58 | operation_name: &'static str, |
59 | vtable: OperationVTable, |
60 | |
61 | trace! |
62 | "Registering operation metadata for {}::{}", |
63 | object_kind, |
64 | operation_name |
65 | ; |
66 | |
67 | self.operations.insert |
68 | ObjectOperationPair |
69 | object_kind, |
70 | operation_name, |
71 | , |
72 | vtable, |
73 | ; |
74 | |
75 | |
76 | |
77 | &mut self, |
78 | object_kind: &'static str, |
79 | setting_name: &'static str, |
80 | vtable: SettingVtable, |
81 | |
82 | trace!; |
83 | |
84 | self.settings.insert |
85 | ObjectSettingPair |
86 | object_kind, |
87 | setting_name, |
88 | , |
89 | vtable, |
90 | ; |
91 | |
92 | |
93 | |
94 | &mut self, |
95 | object_kind: &'static str, |
96 | value_name: &'static str, |
97 | vtable: ValueVTable, |
98 | |
99 | trace!; |
100 | |
101 | self.values.insert |
102 | ObjectValuePair |
103 | object_kind, |
104 | value_name, |
105 | , |
106 | vtable, |
107 | ; |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | pub object_kind: &'s str, |
114 | pub operation_name: &'s str, |
115 | |
116 | |
117 | |
118 | |
119 | Self |
120 | object_kind, |
121 | operation_name, |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | pub object_kind: &'s str, |
129 | pub setting_name: &'s str, |
130 | |
131 | |
132 | |
133 | |
134 | Self |
135 | object_kind, |
136 | setting_name, |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | pub object_kind: &'s str, |
144 | pub value_name: &'s str, |
145 | |
146 | |
147 | |
148 | |
149 | Self |
150 | object_kind, |
151 | value_name, |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | pub inner: *mut (), |
160 | |
161 | |
162 | |
163 | pub unsafe |
164 | Box from_raw |
165 | |
166 | |
167 | pub unsafe |
168 | let ptr: *const T = transmute; |
169 | |
170 | ptr.as_ref .unwrap |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | Self |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | plugins: , |
183 | handlers: RuntimeHandlers, |
184 | |
185 | |
186 | |
187 | |
188 | let _guard = debug_span! .entered; |
189 | |
190 | for in &plugin.initialization.operation_handlers |
191 | let _guard = |
192 | trace_span! .entered; |
193 | |
194 | if self |
195 | .handlers |
196 | .operation_handlers |
197 | .insert |
198 | .is_some |
199 | |
200 | warn! |
201 | |
202 | |
203 | trace! |
204 | |
205 | |
206 | for in &plugin.initialization.value_getters |
207 | let _guard = |
208 | trace_span! .entered; |
209 | |
210 | if self |
211 | .handlers |
212 | .value_getters |
213 | .insert |
214 | .is_some |
215 | |
216 | warn! |
217 | |
218 | |
219 | trace! |
220 | |
221 | |
222 | for in &plugin.initialization.setting_getters |
223 | let _guard = |
224 | trace_span! .entered; |
225 | |
226 | if self |
227 | .handlers |
228 | .setting_getters |
229 | .insert |
230 | .is_some |
231 | |
232 | warn! |
233 | |
234 | |
235 | trace! |
236 | |
237 | |
238 | |
239 | |
240 | &self, |
241 | object_kind: &str, |
242 | operation_name: &str, |
243 | object: &str, |
244 | operation_payload: &[u8], |
245 | |
246 | // let rules = self.handlers.handle_operation(object_kind, operation_name); |
247 | |
248 | // rules.handle(object, operation_payload) |
249 | |
250 | todo! |
251 | |
252 | |
253 | |
254 | &self, |
255 | object: O, |
256 | operation: D, |
257 | |
258 | todo! |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | operation_handlers: |
265 | , |
266 | value_getters: , |
267 | setting_getters: , |
268 | value_change: , |
269 | setting_change: , |
270 | |
271 | |
272 | unsafe |
273 | unsafe |
274 | |
275 | |
276 | |
277 | &mut self, |
278 | pair: , |
279 | handler: OperationHandlerCallback, |
280 | domain: RuntimeDomain, |
281 | |
282 | trace! |
283 | "Inserting operation handler for {}::{}", |
284 | pair.object_kind, |
285 | pair.operation_name |
286 | ; |
287 | |
288 | // There can only be one handler per operation (at least for now?), send a warning if |
289 | // a newly registered handler overwrites the previous handler. |
290 | if self |
291 | .operation_handlers |
292 | .insert |
293 | .is_some |
294 | |
295 | debug!; |
296 | |
297 | |
298 | |
299 | |
300 | &mut self, |
301 | pair: , |
302 | handler: ValueGetterCallback, |
303 | domain: RuntimeDomain, |
304 | |
305 | trace! |
306 | "Inserting value getter for {}::{}", |
307 | pair.object_kind, |
308 | pair.value_name |
309 | ; |
310 | |
311 | if self.value_getters.insert .is_some |
312 | debug! |
313 | "Warning! A newly inserted value getter for {}::{} overwrites a previous handler.", |
314 | pair.object_kind, pair.value_name |
315 | ; |
316 | |
317 | |
318 | |
319 | |
320 | &mut self, |
321 | pair: , |
322 | handler: SettingGetterCallback, |
323 | domain: RuntimeDomain, |
324 | |
325 | trace! |
326 | "Inserting setting getter for {}::{}", |
327 | pair.object_kind, |
328 | pair.setting_name |
329 | ; |
330 | |
331 | if self |
332 | .setting_getters |
333 | .insert |
334 | .is_some |
335 | |
336 | debug!; |
337 | |
338 | |
339 | |
340 | |
341 | &mut self, |
342 | pair: , |
343 | handler: ValueChangeCallback, |
344 | domain: RuntimeDomain, |
345 | |
346 | trace! |
347 | "Inserting value change handler for {}::{}", |
348 | pair.object_kind, |
349 | pair.value_name |
350 | ; |
351 | |
352 | if self.value_change.insert .is_some |
353 | debug!; |
354 | panic!; |
355 | |
356 | |
357 | |
358 | |
359 | &mut self, |
360 | pair: , |
361 | handler: SettingChangeCallback, |
362 | domain: RuntimeDomain, |
363 | |
364 | trace! |
365 | "Inserting setting change handler for {}::{}", |
366 | pair.object_kind, |
367 | pair.setting_name |
368 | ; |
369 | |
370 | if self |
371 | .setting_change |
372 | .insert |
373 | .is_some |
374 | |
375 | debug!; |
376 | panic!; |
377 | |
378 | |
379 | |
380 | |
381 | |
382 | |
383 | &'o self, |
384 | object_kind: &'o str, |
385 | operation_name: &'o str, |
386 | |
387 | new |
388 | |
389 | |
390 | |
391 | |
392 | plugin: PluginHandle, |
393 | |
394 | |
395 | |
396 | |
397 | Self |
398 | plugin: plugin.clone, |
399 | |
400 | |
401 | |
402 | |
403 | self.plugin |
404 | .initialization |
405 | .type_metadata |
406 | .objects |
407 | .get |
408 | .copied |
409 | |
410 | |
411 | |
412 | &self, |
413 | object_kind: &str, |
414 | operation_name: &str, |
415 | |
416 | self.plugin |
417 | .initialization |
418 | .type_metadata |
419 | .operations |
420 | .get |
421 | .copied |
422 | |
423 | |
424 | |
425 | self.plugin |
426 | .initialization |
427 | .type_metadata |
428 | .settings |
429 | .get |
430 | .copied |
431 | |
432 | |
433 | |
434 | self.plugin |
435 | .initialization |
436 | .type_metadata |
437 | .values |
438 | .get |
439 | .copied |
440 | |
441 | |
442 | |
443 | |
444 | |
445 | pub name: String, |
446 | pub version: Version, |
447 | |
448 | |
449 | |
450 | |
451 | pub name: *const u8, |
452 | pub name_len: usize, |
453 | pub version: *const u8, |
454 | pub version_len: usize, |
455 | |
456 | |
457 | |
458 | handle: PluginHandle, |
459 | type_metadata: , |
460 | |
461 | |
462 | |
463 | |
464 | let meta = unsafe ; |
465 | |
466 | let name = unsafe ; |
467 | let version = unsafe ; |
468 | |
469 | let name = from_utf8 .unwrap; |
470 | let version = from_utf8 .unwrap; |
471 | |
472 | PluginMeta |
473 | name: String from, |
474 | version: parse .unwrap, |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | Failure, |
481 | Internal, |
482 | Unhandled, |
483 | |
484 |