SNode.C
Loading...
Searching...
No Matches
net::config::ConfigPhysicalSocket Class Reference

#include <ConfigPhysicalSocket.h>

Inheritance diagram for net::config::ConfigPhysicalSocket:
Collaboration diagram for net::config::ConfigPhysicalSocket:

Public Member Functions

const std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > & getSocketOptions ()
 
ConfigPhysicalSocketaddSocketOption (int optLevel, int optName, int optValue)
 
ConfigPhysicalSocketaddSocketOption (int optLevel, int optName, const std::string &optValue)
 
ConfigPhysicalSocketaddSocketOption (int optLevel, int optName, const std::vector< char > &optValue)
 
ConfigPhysicalSocketremoveSocketOption (int optLevel, int optName)
 
ConfigPhysicalSocketsetRetry (bool retry=true)
 
bool getRetry () const
 
ConfigPhysicalSocketsetRetryOnFatal (bool retry=true)
 
bool getRetryOnFatal () const
 
ConfigPhysicalSocketsetRetryTimeout (double sec)
 
double getRetryTimeout () const
 
ConfigPhysicalSocketsetRetryTries (unsigned int tries=0)
 
unsigned int getRetryTries () const
 
ConfigPhysicalSocketsetRetryBase (double base)
 
double getRetryBase () const
 
ConfigPhysicalSocketsetRetryLimit (unsigned int limit)
 
unsigned int getRetryLimit () const
 
ConfigPhysicalSocketsetRetryJitter (double percent)
 
double getRetryJitter () const
 

Protected Member Functions

 ConfigPhysicalSocket (ConfigInstance *instance)
 
CLI::Option * addSocketOption (const std::string &name, int optLevel, int optName, const std::string &description, const std::string &typeName, const std::string &defaultValue, const CLI::Validator &validator)
 
- Protected Member Functions inherited from net::config::ConfigSection
 ConfigSection (ConfigInstance *instance, const std::string &name, const std::string &description)
 
 ConfigSection (const ConfigSection &)=delete
 
 ConfigSection (ConfigSection &&)=delete
 
ConfigSectionoperator= (const ConfigSection &)=delete
 
ConfigSectionoperator= (ConfigSection &&)=delete
 
CLI::Option * addOption (const std::string &name, const std::string &description)
 
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName)
 
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator)
 
template<typename ValueTypeT >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
 
template<typename ValueTypeT >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
 
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName)
 
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator)
 
template<typename ValueTypeT >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
 
template<typename ValueTypeT >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
 
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue)
 
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue, const CLI::Validator &validator)
 
void required (CLI::Option *opt, bool req=true)
 
bool required () const
 
template<typename ValueType >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue)
 
template<typename ValueType >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue, const CLI::Validator &additionalValidator)
 
template<typename ValueType >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue)
 
template<typename ValueType >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue, const CLI::Validator &additionalValidator)
 

Private Attributes

CLI::Option * retryOpt = nullptr
 
CLI::Option * retryOnFatalOpt = nullptr
 
CLI::Option * retryTriesOpt = nullptr
 
CLI::Option * retryTimeoutOpt = nullptr
 
CLI::Option * retryBaseOpt = nullptr
 
CLI::Option * retryLimitOpt = nullptr
 
CLI::Option * retryJitterOpt = nullptr
 
std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > socketOptionsMapMap
 

Additional Inherited Members

- Protected Attributes inherited from net::config::ConfigSection
CLI::App * section = nullptr
 

Detailed Description

Definition at line 66 of file ConfigPhysicalSocket.h.

Constructor & Destructor Documentation

◆ ConfigPhysicalSocket()

net::config::ConfigPhysicalSocket::ConfigPhysicalSocket ( ConfigInstance * instance)
explicitprotected

Definition at line 59 of file ConfigPhysicalSocket.cpp.

