#[unsafe(no_mangle)]pub extern "C" fn dmsc_device_new(
name: *const c_char,
device_type: i32,
) -> *mut CDMSCDeviceExpand description
Device type enumeration values.
These integer constants identify the category of device being created or managed. The values map to the DMSCDeviceType Rust enumeration.
§Type Mapping
The following mapping applies between C constants and device types:
- 0: CPU - Central processing unit
- 1: GPU - Graphics processing unit
- 2: Memory - RAM resources
- 3: Storage - Persistent storage devices
- 4: Network - Network interfaces
- 5: Sensor - Data acquisition devices
- 6: Actuator - Action execution devices
- 7+: Custom - Application-specific types
§Usage
When creating devices or filtering by type, pass the appropriate constant:
DMSCDevice* cpu = dmsc_device_new("compute-0", 0); // CPU device
DMSCDevice* gpu = dmsc_device_new("render-0", 1); // GPU device§Extensibility
Applications can define custom device types beyond the standard categories by using values greater than or equal to 7. Custom types should be documented and handled appropriately by application code. Creates a new DMSCDevice instance with specified name and device type.
Allocates a new device object with the given identification and classification. The device is created in DISCOVERED state and requires configuration and initialization before use.
§Parameters
name: Pointer to null-terminated C string containing the device name. Must not be NULL. The name should be unique within the device namespace. Names follow naming conventions: lowercase with hyphens for standard devices.device_type: Integer constant indicating the device category. Use predefined constants (0-6) for standard types or custom values for application-specific devices.
§Returns
Pointer to newly allocated DMSCDevice on success, or NULL if:
nameparameter is NULL- Memory allocation fails
- Name contains invalid UTF-8 sequences
§Initial State
A newly created device:
- Has DISCOVERED lifecycle state
- Has no assigned controller (controller must be created separately)
- Has no configured settings (defaults applied)
- Is not registered with any scheduler
§Example
// Create a GPU device
DMSCDevice* gpu = dmsc_device_new("training-gpu-0", DEVICE_TYPE_GPU);
if (gpu == NULL) {
fprintf(stderr, "Failed to create device\n");
return ERROR_DEVICE_CREATION;
}
// Configure and initialize...
// Cleanup when done
dmsc_device_free(gpu);§Naming Conventions
Device names should follow these guidelines:
- Descriptive: Indicate device purpose or location
- Unique: No two devices share the same name
- Consistent: Follow naming pattern for device type
- Persistent: Names remain stable across restarts