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, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 **************************************************************************/
20
21#ifndef MDNS_CACHE_H
22#define MDNS_CACHE_H
23
29#include <mutex>
30#include <string>
31#include <vector>
32
41class MdnsCache {
42public:
43 struct Entry {
44 std::string service_instance;
45 std::string hostname;
46 std::string ip;
47 std::string port;
48 Entry(const std::string& service, const std::string host,
49 const std::string& _ip, const std::string _port)
50 : service_instance(service), hostname(host), ip(_ip), port(_port) {}
51 };
52
53 static MdnsCache& GetInstance();
54
55 MdnsCache& operator=(MdnsCache&) = delete;
56 MdnsCache(const MdnsCache&) = delete;
57
59 void Validate();
60
66 bool Add(const Entry& entry);
67
73 bool Add(const std::string& service, const std::string& host,
74 const std::string& _ip, const std::string& _port);
75
81 bool Add(const std::string& _ip, const std::string& _port);
82
84 const std::vector<Entry>& GetCache() const { return m_cache; }
85
86private:
87 mutable std::mutex m_mutex;
88 std::vector<Entry> m_cache;
89
90 MdnsCache() = default;
91};
92
93#endif // MDNS_CACHE_H
Singleton cache for hosts looked up using mdns.
Definition mdns_cache.h:41
const std::vector< Entry > & GetCache() const
Return read-only cached entries reference.
Definition mdns_cache.h:84
bool Add(const Entry &entry)
Add new entry to the cache.
void Validate()
Check that all entries are accessible, remove stale ones.