rsiot_plc/
component.rs

1use async_trait::async_trait;
2use serde::Serialize;
3
4use rsiot_component_core::{CmpInOut, Component, ComponentError, IComponentProcess};
5use rsiot_messages_core::{AuthPermissions, MsgDataBound};
6
7use crate::{
8    config::Config,
9    fn_process::fn_process,
10    plc::function_block_base::{FunctionBlockBase, IFunctionBlock},
11};
12
13#[cfg_attr(not(feature = "single-thread"), async_trait)]
14#[cfg_attr(feature = "single-thread", async_trait(? Send))]
15impl<TMsg, I, Q, S> IComponentProcess<Config<TMsg, I, Q, S>, TMsg>
16    for Component<Config<TMsg, I, Q, S>, TMsg>
17where
18    TMsg: MsgDataBound + 'static,
19    I: Clone + Default + Send + Serialize + 'static + Sync,
20    Q: Clone + Default + Send + Serialize + 'static + Sync,
21    S: Clone + Default + Send + Serialize + 'static + Sync,
22    FunctionBlockBase<I, Q, S>: IFunctionBlock<I, Q, S>,
23{
24    async fn process(
25        &self,
26        config: Config<TMsg, I, Q, S>,
27        in_out: CmpInOut<TMsg>,
28    ) -> Result<(), ComponentError> {
29        fn_process(
30            in_out.clone_with_new_id("cmp_plc", AuthPermissions::FullAccess),
31            config,
32        )
33        .await
34    }
35}
36
37pub type Cmp<TMsg, I, Q, S> = Component<Config<TMsg, I, Q, S>, TMsg>;