60 : ConfigSection(instance, "socket", "Configuration of socket behavior") {
61 retryOpt = addFlag( //
62 "--retry{true}",
63 "Automatically retry listen|connect",
64 "bool",
65 XSTR(RETRY),
66 CLI::IsMember({"true", "false"}));
67
69 "--retry-on-fatal{true}",
70 [this]() {
71 if (retryOnFatalOpt->as<bool>() && !retryOpt->as<bool>()) {
72 throw CLI::RequiresError(retryOnFatalOpt->get_name(), retryOpt->get_name().append("=true"));
73 }
74 },
75 "Retry also on fatal errors",
76 "bool",
77 XSTR(RETRY_ON_FATAL),
78 CLI::IsMember({"true", "false"}));
80
82 "--retry-timeout",
83 "Timeout of the retry timer",
84 "sec",
85 RETRY_TIMEOUT,
86 CLI::NonNegativeNumber);
88
90 "--retry-tries",
91 "Number of retry attempts before giving up (0 = unlimited)",
92 "tries",
93 RETRY_TRIES,
94 CLI::TypeValidator<unsigned int>());
95 retryTriesOpt->needs(retryOpt);
96
98 "--retry-base",
99 "Base of exponential backoff",
100 "base",
101 RETRY_BASE,
102 CLI::PositiveNumber);
103 retryBaseOpt->needs(retryOpt);
104
106 "--retry-jitter",
107 "Maximum jitter in percent to apply randomly to calculated retry timeout (0 to disable)",
108 "jitter",
109 RETRY_JITTER,
110 CLI::Range(0., 100.));
111 retryJitterOpt->needs(retryOpt);
112
114 "--retry-limit",
115 "Upper limit in seconds of retry timeout (0 for infinite)",
116 "sec",
117 RETRY_LIMIT,
118 CLI::NonNegativeNumber);
119 retryLimitOpt->needs(retryOpt);
120 }
#define XSTR(s)
ConfigSection(ConfigInstance *instance, const std::string &name, const std::string &description)
CLI::Option * addOption(const std::string &name, const std::string &description)
CLI::Option * addFlagFunction(const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue)
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName)

Member Function Documentation

◆ addSocketOption() [1/4]

CLI::Option * net::config::ConfigPhysicalSocket::addSocketOption ( const std::string & name,
int optLevel,
int optName,
const std::string & description,
const std::string & typeName,
const std::string & defaultValue,
const CLI::Validator & validator )
protected

Definition at line 126 of file ConfigPhysicalSocket.cpp.

132 {
133 return addFlagFunction(
134 name,
135 [this, strippedName = name.substr(0, name.find('{')), optLevel, optName]() {
136 try {
137 try {
138 if (section->get_option(strippedName)->as<bool>()) {
139 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, 1));
140 } else {
141 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, 0));
142 }
143 } catch ([[maybe_unused]] CLI::ConversionError& err) {
144 if (socketOptionsMapMap.contains(optLevel)) {
145 socketOptionsMapMap[optLevel].erase(optName);
146 if (socketOptionsMapMap[optLevel].empty()) {
147 socketOptionsMapMap.erase(optLevel);
148 }
149 }
150 }
151 } catch (CLI::OptionNotFound& err) {
152 LOG(ERROR) << err.what();
153 }
154 },
155 description,
156 typeName,
157 defaultValue,
158 validator)
159 ->force_callback();
160 }

◆ addSocketOption() [2/4]

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::addSocketOption ( int optLevel,
int optName,
const std::string & optValue )

Definition at line 168 of file ConfigPhysicalSocket.cpp.

168 {
169 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, optValue));
170
171 return *this;
172 }
std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > socketOptionsMapMap

◆ addSocketOption() [3/4]

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::addSocketOption ( int optLevel,
int optName,
const std::vector< char > & optValue )

Definition at line 174 of file ConfigPhysicalSocket.cpp.

174 {
175 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, optValue));
176
177 return *this;
178 }

◆ addSocketOption() [4/4]

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::addSocketOption ( int optLevel,
int optName,
int optValue )

Definition at line 162 of file ConfigPhysicalSocket.cpp.

162 {
163 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, optValue));
164
165 return *this;
166 }

◆ getRetry()

bool net::config::ConfigPhysicalSocket::getRetry ( ) const

Definition at line 213 of file ConfigPhysicalSocket.cpp.

213 {
214 return retryOpt->as<bool>();
215 }

◆ getRetryBase()

double net::config::ConfigPhysicalSocket::getRetryBase ( ) const

Definition at line 261 of file ConfigPhysicalSocket.cpp.

261 {
262 return retryBaseOpt->as<double>();
263 }

◆ getRetryJitter()

double net::config::ConfigPhysicalSocket::getRetryJitter ( ) const

Definition at line 285 of file ConfigPhysicalSocket.cpp.

285 {
286 return retryJitterOpt->as<double>();
287 }

◆ getRetryLimit()

unsigned int net::config::ConfigPhysicalSocket::getRetryLimit ( ) const

Definition at line 273 of file ConfigPhysicalSocket.cpp.

273 {
274 return retryLimitOpt->as<unsigned int>();
275 }

◆ getRetryOnFatal()

bool net::config::ConfigPhysicalSocket::getRetryOnFatal ( ) const

Definition at line 225 of file ConfigPhysicalSocket.cpp.

225 {
226 return retryOnFatalOpt->as<bool>();
227 }

◆ getRetryTimeout()

