MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ refresh_devices()

size_t MayaFlux::Core::SerialInputBackend::refresh_devices ( )
overridevirtual

Refresh the device list.

Returns
Number of devices found

Re-enumerates available devices. May trigger device callbacks for newly connected or disconnected devices.

Implements MayaFlux::Core::IInputBackend.

Definition at line 147 of file SerialInputBackend.cpp.

148{
149 if (!m_initialized.load() || !m_config.enumerate_ports) {
150 return get_devices().size();
151 }
152
153 const auto found = m_config.enumerator ? m_config.enumerator() : Platform::list_serial_ports();
154 std::vector<DeviceEvent> events;
155 size_t count = 0;
156
157 m_roster.update([&](Roster& roster) {
158 events.clear();
159 bool changed = false;
160 std::set<uint32_t> seen;
161
162 for (const auto& port : found) {
163 const std::string path = port.path.string();
164 const bool configured_port = std::ranges::any_of(roster.entries, [&](const auto& item) {
165 return item.second.configured && item.second.parent == 0 && same_port(item.second.info.port_name, path);
166 });
167 if (configured_port) {
168 continue;
169 }
170
171 const uint32_t id = id_for(roster, "e:" + path);
172 seen.insert(id);
173 if (roster.entries.find(id) == roster.entries.end()) {
174 Entry entry = make_entry(id, path, port.name, m_config.detected_line,
175 m_config.detected_protocol, false);
176 events.emplace_back(entry.info, true);
177 roster.entries.insert_or_assign(id, std::move(entry));
178 changed = true;
179 }
180 }
181
182 std::vector<uint32_t> gone;
183 for (const auto& [id, entry] : roster.entries) {
184 if (!entry.configured && entry.parent == 0 && !entry.device && !seen.contains(id)) {
185 gone.push_back(id);
186 }
187 }
188 for (const uint32_t id : gone) {
189 events.emplace_back(roster.entries.find(id)->second.info, false);
190 roster.entries.erase(id);
191 changed = true;
192 }
193
194 std::vector<uint32_t> orphans;
195 for (const auto& [id, entry] : roster.entries) {
196 if (entry.parent != 0 && roster.entries.find(entry.parent) == roster.entries.end()) {
197 orphans.push_back(id);
198 }
199 }
200 for (const uint32_t id : orphans) {
201 events.emplace_back(roster.entries.find(id)->second.info, false);
202 roster.entries.erase(id);
203 changed = true;
204 }
205
206 count = roster.entries.size();
207 return changed;
208 });
209
210 for (const auto& [info, connected] : events) {
211 notify_device(info, connected);
212 }
213
214 return count;
215}
std::vector< InputDeviceInfo > get_devices() const override
Get list of available devices.
static uint32_t id_for(Roster &roster, const std::string &key)
static Entry make_entry(uint32_t id, const std::string &path, const std::string &name, const SerialLineSettings &line, const SerialProtocolSettings &protocol, bool configured)
Memory::SnapshotCell< Roster > m_roster
void notify_device(const InputDeviceInfo &info, bool connected) const
std::vector< double > count(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sample count per window (as double for pipeline uniformity).
Definition Analysis.cpp:506
std::vector< SerialPortEntry > list_serial_ports()
The serial ports the system exposes, sorted by name.

References MayaFlux::Core::SerialInputBackend::Roster::entries, get_devices(), id_for(), MayaFlux::Core::SerialInputBackend::Entry::info, MayaFlux::Platform::list_serial_ports(), m_config, m_initialized, m_roster, make_entry(), and notify_device().

Referenced by initialize().

Here is the call graph for this function:
Here is the caller graph for this function: