DeviceRegistry

Struct DeviceRegistry 

Source
pub struct DeviceRegistry<C: MemoryConfig> { /* private fields */ }
Available on crate feature iot only.
Expand description

IoT Device Registry CRDT

This CRDT manages distributed device state coordination across IoT networks, enabling gateways and controllers to maintain consistent device inventories.

§Type Parameters

  • C: Memory configuration

§Features

  • Device discovery and registration
  • Connection state tracking
  • Battery and signal monitoring
  • Gateway assignment coordination

§Example

use crdtosphere::prelude::*;
use crdtosphere::iot::{DeviceRegistry, DeviceInfo, ConnectionState};

// Create device registry
let mut registry = DeviceRegistry::<DefaultConfig>::new(1); // Gateway ID 1

// Register new device
registry.register_device(
    42,    // device ID
    0x1001, // device type (sensor)
    1000   // timestamp
)?;

// Update device connection
registry.update_device_connection(42, ConnectionState::Online, 1001)?;

// Query online devices
let online_count = registry.online_devices().count();

Implementations§

Source§

impl<C: MemoryConfig> DeviceRegistry<C>

Source

pub fn new(gateway_id: NodeId) -> Self

Creates a new device registry

§Arguments
  • gateway_id - The ID of this gateway/controller
§Returns

A new device registry CRDT

Source

pub fn register_device( &mut self, device_id: NodeId, device_type: u16, timestamp: u64, ) -> CRDTResult<()>

Registers a new device

§Arguments
  • device_id - Unique device identifier
  • device_type - Device type/category
  • timestamp - Registration timestamp
§Returns

Ok(()) if successful, error otherwise

Source

pub fn update_device_connection( &mut self, device_id: NodeId, state: ConnectionState, timestamp: u64, ) -> CRDTResult<()>

Updates device connection state

§Arguments
  • device_id - Device to update
  • state - New connection state
  • timestamp - Update timestamp
§Returns

Ok(()) if successful, error otherwise

Source

pub fn update_device_status( &mut self, device_id: NodeId, status: DeviceStatus, timestamp: u64, ) -> CRDTResult<()>

Updates device operational status

§Arguments
  • device_id - Device to update
  • status - New operational status
  • timestamp - Update timestamp
§Returns

Ok(()) if successful, error otherwise

Source

pub fn update_device_vitals( &mut self, device_id: NodeId, battery_level: u8, signal_strength: u8, timestamp: u64, ) -> CRDTResult<()>

Updates device battery and signal info

§Arguments
  • device_id - Device to update
  • battery_level - Battery level (0-255)
  • signal_strength - Signal strength (0-255)
  • timestamp - Update timestamp
§Returns

Ok(()) if successful, error otherwise

Source

pub fn all_devices(&self) -> impl Iterator<Item = &DeviceInfo>

Gets all registered devices

§Returns

Iterator over device info

Source

pub fn devices_by_state( &self, state: ConnectionState, ) -> impl Iterator<Item = &DeviceInfo>

Gets devices by connection state

§Arguments
  • state - Connection state to filter by
§Returns

Iterator over devices with the specified state

Source

pub fn online_devices(&self) -> impl Iterator<Item = &DeviceInfo>

Gets online devices

§Returns

Iterator over online devices

Source

pub fn devices_requiring_attention(&self) -> impl Iterator<Item = &DeviceInfo>

Gets devices requiring attention

§Returns

Iterator over devices with critical status

Source

pub fn devices_by_type( &self, device_type: u16, ) -> impl Iterator<Item = &DeviceInfo>

Gets devices by type

§Arguments
  • device_type - Device type to filter by
§Returns

Iterator over devices of the specified type

Source

pub fn devices_by_gateway( &self, gateway_id: NodeId, ) -> impl Iterator<Item = &DeviceInfo>

Gets devices managed by a specific gateway

§Arguments
  • gateway_id - Gateway ID to filter by
§Returns

Iterator over devices managed by the gateway

Source

pub fn get_device(&self, device_id: NodeId) -> Option<&DeviceInfo>

Gets device info by ID

§Arguments
  • device_id - Device ID to look up
§Returns

Device info if found

Source

pub fn device_count(&self) -> usize

Gets the number of registered devices

§Returns

Number of devices

Source

pub fn cleanup_stale_devices( &mut self, current_time: u64, timeout_ms: u64, ) -> usize

Removes stale devices

§Arguments
  • current_time - Current timestamp
  • timeout_ms - Timeout in milliseconds