double net::config::ConfigPhysicalSocket::getRetryTimeout ( ) const

Definition at line 237 of file ConfigPhysicalSocket.cpp.

237 {
238 return retryTimeoutOpt->as<double>();
239 }

◆ getRetryTries()

unsigned int net::config::ConfigPhysicalSocket::getRetryTries ( ) const

Definition at line 249 of file ConfigPhysicalSocket.cpp.

249 {
250 return retryTriesOpt->as<unsigned int>();
251 }

◆ getSocketOptions()

const std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > & net::config::ConfigPhysicalSocket::getSocketOptions ( )

Definition at line 122 of file ConfigPhysicalSocket.cpp.

122 {
123 return socketOptionsMapMap;
124 }

◆ removeSocketOption()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::removeSocketOption ( int optLevel,
int optName )

Definition at line 180 of file ConfigPhysicalSocket.cpp.

180 {
181 socketOptionsMapMap[optLevel].erase(optName);
182 if (socketOptionsMapMap[optLevel].empty()) {
183 socketOptionsMapMap.erase(optLevel);
184 }
185
186 return *this;
187 }

◆ setRetry()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetry ( bool retry = true)

Definition at line 189 of file ConfigPhysicalSocket.cpp.

189 {
190 retryOpt //
191 ->default_val(retry ? "true" : "false")
192 ->clear();
193
194 if (retry) {
195 retryLimitOpt->remove_needs(retryOpt);
196 retryJitterOpt->remove_needs(retryOpt);
197 retryBaseOpt->remove_needs(retryOpt);
198 retryTriesOpt->remove_needs(retryOpt);
199 retryTimeoutOpt->remove_needs(retryOpt);
200 retryOnFatalOpt->remove_needs(retryOpt);
201 } else {
202 retryLimitOpt->needs(retryOpt);
203 retryJitterOpt->needs(retryOpt);
204 retryBaseOpt->needs(retryOpt);
205 retryTriesOpt->needs(retryOpt);
208 }
209
210 return *this;
211 }

◆ setRetryBase()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryBase ( double base)

Definition at line 253 of file ConfigPhysicalSocket.cpp.

253 {
254 retryBaseOpt //
255 ->default_val(base)
256 ->clear();
257
258 return *this;
259 }

◆ setRetryJitter()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryJitter ( double percent)

Definition at line 277 of file ConfigPhysicalSocket.cpp.

277 {
279 ->default_val(percent)
280 ->clear();
281
282 return *this;
283 }

◆ setRetryLimit()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryLimit ( unsigned int limit)

Definition at line 265 of file ConfigPhysicalSocket.cpp.

265 {
267 ->default_val(limit)
268 ->clear();
269
270 return *this;
271 }

◆ setRetryOnFatal()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryOnFatal ( bool retry = true)

Definition at line 217 of file ConfigPhysicalSocket.cpp.

217 {
219 ->default_val(retry ? "true" : "false")
220 ->clear();
221
222 return *this;
223 }

◆ setRetryTimeout()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryTimeout ( double sec)

Definition at line 229 of file ConfigPhysicalSocket.cpp.

229 {
231 ->default_val(sec)
232 ->clear();
233
234 return *this;
235 }

◆ setRetryTries()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryTries ( unsigned int tries = 0)

Definition at line 241 of file ConfigPhysicalSocket.cpp.

241 {
243 ->default_val(tries)
244 ->clear();
245
246 return *this;
247 }

Member Data Documentation

◆ retryBaseOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryBaseOpt = nullptr
private

Definition at line 114 of file ConfigPhysicalSocket.h.

◆ retryJitterOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryJitterOpt = nullptr
private

Definition at line 116 of file ConfigPhysicalSocket.h.

◆ retryLimitOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryLimitOpt = nullptr
private

Definition at line 115 of file ConfigPhysicalSocket.h.

◆ retryOnFatalOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryOnFatalOpt = nullptr
private

Definition at line 111 of file ConfigPhysicalSocket.h.

◆ retryOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryOpt = nullptr
private

Definition at line 110 of file ConfigPhysicalSocket.h.

◆ retryTimeoutOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryTimeoutOpt = nullptr
private

Definition at line 113 of file ConfigPhysicalSocket.h.

◆ retryTriesOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryTriesOpt = nullptr
private

Definition at line 112 of file ConfigPhysicalSocket.h.

◆ socketOptionsMapMap

std::map<int, std::map<int, const net::phy::PhysicalSocketOption> > net::config::ConfigPhysicalSocket::socketOptionsMapMap
private

Definition at line 118 of file ConfigPhysicalSocket.h.


The documentation for this class was generated from the following files: