reactive_graph_plugin_delegates/
entity_behaviour_registry_impl.rs1use async_trait::async_trait;
2use std::sync::Arc;
3
4use uuid::Uuid;
5
6use reactive_graph_behaviour_model_api::prelude::*;
7
8use reactive_graph_reactive_model_impl::ReactiveEntity;
9
10pub struct EntityBehaviourRegistryDelegate {
11 entity_behaviour_manager: Arc<dyn reactive_graph_behaviour_service_api::EntityBehaviourManager + Send + Sync>,
12 entity_behaviour_registry: Arc<dyn reactive_graph_behaviour_service_api::EntityBehaviourRegistry + Send + Sync>,
13 reactive_entity_manager: Arc<dyn reactive_graph_reactive_service_api::ReactiveEntityManager + Send + Sync>,
14}
15
16impl EntityBehaviourRegistryDelegate {
17 pub fn new(
18 entity_behaviour_manager: Arc<dyn reactive_graph_behaviour_service_api::EntityBehaviourManager + Send + Sync>,
19 entity_behaviour_registry: Arc<dyn reactive_graph_behaviour_service_api::EntityBehaviourRegistry + Send + Sync>,
20 reactive_entity_manager: Arc<dyn reactive_graph_reactive_service_api::ReactiveEntityManager + Send + Sync>,
21 ) -> Self {
22 Self {
23 entity_behaviour_manager,
24 entity_behaviour_registry,
25 reactive_entity_manager,
26 }
27 }
28}
29
30#[async_trait]
31impl reactive_graph_plugin_api::EntityBehaviourRegistry for EntityBehaviourRegistryDelegate {
32 async fn register(&self, entity_behaviour_ty: EntityBehaviourTypeId, factory: Arc<dyn BehaviourFactory<Uuid, ReactiveEntity> + Send + Sync>) {
33 self.entity_behaviour_registry.register(entity_behaviour_ty.clone(), factory);
34 self.reactive_entity_manager.add_behaviour_to_all_entity_instances(&entity_behaviour_ty);
35 }
36
37 async fn unregister(&self, entity_behaviour_ty: &EntityBehaviourTypeId) {
38 self.entity_behaviour_registry.unregister(entity_behaviour_ty);
39 self.entity_behaviour_manager.remove_behaviours_by_behaviour(&entity_behaviour_ty.behaviour_ty);
40 }
41}