§Returns

Number of devices removed

Source

pub fn validate_registry(&self) -> CRDTResult<()>

Validates device registry data

§Returns

Ok(()) if valid, error otherwise

Trait Implementations§

Source§

impl<C: MemoryConfig> BoundedCRDT<C> for DeviceRegistry<C>

Source§

const MAX_SIZE_BYTES: usize = 1_560usize

Maximum size in bytes this CRDT can occupy
Source§

const MAX_ELEMENTS: usize = 64usize

Maximum number of elements this CRDT can contain
Source§

fn memory_usage(&self) -> usize

Returns the current memory usage in bytes
Source§

fn element_count(&self) -> usize

Returns the current number of elements
Source§

fn compact(&mut self) -> CRDTResult<usize>

Compacts the CRDT to reduce memory usage if possible
Source§

fn can_add_element(&self) -> bool

Checks if adding an element would exceed memory bounds
Source§

const ALIGNMENT: usize = C::MEMORY_ALIGNMENT

Memory alignment requirement in bytes
Source§

fn remaining_capacity(&self) -> usize

Returns the remaining memory capacity in bytes
Source§

fn is_at_capacity(&self) -> bool

Checks if the CRDT is at its memory limit
Source§

fn utilization_percent(&self) -> u8

Returns the memory utilization as a percentage (0-100)
Source§

fn max_elements(&self) -> usize

Returns the maximum number of elements that can be stored
Source§

fn validate_bounds(&self) -> CRDTResult<()>

Validates that the CRDT is within its memory bounds
Source§

fn memory_stats(&self) -> MemoryStats

Returns memory statistics for this CRDT
Source§

impl<C: MemoryConfig> CRDT<C> for DeviceRegistry<C>

Source§

type Error = CRDTError

The error type for CRDT operations
Source§

fn merge(&mut self, other: &Self) -> CRDTResult<()>

Merges another CRDT instance into this one Read more
Source§

fn eq(&self, other: &Self) -> bool

Checks if this CRDT is equal to another Read more
Source§

fn size_bytes(&self) -> usize

Returns the current size of the CRDT in bytes Read more
Source§

fn validate(&self) -> CRDTResult<()>

Validates the internal consistency of the CRDT Read more
Source§

fn state_hash(&self) -> u32

Returns a hash of the CRDT’s logical state Read more
Source§

fn can_merge(&self, _other: &Self) -> bool

Checks if the CRDT can be merged with another without exceeding limits Read more
Source§

impl<C: Clone + MemoryConfig> Clone for DeviceRegistry<C>

Source§

fn clone(&self) -> DeviceRegistry<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + MemoryConfig> Debug for DeviceRegistry<C>

Source§

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

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

impl<C: MemoryConfig> RealTimeCRDT<C> for DeviceRegistry<C>

Source§

const MAX_MERGE_CYCLES: u32 = 200u32

Maximum number of CPU cycles for merge operation
Source§

const MAX_VALIDATE_CYCLES: u32 = 100u32

Maximum number of CPU cycles for validation
Source§

const MAX_SERIALIZE_CYCLES: u32 = 150u32

Maximum number of CPU cycles for serialization
Source§

fn merge_bounded(&mut self, other: &Self) -> CRDTResult<()>

Performs a bounded merge operation Read more
Source§

fn validate_bounded(&self) -> CRDTResult<()>

Performs bounded validation Read more
Source§

fn remaining_budget(&self) -> Option<u32>

Returns the current execution time budget remaining
Source§

fn set_budget(&mut self, _cycles: u32)

Sets the execution time budget for operations
Source§

fn merge_wcet(&self) -> u32

Returns the worst-case execution time for merge in CPU cycles
Source§

fn validate_wcet(&self) -> u32

Returns the worst-case execution time for validation in CPU cycles
Source§

fn can_meet_deadline( &self, operation: RTOperation, deadline_cycles: u32, ) -> bool

Checks if the operation can complete within the given deadline

Auto Trait Implementations§

§

impl<C> Freeze for DeviceRegistry<C>

§

impl<C> RefUnwindSafe for DeviceRegistry<C>
where C: RefUnwindSafe,

§

impl<C> Send for DeviceRegistry<C>
where C: Send,

§

impl<C> Sync for DeviceRegistry<C>
where C: Sync,

§

impl<C> Unpin for DeviceRegistry<C>
where C: Unpin,

§

impl<C> UnwindSafe for DeviceRegistry<C>
where C: UnwindSafe,

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
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.