Skip to main content

CuContext

Struct CuContext 

Source
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 clock and Deref<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: RobotClock

Runtime clock. Kept as a field for direct access (context.clock.now()).

Implementations§

Source§

impl CuContext

Source

pub fn builder(clock: RobotClock) -> CuContextBuilder

Starts a context builder from a clock.

Source

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
Source

pub fn new_with_clock() -> CuContext

Creates a context backed by a real robot clock.

Defaults:

  • cl_id = 0
  • no task id table
Source

pub fn new_mock_clock() -> (CuContext, RobotClockMock)

Creates a context backed by a mock clock.

Returns both the context and its RobotClockMock control handle.

Source

pub fn set_current_component(&mut self, component_index: usize)

Sets the currently executing component index.

Source

pub fn clear_current_component(&mut self)

Clears the currently executing component.

Source

pub fn set_current_task(&mut self, task_index: usize)

Sets the currently executing task index.

Source

pub fn clear_current_task(&mut self)

Clears the currently executing task.

Source

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.

Source

pub fn instance_id(&self) -> u32

Returns the runtime instance id attached to this context.

Source

pub fn subsystem_code(&self) -> u16

Returns the compile-time subsystem code for this Copper process.

Source

pub fn current_component_id(&self) -> Option<usize>

Returns the current component index, if any.

Source

pub fn task_index(&self) -> Option<usize>

Returns the current task index, if any.

Source

pub fn task_id(&self) -> Option<&'static str>

Returns the current task id, if any.

Methods from Deref<Target = RobotClock>§

Source

pub fn is_mock(&self) -> bool

Whether time is controlled explicitly by a mock handle.

Source

pub fn now(&self) -> CuTime

Reads execution time: local elapsed time, or the selected reference epoch.

Source

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);
Source

pub fn recent(&self) -> CuTime

Reads the same timeline through the backend’s recent-time operation.

Source

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));
Source

pub fn busy_wait_for(&self, duration: CuDuration)

Spins for a duration measured on this clock’s undisciplined timeline.

Source

pub fn busy_wait_until(&self, time: CuInstant)

Spins until a raw deadline from this clock or one of its clones.

Source

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§

Source§

impl Clone for CuContext

Source§

fn clone(&self) -> CuContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CuContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for CuContext

Source§

type Target = RobotClock

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<CuContext as Deref>::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> PayloadDefaultHandlePolicyApply for T
where T: ?Sized,

Source§

impl<T> PayloadDefaultLoggingPolicy for T
where T: ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.