Thermal Camera SDK 10.0.1
SDK for Optris Thermal Cameras
Loading...
Searching...
No Matches
EnumerationManager.h
Go to the documentation of this file.
1// Copyright (c) 2025 Optris GmbH Co. KG
2
10
11#pragma once
12
13#include <vector>
14#include <thread>
15#include <mutex>
16#include <memory>
17#include <atomic>
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
80 OTC_SDK_API std::vector<DeviceInfo> getDetectedDevices(int seconds = 0);
81
82
89
96
97
107
121
124
130 OTC_SDK_API bool isRunning() const noexcept;
131
132
138 OTC_SDK_API void setDetectionPeriod(int period) noexcept;
139
145 OTC_SDK_API int getDetectionPeriod() const noexcept;
146
147
156 OTC_SDK_API void registerDetector(const std::string& name, std::shared_ptr<EnumerationDetector> detector);
157
165 OTC_SDK_API std::shared_ptr<EnumerationDetector> getDetector(const std::string& name);
166
167
168private:
169 using Mutex = std::mutex;
170 using Lock = std::unique_lock<Mutex>;
171 using Condition = std::condition_variable;
172
173
175
176
177 void detectDevices();
178
179 void notifyClientsOfDetection(const DeviceInfo& deviceInfo);
180 void notifyClientsOfLostDetection(const DeviceInfo& deviceInfo);
181
182 void waitForFirstPass(int seconds);
183
184
185 Mutex _detectedDevicesMutex;
186 std::set<DeviceInfo> _detectedDevices;
187
188 Mutex _runMutex;
189 std::atomic<bool> _shutdown;
190 std::atomic<bool> _running;
191 std::atomic<int> _period;
192 std::unique_ptr<std::thread> _thread;
193
194 Mutex _firstPassMutex;
195 Condition _firstPassCondition;
196 bool _firstPassComplete;
197
198 Mutex _clientsMutex;
199 std::unordered_set<EnumerationClient*> _clients;
200
201 Mutex _detectorsMutex;
202 std::unordered_map<std::string, std::shared_ptr<EnumerationDetector>> _detectors;
203};
204
205
206// Inline implementations
207inline void EnumerationManager::setDetectionPeriod(int period) noexcept
208{
209 _period = period;
210}
211
212inline int EnumerationManager::getDetectionPeriod() const noexcept
213{
214 return _period;
215}
216
217} // 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:32
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:24
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 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 void addClient(EnumerationClient *client)
Adds an observer/client that will be updated if a device detection status changes.
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:207
static OTC_SDK_API EnumerationManager & getInstance() noexcept
Returns an instance of the EnumerationManager.
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 int getDetectionPeriod() const noexcept
Returns the minimum period in milliseconds for a single connection event detection run.
Definition EnumerationManager.h:212
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 void registerDetector(const std::string &name, std::shared_ptr< EnumerationDetector > detector)
Registers a new detector for connected devices.
OTC_SDK_API std::vector< DeviceInfo > getDetectedDevices(int seconds=0)
Returns information about the currently detected devices.
Main SDK namespace.
Definition DeviceInfo.h:23