[−][src]Struct haiku::app::Context
Execution context for a Handler
All Handers execute in the context of a Looper. The Context object is passed to your Handler in the message_received() method, so that you can interact with other parts of the system.
The context contains three messengers, that may be used to send messages to certain destinations, or to use as reply addresses while sending messages. Additionally, the Context gives access to the current application state.
Fields
handler_messenger: Messenger
The messenger to the current Handler
This Messenger is most useful as a reply address for any messages you are sending out.
looper: LooperDelegate
Interact with the current Looper
This is the Looper that is the context for the current message
Note that in some cases, this will be the same message queue as the application delegate.
application: ApplicationDelegate
Interact with the current Application object
This gives access to the global application struct
application_state: Arc<Mutex<A>>
Access the global Application state
This state is shared among the whole application. It is locked behind a Mutex, to allow thread-safe access. Note that using the application state is 'dangerous', in the sense that it may lead to deadlocks when two interdependent threads are waiting for access to it. Imagine this scenario:
- Looper A gets a reference to the application state, locking it.
- Looper A sends a Message to Looper B and waits for a reply
- Looper B receives the message. While handling that message, it tries to get a reference to the application state. Since the application state is already locks, both threads will be waiting for each other.
There are two best practises:
- Do not use synchronous messaging, unless you know what you are doing.
- If you do need access to the application state, use the lock() method of the Mutex, and drop the Guard as soon as you are done.
Auto Trait Implementations
impl<A> RefUnwindSafe for Context<A>
impl<A> Send for Context<A>
impl<A> Sync for Context<A>
impl<A> Unpin for Context<A>
impl<A> UnwindSafe for Context<A>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,