Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
oldrev committed Oct 12, 2023
1 parent 359cd26 commit d51f3bf
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 48 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions flows.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"id": "dee0d1b0cfd62a6c",
"type": "tab",
"label": "流程 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "bf843d35fe7cf583",
"type": "inject",
"z": "dee0d1b0cfd62a6c",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 350,
"y": 180,
"wires": [
[
"c75509302b4b8fc1"
]
]
},
{
"id": "c75509302b4b8fc1",
"type": "debug",
"z": "dee0d1b0cfd62a6c",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 540,
"y": 180,
"wires": []
}
]
3 changes: 2 additions & 1 deletion libs/abstractions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ strip = true

[dependencies]
async-trait = "0.1.73"
tokio = "1.33.0"
thiserror = "1.0.49"
tokio = "1.33.0"
34 changes: 14 additions & 20 deletions libs/abstractions/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
use std::{sync::Arc, cell::RefCell};
use tokio::sync::{Mutex};
use async_trait::async_trait;
use crate::nodes::*;
use crate::Variant;

use async_trait::async_trait;
use std::cell::RefCell;
use std::sync::{Arc, Mutex};

#[async_trait]
pub trait FlowBehavior {
pub trait FlowBehavior : Send + Sync {
fn id(&self) -> u64;
fn name(&self) -> &str;
async fn start(&self);
async fn stop(&self);
}
fn label(&self) -> &str;

#[async_trait]
pub trait FlowEngine {
async fn start(&self);
async fn stop(&self);
async fn start(&mut self);
async fn stop(&mut self);
}

#[derive(Clone)]
pub struct Engine {
pub nodes: Arc<Mutex<Vec<Box<dyn FlowBehavior>>>>,
}
pub type Flows = Vec<Arc<Mutex<Box<dyn FlowBehavior>>>>;

#[async_trait]
pub trait FlowEngineBehavior {
async fn start(&self);
async fn stop(&self);
pub trait FlowEngine: Send + Sync {
fn get_flows(&self) -> &Flows;
fn get_flows_mut(&mut self) -> &mut Flows;

async fn start(&mut self);
async fn stop(&mut self);
}
19 changes: 18 additions & 1 deletion libs/abstractions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod nodes;
use thiserror::Error;

pub mod engine;
pub mod nodes;
pub mod variant;

pub use crate::variant::Variant;
Expand All @@ -20,3 +22,18 @@ pub trait Plugin {
/// Callbacks can take arguments and return values
fn callback2(&self, i: i32) -> i32;
}

#[derive(Error, Debug)]
pub enum EdgeLinkError {

#[error("Invalid 'flows.json': {0}")]
BadFlowsJson(String),

#[error("Missing attribute: {0}")]
MissingAttribute(String),

}

pub type Error = Box<dyn std::error::Error + Send + Sync>;

pub type Result<T> = std::result::Result<T, Error>;
4 changes: 2 additions & 2 deletions libs/abstractions/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct BaseNode {

#[async_trait]
pub trait NodeBehavior: Send {
async fn start(&self);
async fn stop(&self);
async fn start(&mut self);
async fn stop(&mut self);
}

pub struct FlowNode {
Expand Down
3 changes: 3 additions & 0 deletions libs/edgelink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ async-trait = "0.1.73"
ciborium = "0.2.1"
log = "0.4.20"
inventory = "0.3.12"
serde_json = "1.0.107"
serde = "1.0.188"
anyhow = "1.0.75"
Loading

0 comments on commit d51f3bf

Please sign in to comment.