libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mdnstypebrowser.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/buffer.h>
17#include <promeki/duration.h>
18#include <promeki/error.h>
19#include <promeki/list.h>
20#include <promeki/map.h>
22#include <promeki/mutex.h>
24#include <promeki/objectbase.h>
26#include <promeki/timestamp.h>
27
28PROMEKI_NAMESPACE_BEGIN
29
30class MdnsManager;
31
64class MdnsTypeBrowser : public ObjectBase {
65 PROMEKI_OBJECT(MdnsTypeBrowser, ObjectBase)
66 public:
68 static constexpr int64_t InitialQueryIntervalMs = 1000;
69
71 static constexpr int64_t MaxQueryIntervalMs = 3600 * 1000;
72
74 explicit MdnsTypeBrowser(ObjectBase *parent = nullptr);
75
77 ~MdnsTypeBrowser() override;
78
80 void setManager(MdnsManager *manager);
81
83 MdnsManager *manager() const { return _manager; }
84
86 MdnsManager *effectiveManager() const;
87
89 bool isActive() const { return _active.value(); }
90
92 Error start();
93
95 void stop();
96
98 Error sendQuery();
99
101 void handlePacket(const Buffer &data, const SocketAddress &sender,
102 const NetworkInterface &iface);
103
105 void onManagerTick(const TimeStamp &now);
106
108 List<MdnsServiceType> types() const;
109
111 void clearCache();
112
114 PROMEKI_SIGNAL(typeFound, MdnsServiceType);
116 PROMEKI_SIGNAL(typeLost, MdnsServiceType);
117
118 private:
119 struct Entry {
120 MdnsServiceType type;
121 TimeStamp lastSeen;
122 Duration ttl;
123 };
124
125 MdnsManager *_manager = nullptr;
126 mutable Mutex _entriesMtx;
127 Map<String, Entry> _entries; // keyed by case-folded type fqdn
128 Atomic<bool> _active;
129
130 TimeStamp _nextQueryAt;
131 Duration _currentInterval;
132};
133
134PROMEKI_NAMESPACE_END
135
136#endif // PROMEKI_ENABLE_MDNS