libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mdnsresolver.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_MDNS
13#include <cstdint>
14#include <promeki/namespace.h>
15#include <promeki/atomic.h>
16#include <promeki/duration.h>
17#include <promeki/error.h>
20#include <promeki/objectbase.h>
21#include <promeki/timerevent.h>
22#include <promeki/string.h>
23#include <promeki/uniqueptr.h>
24
25PROMEKI_NAMESPACE_BEGIN
26
27class MdnsBrowser;
28class MdnsManager;
29
73class MdnsResolver : public ObjectBase {
74 PROMEKI_OBJECT(MdnsResolver, ObjectBase)
75 public:
77 static constexpr int64_t DefaultTimeoutMs = 3000;
78
87 explicit MdnsResolver(const MdnsServiceInstance &target, ObjectBase *parent = nullptr);
88
90 ~MdnsResolver() override;
91
93 const MdnsServiceInstance &target() const { return _target; }
94
102 void setManager(MdnsManager *manager);
103
105 MdnsManager *manager() const;
106
108 void setTimeout(const Duration &timeout);
109
111 const Duration &timeout() const { return _timeout; }
112
124 Error resolve();
125
133 void stop();
134
136 bool isActive() const { return _active.value(); }
137
139 MdnsServiceInstance snapshot() const;
140
142 PROMEKI_SIGNAL(resolved, MdnsServiceInstance);
143
145 PROMEKI_SIGNAL(failed, Error);
146
147 protected:
149 void timerEvent(TimerEvent *e) override;
150
151 private:
152 // Called by the internal browser's serviceFound /
153 // serviceUpdated slots.
154 void onBrowserFound(MdnsServiceInstance inst);
155 void onBrowserUpdated(MdnsServiceInstance inst);
156 void onBrowserLost(MdnsServiceInstance inst);
157
158 // Returns @c true when the in-progress snapshot is
159 // "complete enough" to fire @ref resolvedSignal. The
160 // criterion is: port + hostname known AND at least one
161 // address (v4 or v6) recorded.
162 static bool isComplete(const MdnsServiceInstance &inst);
163
164 MdnsServiceInstance _target;
165 UniquePtr<MdnsBrowser> _browser;
166 MdnsServiceInstance _snapshot;
167 Duration _timeout;
168 int _timerId = -1;
169 Atomic<bool> _active;
170 Atomic<bool> _emitted;
171};
172
173PROMEKI_NAMESPACE_END
174
175#endif // PROMEKI_ENABLE_MDNS