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