Thermal Camera SDK 11.3.0
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
10
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
57
58
67
68
82 OTC_SDK_API std::vector<DeviceInfo> getDetectedDevices(int seconds = 0);
83
84
91
98
99
109
123
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
161
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
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 Lock = std::unique_lock<Mutex>;
269 using ScopedLock = std::scoped_lock<Mutex, Mutex>;
270 using Condition = std::condition_variable;
271
272
274
275
276 void detectDevices();
277 void debounceLostDetections(std::vector<DeviceInfo>& currentlyDetected);
278
279 void runThread();
280
281 void notifyClientsOfDetection(const DeviceInfo& deviceInfo);
282 void notifyClientsOfLostDetection(const DeviceInfo& deviceInfo);
283 void notifyClientsOfChangedDetection(const DeviceInfo& deviceInfo);
284
285 void waitForDetectionUpdate(int seconds);
286 void notifyOfDetectionUpdate();
287
288 void setDeviceBusy(unsigned long serialNumber, const std::string& connectionInterface, bool busy);
289
290
291 Mutex _detectedDevicesMutex;
292 std::vector<DeviceInfo> _detectedDevices;
293
295 Mutex _runMutex;
296
298 std::unique_ptr<std::thread> _runThread;
299 // Synchronizes when the run thread should start to the detection loop.
300 Mutex _runThreadMutex;
301 Condition _runThreadCondition;
302 std::atomic<bool> _runThreadActive;
303
305 std::atomic<bool> _running;
307 std::atomic<bool> _actuallyRunning;
309 std::atomic<int> _period;
310
311
312 Mutex _waitForDetectionUpdateMutex;
313 Condition _waitForDetectionUpdateCondition;
314 bool _waitForDetectionUpdateComplete;
315
316 Mutex _waitForDetectionUpdateConditionsMutex;
317 bool _newDetectorAdded;
318
319 Mutex _clientsMutex;
320 std::unordered_set<EnumerationClient*> _clients;
321
322 Mutex _detectorsMutex;
323 std::unordered_map<std::string, std::shared_ptr<EnumerationDetector>> _detectors;
324};
325
326
327// Inline implementations
328inline void EnumerationManager::setDetectionPeriod(int period) noexcept
329{
330 _period = period;
331}
332
333inline int EnumerationManager::getDetectionPeriod() const noexcept
334{
335 return _period;
336}
337
338} // namespace optris
Contains defines controlling the Windows DLL export and import of symbols.
#define OTC_SDK_API
Only needed when working with Windows DLLs.
Definition Api.h:65
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
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:328
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:333
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