simplify GUID printing
This commit is contained in:
+5
-8
@@ -458,10 +458,8 @@ void Context::Pvt::onBeacon(const UDPManager::Beacon& msg)
|
||||
beaconSenders.emplace(msg.src, BTrack{msg.guid, now});
|
||||
}
|
||||
|
||||
log_debug_printf(io, "%s New server %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
|
||||
msg.src.tostring().c_str(),
|
||||
guid[0], guid[1], guid[2], guid[3], guid[4], guid[5], guid[6], guid[7], guid[8], guid[9], guid[10], guid[11],
|
||||
msg.server.tostring().c_str());
|
||||
log_debug_printf(io, "%s\n",
|
||||
std::string(SB()<<msg.src<<" New server "<<guid<<' '<<msg.server).c_str());
|
||||
|
||||
poke(false);
|
||||
}
|
||||
@@ -527,7 +525,7 @@ bool Context::Pvt::onSearch()
|
||||
}
|
||||
|
||||
if(cmd==CMD_SEARCH_RESPONSE) {
|
||||
std::array<uint8_t, 12> guid;
|
||||
ServerGUID guid;
|
||||
SockAddr serv;
|
||||
uint16_t port = 0;
|
||||
uint8_t found = 0u;
|
||||
@@ -787,9 +785,8 @@ void Context::Pvt::tickBeaconClean()
|
||||
|
||||
if(age < -15.0 || age > 2.1*180.0) {
|
||||
auto& guid = cur->second.guid;
|
||||
log_debug_printf(io, "Lost server %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
|
||||
guid[0], guid[1], guid[2], guid[3], guid[4], guid[5], guid[6], guid[7], guid[8], guid[9], guid[10], guid[11],
|
||||
cur->first.tostring().c_str());
|
||||
log_debug_printf(io, "%s\n",
|
||||
std::string(SB()<<" Lost server "<<guid<<' '<<cur->first).c_str());
|
||||
|
||||
beaconSenders.erase(cur);
|
||||
}
|
||||
|
||||
+2
-2
@@ -145,7 +145,7 @@ struct Channel {
|
||||
size_t nSearch = 0u;
|
||||
|
||||
// GUID of last positive reply when state!=Searching
|
||||
std::array<uint8_t, 12> guid;
|
||||
ServerGUID guid;
|
||||
SockAddr replyAddr;
|
||||
|
||||
std::list<std::weak_ptr<OperationBase>> pending;
|
||||
@@ -192,7 +192,7 @@ struct Context::Pvt
|
||||
bool poked = false;
|
||||
|
||||
struct BTrack {
|
||||
std::array<uint8_t, 12> guid;
|
||||
ServerGUID guid;
|
||||
epicsTimeStamp lastRx;
|
||||
};
|
||||
std::map<SockAddr, BTrack> beaconSenders;
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ struct PVXS_API Config {
|
||||
bool auto_beacon = true;
|
||||
|
||||
//! Server unique ID. Only meaningful in readback via Server::config()
|
||||
std::array<uint8_t, 12> guid{};
|
||||
ServerGUID guid{};
|
||||
|
||||
// compat
|
||||
static inline Config from_env() { return Config{}.applyEnv(); }
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define PVXS_UTIL_H
|
||||
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <type_traits>
|
||||
@@ -68,6 +69,11 @@ inline detail::Escaper escape(const char* s,size_t n) {
|
||||
return detail::Escaper(s,n);
|
||||
}
|
||||
|
||||
struct ServerGUID : public std::array<uint8_t, 12> {};
|
||||
|
||||
PVXS_API
|
||||
std::ostream& operator<<(std::ostream&, const ServerGUID&);
|
||||
|
||||
#if !defined(__rtems__) && !defined(vxWorks)
|
||||
|
||||
/** Minimal portable process signal handling in CLI tools.
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ struct PVXS_API UDPManager
|
||||
struct Beacon {
|
||||
SockAddr& src;
|
||||
SockAddr server;
|
||||
std::array<uint8_t, 12> guid;
|
||||
ServerGUID guid;
|
||||
Beacon(SockAddr& src) :src(src) {}
|
||||
};
|
||||
//! Create subscription for Beacon messages.
|
||||
|
||||
@@ -253,6 +253,16 @@ std::ostream& operator<<(std::ostream& strm, const Escaper& esc)
|
||||
|
||||
} // namespace detail
|
||||
|
||||
std::ostream& operator<<(std::ostream& strm, const ServerGUID& guid)
|
||||
{
|
||||
Restore R(strm);
|
||||
strm.width(2);
|
||||
strm<<"0x"<<std::hex<<std::setfill('0');
|
||||
for(size_t i=0; i<guid.size(); i++)
|
||||
strm<<std::setw(2)<<unsigned(guid[i]);
|
||||
return strm;
|
||||
}
|
||||
|
||||
#if !defined(__rtems__) && !defined(vxWorks)
|
||||
|
||||
static
|
||||
|
||||
@@ -251,6 +251,25 @@ public:
|
||||
PVXS_API
|
||||
std::ostream& operator<<(std::ostream& strm, const SockAddr& addr);
|
||||
|
||||
//! Scoped restore of std::ostream state (format flags, fill char, and field width)
|
||||
struct Restore {
|
||||
std::ostream& strm;
|
||||
std::ios_base::fmtflags pflags;
|
||||
std::ostream::char_type pfill;
|
||||
std::streamsize pwidth;
|
||||
Restore(std::ostream& strm)
|
||||
:strm(strm)
|
||||
,pflags(strm.flags())
|
||||
,pfill(strm.fill())
|
||||
,pwidth(strm.width())
|
||||
{}
|
||||
~Restore() {
|
||||
strm.flags(pflags);
|
||||
strm.fill(pfill);
|
||||
strm.width(pwidth);
|
||||
}
|
||||
};
|
||||
|
||||
template<std::atomic<size_t>* Cnt>
|
||||
struct InstCounter
|
||||
{
|
||||
|
||||
+2
-4
@@ -232,10 +232,8 @@ int main(int argc, char *argv[])
|
||||
return;
|
||||
|
||||
const auto& guid = msg.guid;
|
||||
log_info_printf(out, "%s Beacon %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
|
||||
msg.src.tostring().c_str(),
|
||||
guid[0], guid[1], guid[2], guid[3], guid[4], guid[5], guid[6], guid[7], guid[8], guid[9], guid[10], guid[11],
|
||||
msg.server.tostring().c_str());
|
||||
log_debug_printf(out, "%s\n",
|
||||
std::string(pva::impl::SB()<<msg.src<<" Beacon "<<guid<<' '<<msg.server).c_str());
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user