SNode.C
Loading...
Searching...
No Matches
ConfigAddress.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NET_RC_CONFIG_CONFIGADDRESS_H
21#define NET_RC_CONFIG_CONFIGADDRESS_H
22
23#include "net/config/ConfigAddressLocal.h"
24#include "net/config/ConfigAddressRemote.h"
25#include "net/config/ConfigAddressReverse.h"
26#include "net/rc/SocketAddress.h"
27
28namespace net::config {
29 class ConfigInstance;
30}
31
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33
34#include <cstdint>
35#include <string>
36
37namespace CLI {
38 class Option;
39} // namespace CLI
40
41#endif /* DOXYGEN_SHOULD_SKIP_THIS */
42
43namespace net::rc::config {
44
45 template <template <typename SocketAddressT> typename ConfigAddressTypeT>
46 class ConfigAddressReverse : public ConfigAddressTypeT<net::rc::SocketAddress> {
47 private:
48 using Super = ConfigAddressTypeT<SocketAddress>;
49
50 protected:
51 using Super::Super;
52 };
53
54 template <template <typename SocketAddressT> typename ConfigAddressTypeT>
55 class ConfigAddress : public ConfigAddressTypeT<net::rc::SocketAddress> {
56 private:
57 using Super = ConfigAddressTypeT<net::rc::SocketAddress>;
58
59 protected:
60 explicit ConfigAddress(net::config::ConfigInstance* instance,
61 const std::string& addressOptionName,
62 const std::string& addressOptionDescription);
63
64 private:
65 SocketAddress* init() final;
66
67 public:
68 ConfigAddress& setSocketAddress(const SocketAddress& socketAddress);
69
70 ConfigAddress& setBtAddress(const std::string& btAddress);
71 std::string getBtAddress() const;
72
73 ConfigAddress& setChannel(uint8_t channel);
74 uint8_t getChannel() const;
75
76 protected:
77 ConfigAddress& setBtAddressRequired(bool required = true);
78 ConfigAddress& setChannelRequired(bool required = true);
79
80 CLI::Option* btAddressOpt = nullptr;
81 CLI::Option* channelOpt = nullptr;
82 };
83
84} // namespace net::rc::config
85
86extern template class net::config::ConfigAddress<net::rc::SocketAddress>;
87extern template class net::config::ConfigAddressLocal<net::rc::SocketAddress>;
88extern template class net::config::ConfigAddressRemote<net::rc::SocketAddress>;
89extern template class net::config::ConfigAddressReverse<net::rc::SocketAddress>;
90extern template class net::config::ConfigAddressBase<net::rc::SocketAddress>;
91extern template class net::rc::config::ConfigAddress<net::config::ConfigAddressLocal>;
92extern template class net::rc::config::ConfigAddress<net::config::ConfigAddressRemote>;
93extern template class net::rc::config::ConfigAddressReverse<net::config::ConfigAddressReverse>;
94
95#endif // NET_RC_CONFIG_CONFIGADDRESS_H
SocketAddress * init() final
std::string getBtAddress() const
ConfigAddress(net::config::ConfigInstance *instance, const std::string &addressOptionName, const std::string &addressOptionDescription)
ConfigAddress & setChannel(uint8_t channel)
ConfigAddress & setBtAddress(const std::string &btAddress)
ConfigAddress & setSocketAddress(const SocketAddress &socketAddress)
ConfigAddress & setChannelRequired(bool required=true)
ConfigAddress & setBtAddressRequired(bool required=true)