mirror of
https://framagit.org/ppom/reaction
synced 2026-03-14 12:45:47 +01:00
Add PersistData to trait
This commit is contained in:
parent
b9550e3acb
commit
7c5c5ff757
3 changed files with 17 additions and 4 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use reaction_plugin::{
|
||||
ActionImpl, Exec, Hello, Line, Manifest, PluginInfo, RemoteResult, StreamImpl, Value,
|
||||
ActionImpl, Exec, Hello, Line, Manifest, PersistData, PluginInfo, RemoteResult, StreamImpl,
|
||||
Value,
|
||||
};
|
||||
use remoc::{rch::mpsc, rtc};
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ struct Plugin {
|
|||
}
|
||||
|
||||
impl PluginInfo for Plugin {
|
||||
async fn manifest(&self) -> Result<Manifest, rtc::CallError> {
|
||||
async fn manifest(&mut self, _data: PersistData) -> Result<Manifest, rtc::CallError> {
|
||||
Ok(Manifest {
|
||||
hello: Hello::hello(),
|
||||
streams: BTreeSet::from(["virtual".into()]),
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ use std::{
|
|||
};
|
||||
|
||||
use remoc::{
|
||||
Connect, rch,
|
||||
Connect,
|
||||
rch::{self, mpsc},
|
||||
rtc::{self, Server},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -46,7 +47,7 @@ use tokio::io::{stdin, stdout};
|
|||
#[rtc::remote]
|
||||
pub trait PluginInfo {
|
||||
/// Return the manifest of the plugin.
|
||||
async fn manifest(&self) -> Result<Manifest, rtc::CallError>;
|
||||
async fn manifest(&mut self, data: PersistData) -> Result<Manifest, rtc::CallError>;
|
||||
|
||||
/// Return one stream of a given type if it exists
|
||||
async fn stream_impl(
|
||||
|
|
@ -158,6 +159,16 @@ pub enum Value {
|
|||
Object(BTreeMap<String, Value>),
|
||||
}
|
||||
|
||||
/// Data persisted by reaction for the plugin.
|
||||
/// This is persisted as a single JSON file by reaction, so it is not suitable for big sizes of data.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PersistData {
|
||||
/// Data persisted by the plugin in a previous run
|
||||
pub persisted_data: Value,
|
||||
/// Sender of data to be persisted by the plugin for a previous run
|
||||
pub persist_data: mpsc::Sender<Value>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct StreamImpl {
|
||||
pub stream: rch::mpsc::Receiver<Line>,
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ impl Plugin {
|
|||
}
|
||||
Command::new(&self.path)
|
||||
};
|
||||
command.arg("serve");
|
||||
debug!(
|
||||
"plugin {}: running command: {:?}",
|
||||
self.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue