[−][src]Macro apis::def_session
Macro to define all parts of a session.
Defines an instance of session:Context
with the given name and the
following associated types:
type MID = MessageId
type CID = ChannelId
type PID = ProcessId
type GMSG = GlobalMessage
type GPROC = GlobalProcess
type GPRES = GlobalPresult
Process and message types with the given names and specifications are defined with implementations of relevant traits.
Process handle_message
and update
behavior is provided as a block of
code which is to be run inside of the actual trait methods where self
is
bound to the provided identifier in both cases, and the message_in
(global message) argument of handle_message
is bound to the provided
identifier.
Examples
From examples/simplex.rs
-- defines two processes (Chargen
and Upcase
)
connected by a channel sending Charstreammessage
s:
#![feature(const_fn)] #![feature(try_from)] extern crate apis; use apis::{channel, message, process, session}; apis::def_session! { context Mycontext { PROCESSES where let process = self, let message_in = message_in [ process Chargen (update_count : u64) { kind { process::Kind::Isochronous { tick_ms: 20, ticks_per_update: 1 } } sourcepoints [Charstream] endpoints [] handle_message { apis::process::ControlFlow::Break } update { apis::process::ControlFlow::Break } } process Upcase (history : String) { kind { process::Kind::asynchronous_default() } sourcepoints [] endpoints [Charstream] handle_message { apis::process::ControlFlow::Break } update { apis::process::ControlFlow::Break } } ] CHANNELS [ channel Charstream <Charstreammessage> (Simplex) { producers [Chargen] consumers [Upcase] } ] MESSAGES [ message Charstreammessage { Achar (char), Quit } ] } }
The handle_message
and update
definitions have been ommitted for
brevity, but in general any block of code can be substituted that
references the self
and message_in
bindings.