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>
impl<C: MemoryConfig> DeviceRegistry<C>
Sourcepub fn register_device(
&mut self,
device_id: NodeId,
device_type: u16,
timestamp: u64,
) -> CRDTResult<()>
pub fn register_device( &mut self, device_id: NodeId, device_type: u16, timestamp: u64, ) -> CRDTResult<()>
Sourcepub fn update_device_connection(
&mut self,
device_id: NodeId,
state: ConnectionState,
timestamp: u64,
) -> CRDTResult<()>
pub fn update_device_connection( &mut self, device_id: NodeId, state: ConnectionState, timestamp: u64, ) -> CRDTResult<()>
Sourcepub fn update_device_status(
&mut self,
device_id: NodeId,
status: DeviceStatus,
timestamp: u64,
) -> CRDTResult<()>
pub fn update_device_status( &mut self, device_id: NodeId, status: DeviceStatus, timestamp: u64, ) -> CRDTResult<()>
Sourcepub fn update_device_vitals(
&mut self,
device_id: NodeId,
battery_level: u8,
signal_strength: u8,
timestamp: u64,
) -> CRDTResult<()>
pub fn update_device_vitals( &mut self, device_id: NodeId, battery_level: u8, signal_strength: u8, timestamp: u64, ) -> CRDTResult<()>
Sourcepub fn all_devices(&self) -> impl Iterator<Item = &DeviceInfo>
pub fn all_devices(&self) -> impl Iterator<Item = &DeviceInfo>
Sourcepub fn devices_by_state(
&self,
state: ConnectionState,
) -> impl Iterator<Item = &DeviceInfo>
pub fn devices_by_state( &self, state: ConnectionState, ) -> impl Iterator<Item = &DeviceInfo>
Sourcepub fn online_devices(&self) -> impl Iterator<Item = &DeviceInfo>
pub fn online_devices(&self) -> impl Iterator<Item = &DeviceInfo>
Sourcepub fn devices_requiring_attention(&self) -> impl Iterator<Item = &DeviceInfo>
pub fn devices_requiring_attention(&self) -> impl Iterator<Item = &DeviceInfo>
Sourcepub fn devices_by_type(
&self,
device_type: u16,
) -> impl Iterator<Item = &DeviceInfo>
pub fn devices_by_type( &self, device_type: u16, ) -> impl Iterator<Item = &DeviceInfo>
Sourcepub fn devices_by_gateway(
&self,
gateway_id: NodeId,
) -> impl Iterator<Item = &DeviceInfo>
pub fn devices_by_gateway( &self, gateway_id: NodeId, ) -> impl Iterator<Item = &DeviceInfo>
Sourcepub fn get_device(&self, device_id: NodeId) -> Option<&DeviceInfo>
pub fn get_device(&self, device_id: NodeId) -> Option<&DeviceInfo>
Sourcepub fn device_count(&self) -> usize
pub fn device_count(&self) -> usize
Sourcepub fn cleanup_stale_devices(
&mut self,
current_time: u64,
timeout_ms: u64,
) -> usize
pub fn cleanup_stale_devices( &mut self, current_time: u64, timeout_ms: u64, ) -> usize
Sourcepub fn validate_registry(&self) -> CRDTResult<()>
pub fn validate_registry(&self) -> CRDTResult<()>
Trait Implementations§
Source§impl<C: MemoryConfig> BoundedCRDT<C> for DeviceRegistry<C>
impl<C: MemoryConfig> BoundedCRDT<C> for DeviceRegistry<C>
Source§const MAX_SIZE_BYTES: usize = 1_560usize
const MAX_SIZE_BYTES: usize = 1_560usize
Maximum size in bytes this CRDT can occupy
Source§const MAX_ELEMENTS: usize = 64usize
const MAX_ELEMENTS: usize = 64usize
Maximum number of elements this CRDT can contain
Source§fn memory_usage(&self) -> usize
fn memory_usage(&self) -> usize
Returns the current memory usage in bytes
Source§fn element_count(&self) -> usize
fn element_count(&self) -> usize
Returns the current number of elements
Source§fn compact(&mut self) -> CRDTResult<usize>
fn compact(&mut self) -> CRDTResult<usize>
Compacts the CRDT to reduce memory usage if possible
Source§fn can_add_element(&self) -> bool
fn can_add_element(&self) -> bool
Checks if adding an element would exceed memory bounds
Source§fn remaining_capacity(&self) -> usize
fn remaining_capacity(&self) -> usize
Returns the remaining memory capacity in bytes
Source§fn is_at_capacity(&self) -> bool
fn is_at_capacity(&self) -> bool
Checks if the CRDT is at its memory limit
Source§fn utilization_percent(&self) -> u8
fn utilization_percent(&self) -> u8
Returns the memory utilization as a percentage (0-100)
Source§fn max_elements(&self) -> usize
fn max_elements(&self) -> usize
Returns the maximum number of elements that can be stored
Source§fn validate_bounds(&self) -> CRDTResult<()>
fn validate_bounds(&self) -> CRDTResult<()>
Validates that the CRDT is within its memory bounds
Source§fn memory_stats(&self) -> MemoryStats
fn memory_stats(&self) -> MemoryStats
Returns memory statistics for this CRDT
Source§impl<C: MemoryConfig> CRDT<C> for DeviceRegistry<C>
impl<C: MemoryConfig> CRDT<C> for DeviceRegistry<C>
Source§impl<C: Clone + MemoryConfig> Clone for DeviceRegistry<C>
impl<C: Clone + MemoryConfig> Clone for DeviceRegistry<C>
Source§fn clone(&self) -> DeviceRegistry<C>
fn clone(&self) -> DeviceRegistry<C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<C: Debug + MemoryConfig> Debug for DeviceRegistry<C>
impl<C: Debug + MemoryConfig> Debug for DeviceRegistry<C>
Source§impl<C: MemoryConfig> RealTimeCRDT<C> for DeviceRegistry<C>
impl<C: MemoryConfig> RealTimeCRDT<C> for DeviceRegistry<C>
Source§const MAX_MERGE_CYCLES: u32 = 200u32
const MAX_MERGE_CYCLES: u32 = 200u32
Maximum number of CPU cycles for merge operation
Source§const MAX_VALIDATE_CYCLES: u32 = 100u32
const MAX_VALIDATE_CYCLES: u32 = 100u32
Maximum number of CPU cycles for validation
Source§const MAX_SERIALIZE_CYCLES: u32 = 150u32
const MAX_SERIALIZE_CYCLES: u32 = 150u32
Maximum number of CPU cycles for serialization
Source§fn merge_bounded(&mut self, other: &Self) -> CRDTResult<()>
fn merge_bounded(&mut self, other: &Self) -> CRDTResult<()>
Performs a bounded merge operation Read more
Source§fn validate_bounded(&self) -> CRDTResult<()>
fn validate_bounded(&self) -> CRDTResult<()>
Performs bounded validation Read more
Source§fn remaining_budget(&self) -> Option<u32>
fn remaining_budget(&self) -> Option<u32>
Returns the current execution time budget remaining
Source§fn set_budget(&mut self, _cycles: u32)
fn set_budget(&mut self, _cycles: u32)
Sets the execution time budget for operations
Source§fn merge_wcet(&self) -> u32
fn merge_wcet(&self) -> u32
Returns the worst-case execution time for merge in CPU cycles
Source§fn validate_wcet(&self) -> u32
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
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> 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
Mutably borrows from an owned value. Read more