Thermal Camera SDK 10.1.1
SDK for Optris Thermal Cameras
Loading...
Searching...
No Matches
EnumerationManager.h
Go to the documentation of this file.
1// Copyright (c) 2008-2025 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 <set>
19#include <condition_variable>
20#include <unordered_set>
21#include <unordered_map>
22
23#include "otcsdk/Api.h"
27
28
29namespace optris
30{
31
44{
45public:
50
55
58
59
68
69
83 OTC_SDK_API std::vector<DeviceInfo> getDetectedDevices(int seconds = 0);
84
85
92
99
100
110
124
131
137 OTC_SDK_API bool isRunning() const noexcept;
138
139
145 OTC_SDK_API void setDetectionPeriod(int period) noexcept;
146
152 OTC_SDK_API int getDetectionPeriod() const noexcept;
153
154
162
169
182 OTC_SDK_API std::string addEthernetDetector(const std::string& networkAddress);
183
195 OTC_SDK_API bool removeEthernetDetector(const std::string& networkAddress);
196
209 OTC_SDK_API std::string addEthernetDetector(const IpAddress& networkAddress, int cidr);
210
221 OTC_SDK_API bool removeEthernetDetector(const IpAddress& networkAddress, int cidr);
222
233 OTC_SDK_API std::string addDetector(const std::string& name, std::shared_ptr<EnumerationDetector> detector);
234
242 OTC_SDK_API bool removeDetector(const std::string& name);
243
246
252 OTC_SDK_API std::vector<std::string> getDetectorNames();
253
261 OTC_SDK_API std::shared_ptr<EnumerationDetector> getDetector(const std::string& name);
262
263
264private:
265 using Mutex = std::mutex;
266 using Lock = std::unique_lock<Mutex>;
267 using Condition = std::condition_variable;
268
269
271
272
273 void detectDevices();
274
275 void notifyClientsOfDetection(const DeviceInfo& deviceInfo);
276 void notifyClientsOfLostDetection(const DeviceInfo& deviceInfo);
277 void notifyClientsOfChangedDetection(const DeviceInfo& deviceInfo);
278
279 void waitForDetectionUpdate(int seconds);
280 void notifyOfDetectionUpdate();
281
282
283 Mutex _detectedDevicesMutex;
284 std::set<DeviceInfo> _detectedDevices;
285
286 Mutex _runMutex;
287 std::atomic<bool> _shutdown;
288 std::atomic<bool> _running;
289 std::atomic<int> _period;
290 std::unique_ptr<std::thread> _thread;
291
292 Mutex _waitForDetectionUpdateMutex;
293 Condition _waitForDetectionUpdateCondition;
294 bool _waitForDetectionUpdateComplete;
295
296 Mutex _waitForDetectionUpdateConditionsMutex;
297 bool _newDetectorAdded;
298
299 Mutex _clientsMutex;
300 std::unordered_set<EnumerationClient*> _clients;
301
302 Mutex _detectorsMutex;
303 std::unordered_map<std::string, std::shared_ptr<EnumerationDetector>> _detectors;
304};
305
306
307// Inline implementations
308inline void EnumerationManager::setDetectionPeriod(int period) noexcept
309{
310 _period = period;
311}
312
313inline int EnumerationManager::getDetectionPeriod() const noexcept
314{
315 return _period;
316}
317
318} // 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 interface definition for classes that wish to be updated about the detection of availabl...
Contains the interface definition for classes detecting available devices.
Holds important information about a device.
Definition DeviceInfo.h:33
Defines the interface for classes that want to be updated about the detection of available devices.
Definition EnumerationClient.h:25
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 EnumerationManager & operator=(EnumerationManager &&)=delete
No move assignment.
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 EnumerationManager & operator=(const EnumerationManager &)=delete
No copy assignment.
OTC_SDK_API void run()
Runs the connection event detection continuously.
virtual 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.
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:308
OTC_SDK_API std::shared_ptr< EnumerationDetector > getDetector(const std::string &name)
Return the detector registered under the given name.
OTC_SDK_API 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:313
OTC_SDK_API bool isRunning() const noexcept
Returns whether the connection event detection is running.
OTC_SDK_API EnumerationManager(EnumerationManager &&)=delete
No move constructor.
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 DeviceInfo.h:24