Expand description
Device management and scheduling Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of Ri. The Ri project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§Device Control Module
This module provides comprehensive smart device control functionality for Ri, including device discovery, control, and resource scheduling. It enables efficient management of devices and their resources across distributed environments.
§Key Components
- RiDeviceControlModule: Main device control module implementing service module traits
- RiDevice: Device representation with type, status, and capabilities
- RiDeviceType: Enum defining supported device types
- RiDeviceStatus: Enum defining device statuses
- RiDeviceCapabilities: Device capabilities structure
- RiDeviceController: Device controller for managing devices
- RiDeviceScheduler: Device scheduler for resource allocation
- RiResourcePool: Resource pool for managing device resources
- RiResourcePoolManager: Manager for multiple resource pools
- RiResourcePoolStatistics: Statistics for resource pool monitoring
- RiDeviceControlConfig: Configuration for device control behavior
- RiDiscoveryResult: Result structure for device discovery
- RiResourceRequest: Request structure for resource allocation
- RiResourceAllocation: Result structure for resource allocation
- RiResourcePoolStatus: Status structure for resource pools
§Design Principles
- Device Abstraction: Unified interface for different device types
- Auto Discovery: Automatic device discovery in the network/environment
- Resource Scheduling: Intelligent resource allocation and scheduling
- Configurable: Highly configurable device control behavior
- Async Support: Full async/await compatibility
- Resource Pooling: Efficient management of device resources through pooling
- Service Module Integration: Implements service module traits for seamless integration
- Thread-safe: Uses Arc and RwLock for safe concurrent access
- Non-critical: Device control failures should not break the entire application
- Monitoring: Comprehensive statistics for device and resource monitoring
- Scalable: Designed to handle large numbers of devices and concurrent tasks
§Usage
use ri::prelude::*;
use ri::device::{RiDeviceControlConfig, RiResourceRequest, RiDeviceType, RiDeviceCapabilities};
async fn example() -> RiResult<()> {
// Create device control configuration
let device_config = RiDeviceControlConfig {
discovery_enabled: true,
discovery_interval_secs: 30,
auto_scheduling_enabled: true,
max_concurrent_tasks: 100,
resource_allocation_timeout_secs: 60,
};
// Create device control module
let device_module = RiDeviceControlModule::new()
.with_config(device_config);
// Discover devices
let discovery_result = device_module.discover_devices().await?;
println!("Discovered {} devices, total devices: {}",
discovery_result.discovered_devices.len(),
discovery_result.total_devices);
// Get device status
let devices = device_module.get_device_status().await?;
println!("Current devices: {:?}", devices);
// Create resource request
let resource_request = RiResourceRequest {
request_id: "request-123".to_string(),
device_type: RiDeviceType::Compute,
required_capabilities: RiDeviceCapabilities {
cpu_cores: Some(4),
memory_gb: Some(8.0),
storage_gb: Some(100.0),
gpu_enabled: Some(true),
network_speed_mbps: Some(1000.0),
extra: Default::default(),
},
priority: 5,
timeout_secs: 30,
};
// Allocate resource
if let Some(allocation) = device_module.allocate_resource(resource_request).await? {
println!("Allocated device: {} (ID: {})",
allocation.device_name,
allocation.device_id);
// Release resource after use
device_module.release_resource(&allocation.allocation_id).await?;
}
Ok(())
}Re-exports§
pub use pool::RiResourcePool;pub use pool::RiResourcePoolManager;pub use pool::RiConnectionPoolStatistics;pub use scheduler::RiDeviceScheduler;pub use discovery_scheduler::RiDeviceDiscoveryEngine;pub use discovery_scheduler::RiResourceScheduler;pub use discovery::RiDeviceDiscovery;pub use discovery::DiscoveryConfig;pub use discovery::DiscoveryStats;pub use discovery::DiscoveryStrategy;pub use discovery::HardwareCategory;pub use discovery::PlatformInfo;pub use discovery::PlatformType;pub use discovery::Architecture;pub use discovery::PlatformCompatibility;pub use discovery::ProviderRegistry;pub use discovery::RiHardwareProvider;pub use discovery::PluginRegistry;pub use discovery::RiHardwareDiscoveryPlugin;pub use discovery::PluginMetadata;pub use discovery::PluginStatus;pub use discovery::PluginError;pub use discovery::AsyncDiscovery;
Modules§
- discovery
- Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
- discovery_
scheduler - Copyright © 2025 Wenze Wei. All Rights Reserved.
- pool
- Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
- scheduler
- Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
Structs§
- RiAffinity
Rules - Affinity and anti-affinity rules for device selection.
- RiDevice
- Smart device representation
- RiDevice
Capabilities - Device capabilities structure
- RiDevice
Config - Configuration for device module
- RiDevice
Control Config - Configuration for device control module
- RiDevice
Control Module - Main device control module for Ri.
- RiDevice
Controller - Device controller - manages device lifecycle and state
- RiDevice
Health Metrics - Device health metrics structure
- RiDevice
Scheduling Config - Scheduling configuration for device control module
- RiDiscovery
Result - Result structure for device discovery operations.
- RiNetwork
Device Info - Network device information for remote device discovery
- RiResource
Allocation - Result structure for resource allocation.
- RiResource
Pool Status - Status structure for resource pools.
- RiResource
Request - Request structure for resource allocation.
- RiResource
Weights - Multi-dimensional resource weights for scheduling.
Enums§
- RiDevice
Status - Device status enumeration
- RiDevice
Type - Device type enumeration
- RiRequest
SlaClass - SLA class for a resource request.