Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
mm::node::DeviceSet Struct Reference

One published generation of the bus: the driver that owns the socket, and the devices found on it. More...

#include <device_manager.h>

Collaboration diagram for mm::node::DeviceSet:
[legend]

Public Member Functions

Devicefind (uint16_t slavePosition)
 Device at slavePosition, or nullptr when the set holds none.
 
const Devicefind (uint16_t slavePosition) const
 Const overload of find. Same contract.
 

Public Attributes

std::shared_ptr< mm::comm::FieldbusDriverdriver
 The driver every device in this set talks through. Shared, so a retired set keeps it alive.
 
std::vector< Devicedevices
 The devices in bus order: index 0 is position 1. Frozen once the set is published.
 
uint64_t topologyGeneration = 0
 The value DeviceManager::topologyGeneration reported when this set was published.
 

Detailed Description

One published generation of the bus: the driver that owns the socket, and the devices found on it.

A set is built by init or scan, published once, and never modified after that. Publishing freezes the devices vector, not the devices in it — each Device guards its own parameter map with its own mutex.

The set is what makes device lifetime a refcount rather than a lock. Every off-RT caller works through a std::shared_ptr to one (DeviceManager::deviceSet), so a Device& stays valid for as long as the caller holds that pointer. A concurrent scan does not wait for the caller and does not invalidate the reference: it publishes a new set, and the old one dies when its last holder drops it. The retired devices keep working against their own driver, which the set also owns, so a transfer against hardware that is no longer on the bus fails cleanly instead of touching freed memory.

The RT thread does not touch the shared_ptr, because std::atomic<std::shared_ptr<T>> is not lock-free (and libc++ does not implement it at all). It reads a raw published pointer instead, drained by ProcessData::pauseCycle exactly as the process image is.

Member Function Documentation

◆ find() [1/2]

Device * mm::node::DeviceSet::find ( uint16_t  slavePosition)

Device at slavePosition, or nullptr when the set holds none.

◆ find() [2/2]

const Device * mm::node::DeviceSet::find ( uint16_t  slavePosition) const

Const overload of find. Same contract.

Member Data Documentation

◆ devices

std::vector<Device> mm::node::DeviceSet::devices

The devices in bus order: index 0 is position 1. Frozen once the set is published.

◆ driver

std::shared_ptr<mm::comm::FieldbusDriver> mm::node::DeviceSet::driver

The driver every device in this set talks through. Shared, so a retired set keeps it alive.

◆ topologyGeneration

uint64_t mm::node::DeviceSet::topologyGeneration = 0

The value DeviceManager::topologyGeneration reported when this set was published.


The documentation for this struct was generated from the following files: