reactive_graph_std_logical/
plugin.rs1use reactive_graph_plugin_api::EntityBehaviourRegistry;
2use reactive_graph_plugin_api::prelude::plugin::*;
3use reactive_graph_plugin_api::prelude::providers::*;
4
5use reactive_graph_std_logical_model::BEHAVIOUR_IF_THEN_ELSE;
6use reactive_graph_std_logical_model::BEHAVIOUR_TOGGLE;
7use reactive_graph_std_logical_model::BEHAVIOUR_TRIGGER;
8use reactive_graph_std_logical_model::ENTITY_BEHAVIOUR_IF_THEN_ELSE;
9use reactive_graph_std_logical_model::ENTITY_BEHAVIOUR_TOGGLE;
10use reactive_graph_std_logical_model::ENTITY_BEHAVIOUR_TRIGGER;
11
12use crate::behaviour::entity::gate::function::LOGICAL_GATES;
13use crate::behaviour::entity::if_then_else::IfThenElseFactory;
14use crate::behaviour::entity::operation::function::LOGICAL_OPERATIONS;
15use crate::behaviour::entity::toggle::ToggleFactory;
16use crate::behaviour::entity::trigger::TriggerFactory;
17
18export_plugin!({
19 "dependencies": [
20 { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" },
21 { "name": "reactive-graph-std-trigger", "version": ">=0.10.0, <0.11.0" },
22 { "name": "reactive-graph-std-result", "version": ">=0.10.0, <0.11.0" },
23 { "name": "reactive-graph-std-connector", "version": ">=0.10.0, <0.11.0" }
24 ]
25});
26
27#[injectable]
28pub trait LogicalPlugin: Plugin + Send + Sync {}
29
30#[derive(Component)]
31pub struct LogicalPluginImpl {
32 component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
33
34 #[component(default = "component_provider_registry")]
35 component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
36
37 entity_types_provider: Arc<dyn TypeProvider<EntityTypes> + Send + Sync>,
38
39 #[component(default = "entity_types_provider_registry")]
40 entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
41
42 #[component(default = "entity_behaviour_registry")]
43 entity_behaviour_registry: Arc<dyn EntityBehaviourRegistry + Send + Sync>,
44}
45
46#[async_trait]
47#[component_alias]
48impl Plugin for LogicalPluginImpl {
49 async fn activate(&self) -> Result<(), PluginActivationError> {
50 self.component_provider_registry.register_provider(self.component_provider.clone()).await;
51 self.entity_type_provider_registry.register_provider(self.entity_types_provider.clone()).await;
52
53 let factory = Arc::new(IfThenElseFactory::new(BEHAVIOUR_IF_THEN_ELSE.clone()));
55 self.entity_behaviour_registry.register(ENTITY_BEHAVIOUR_IF_THEN_ELSE.clone(), factory).await;
56
57 let factory = Arc::new(ToggleFactory::new(BEHAVIOUR_TOGGLE.clone()));
59 self.entity_behaviour_registry.register(ENTITY_BEHAVIOUR_TOGGLE.clone(), factory).await;
60
61 let factory = Arc::new(TriggerFactory::new(BEHAVIOUR_TRIGGER.clone()));
63 self.entity_behaviour_registry.register(ENTITY_BEHAVIOUR_TRIGGER.clone(), factory).await;
64
65 self.entity_behaviour_registry.register_all(&LOGICAL_OPERATIONS.get_factories()).await;
67 self.entity_behaviour_registry.register_all(&LOGICAL_GATES.get_factories()).await;
68
69 Ok(())
70 }
71
72 async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
73 self.entity_behaviour_registry.unregister_all(&LOGICAL_GATES.to_entity_behaviour_tys()).await;
74 self.entity_behaviour_registry
75 .unregister_all(&LOGICAL_OPERATIONS.to_entity_behaviour_tys())
76 .await;
77 self.entity_behaviour_registry.unregister(&ENTITY_BEHAVIOUR_TRIGGER).await;
78 self.entity_behaviour_registry.unregister(&ENTITY_BEHAVIOUR_TOGGLE).await;
79 self.entity_behaviour_registry.unregister(&ENTITY_BEHAVIOUR_IF_THEN_ELSE).await;
80
81 self.entity_type_provider_registry.unregister_provider(self.entity_types_provider.id()).await;
82 self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
83 Ok(())
84 }
85}