Add PersistData to trait

This commit is contained in:
ppom 2025-10-20 12:00:00 +02:00
commit 7c5c5ff757
No known key found for this signature in database
3 changed files with 17 additions and 4 deletions

View file

@ -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()]),

View file

@ -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>,

View file

@ -112,6 +112,7 @@ impl Plugin {
}
Command::new(&self.path)
};
command.arg("serve");
debug!(
"plugin {}: running command: {:?}",
self.name,