-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
553140e
commit 921cda9
Showing
6 changed files
with
124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
pub mod introspection; | ||
pub mod marker; | ||
pub mod reactor; | ||
|
||
mod error; | ||
pub use error::IceoryxError; | ||
|
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,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
//! Control to register/unregister handler and stop the reactor | ||
use super::{Event, Handler, State}; | ||
|
||
use std::sync::Arc; | ||
|
||
pub struct Control { | ||
condition_variable: Arc<Box<ffi::ConditionVariable>>, | ||
// TODO queue sender | ||
} | ||
|
||
impl Control { | ||
pub(super) fn new(condition_variable: Arc<Box<ffi::ConditionVariable>>) -> Self { | ||
Self { condition_variable } | ||
} | ||
|
||
pub fn attach_event<T: Event>(source: Box<dyn Event>, handler: Box<Handler<T>>) { | ||
unimplemented!() | ||
} | ||
|
||
pub fn attach_state<T: State>(source: Box<dyn State>, handler: Box<Handler<T>>) { | ||
unimplemented!() | ||
} | ||
} |
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,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
use std::sync::Arc; | ||
|
||
pub(super) struct Demultiplexer { | ||
condition_variable: Arc<Box<ffi::ConditionVariable>>, | ||
// TODO queue receiver | ||
} | ||
|
||
impl Demultiplexer { | ||
pub(super) fn new(condition_variable: Arc<Box<ffi::ConditionVariable>>) -> Self { | ||
Self { condition_variable } | ||
} | ||
} |
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,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
//! Dispatches the events according to the registered handler | ||
use super::Demultiplexer; | ||
|
||
use std::sync::Arc; | ||
|
||
pub struct Dispatcher { | ||
demux: Demultiplexer, | ||
// TODO queue receiver | ||
} | ||
|
||
impl Dispatcher { | ||
pub(super) fn new(condition_variable: Arc<Box<ffi::ConditionVariable>>) -> Self { | ||
Self { | ||
demux: Demultiplexer::new(condition_variable), | ||
} | ||
} | ||
} |
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,15 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
//! Event handler dispatched by the reactor | ||
use std::marker::PhantomData; | ||
|
||
pub trait Event {} | ||
|
||
pub trait State {} | ||
|
||
pub struct Handler<T> { | ||
_phantom: PhantomData<T>, | ||
} |
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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
//! Implements the reactor pattern | ||
//! | ||
//! Subscriber can use the `Control` to register at the reactor and the `Dispatcher` | ||
//! calls the registered handler functions. | ||
use std::sync::Arc; | ||
|
||
mod control; | ||
pub use control::Control; | ||
|
||
mod demultiplexer; | ||
use demultiplexer::Demultiplexer; | ||
|
||
mod dispatcher; | ||
pub use dispatcher::Dispatcher; | ||
|
||
mod handler; | ||
pub use handler::Event; | ||
pub use handler::Handler; | ||
pub use handler::State; | ||
|
||
struct Reactor { | ||
control: Control, | ||
dispatcher: Dispatcher, | ||
} | ||
|
||
impl Reactor { | ||
pub fn new() -> Self { | ||
let condition_variable = Arc::new(ffi::ConditionVariable::new()); | ||
let control = Control::new(condition_variable.clone()); | ||
let dispatcher = Dispatcher::new(condition_variable); | ||
|
||
Self { | ||
control, | ||
dispatcher, | ||
} | ||
} | ||
} |