OpenCPN Partial API docs
Loading...
Searching...
No Matches
mdns_cache.h
Go to the documentation of this file.
1
2/***************************************************************************
3 * Copyright (C) 2024 Alec Leamas *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef MDNS_CACHE_H
26#define MDNS_CACHE_H
27
28#include <mutex>
29#include <string>
30#include <vector>
31
40class MdnsCache {
41public:
42 struct Entry {
43 std::string service_instance;
44 std::string hostname;
45 std::string ip;
46 std::string port;
47 Entry(const std::string& service, const std::string host,
48 const std::string& _ip, const std::string _port)
49 : service_instance(service), hostname(host), ip(_ip), port(_port) {}
50 };
51
52 static MdnsCache& GetInstance();
53
54 MdnsCache& operator=(MdnsCache&) = delete;
55 MdnsCache(const MdnsCache&) = delete;
56
58 void Validate();
59
65 bool Add(const Entry& entry);
66
72 bool Add(const std::string& service, const std::string& host,
73 const std::string& _ip, const std::string& _port);
74
80 bool Add(const std::string& _ip, const std::string& _port);
81
83 const std::vector<Entry>& GetCache() const { return m_cache; }
84
85private:
86 mutable std::mutex m_mutex;
87 std::vector<Entry> m_cache;
88
89 MdnsCache() = default;
90};
91
92#endif // MDNS_CACHE_H
Singleton cache for hosts looked up using mdns.
Definition mdns_cache.h:40
const std::vector< Entry > & GetCache() const
Return read-only cached entries reference.
Definition mdns_cache.h:83
bool Add(const Entry &entry)
Add new entry to the cache.
void Validate()
Check that all entries are accessible, remove stale ones.