fj_kernel/services/
mod.rs1mod objects;
6mod service;
7mod validation;
8
9use crate::objects::{Object, ObjectSet, Objects, WithHandle};
10
11pub use self::{
12 objects::{InsertObject, Operation},
13 service::{Service, State},
14 validation::{Validation, ValidationCommand, ValidationEvent},
15};
16
17pub struct Services {
19 pub objects: Service<Objects>,
23
24 pub validation: Service<Validation>,
28}
29
30impl Services {
31 pub fn new() -> Self {
33 let objects = Service::<Objects>::default();
34 let validation = Service::default();
35
36 Self {
37 objects,
38 validation,
39 }
40 }
41
42 pub fn insert_object(&mut self, object: Object<WithHandle>) {
44 let mut object_events = Vec::new();
45 self.objects
46 .execute(Operation::InsertObject { object }, &mut object_events);
47
48 for object_event in object_events {
49 let command = ValidationCommand::ValidateObject {
50 object: object_event.object.into(),
51 };
52 self.validation.execute(command, &mut Vec::new());
53 }
54 }
55
56 pub fn only_validate(&mut self, objects: impl Into<ObjectSet>) {
58 let objects = objects.into();
59
60 let mut events = Vec::new();
61 self.validation
62 .execute(ValidationCommand::OnlyValidate { objects }, &mut events);
63 }
64}
65
66impl Default for Services {
67 fn default() -> Self {
68 Self::new()
69 }
70}