From bd7ba0db624b42cfd59fb84bafa5198ff3f113fc Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 20 Jan 2021 09:12:52 -0800 Subject: [PATCH] simplify GUID printing --- src/client.cpp | 13 +++++-------- src/clientimpl.h | 4 ++-- src/pvxs/server.h | 2 +- src/pvxs/util.h | 6 ++++++ src/udp_collector.h | 2 +- src/util.cpp | 10 ++++++++++ src/utilpvt.h | 19 +++++++++++++++++++ tools/pvxvct.cpp | 6 ++---- 8 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 4423034..42b7020 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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()< 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 "<first).c_str()); beaconSenders.erase(cur); } diff --git a/src/clientimpl.h b/src/clientimpl.h index 17a9c88..38b971c 100644 --- a/src/clientimpl.h +++ b/src/clientimpl.h @@ -145,7 +145,7 @@ struct Channel { size_t nSearch = 0u; // GUID of last positive reply when state!=Searching - std::array guid; + ServerGUID guid; SockAddr replyAddr; std::list> pending; @@ -192,7 +192,7 @@ struct Context::Pvt bool poked = false; struct BTrack { - std::array guid; + ServerGUID guid; epicsTimeStamp lastRx; }; std::map beaconSenders; diff --git a/src/pvxs/server.h b/src/pvxs/server.h index 6176d56..f479fc8 100644 --- a/src/pvxs/server.h +++ b/src/pvxs/server.h @@ -145,7 +145,7 @@ struct PVXS_API Config { bool auto_beacon = true; //! Server unique ID. Only meaningful in readback via Server::config() - std::array guid{}; + ServerGUID guid{}; // compat static inline Config from_env() { return Config{}.applyEnv(); } diff --git a/src/pvxs/util.h b/src/pvxs/util.h index da30770..92acf9d 100644 --- a/src/pvxs/util.h +++ b/src/pvxs/util.h @@ -8,6 +8,7 @@ #define PVXS_UTIL_H #include +#include #include #include #include @@ -68,6 +69,11 @@ inline detail::Escaper escape(const char* s,size_t n) { return detail::Escaper(s,n); } +struct ServerGUID : public std::array {}; + +PVXS_API +std::ostream& operator<<(std::ostream&, const ServerGUID&); + #if !defined(__rtems__) && !defined(vxWorks) /** Minimal portable process signal handling in CLI tools. diff --git a/src/udp_collector.h b/src/udp_collector.h index f90fcd4..f9437f2 100644 --- a/src/udp_collector.h +++ b/src/udp_collector.h @@ -36,7 +36,7 @@ struct PVXS_API UDPManager struct Beacon { SockAddr& src; SockAddr server; - std::array guid; + ServerGUID guid; Beacon(SockAddr& src) :src(src) {} }; //! Create subscription for Beacon messages. diff --git a/src/util.cpp b/src/util.cpp index 08f31e6..336ad80 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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"<* Cnt> struct InstCounter { diff --git a/tools/pvxvct.cpp b/tools/pvxvct.cpp index 0c8c559..608d4e9 100644 --- a/tools/pvxvct.cpp +++ b/tools/pvxvct.cpp @@ -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()<