1use std::collections::BTreeMap;
2
3use enum_as_inner::EnumAsInner;
4use ffi_rpc::{
5 self, abi_stable, async_trait,
6 ffi_rpc_macro::{self, plugin_api},
7 rmp_serde,
8};
9use semver::Version;
10use serde::{Deserialize, Serialize};
11use skynet_api::{HyUuid, Result, service::SResult, uuid};
12
13pub use semver;
14pub mod entity;
15pub mod viewer;
16
17pub const VERSION: &str = env!("CARGO_PKG_VERSION");
18pub const ID: HyUuid = HyUuid(uuid!("4adaf7d3-b877-43c3-82bd-da3689dc3920"));
19
20#[plugin_api(TaskService)]
21pub trait Service: Send + Sync {
22 async fn api_version() -> Version;
23 async fn create(name: String, detail: Option<String>, cb: String) -> SResult<HyUuid>;
24 async fn stop(id: HyUuid) -> bool;
25 async fn create_script(
26 name: String,
27 detail: Option<String>,
28 sid: HyUuid,
29 ) -> SResult<Option<HyUuid>>;
30 async fn create_code(name: String, detail: Option<String>, code: String) -> SResult<HyUuid>;
31}
32
33#[plugin_api(TaskCallback)]
34pub trait Callback: Send + Sync {
35 async fn stop(id: HyUuid) -> bool;
36}
37
38#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, EnumAsInner)]
39pub enum Value {
40 String(String),
41 Integer(i64),
42 Float(f64),
43 Bool(bool),
44}
45
46impl From<String> for Value {
47 fn from(value: String) -> Self {
48 Self::String(value)
49 }
50}
51
52impl From<i32> for Value {
53 fn from(value: i32) -> Self {
54 Self::Integer(value.into())
55 }
56}
57
58impl From<i64> for Value {
59 fn from(value: i64) -> Self {
60 Self::Integer(value)
61 }
62}
63
64impl From<f64> for Value {
65 fn from(value: f64) -> Self {
66 Self::Float(value)
67 }
68}
69
70impl From<bool> for Value {
71 fn from(value: bool) -> Self {
72 Self::Bool(value)
73 }
74}
75
76#[plugin_api(TaskScript)]
77pub trait Script: Send + Sync {
78 async fn call(name: String, param: BTreeMap<String, Value>)
79 -> SResult<BTreeMap<String, Value>>;
80}