提交 fce6282c authored 作者: Serhij S's avatar Serhij S

EAPI actions return payload

上级 ec4fcf19
...@@ -89,7 +89,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> { ...@@ -89,7 +89,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let params = action.take_unit_params()?; let params = action.take_unit_params()?;
let val = u8::deserialize(params.value)?; let val = u8::deserialize(params.value)?;
context.variables().fan.store(val != 0, Ordering::Release); context.variables().fan.store(val != 0, Ordering::Release);
Ok(()) Ok(None)
}); });
// this creates a connector instance with the name `fieldbus.HOSTNAME.plc`. To use a custom // this creates a connector instance with the name `fieldbus.HOSTNAME.plc`. To use a custom
// name, use `EAPI::new` instead. // name, use `EAPI::new` instead.
......
...@@ -8,7 +8,8 @@ pub use eva_common::acl::OIDMask; ...@@ -8,7 +8,8 @@ pub use eva_common::acl::OIDMask;
use eva_common::common_payloads::ParamsId; use eva_common::common_payloads::ParamsId;
use eva_common::events::{RawStateEventOwned, RAW_STATE_TOPIC}; use eva_common::events::{RawStateEventOwned, RAW_STATE_TOPIC};
use eva_common::payload::{pack, unpack}; use eva_common::payload::{pack, unpack};
use eva_common::value::{to_value, Value}; use eva_common::value::to_value;
pub use eva_common::value::Value;
pub use eva_common::OID; pub use eva_common::OID;
use eva_sdk::controller::format_action_topic; use eva_sdk::controller::format_action_topic;
pub use eva_sdk::controller::Action; pub use eva_sdk::controller::Action;
...@@ -195,7 +196,7 @@ where ...@@ -195,7 +196,7 @@ where
/// Action handler functions type /// Action handler functions type
pub type ActionHandlerFn<D, V> = fn(&mut Action, context: &Context<D, V>) -> ActionResult; pub type ActionHandlerFn<D, V> = fn(&mut Action, context: &Context<D, V>) -> ActionResult;
/// The result type of action handler functions /// The result type of action handler functions
pub type ActionResult = std::result::Result<(), Box<dyn std::error::Error>>; pub type ActionResult = std::result::Result<Option<Value>, Box<dyn std::error::Error>>;
type ActionHandlers<D, V> = Arc<BTreeMap<OID, ActionHandlerFn<D, V>>>; type ActionHandlers<D, V> = Arc<BTreeMap<OID, ActionHandlerFn<D, V>>>;
type BulkActionHandlers<D, V> = Arc<Vec<(OIDMask, ActionHandlerFn<D, V>)>>; type BulkActionHandlers<D, V> = Arc<Vec<(OIDMask, ActionHandlerFn<D, V>)>>;
...@@ -290,7 +291,7 @@ where ...@@ -290,7 +291,7 @@ where
let context = self.context.clone(); let context = self.context.clone();
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let topic = Arc::new(format_action_topic(action.oid())); let topic = Arc::new(format_action_topic(action.oid()));
let payload = if let Err(e) = handle_action( let payload = match handle_action(
&mut action, &mut action,
topic.clone(), topic.clone(),
tx.clone(), tx.clone(),
...@@ -298,9 +299,8 @@ where ...@@ -298,9 +299,8 @@ where
bulk_action_handlers, bulk_action_handlers,
&context, &context,
) { ) {
action.event_failed(1, None, Some(Value::String(e.to_string()))) Ok(v) => action.event_completed(v),
} else { Err(e) => action.event_failed(1, None, Some(Value::String(e.to_string()))),
action.event_completed(None)
}; };
match pack(&payload) { match pack(&payload) {
Ok(packed) => { Ok(packed) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论