reactive_graph_sys_binary/
plugin.rs1use reactive_graph_plugin_api::EntityComponentBehaviourRegistry;
2use reactive_graph_plugin_api::WebResourceManager;
3use reactive_graph_plugin_api::prelude::plugin::*;
4use reactive_graph_plugin_api::prelude::providers::*;
5
6use crate::behaviour::component::load_binary_data::LoadBinaryDataFactory;
7use crate::behaviour::component::save_binary_data::SaveBinaryDataFactory;
8use reactive_graph_sys_binary_model::BEHAVIOUR_LOAD_BINARY_DATA;
9use reactive_graph_sys_binary_model::BEHAVIOUR_SAVE_BINARY_DATA;
10use reactive_graph_sys_binary_model::COMPONENT_BEHAVIOUR_LOAD_BINARY_DATA;
11use reactive_graph_sys_binary_model::COMPONENT_BEHAVIOUR_SAVE_BINARY_DATA;
12
13export_plugin!({
14 "dependencies": [
15 { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" },
16 { "name": "reactive-graph-std-trigger", "version": ">=0.10.0, <0.11.0" },
17 { "name": "reactive-graph-sys-file", "version": ">=0.10.0, <0.11.0" }
18 ]
19});
20
21#[injectable]
22pub trait BinaryPlugin: Plugin + Send + Sync {}
23
24#[derive(Component)]
25pub struct BinaryPluginImpl {
26 component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
27
28 #[component(default = "component_provider_registry")]
29 component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
30
31 entity_types_provider: Arc<dyn TypeProvider<EntityTypes> + Send + Sync>,
32
33 #[component(default = "entity_types_provider_registry")]
34 entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
35
36 #[component(default = "entity_component_behaviour_registry")]
37 entity_component_behaviour_registry: Arc<dyn EntityComponentBehaviourRegistry + Send + Sync>,
38
39 web_resource_provider: Arc<dyn WebResourceProvider + Send + Sync>,
40
41 #[component(default = "web_resource_manager")]
42 web_resource_manager: Arc<dyn WebResourceManager + Send + Sync>,
43}
44
45#[async_trait]
46#[component_alias]
47impl Plugin for BinaryPluginImpl {
48 async fn activate(&self) -> Result<(), PluginActivationError> {
49 self.component_provider_registry.register_provider(self.component_provider.clone()).await;
50 self.entity_type_provider_registry.register_provider(self.entity_types_provider.clone()).await;
51
52 let factory = Arc::new(LoadBinaryDataFactory::new(BEHAVIOUR_LOAD_BINARY_DATA.clone()));
54 self.entity_component_behaviour_registry
55 .register(COMPONENT_BEHAVIOUR_LOAD_BINARY_DATA.clone(), factory)
56 .await;
57
58 let factory = Arc::new(SaveBinaryDataFactory::new(BEHAVIOUR_SAVE_BINARY_DATA.clone()));
60 self.entity_component_behaviour_registry
61 .register(COMPONENT_BEHAVIOUR_SAVE_BINARY_DATA.clone(), factory)
62 .await;
63 self.web_resource_manager.register_provider(self.web_resource_provider.clone()).await;
64
65 Ok(())
66 }
67
68 async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
69 self.web_resource_manager.unregister_provider(self.web_resource_provider.id()).await;
70 self.entity_component_behaviour_registry.unregister(&COMPONENT_BEHAVIOUR_SAVE_BINARY_DATA).await;
71 self.entity_component_behaviour_registry.unregister(&COMPONENT_BEHAVIOUR_LOAD_BINARY_DATA).await;
72 self.entity_type_provider_registry.unregister_provider(self.entity_types_provider.id()).await;
73 self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
74 Ok(())
75 }
76}