Struct roboplc::controller::Controller
source · pub struct Controller<D, V>{ /* private fields */ }
Expand description
Controller, used to manage workers and their context
Generic parameter D
is the message type for the controller’s Hub
messages.
Generic parameter V
is the type of shared variables. If shared variables are not required, it
can be set to ()
.
Implementations§
source§impl<D, V> Controller<D, V>
impl<D, V> Controller<D, V>
sourcepub fn new() -> Selfwhere
V: Default,
pub fn new() -> Selfwhere
V: Default,
Creates a new controller instance, variables MUST implement Default
trait
sourcepub fn new_with_variables(variables: V) -> Self
pub fn new_with_variables(variables: V) -> Self
Creates a new controller instance with a pre-defined variables object
sourcepub fn spawn_worker<W: Worker<D, V> + WorkerOptions + 'static>(
&mut self,
worker: W
) -> Result<()>
pub fn spawn_worker<W: Worker<D, V> + WorkerOptions + 'static>( &mut self, worker: W ) -> Result<()>
Spawns a worker
sourcepub fn spawn_task<F>(&mut self, name: &str, f: F) -> Result<()>
pub fn spawn_task<F>(&mut self, name: &str, f: F) -> Result<()>
Spawns a task thread (non-real-time) with the default options
sourcepub fn register_signals(&mut self, shutdown_timeout: Duration) -> Result<()>
pub fn register_signals(&mut self, shutdown_timeout: Duration) -> Result<()>
Registers SIGINT and SIGTERM signals to a thread which terminates the controller with a
dummy handler (see Controller::register_signals_with_shutdown_handler()
).
sourcepub fn register_signals_with_shutdown_handler<H>(
&mut self,
handle_fn: H,
shutdown_timeout: Duration
) -> Result<()>
pub fn register_signals_with_shutdown_handler<H>( &mut self, handle_fn: H, shutdown_timeout: Duration ) -> Result<()>
Registers SIGINT and SIGTERM signals to a thread which terminates the controller.
Note: to properly terminate all workers must either periodically check the controller state
with Context::is_online()
or be marked as blocking by overriding
WorkerOptions::worker_is_blocking()
(or setting blocking
to true
in WorkerOpts
derive macro).
Workers that listen to hub messages may also receive a custom termination message and gracefully shut themselves down. For such functionality a custom signal handler should be implemented (See https://github.com/roboplc/roboplc/blob/main/examples/shutdown.rs).
The thread is automatically spawned with FIFO scheduling and the highest priority on CPU 0 or falled back to non-realtime.
sourcepub fn block_while_online(&self)
pub fn block_while_online(&self)
Blocks until the controller goes into stopping/stopped
sourcepub fn supervisor(&self) -> &Supervisor<()>
pub fn supervisor(&self) -> &Supervisor<()>
Controller Supervisor
instance
Trait Implementations§
Auto Trait Implementations§
impl<D, V> Freeze for Controller<D, V>
impl<D, V> !RefUnwindSafe for Controller<D, V>
impl<D, V> Send for Controller<D, V>
impl<D, V> Sync for Controller<D, V>
impl<D, V> Unpin for Controller<D, V>
impl<D, V> !UnwindSafe for Controller<D, V>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more