Thermal Camera SDK 11.4.10
SDK for Optris Thermal Cameras
Loading...
Searching...
No Matches
EnumerationManager.h
Go to the documentation of this file.
1// Copyright (c) 2008-2026 Optris GmbH & Co. KG
2
11#pragma once
12
13#include <atomic>
14#include <vector>
15#include <thread>
16#include <mutex>
17#include <memory>
18#include <condition_variable>
19#include <unordered_set>
20#include <unordered_map>
21
22#include "otcsdk/Api.h"
26
27
28namespace optris
29{
30
43{
44public:
49
54
56 OTC_SDK_API ~EnumerationManager();
57
58
66 OTC_SDK_API static EnumerationManager& getInstance();
67
68
82 OTC_SDK_API std::vector<DeviceInfo> getDetectedDevices(int seconds = 0);
83
84
90 OTC_SDK_API void addClient(EnumerationClient* client);
91
97 OTC_SDK_API bool removeClient(EnumerationClient* client);
98
99
108 OTC_SDK_API void run();
109
122 OTC_SDK_API bool runAsync();
123
129 OTC_SDK_API void stopRunning();
130
136 OTC_SDK_API bool isRunning() const noexcept;
137
138
144 OTC_SDK_API void setDetectionPeriod(int period) noexcept;
145
151 OTC_SDK_API int getDetectionPeriod() const noexcept;
152
153
160 OTC_SDK_API std::string addUsbDetector();
161
167 OTC_SDK_API bool removeUsbDetector();
168
181 OTC_SDK_API std::string addEthernetDetector(const std::string& networkAddress);
182
194 OTC_SDK_API bool removeEthernetDetector(const std::string& networkAddress);
195
208 OTC_SDK_API std::string addEthernetDetector(const IpAddress& networkAddress, int cidr);
209
220 OTC_SDK_API bool removeEthernetDetector(const IpAddress& networkAddress, int cidr);
221
232 OTC_SDK_API std::string addDetector(const std::string& name, std::shared_ptr<EnumerationDetector> detector);
233
241 OTC_SDK_API bool removeDetector(const std::string& name);
242
244 OTC_SDK_API void clearDetectors();
245
251 OTC_SDK_API std::vector<std::string> getDetectorNames();
252
260 OTC_SDK_API std::shared_ptr<EnumerationDetector> getDetector(const std::string& name);
261
262
263private:
264 friend class DeviceClaimService;
265
266
267 using Mutex = std::mutex;
268 using RecursiveMutex = std::recursive_mutex;
269 using Lock = std::unique_lock<Mutex>;
270 using RecursiveLock = std::unique_lock<RecursiveMutex>;
271 using ScopedLock = std::scoped_lock<RecursiveMutex, RecursiveMutex>;
272 using Condition = std::condition_variable;
273
274
276
277
278 void detectDevices();
279 void debounceLostDetections(std::vector<DeviceInfo>& currentlyDetected);
280
281 void runThread();
282
283 void notifyClientsOfDetection(const DeviceInfo& deviceInfo);
284 void notifyClientsOfLostDetection(const DeviceInfo& deviceInfo);
285 void notifyClientsOfChangedDetection(const DeviceInfo& deviceInfo);
286
287 void waitForDetectionUpdate(int seconds);
288 void notifyOfDetectionUpdate();
289
290 void setDeviceBusy(unsigned long serialNumber, const std::string& connectionInterface, bool busy);
291
292
293 RecursiveMutex _detectedDevicesMutex;
294 std::vector<DeviceInfo> _detectedDevices;
295
297 Mutex _runMutex;
298
300 std::unique_ptr<std::thread> _runThread;
301 // Synchronizes when the run thread should start to the detection loop.
302 Mutex _runThreadMutex;
303 Condition _runThreadCondition;
304 std::atomic<bool> _runThreadActive;
305
307 std::atomic<bool> _running;
309 std::atomic<bool> _actuallyRunning;
311 std::atomic<int> _period;
312
313
314 Mutex _waitForDetectionUpdateMutex;
315 Condition _waitForDetectionUpdateCondition;
316 bool _waitForDetectionUpdateComplete;
317
318 Mutex _waitForDetectionUpdateConditionsMutex;
319 bool _newDetectorAdded;
320
321 RecursiveMutex _clientsMutex;
322 std::unordered_set<EnumerationClient*> _clients;
323
324 Mutex _detectorsMutex;
325 std::unordered_map<std::string, std::shared_ptr<EnumerationDetector>> _detectors;
326};
327
328
329// Inline implementations
330inline void EnumerationManager::setDetectionPeriod(int period) noexcept
331{
332 _period = period;
333}
334
335inline int EnumerationManager::getDetectionPeriod() const noexcept
336{
337 return _period;
338}
339
340} // namespace optris
Contains defines controlling the Windows DLL export and import of symbols.
Contains a class encapsulating important information about devices.
Contains the base class for all clients observing the EnumerationManager.
Contains the interface definition for classes detecting available devices.
Holds important information about a device.
Definition DeviceInfo.h:33
Base class for all clients observing the EnumerationManager.
Definition EnumerationClient.h:21
Common interface for classes detecting available devices.
Definition EnumerationDetector.h:23
Detects and monitors available devices.
Definition EnumerationManager.h:43
OTC_SDK_API std::vector< std::string > getDetectorNames()
Returns the names of all added detectors.
OTC_SDK_API bool removeClient(EnumerationClient *client)
Removes the given observer/client.
OTC_SDK_API bool runAsync()
Runs the connection event detection continuously in a dedicated thread.
OTC_SDK_API std::string addUsbDetector()
Adds a detector for USB devices.
OTC_SDK_API std::string addDetector(const std::string &name, std::shared_ptr< EnumerationDetector > detector)
Adds a new detector for connected devices.
OTC_SDK_API void clearDetectors()
Clears all added detectors.
OTC_SDK_API void run()
Runs the connection event detection continuously.
OTC_SDK_API ~EnumerationManager()
Destructor.
OTC_SDK_API bool removeEthernetDetector(const std::string &networkAddress)
Remove the Ethernet detector for the specified network.
OTC_SDK_API void addClient(EnumerationClient *client)
Adds an observer/client that will be updated if a device detection status changes.
EnumerationManager & operator=(EnumerationManager &&)=delete
No move assignment.
OTC_SDK_API bool removeDetector(const std::string &name)
Removes the detector with the given name.
OTC_SDK_API void stopRunning()
Stops the continuous connection event detection.
OTC_SDK_API void setDetectionPeriod(int period) noexcept
Sets the minimum period in milliseconds for a single connection event detection run.
Definition EnumerationManager.h:330
EnumerationManager(EnumerationManager &&)=delete
No move constructor.
EnumerationManager & operator=(const EnumerationManager &)=delete
No copy assignment.
OTC_SDK_API std::shared_ptr< EnumerationDetector > getDetector(const std::string &name)
Return the detector registered under the given name.
EnumerationManager(const EnumerationManager &)=delete
No copy constructor.
OTC_SDK_API bool removeUsbDetector()
Removes the detector for USB devices.
static OTC_SDK_API EnumerationManager & getInstance()
Returns an instance of the EnumerationManager.
OTC_SDK_API int getDetectionPeriod() const noexcept
Returns the minimum period in milliseconds for a single connection event detection run.
Definition EnumerationManager.h:335
OTC_SDK_API bool isRunning() const noexcept
Returns whether the connection event detection is running.
OTC_SDK_API std::vector< DeviceInfo > getDetectedDevices(int seconds=0)
Returns information about the currently detected devices.
OTC_SDK_API std::string addEthernetDetector(const std::string &networkAddress)
Adds a detector for Ethernet devices in the specified network.
Encapsulates an IP v4 address.
Definition IpAddress.h:33
Main SDK namespace.
Definition AlarmChannel.h:21