-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
861 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "csv-event-journal-msr-plugin" | ||
version = "0.0.0" | ||
description = "Industrial Automation Toolbox - CSV Event Journal Plugin" | ||
authors = ["slowtec GmbH <[email protected]>"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
log = "0.4" | ||
thiserror = "1" | ||
tokio = { version = "*", default_features = false, features = ["rt-multi-thread", "sync"] } | ||
|
||
# Workspace dependencies | ||
msr-core = { version = "*", default_features = false, features = ["csv-event-journal"] } | ||
msr-plugin = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use msr_core::csv_event_journal::Entry; | ||
|
||
use super::{Config, RecordEntryOutcome, ResultSender, State}; | ||
|
||
#[derive(Debug)] | ||
pub enum Command { | ||
ReplaceConfig(ResultSender<Config>, Config), | ||
SwitchState(ResultSender<()>, State), | ||
RecordEntry(ResultSender<RecordEntryOutcome>, Entry), | ||
Shutdown(ResultSender<()>), | ||
} |
77 changes: 77 additions & 0 deletions
77
plugins/csv-event-journal-msr-plugin/src/api/controller.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use msr_core::csv_event_journal::{Entry, StoredRecord}; | ||
use msr_plugin::{reply_channel, send_message_receive_result}; | ||
|
||
use crate::internal::MessageSender; | ||
|
||
use super::{query, Command, Config, PluginResult, Query, RecordEntryOutcome, State, Status}; | ||
|
||
/// Remote controller for the plugin | ||
/// | ||
/// Wraps the message-based communication with the plugin | ||
/// into asynchronous functions. | ||
#[derive(Debug, Clone)] | ||
pub struct Controller { | ||
message_tx: MessageSender, | ||
} | ||
|
||
impl Controller { | ||
pub const fn new(message_tx: MessageSender) -> Self { | ||
Self { message_tx } | ||
} | ||
|
||
pub async fn command_replace_config(&self, new_config: Config) -> PluginResult<Config> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let command = Command::ReplaceConfig(reply_tx, new_config); | ||
|
||
send_message_receive_result(command, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn command_switch_state(&self, new_state: State) -> PluginResult<()> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let command = Command::SwitchState(reply_tx, new_state); | ||
send_message_receive_result(command, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn command_record_entry(&self, new_entry: Entry) -> PluginResult<RecordEntryOutcome> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let command = Command::RecordEntry(reply_tx, new_entry); | ||
|
||
send_message_receive_result(command, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn command_shutdown(&self) -> PluginResult<()> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let command = Command::Shutdown(reply_tx); | ||
send_message_receive_result(command, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn query_config(&self) -> PluginResult<Config> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let query = Query::Config(reply_tx); | ||
send_message_receive_result(query, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn query_status(&self, request: query::StatusRequest) -> PluginResult<Status> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let query = Query::Status(reply_tx, request); | ||
send_message_receive_result(query, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn query_recent_records( | ||
&self, | ||
request: query::RecentRecordsRequest, | ||
) -> PluginResult<Vec<StoredRecord>> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let query = Query::RecentRecords(reply_tx, request); | ||
send_message_receive_result(query, &self.message_tx, reply_rx).await | ||
} | ||
|
||
pub async fn query_filter_records( | ||
&self, | ||
request: query::FilterRecordsRequest, | ||
) -> PluginResult<Vec<StoredRecord>> { | ||
let (reply_tx, reply_rx) = reply_channel(); | ||
let query = Query::FilterRecords(reply_tx, request); | ||
send_message_receive_result(query, &self.message_tx, reply_rx).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use super::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Event { | ||
Lifecycle(LifecycleEvent), | ||
Notification(NotificationEvent), | ||
Incident(IncidentEvent), | ||
} | ||
|
||
/// Common lifecycle events | ||
#[derive(Debug, Clone)] | ||
pub enum LifecycleEvent { | ||
Started, | ||
Stopped, | ||
ConfigChanged(Config), | ||
StateChanged(State), | ||
} | ||
|
||
/// Regular notifications for informational purposes | ||
#[derive(Debug, Clone)] | ||
pub struct NotificationEvent { | ||
// Empty placeholder | ||
} | ||
|
||
/// Unexpected incidents that might require (manual) intervention | ||
#[derive(Debug, Clone)] | ||
pub enum IncidentEvent { | ||
IoWriteError { | ||
os_code: Option<i32>, | ||
message: String, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::*; | ||
|
||
// Re-export internal types that are used in the public API | ||
pub use crate::internal::context::{ | ||
Config, EntryNotRecorded, EntryRecorded, RecordEntryOutcome, State, Status, | ||
}; | ||
|
||
pub mod controller; | ||
pub use self::controller::Controller; | ||
|
||
pub mod command; | ||
pub use self::command::Command; | ||
|
||
pub mod query; | ||
pub use self::query::Query; | ||
|
||
pub mod event; | ||
pub use self::event::Event; | ||
|
||
#[derive(Debug)] | ||
pub enum Message { | ||
Command(Command), | ||
Query(Query), | ||
} | ||
|
||
impl From<Command> for Message { | ||
fn from(command: Command) -> Self { | ||
Self::Command(command) | ||
} | ||
} | ||
|
||
impl From<Query> for Message { | ||
fn from(query: Query) -> Self { | ||
Self::Query(query) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::num::NonZeroUsize; | ||
|
||
use msr_core::csv_event_journal::{RecordFilter, StoredRecord}; | ||
|
||
use super::{Config, ResultSender, Status}; | ||
|
||
#[derive(Debug)] | ||
pub enum Query { | ||
Config(ResultSender<Config>), | ||
Status(ResultSender<Status>, StatusRequest), | ||
RecentRecords(ResultSender<Vec<StoredRecord>>, RecentRecordsRequest), | ||
FilterRecords(ResultSender<Vec<StoredRecord>>, FilterRecordsRequest), | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct StatusRequest { | ||
pub with_storage_statistics: bool, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RecentRecordsRequest { | ||
pub limit: NonZeroUsize, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct FilterRecordsRequest { | ||
pub limit: NonZeroUsize, | ||
pub filter: RecordFilter, | ||
} |
Oops, something went wrong.