提交 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>> {
let params = action.take_unit_params()?;
let val = u8::deserialize(params.value)?;
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
// name, use `EAPI::new` instead.
......
......@@ -8,7 +8,8 @@ pub use eva_common::acl::OIDMask;
use eva_common::common_payloads::ParamsId;
use eva_common::events::{RawStateEventOwned, RAW_STATE_TOPIC};
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;
use eva_sdk::controller::format_action_topic;
pub use eva_sdk::controller::Action;
......@@ -195,7 +196,7 @@ where
/// Action handler functions type
pub type ActionHandlerFn<D, V> = fn(&mut Action, context: &Context<D, V>) -> ActionResult;
/// 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 BulkActionHandlers<D, V> = Arc<Vec<(OIDMask, ActionHandlerFn<D, V>)>>;
......@@ -290,7 +291,7 @@ where
let context = self.context.clone();
tokio::task::spawn_blocking(move || {
let topic = Arc::new(format_action_topic(action.oid()));
let payload = if let Err(e) = handle_action(
let payload = match handle_action(
&mut action,
topic.clone(),
tx.clone(),
......@@ -298,9 +299,8 @@ where
bulk_action_handlers,
&context,
) {
action.event_failed(1, None, Some(Value::String(e.to_string())))
} else {
action.event_completed(None)
Ok(v) => action.event_completed(v),
Err(e) => action.event_failed(1, None, Some(Value::String(e.to_string()))),
};
match pack(&payload) {
Ok(packed) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论