libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mdnsserviceinstance.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/datatype.h>
16#include <promeki/string.h>
17#include <promeki/list.h>
18#include <promeki/result.h>
19#include <promeki/error.h>
20#include <promeki/timestamp.h>
21#include <promeki/duration.h>
22#include <promeki/ipv4address.h>
23#include <promeki/ipv6address.h>
26
27PROMEKI_NAMESPACE_BEGIN
28
29class DataStream;
30class TextStream;
31
70class MdnsServiceInstance {
71 public:
72 PROMEKI_DATATYPE(MdnsServiceInstance, DataTypeMdnsServiceInstance, 1)
73
74
75 Error writeToStream(DataStream &s) const;
77 template <uint32_t V> static Result<MdnsServiceInstance> readFromStream(DataStream &s);
78
80 static constexpr int InvalidInterfaceIndex = -1;
81
82 MdnsServiceInstance() = default;
83
85 const String &instanceName() const { return _instanceName; }
86 void setInstanceName(const String &v) { _instanceName = v; }
87
89 const MdnsServiceType &type() const { return _type; }
90 void setType(const MdnsServiceType &v) { _type = v; }
91
93 const String &hostname() const { return _hostname; }
94 void setHostname(const String &v) { _hostname = v; }
95
97 uint16_t port() const { return _port; }
98 void setPort(uint16_t v) { _port = v; }
99
101 const List<Ipv4Address> &ipv4Addresses() const { return _v4; }
102 void setIpv4Addresses(const List<Ipv4Address> &v) { _v4 = v; }
103
105 const List<Ipv6Address> &ipv6Addresses() const { return _v6; }
106 void setIpv6Addresses(const List<Ipv6Address> &v) { _v6 = v; }
107
109 const MdnsTxtRecord &txt() const { return _txt; }
110 void setTxt(const MdnsTxtRecord &v) { _txt = v; }
111
120 int interfaceIndex() const { return _interfaceIndex; }
121 void setInterfaceIndex(int v) { _interfaceIndex = v; }
122
130 const TimeStamp &lastSeen() const { return _lastSeen; }
131 void setLastSeen(const TimeStamp &v) { _lastSeen = v; }
132
141 const Duration &ttl() const { return _ttl; }
142 void setTtl(const Duration &v) { _ttl = v; }
143
145 bool isValid() const { return !_instanceName.isEmpty() && _type.isValid(); }
146
152 String fqdn() const;
153
168 bool operator==(const MdnsServiceInstance &other) const;
169 bool operator!=(const MdnsServiceInstance &other) const { return !(*this == other); }
170
182 bool hasSameContent(const MdnsServiceInstance &other) const;
183
192 bool hasSameSnapshot(const MdnsServiceInstance &other) const;
193
195 String toString() const;
196
197 private:
198 String _instanceName;
199 MdnsServiceType _type;
200 String _hostname;
201 uint16_t _port = 0;
202 List<Ipv4Address> _v4;
203 List<Ipv6Address> _v6;
204 MdnsTxtRecord _txt;
205 int _interfaceIndex = InvalidInterfaceIndex;
206 TimeStamp _lastSeen;
207 Duration _ttl;
208};
209
211TextStream &operator<<(TextStream &stream, const MdnsServiceInstance &inst);
212
213PROMEKI_NAMESPACE_END
214
215#endif // PROMEKI_ENABLE_MDNS