libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
networkinterfacemonitor.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
13#include <promeki/objectbase.h>
14#include <promeki/error.h>
16#include <promeki/ipv4address.h>
17#include <promeki/ipv6address.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
61class NetworkInterfaceMonitor : public ObjectBase {
62 PROMEKI_OBJECT(NetworkInterfaceMonitor, ObjectBase)
63 public:
65 static constexpr unsigned int DefaultDebounceMs = 50;
66
68 explicit NetworkInterfaceMonitor(ObjectBase *parent = nullptr);
69
71 ~NetworkInterfaceMonitor() override;
72
85 Error start();
86
96 void stop();
97
99 bool isRunning() const { return _running; }
100
109 void setDebounceMs(unsigned int ms) { _debounceMs = ms; }
110
112 unsigned int debounceMs() const { return _debounceMs; }
113
123 void testForceRescan();
124
133 static NetworkInterfaceMonitor *anyRunning();
134
136 PROMEKI_SIGNAL(interfaceAdded, NetworkInterface);
138 PROMEKI_SIGNAL(interfaceRemoved, NetworkInterface);
140 PROMEKI_SIGNAL(linkUp, NetworkInterface);
142 PROMEKI_SIGNAL(linkDown, NetworkInterface);
144 PROMEKI_SIGNAL(addressAddedIpv4, NetworkInterface, Ipv4Address);
146 PROMEKI_SIGNAL(addressRemovedIpv4, NetworkInterface, Ipv4Address);
148 PROMEKI_SIGNAL(addressAddedIpv6, NetworkInterface, Ipv6Address);
150 PROMEKI_SIGNAL(addressRemovedIpv6, NetworkInterface, Ipv6Address);
157 PROMEKI_SIGNAL(interfacesChanged);
158
168 void kickDebounce();
169
170 private:
171 // Runs the diff cycle synchronously on the monitor's
172 // affinity thread. Called by the debounce timer or
173 // @ref testForceRescan.
174 void runDiff();
175
176 bool _running = false;
177 int _debounceTimer = -1;
178 unsigned int _debounceMs = DefaultDebounceMs;
179
180 struct PreviousEntry {
181 NetworkInterfaceImplPtr impl;
182 NetworkInterfaceData data;
183 };
184 // Keyed by raw impl pointer (const because SharedPtr
185 // exposes only @c const access) — Stage 1 stabilises
186 // impl identity so the pointer is a stable per-iface
187 // key. The @c PreviousEntry holds a SharedPtr too, so
188 // the impl outlives a registry-driven eviction
189 // mid-cycle.
190 struct Private;
191 Private *_priv;
192};
193
209Error networkInterfaceMonitorPlatformOpen(NetworkInterfaceMonitor *m);
210
212void networkInterfaceMonitorPlatformClose(NetworkInterfaceMonitor *m);
213
214PROMEKI_NAMESPACE_END
215
216#endif // PROMEKI_ENABLE_NETWORK