pub struct CuContext {
pub clock: RobotClock,
/* private fields */
}Expand description
Execution context passed to task and bridge callbacks.
CuContext provides callback code with:
- time access through
clockandDeref<Target = RobotClock> - current execution sequence id via
cl_id() - process instance metadata via
instance_id() - compile-time subsystem identity via
subsystem_code() - current component metadata via
current_component_id() - current task metadata via
task_id()/task_index()
The execution sequence id matches the copper-list id of the iteration being
processed. It is also available in other lifecycle callbacks
(start/preprocess/postprocess/stop) for continuity, but outside
process callbacks it must not be treated as a live copper-list handle.
The runtime creates one context per execution loop and updates transient fields such as the currently executing component/task before each callback.
Fields§
§clock: RobotClockRuntime clock. Kept as a field for direct access (context.clock.now()).
Implementations§
Source§impl CuContext
impl CuContext
Sourcepub fn builder(clock: RobotClock) -> CuContextBuilder
pub fn builder(clock: RobotClock) -> CuContextBuilder
Starts a context builder from a clock.
Sourcepub fn from_clock(clock: RobotClock) -> CuContext
pub fn from_clock(clock: RobotClock) -> CuContext
Creates a context from an existing clock with default metadata.
Defaults:
cl_id = 0- no task id table
Sourcepub fn new_with_clock() -> CuContext
pub fn new_with_clock() -> CuContext
Creates a context backed by a real robot clock.
Defaults:
cl_id = 0- no task id table
Sourcepub fn new_mock_clock() -> (CuContext, RobotClockMock)
pub fn new_mock_clock() -> (CuContext, RobotClockMock)
Creates a context backed by a mock clock.
Returns both the context and its RobotClockMock control handle.
Sourcepub fn set_current_component(&mut self, component_index: usize)
pub fn set_current_component(&mut self, component_index: usize)
Sets the currently executing component index.
Sourcepub fn clear_current_component(&mut self)
pub fn clear_current_component(&mut self)
Clears the currently executing component.
Sourcepub fn set_current_task(&mut self, task_index: usize)
pub fn set_current_task(&mut self, task_index: usize)
Sets the currently executing task index.
Sourcepub fn clear_current_task(&mut self)
pub fn clear_current_task(&mut self)
Clears the currently executing task.
Sourcepub fn cl_id(&self) -> u64
pub fn cl_id(&self) -> u64
Returns the current execution sequence id.
In process callbacks, this value is the id of the copper-list being
processed. In other lifecycle callbacks, this value is still meaningful
for sequencing but does not imply that a copper-list instance is alive.
Sourcepub fn instance_id(&self) -> u32
pub fn instance_id(&self) -> u32
Returns the runtime instance id attached to this context.
Sourcepub fn subsystem_code(&self) -> u16
pub fn subsystem_code(&self) -> u16
Returns the compile-time subsystem code for this Copper process.
Sourcepub fn current_component_id(&self) -> Option<usize>
pub fn current_component_id(&self) -> Option<usize>
Returns the current component index, if any.
Sourcepub fn task_index(&self) -> Option<usize>
pub fn task_index(&self) -> Option<usize>
Returns the current task index, if any.
Methods from Deref<Target = RobotClock>§
Sourcepub fn now(&self) -> CuTime
pub fn now(&self) -> CuTime
Reads execution time: local elapsed time, or the selected reference epoch.
Sourcepub fn origin(&self) -> ClockOrigin
pub fn origin(&self) -> ClockOrigin
Describes the source and epoch of execution timestamps without converting them.
Reference metadata is published with the execution mapping and shared by clones. Before initial acquisition, the local origin remains in effect. During resynchronization, the previous epoch remains in effect while the execution clock slews. Providers must preserve the epoch across resync. This accessor performs no counter read, allocation, or reference I/O.
use cu29_clock::{ClockEpoch, ClockSource, RobotClock};
let (clock, _) = RobotClock::mock();
assert_eq!(clock.origin().source, ClockSource::Mock);
assert_eq!(clock.origin().epoch, ClockEpoch::Local);Sourcepub fn recent(&self) -> CuTime
pub fn recent(&self) -> CuTime
Reads the same timeline through the backend’s recent-time operation.
Sourcepub fn raw_now(&self) -> CuInstant
pub fn raw_now(&self) -> CuInstant
Reads undisciplined local counter time in nanoseconds.
Clones share the counter origin and calibration. Independently constructed clocks have their own origins; compare raw readings only within one clock and its clones. Reference capture and elapsed-time measurements use this timeline, which is unaffected by execution-clock synchronization.
use cu29_clock::{CuDuration, RobotClock};
let (clock, control) = RobotClock::mock();
let start = clock.raw_now();
control.increment(CuDuration::from_millis(1));
assert_eq!(clock.raw_now() - start, CuDuration::from_millis(1));Sourcepub fn busy_wait_for(&self, duration: CuDuration)
pub fn busy_wait_for(&self, duration: CuDuration)
Spins for a duration measured on this clock’s undisciplined timeline.
Sourcepub fn busy_wait_until(&self, time: CuInstant)
pub fn busy_wait_until(&self, time: CuInstant)
Spins until a raw deadline from this clock or one of its clones.
Sourcepub fn sync_status(&self) -> Option<SyncStatus>
pub fn sync_status(&self) -> Option<SyncStatus>
Current domain, uncertainty and synchronization health.
Available with or without clock-sync. Returns None when synchronization
is disabled or no discipline has been published. Without the feature this
does not read the counter or require synchronization storage.
use cu29_clock::{RobotClock, sync::SyncStatus};
let (clock, _) = RobotClock::mock();
let quality: Option<SyncStatus> = clock.sync_status();
assert_eq!(quality, None);Trait Implementations§
Auto Trait Implementations§
impl Freeze for CuContext
impl RefUnwindSafe for CuContext
impl Send for CuContext
impl Sync for CuContext
impl Unpin for CuContext
impl UnsafeUnpin for CuContext
impl UnwindSafe for CuContext
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
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