10 namespace SWC {
namespace client {
namespace Mngr {
15 :
Hosts(1, endpoints),
16 role(a_role), cid_begin(a_cid_begin), cid_end(a_cid_end),
23 role(a_role), cid_begin(a_cid_begin), cid_end(a_cid_end),
35 for(
auto& endpoint : new_endpoints) {
38 return found_host->
swap(new_endpoints);
52 _get_host(endpoint, found_host);
53 return bool(found_host);
62 for(
auto& endpoints : *
this) {
64 for(
auto& endpoint : endpoints)
65 out <<
" " << endpoint <<
'\n';
72 for(
auto& endpoints : *
this) {
73 for(
auto& point : endpoints) {
82 for(
auto& points : *
this) {
83 if(std::find(points.cbegin(), points.cend(), point) != points.cend()) {
94 settings.get<Config::Property::Value_strings_g>(
"swc.mngr.host")),
95 cfg_port(settings.get_i16(
"swc.mngr.port")),
96 m_mutex(), m_active_g_host(), m_nets() {
99 settings.
get_strs(
"swc.comm.network.priority"),
104 "swc.comm.network.priority error(%s)",
105 ec.message().c_str());
110 :
Vec(std::move(groups)),
111 cfg_hosts(other.cfg_hosts), cfg_port(other.cfg_port),
112 m_mutex(), m_active_g_host(), m_nets(other.m_nets) {
117 [cb=shared_from_this()]{ cb->on_cfg_update(); });
119 return shared_from_this();
126 for(
auto& group : *
this)
137 std::string host_or_ips;
150 for(
auto& cfg :
hosts) {
153 if((at = cfg.find_first_of(
'|')) == std::string::npos) {
159 cfg_chk = cfg.substr(at_offset = 0, at);
160 if((at_chk = cfg_chk.find_first_of(
'{')) != std::string::npos) {
161 cfg_chk = cfg_chk.substr(++at_chk, cfg_chk.find_first_of(
'}')-1);
167 if((at_chk = cfg_chk.find_first_of(
',')) == std::string::npos)
169 cfg_chk = cfg_chk.substr(++at_chk);
171 at = cfg.find_first_of(
'|', at_offset = ++at);
177 cfg_chk = cfg.substr(at_offset, at-at_offset);
178 if((at_chk = cfg_chk.find_first_of(
'[')) != std::string::npos) {
179 cfg_chk = cfg_chk.substr(++at_chk, cfg_chk.find_first_of(
']')-1);
180 auto col_range_at = cfg_chk.find_first_of(
'-');
181 auto b = cfg_chk.substr(0, col_range_at);
182 auto e = cfg_chk.substr(col_range_at+1);
188 at = cfg.find_first_of(
'|', at_offset = ++at);
197 cfg_chk = cfg.substr(at_offset);
198 if((at_chk = cfg_chk.find_first_of(
'|')) == std::string::npos) {
199 host_or_ips = cfg_chk;
202 host_or_ips = cfg_chk.substr(0, at_chk);
206 _add_host(role, col_begin, col_end, port, host_or_ips);
215 uint16_t port, std::string host_or_ips) {
220 auto addr = host_or_ips;
221 at = host_or_ips.find_first_of(
',');
222 if(at != std::string::npos) {
223 addr = host_or_ips.substr(0, at);
224 host_or_ips = host_or_ips.substr(at+1, host_or_ips.length());
232 }
while(at != std::string::npos);
237 if(endpoints.
empty())
239 for(
auto& group : *
this) {
240 if(group->role == role &&
241 group->cid_begin == cid_begin &&
242 group->cid_end == cid_end)
243 return group->add_host(endpoints);
257 for(
auto& group : *
this) {
258 if(group->role & role && (
260 (group->cid_begin <= cid && (!group->cid_end || group->cid_end >= cid))
262 hosts = group->get_hosts();
263 group_host.
role = group->role;
265 group_host.
cid_end = group->cid_end;
275 for(
auto& group : *
this) {
276 for(
auto& endpoint : endpoints) {
277 if(group->is_in_group(endpoint) &&
278 std::find(hgroups.
cbegin(), hgroups.
cend(), group) == hgroups.
cend())
292 for(
auto& group : *
this) {
293 if((!role || group->role & role) &&
294 (!cid_begin || group->cid_begin <= cid_begin) &&
295 (!cid_end || group->cid_end ||
296 (cid_end && group->cid_end >= cid_end))) {
297 group->apply_endpoints(endpoints);
304 out <<
"manager-groups:\n";
307 for(
auto& group : *
this)
317 if(g_host.role == it->role &&
318 g_host.cid_begin == it->cid_begin &&
319 g_host.cid_end == it->cid_end) {
320 it->endpoints = std::move(g_host.endpoints);
343 host.cid_begin <= cid &&
344 (!host.cid_end || host.cid_end >= cid)) {
345 endpoints = host.endpoints;
355 if(host.role & role) {
356 endpoints = host.endpoints;