mirror of
https://framagit.org/ppom/reaction
synced 2026-03-14 12:45:47 +01:00
Change plugin interface: oneshot load_config and start
Instead of multiple stream_impl / action_impl and one finish_setup. This made plugin implementations awkward: they often got some conf and couldn't determine if it was valid or not. Now they get all the conf in one function and don't have to keep partial state from one call to another. This has the other important benefit that configuration loading is separated from startup. This will make plugin lifecycle management less clunky.
This commit is contained in:
parent
b906c237bd
commit
f786a1d281
1 changed files with 29 additions and 23 deletions
|
|
@ -123,31 +123,20 @@ pub trait PluginInfo {
|
|||
/// Return the manifest of the plugin.
|
||||
async fn manifest(&mut self) -> Result<Manifest, rtc::CallError>;
|
||||
|
||||
/// Return one stream of a given type.
|
||||
/// Errors if the type does not exist or if config is invalid.
|
||||
async fn stream_impl(
|
||||
/// Load all plugin stream and action configurations,
|
||||
/// Errors if config is invalid.
|
||||
///
|
||||
/// The plugin should not start running mutable commands here:
|
||||
/// It should be ok to quit without cleanup for now.
|
||||
async fn load_config(
|
||||
&mut self,
|
||||
stream_name: String,
|
||||
stream_type: String,
|
||||
config: Value,
|
||||
) -> RemoteResult<StreamImpl>;
|
||||
streams: Vec<StreamConfig>,
|
||||
actions: Vec<ActionConfig>,
|
||||
) -> RemoteResult<(Vec<StreamImpl>, Vec<ActionImpl>)>;
|
||||
|
||||
/// Return one action of a given type.
|
||||
/// Errors if the type does not exist or if config is invalid.
|
||||
async fn action_impl(
|
||||
&mut self,
|
||||
stream_name: String,
|
||||
filter_name: String,
|
||||
action_name: String,
|
||||
action_type: String,
|
||||
config: Value,
|
||||
patterns: Vec<String>,
|
||||
) -> RemoteResult<ActionImpl>;
|
||||
|
||||
/// Notify the plugin that setup is finished, permitting a last occasion to report an error
|
||||
/// (For example if a stream wants a companion action but it hasn't been initialized)
|
||||
/// Notify the plugin that setup is finished, permitting a last occasion to report an error that'll make reaction exit.
|
||||
/// All initialization (opening remote connections, starting streams, etc) should happen here.
|
||||
async fn finish_setup(&mut self) -> RemoteResult<()>;
|
||||
async fn start(&mut self) -> RemoteResult<()>;
|
||||
|
||||
/// Notify the plugin that reaction is quitting and that the plugin should quit too.
|
||||
/// A few seconds later, the plugin will receive SIGTERM.
|
||||
|
|
@ -155,6 +144,23 @@ pub trait PluginInfo {
|
|||
async fn close(mut self) -> RemoteResult<()>;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct StreamConfig {
|
||||
pub stream_name: String,
|
||||
pub stream_type: String,
|
||||
pub config: Value,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct ActionConfig {
|
||||
pub stream_name: String,
|
||||
pub filter_name: String,
|
||||
pub action_name: String,
|
||||
pub action_type: String,
|
||||
pub config: Value,
|
||||
pub patterns: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Manifest {
|
||||
// Protocol version. available as the [`hello!`] macro.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue