get rid of piForeach

apply some code analyzer recommendations
ICU flag now check if libicu exists
prepare for more accurate growth of containers (limited PoT, then constantly increase size)
This commit is contained in:
2024-11-20 20:01:47 +03:00
parent 24112498ce
commit caa7880cc4
40 changed files with 415 additions and 320 deletions

View File

@@ -114,7 +114,7 @@ bool PIBinaryLog::openDevice() {
PIDir ld(logDir());
if (ld.isExists()) {
PIVector<PIFile::FileInfo> es = ld.allEntries();
piForeachC(PIFile::FileInfo & i, es) {
for (const auto & i: es) {
if (i.extension() == "binlog" && i.isFile() && i.baseName().startsWith(filePrefix())) {
setPath(i.path);
break;

View File

@@ -107,7 +107,7 @@ PIConfig::Entry PIConfig::Entry::_empty;
PIConfig::Branch PIConfig::Branch::allLeaves() {
Branch b;
b.delim = delim;
piForeach(Entry * i, *this) {
for (auto * i: *this) {
if (i->isLeaf())
b << i;
else
@@ -128,7 +128,7 @@ PIConfig::Entry & PIConfig::Branch::getValue(const PIString & vname, const PIStr
PIString name = tree.front();
tree.pop_front();
Entry * ce = 0;
piForeach(Entry * i, *this)
for (auto * i: *this)
if (i->_name == name) {
ce = i;
break;
@@ -140,7 +140,7 @@ PIConfig::Entry & PIConfig::Branch::getValue(const PIString & vname, const PIStr
if (exist != 0) *exist = false;
return _empty;
}
piForeach(PIString & i, tree) {
for (auto & i: tree) {
ce = ce->findChild(i);
if (ce == 0) {
_empty._name = vname;
@@ -158,11 +158,11 @@ PIConfig::Entry & PIConfig::Branch::getValue(const PIString & vname, const PIStr
PIConfig::Branch PIConfig::Branch::getValues(const PIString & name) {
Branch b;
b.delim = delim;
piForeach(Entry * i, *this) {
for (auto * i: *this) {
if (i->isLeaf()) {
if (i->_name.find(name) >= 0) b << i;
} else {
piForeach(Entry * j, i->_children)
for (auto * j: i->_children)
if (j->_name.find(name) >= 0) b << j;
}
}
@@ -173,7 +173,7 @@ PIConfig::Branch PIConfig::Branch::getValues(const PIString & name) {
PIConfig::Branch PIConfig::Branch::getLeaves() {
Branch b;
b.delim = delim;
piForeach(Entry * i, *this)
for (auto * i: *this)
if (i->isLeaf()) b << i;
return b;
}
@@ -182,7 +182,7 @@ PIConfig::Branch PIConfig::Branch::getLeaves() {
PIConfig::Branch PIConfig::Branch::getBranches() {
Branch b;
b.delim = delim;
piForeach(Entry * i, *this)
for (auto * i: *this)
if (!i->isLeaf()) b << i;
return b;
}
@@ -203,7 +203,7 @@ bool PIConfig::Branch::entryExists(const Entry * e, const PIString & name) const
if (e->_children.isEmpty()) {
return (e->_name == name);
}
piForeachC(Entry * i, e->_children)
for (const auto * i: e->_children)
if (entryExists(i, name)) return true;
return false;
}
@@ -212,7 +212,7 @@ bool PIConfig::Branch::entryExists(const Entry * e, const PIString & name) const
PIConfig::Entry & PIConfig::Entry::getValue(const PIString & vname, const PIString & def, bool * exist) {
PIStringList tree = vname.split(delim);
Entry * ce = this;
piForeach(PIString & i, tree) {
for (auto & i: tree) {
ce = ce->findChild(i);
if (ce == 0) {
_empty._name = vname;
@@ -230,7 +230,7 @@ PIConfig::Entry & PIConfig::Entry::getValue(const PIString & vname, const PIStri
PIConfig::Branch PIConfig::Entry::getValues(const PIString & vname) {
Branch b;
b.delim = delim;
piForeach(Entry * i, _children)
for (auto * i: _children)
if (i->_name.find(vname) >= 0) b << i;
return b;
}
@@ -240,7 +240,7 @@ bool PIConfig::Entry::entryExists(const Entry * e, const PIString & name) const
if (e->_children.isEmpty()) {
return (e->_name == name);
}
piForeachC(Entry * i, e->_children)
for (const auto * i: e->_children)
if (entryExists(i, name)) return true;
return false;
}
@@ -253,7 +253,7 @@ void PIConfig::Entry::coutt(std::ostream & s, const PIString & p) const {
s << p << _name << " = " << _value << std::endl;
else
std::cout << p << _name << std::endl;
piForeachC(Entry * i, _children)
for (const auto * i: _children)
i->coutt(s, nl);
}
#endif
@@ -265,7 +265,7 @@ void PIConfig::Entry::piCoutt(PICout s, const PIString & p) const {
s << p << _name << " = " << _value << " (" << _type << " " << _comment << ")" << PICoutManipulators::NewLine;
else
s << p << _name << PICoutManipulators::NewLine;
piForeachC(Entry * i, _children)
for (const auto * i: _children)
i->piCoutt(s, nl);
}
@@ -368,7 +368,7 @@ void PIConfig::_destroy() {
piDeleteSafety(stream);
if (own_dev && dev) delete dev;
dev = nullptr;
piForeach(PIConfig * c, inc_devs)
for (auto * c: inc_devs)
delete c;
inc_devs.clear();
}
@@ -445,7 +445,7 @@ bool PIConfig::isOpened() const {
PIConfig::Entry & PIConfig::getValue(const PIString & vname, const PIString & def, bool * exist) {
PIStringList tree = vname.split(delim);
Entry * ce = &root;
piForeach(PIString & i, tree) {
for (auto & i: tree) {
ce = ce->findChild(i);
if (ce == 0) {
if (exist != 0) *exist = false;
@@ -463,7 +463,7 @@ PIConfig::Entry & PIConfig::getValue(const PIString & vname, const PIString & de
PIConfig::Branch PIConfig::getValues(const PIString & vname) {
Branch b;
b.delim = delim;
piForeach(Entry * i, root._children)
for (auto * i: root._children)
if (i->_name.find(vname) >= 0) b << i;
return b;
};
@@ -477,7 +477,7 @@ void PIConfig::addEntry(const PIString & name, const PIString & value, const PIS
tree.pop_back();
Entry *te, *ce, *entry = &root;
if (tree.isEmpty()) toRoot = true;
piForeach(PIString & i, tree) {
for (auto & i: tree) {
te = entry->findChild(i);
if (te == 0) {
ce = new Entry();
@@ -550,7 +550,7 @@ void PIConfig::setValue(const PIString & name, const PIString & value, const PIS
int PIConfig::entryIndex(const PIString & name) {
PIStringList tree = name.split(delim);
Entry * ce = &root;
piForeach(PIString & i, tree) {
for (auto & i: tree) {
ce = ce->findChild(i);
if (ce == 0) return -1;
}
@@ -716,7 +716,7 @@ bool PIConfig::entryExists(const Entry * e, const PIString & name) const {
if (e->_children.isEmpty()) {
return (e->_name == name);
}
piForeachC(Entry * i, e->_children)
for (const auto * i: e->_children)
if (entryExists(i, name)) return true;
return false;
}
@@ -725,7 +725,7 @@ bool PIConfig::entryExists(const Entry * e, const PIString & name) const {
void PIConfig::updateIncludes() {
if (internal) return;
all_includes.clear();
piForeach(PIConfig * c, includes)
for (auto * c: includes)
all_includes << c->allLeaves();
}
@@ -744,7 +744,7 @@ PIString PIConfig::parseLine(PIString v) {
if (ex) {
r = me._value;
} else {
piForeachC(PIConfig::Entry * e, all_includes)
for (const auto * e: all_includes)
if (e->_full_name == w) {
r = e->_value;
break;
@@ -763,9 +763,7 @@ void PIConfig::parse() {
Entry *entry = 0, *te = 0, *ce = 0;
int ind, sind;
bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false;
piForeach(PIConfig * c, inc_devs)
delete c;
inc_devs.clear();
piDeleteAllAndClear(inc_devs);
includes.clear();
if (!isOpened()) return;
_seekToBeginDev();
@@ -835,7 +833,7 @@ void PIConfig::parse() {
name = tree.back();
tree.pop_back();
entry = &root;
piForeachC(PIString & i, tree) {
for (const auto & i: tree) {
te = entry->findChild(i);
if (te == 0) {
ce = new Entry();

View File

@@ -102,7 +102,7 @@ public:
Branch getBranches();
Branch & filter(const PIString & f);
bool isEntryExists(const PIString & name) const {
piForeachC(Entry * i, *this)
for (const auto * i: *this)
if (entryExists(i, name)) return true;
return false;
}
@@ -115,7 +115,7 @@ public:
private:
bool entryExists(const Entry * e, const PIString & name) const;
void allLeaves(Branch & b, Entry * e) {
piForeach(Entry * i, e->_children) {
for (auto * i: e->_children) {
if (i->isLeaf())
b << i;
else
@@ -124,12 +124,12 @@ public:
}
#ifdef PIP_STD_IOSTREAM
void coutt(std::ostream & s, const PIString & p) const {
piForeachC(Entry * i, *this)
for (const auto * i: *this)
i->coutt(s, p);
}
#endif
void piCoutt(PICout s, const PIString & p) const {
piForeachC(Entry * i, *this)
for (const auto * i: *this)
i->piCoutt(s, p);
}
@@ -165,14 +165,14 @@ public:
//! Returns first child with name "name"
Entry * findChild(const PIString & name) {
piForeach(Entry * i, _children)
for (auto * i: _children)
if (i->_name == name) return i;
return 0;
}
//! Returns first child with name "name"
const Entry * findChild(const PIString & name) const {
piForeachC(Entry * i, _children)
for (const auto * i: _children)
if (i->_name == name) return i;
return 0;
}
@@ -425,7 +425,7 @@ public:
#endif
void piCoutt(PICout s, const PIString & p) const;
void deleteBranch() {
piForeach(Entry * i, _children) {
for (auto * i: _children) {
i->deleteBranch();
delete i;
}
@@ -573,7 +573,7 @@ public:
//! Returns all top-level entries
Branch allTree() {
Branch b;
piForeach(Entry * i, root._children)
for (auto * i: root._children)
b << i;
b.delim = delim;
return b;
@@ -636,14 +636,14 @@ private:
void _writeDev(const PIString & l);
int childCount(const Entry * e) const {
int c = 0;
piForeachC(Entry * i, e->_children)
for (const auto * i: e->_children)
c += childCount(i);
c += e->_children.size_s();
return c;
}
bool entryExists(const Entry * e, const PIString & name) const;
void buildFullNames(Entry * e) {
piForeach(Entry * i, e->_children) {
for (auto * i: e->_children) {
if (e != &root)
i->_full_name = e->_full_name + delim + i->_name;
else
@@ -652,13 +652,13 @@ private:
}
}
void allLeaves(Branch & b, Entry * e) {
piForeach(Entry * i, e->_children) {
for (auto * i: e->_children) {
if ((!i->_value.isEmpty() && !i->isLeaf()) || i->isLeaf()) b << i;
allLeaves(b, i);
}
}
void setEntryDelim(Entry * e, const PIString & d) {
piForeach(Entry * i, e->_children)
for (auto * i: e->_children)
setEntryDelim(i, d);
e->delim = d;
}
@@ -669,7 +669,7 @@ private:
}
void removeEntry(Branch & b, Entry * e);
void deleteEntry(Entry * e) {
piForeach(Entry * i, e->_children)
for (auto * i: e->_children)
deleteEntry(i);
delete e;
}

View File

@@ -234,7 +234,7 @@ bool PIDir::make(bool withParents) {
l.removeAll("");
// piCout << l;
PIString cdp;
piForeachC(PIString & i, l) {
for (const auto & i: l) {
if (!cdp.isEmpty()
#ifndef WINDOWS
|| is_abs
@@ -400,10 +400,10 @@ PIVector<PIFile::FileInfo> PIDir::allEntries() {
PIStringList cdirs, ndirs;
cdirs << path();
while (!cdirs.isEmpty()) {
piForeachC(PIString & d, cdirs) {
for (const auto & d: cdirs) {
scan_ = d;
PIVector<PIFile::FileInfo> el = PIDir(d).entries();
piForeachC(PIFile::FileInfo & de, el) {
for (const auto & de: el) {
if (de.name() == "." || de.name() == "..") continue;
if (de.isSymbolicLink()) continue; /// TODO: resolve symlinks
if (de.isDir()) {

View File

@@ -229,7 +229,7 @@ PIString PIEthernet::macFromBytes(const PIByteArray & mac) {
PIByteArray PIEthernet::macToBytes(const PIString & mac) {
PIByteArray r;
PIStringList sl = mac.split(PIStringAscii(":"));
piForeachC(PIString & i, sl)
for (const auto & i: sl)
r << uchar(i.toInt(16));
return r;
}
@@ -997,7 +997,7 @@ PIString PIEthernet::constructFullPathDevice() const {
ret += ":" + readIP() + ":" + PIString::fromNumber(readPort());
if (type() == PIEthernet::UDP) {
ret += ":" + sendIP() + ":" + PIString::fromNumber(sendPort());
piForeachC(PIString & m, multicastGroups())
for (const auto & m: multicastGroups())
ret += ":mcast:" + m;
}
return ret;
@@ -1067,7 +1067,7 @@ void PIEthernet::configureFromVariantDevice(const PIPropertyStorage & d) {
setSendIP(d.propertyValueByName("send IP").toString());
setSendPort(d.propertyValueByName("send port").toInt());
PIStringList mcgl = d.propertyValueByName("multicast").toStringList();
piForeachC(PIString & g, mcgl) {
for (const auto & g: mcgl) {
joinMulticastGroup(g);
}
}
@@ -1260,8 +1260,8 @@ PIVector<PINetworkAddress> PIEthernet::allAddresses() {
PIEthernet::InterfaceList il = interfaces();
PIVector<PINetworkAddress> ret;
bool has_127 = false;
piForeachC(PIEthernet::Interface & i, il) {
if (i.address == "127.0.0.1") has_127 = true;
for (const auto & i: il) {
if (i.address.startsWith("127.0.0.")) has_127 = true;
PINetworkAddress a(i.address);
if (a.ip() == 0) continue;
ret << a;

View File

@@ -130,7 +130,7 @@ PIPeer::PeerInfo::PeerAddress::PeerAddress(const PINetworkAddress & a, const PIN
int PIPeer::PeerInfo::ping() const {
int ret = -1;
piForeachC(PeerAddress & a, addresses)
for (const auto & a: addresses)
if (a.ping > 0.) {
if (ret < 0)
ret = piRoundd(a.ping);
@@ -155,7 +155,7 @@ void PIPeer::PeerInfo::destroy() {
PINetworkAddress PIPeer::PeerInfo::fastestAddress() const {
double mp = -1.;
PINetworkAddress ret;
piForeachC(PeerAddress & a, addresses) {
for (const auto & a: addresses) {
if (a.ping <= 0.) continue;
if ((mp < 0) || (mp > a.ping)) {
mp = a.ping;
@@ -166,6 +166,27 @@ PINetworkAddress PIPeer::PeerInfo::fastestAddress() const {
}
void PIPeer::PeerInfo::addNeighbour(const PIString & n) {
if (!neighbours.contains(n)) neighbours << n;
}
void PIPeer::PeerInfo::addNeighbours(const PIStringList & l) {
for (const auto & n: l)
if (!neighbours.contains(n)) neighbours << n;
}
void PIPeer::PeerInfo::removeNeighbour(const PIString & n) {
neighbours.removeAll(n);
}
void PIPeer::PeerInfo::resetPing() {
for (auto & a: addresses)
a.ping = -1;
}
REGISTER_DEVICE(PIPeer)
PIPeer::PIPeer(const PIString & n)
@@ -226,7 +247,7 @@ void PIPeer::initEths(PIStringList al) {
// piCoutObj << "initEths start";
PIEthernet * ce;
const PIEthernet::Interface * cint = 0;
piForeachC(PIString & a, al) {
for (const auto & a: al) {
ce = new PIEthernet();
ce->setDebug(false);
ce->setName("_S.PIPeer.traf_rec_" + a);
@@ -261,7 +282,7 @@ void PIPeer::initMBcasts(PIStringList al) {
PIString nm;
al << _PIPEER_MULTICAST_IP;
// piCoutObj << "initMBcasts start" << al;
piForeachC(PIString & a, al) {
for (const auto & a: al) {
// piCout << "mcast try" << a;
ce = new PIEthernet();
ce->setDebug(false);
@@ -282,7 +303,7 @@ void PIPeer::initMBcasts(PIStringList al) {
}
}
al.removeAll(_PIPEER_MULTICAST_IP);
piForeachC(PIString & a, al) {
for (const auto & a: al) {
ce = new PIEthernet();
ce->setDebug(false);
ce->setName("_S.PIPeer.bcast_" + a);
@@ -429,6 +450,42 @@ bool PIPeer::send(const PIString & to, const void * data, int size) {
}
bool PIPeer::send(const PeerInfo * to, const PIByteArray & data) {
if (!to) return false;
return send(to->name, data.data(), data.size_s());
}
bool PIPeer::send(const PeerInfo * to, const PIString & data) {
if (!to) return false;
return send(to->name, data.data(), data.size_s());
}
bool PIPeer::send(const PeerInfo * to, const void * data, int size) {
if (!to) return false;
return send(to->name, data, size);
}
void PIPeer::sendToAll(const PIByteArray & data) {
for (const auto & i: peers)
send(i.name, data.data(), data.size_s());
}
void PIPeer::sendToAll(const PIString & data) {
for (const auto & i: peers)
send(i.name, data.data(), data.size_s());
}
void PIPeer::sendToAll(const void * data, int size) {
for (const auto & i: peers)
send(i.name, data, size);
}
bool PIPeer::sendInternal(const PIString & to, const PIByteArray & data) {
PIMutexLocker mlocker(peers_mutex);
PeerInfo * dp = quickestPeer(to);
@@ -484,7 +541,7 @@ bool PIPeer::dataRead(const uchar * readed, ssize_t size) {
sba << int(6) << to << from << addr << time;
// piCout << " ping from" << from << addr << ", send back to" << pi->name;
send_mutex.lock();
piForeachC(PeerInfo::PeerAddress & a, pi->addresses) {
for (const auto & a: pi->addresses) {
if (eth_send.send(a.address, sba)) diag_s.received(sba.size_s());
}
send_mutex.unlock();
@@ -501,10 +558,10 @@ bool PIPeer::dataRead(const uchar * readed, ssize_t size) {
// piCout << "ping reply" << to << from << addr;
PIMutexLocker plocker(peers_mutex);
if (to == self_info.name) { // ping echo
piForeach(PeerInfo & p, peers) {
for (auto & p: peers) {
if (!p.isNeighbour()) continue;
if (p.name != from) continue;
piForeach(PeerInfo::PeerAddress & a, p.addresses) {
for (auto & a: p.addresses) {
if (a.address != addr) continue;
if (a.last_ping >= time) break;
ptime = ctime - time;
@@ -662,11 +719,11 @@ bool PIPeer::mbcastRead(const uchar * data, ssize_t size) {
}
ch = true;
}
piForeach(PeerInfo & rpeer, rpeers) {
for (auto & rpeer: rpeers) {
// piCout << " to sync " << rpeer.name;
if (rpeer.name == self_info.name) continue;
bool exist = false;
piForeach(PeerInfo & peer, peers) {
for (auto & peer: peers) {
if (peer.name == rpeer.name) {
exist = true;
if (isPeerRecent(peer, rpeer)) {
@@ -706,7 +763,7 @@ bool PIPeer::mbcastRead(const uchar * data, ssize_t size) {
}
// piCout << "***";
// piCout << self_info.name << self_info.neighbours;
piForeach(PeerInfo & i, peers) {
for (auto & i: peers) {
if (i.dist == 0) {
self_info.addNeighbour(i.name);
i.addNeighbour(self_info.name);
@@ -737,11 +794,11 @@ bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
void PIPeer::sendMBcast(const PIByteArray & ba) {
send_mc_mutex.lock();
// piCout << "sendMBcast" << ba.size() << "bytes ...";
piForeach(PIEthernet * e, eths_mcast) {
for (auto * e: eths_mcast) {
if (e->isOpened())
if (e->send(ba)) diag_s.sended(ba.size_s());
}
piForeach(PIEthernet * e, eths_bcast) {
for (auto * e: eths_bcast) {
if (e->isOpened())
if (e->send(ba)) diag_s.sended(ba.size_s());
}
@@ -750,7 +807,7 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
if (eth_lo.send(ba)) diag_s.sended(ba.size_s());
}
PIVector<PIEthernet *> cl = eth_tcp_srv.clients();
piForeach(PIEthernet * e, cl) {
for (auto * e: cl) {
if (e->isOpened() && e->isConnected())
if (e->send(ba)) diag_s.sended(ba.size_s());
}
@@ -763,7 +820,7 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
void PIPeer::removeNeighbour(const PIString & name) {
piForeach(PeerInfo & p, peers)
for (auto & p: peers)
p.neighbours.removeOne(name);
self_info.removeNeighbour(name);
}
@@ -809,11 +866,11 @@ void PIPeer::pingNeighbours() {
PIByteArray ba, sba;
ba << int(5) << self_info.name;
// piCoutObj << "*** pingNeighbours" << peers.size() << "...";
piForeach(PeerInfo & p, peers) {
for (auto & p: peers) {
if (!p.isNeighbour()) continue;
// piCout << " ping neighbour" << p.name << p.ping();
send_mutex.lock();
piForeach(PeerInfo::PeerAddress & a, p.addresses) {
for (auto & a: p.addresses) {
// piCout << " address" << a.address << a.wait_ping;
if (a.wait_ping) {
if ((PISystemTime::current(true) - a.last_ping).abs().toSeconds() <= _PIPEER_PING_TIMEOUT) continue;
@@ -891,7 +948,7 @@ void PIPeer::syncPeers() {
ba << int(3) << self_info.name << self_info << peers;
peers_mutex.unlock();
sendMBcast(ba);
piForeachC(PIString & p, dpeers) {
for (const auto & p: dpeers) {
peerDisconnected(p);
peerDisconnectedEvent(p);
}
@@ -930,6 +987,12 @@ void PIPeer::changeName(const PIString & new_name) {
}
void PIPeer::setTcpServerIP(const PIString & ip) {
server_ip = ip;
tcpClientReconnect();
}
ssize_t PIPeer::bytesAvailable() const {
ssize_t ret = 0;
read_buffer_mutex.lock();
@@ -1054,7 +1117,7 @@ void PIPeer::buildMap() {
// piCout << "[PIPeer \"" + name_ + "\"] buildMap";
peers_map.clear();
addresses_map.clear();
piForeach(PeerInfo & i, peers) {
for (auto & i: peers) {
i.trace = -1;
peers_map[i.name] = &i;
}
@@ -1065,8 +1128,8 @@ void PIPeer::buildMap() {
while (!cwave.isEmpty()) {
nwave.clear();
++cwi;
piForeachC(PeerInfo * p, cwave) {
piForeachC(PIString & nn, p->neighbours) {
for (const auto * p: cwave) {
for (const auto & nn: p->neighbours) {
PeerInfo * np = peers_map.value(nn);
if (!np) continue;
if (np->trace >= 0) continue;
@@ -1077,14 +1140,14 @@ void PIPeer::buildMap() {
cwave = nwave;
}
PIVector<PeerInfo *> cpath;
piForeach(PeerInfo & c, peers) {
for (auto & c: peers) {
cpath.clear();
cpath << &c;
cwave << &c;
for (int w = c.trace - 1; w >= 0; --w) {
nwave.clear();
piForeachC(PeerInfo * p, cwave) {
piForeachC(PIString & nn, p->neighbours) {
for (const auto * p: cwave) {
for (const auto & nn: p->neighbours) {
PeerInfo * np = peers_map.value(nn);
if (!np) continue;
if (np->trace != w) continue;
@@ -1103,3 +1166,10 @@ void PIPeer::buildMap() {
void PIPeer::tcpClientReconnect() {
eth_tcp_cli.connect(server_ip, _PIPEER_TCP_PORT);
}
bool PIPeer::hasPeer(const PIString & name) {
for (const auto & i: peers)
if (i.name == name) return true;
return false;
}

View File

@@ -72,18 +72,10 @@ public:
PINetworkAddress fastestAddress() const;
protected:
void addNeighbour(const PIString & n) {
if (!neighbours.contains(n)) neighbours << n;
}
void addNeighbours(const PIStringList & l) {
piForeachC(PIString & n, l)
if (!neighbours.contains(n)) neighbours << n;
}
void removeNeighbour(const PIString & n) { neighbours.removeAll(n); }
void resetPing() {
for (int i = 0; i < addresses.size_s(); ++i)
addresses[i].ping = -1;
}
void addNeighbour(const PIString & n);
void addNeighbours(const PIStringList & l);
void removeNeighbour(const PIString & n);
void resetPing();
void init();
void destroy();
@@ -101,30 +93,12 @@ public:
bool send(const PeerInfo & to, const PIByteArray & data) { return send(to.name, data.data(), data.size_s()); }
bool send(const PeerInfo & to, const PIString & data) { return send(to.name, data.data(), data.size_s()); }
bool send(const PeerInfo & to, const void * data, int size) { return send(to.name, data, size); }
bool send(const PeerInfo * to, const PIByteArray & data) {
if (to == 0) return false;
return send(to->name, data.data(), data.size_s());
}
bool send(const PeerInfo * to, const PIString & data) {
if (to == 0) return false;
return send(to->name, data.data(), data.size_s());
}
bool send(const PeerInfo * to, const void * data, int size) {
if (to == 0) return false;
return send(to->name, data, size);
}
void sendToAll(const PIByteArray & data) {
piForeachC(PeerInfo & i, peers)
send(i.name, data.data(), data.size_s());
}
void sendToAll(const PIString & data) {
piForeachC(PeerInfo & i, peers)
send(i.name, data.data(), data.size_s());
}
void sendToAll(const void * data, int size) {
piForeachC(PeerInfo & i, peers)
send(i.name, data, size);
}
bool send(const PeerInfo * to, const PIByteArray & data);
bool send(const PeerInfo * to, const PIString & data);
bool send(const PeerInfo * to, const void * data, int size);
void sendToAll(const PIByteArray & data);
void sendToAll(const PIString & data);
void sendToAll(const void * data, int size);
bool isMulticastReceive() const { return !eths_mcast.isEmpty(); }
bool isBroadcastReceive() const { return !eths_bcast.isEmpty(); }
@@ -145,10 +119,7 @@ public:
void changeName(const PIString & new_name);
const PIString & trustPeerName() const { return trust_peer; }
void setTrustPeerName(const PIString & peer_name) { trust_peer = peer_name; }
void setTcpServerIP(const PIString & ip) {
server_ip = ip;
tcpClientReconnect();
}
void setTcpServerIP(const PIString & ip);
ssize_t bytesAvailable() const override;
@@ -180,11 +151,7 @@ private:
EVENT_HANDLER1(void, newTcpClient, PIEthernet *, client);
EVENT_HANDLER(void, tcpClientReconnect);
bool hasPeer(const PIString & name) {
piForeachC(PeerInfo & i, peers)
if (i.name == name) return true;
return false;
}
bool hasPeer(const PIString & name);
bool removePeer(const PIString & name);
void removeNeighbour(const PIString & name);
void addPeer(const PeerInfo & pd);

View File

@@ -685,7 +685,7 @@ bool PISerial::openDevice() {
if (!pl.startsWith("/") && !pl.startsWith("com")) {
p.clear();
PIVector<DeviceInfo> devs = availableDevicesInfo();
piForeachC(DeviceInfo & d, devs) {
for (const auto & d: devs) {
if (d.id() == pl) {
p = d.path;
break;
@@ -1011,7 +1011,7 @@ PIPropertyStorage PISerial::constructVariantDevice() const {
PIVariantTypes::Enum e;
PIVector<int> as = availableSpeeds();
piForeachC(int s, as) {
for (const auto s: as) {
e << PIVariantTypes::Enumerator(s, PIString::fromNumber(s));
}
e.selectValue((int)inSpeed());
@@ -1073,7 +1073,7 @@ PIVector<int> PISerial::availableSpeeds() {
PIStringList PISerial::availableDevices(bool test) {
PIVector<DeviceInfo> devs = availableDevicesInfo(test);
PIStringList ret;
piForeachC(DeviceInfo & d, devs)
for (const auto & d: devs)
ret << d.path;
return ret;
}
@@ -1232,8 +1232,8 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
# ifdef LINUX
char linkbuf[1024];
# endif
piForeachC(PIFile::FileInfo & e, de) { // TODO changes in FileInfo
piForeachC(PIString & p, prefixes) {
for (const auto & e: de) { // TODO changes in FileInfo
for (const auto & p: prefixes) {
if (e.name().startsWith(p)) {
di = DeviceInfo();
di.path = e.path;