From 63912a017acf3e3186dfaaecd0076e08b079110d Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 24 Jul 2020 19:12:17 -0700 Subject: [PATCH] add operator<< for Server --- src/pvxs/server.h | 7 +++ src/pvxs/source.h | 2 + src/server.cpp | 107 +++++++++++++++++++++++++++++++++++++++ src/serverconn.h | 2 + src/serverget.cpp | 13 +++++ src/serverintrospect.cpp | 5 ++ src/servermon.cpp | 5 ++ src/sharedpv.cpp | 13 ++++- 8 files changed, 153 insertions(+), 1 deletion(-) diff --git a/src/pvxs/server.h b/src/pvxs/server.h index e603f71..4de9b84 100644 --- a/src/pvxs/server.h +++ b/src/pvxs/server.h @@ -107,11 +107,18 @@ public: explicit operator bool() const { return !!pvt; } + friend + PVXS_API + std::ostream& operator<<(std::ostream& strm, const Server& serv); + struct Pvt; private: std::shared_ptr pvt; }; +PVXS_API +std::ostream& operator<<(std::ostream& strm, const Server& serv); + //! Configuration for a Server struct PVXS_API Config { //! List of network interface addresses (**not** host names) to which this server will bind. diff --git a/src/pvxs/source.h b/src/pvxs/source.h index 6b99c84..3eff171 100644 --- a/src/pvxs/source.h +++ b/src/pvxs/source.h @@ -228,6 +228,8 @@ struct PVXS_API Source { /** A Client is requesting a list of Channel names which we may claim. */ virtual List onList(); + + virtual void show(std::ostream& strm); }; }} // namespace pvxs::server diff --git a/src/server.cpp b/src/server.cpp index 14d8e25..a953dd6 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -219,6 +219,101 @@ Server& Server::interrupt() return *this; } +std::ostream& operator<<(std::ostream& strm, const Server& serv) +{ + auto detail = Detailed::level(strm); + + if(!serv.pvt) { + strm<sourcesLock.lockReader()); + + for(auto& pair : serv.pvt->sources) { + strm<0) { + Indented I(strm); + Detailed D(strm, detail-1); + pair.second->show(strm); + } + strm<<"\n"; + } + } + + if(detail<2) + return strm; + + serv.pvt->acceptor_loop.call([&serv, &strm, detail](){ + strm<state) { +#define CASE(STATE) case Server::Pvt::STATE: strm<< #STATE; break + CASE(Stopped); + CASE(Starting); + CASE(Running); + CASE(Stopping); +#undef CASE + } + strm<<"\n"; + + Indented I(strm); + + for(auto& pair : serv.pvt->connections) { + auto conn = pair.first; + + strm<peerName + <<" backlog="<backlog.size() + <<" auth="<autoMethod<<"\n"; + if(detail>2) + strm<credentials; + + if(detail<=2) + continue; + + Indented I(strm); + + for(auto& pair : conn->chanBySID) { + auto& chan = pair.second; + + if(chan->state==ServerChan::Creating) { + strm<state==ServerChan::Destroy) { + strm<opByIOID.empty()) { + strm<opByIOID) { + auto& op = pair.second; + if(!op) { + strm<state) { +#define CASE(STATE) case ServerOp::STATE: strm<< #STATE; break + CASE(Creating); + CASE(Idle); + CASE(Executing); + CASE(Dead); +#undef CASE + } + strm<<" ioid="<show(strm); + } + } + } + } + }); + } + + return strm; +} + Server::Pvt::Pvt(const Config &conf) :effective(conf) ,beaconMsg(128) @@ -565,6 +660,18 @@ Source::List Source::onList() { return Source::List{}; } +void Source::show(std::ostream& strm) +{ + auto list(onList()); + strm<<(list.dynamic ? "Dynamic":"")<<"Source"; + Indented I(strm); + if(list.names) { + for(auto& name : *list.names) { + strm<<"\n"<opByIOID.erase(ioid); } + void show(std::ostream& strm) const override final + { + strm<<"INFO\n"; + } + INST_COUNTER(ServerIntrospect); }; diff --git a/src/servermon.cpp b/src/servermon.cpp index 1d37030..c56c164 100644 --- a/src/servermon.cpp +++ b/src/servermon.cpp @@ -195,6 +195,11 @@ struct MonitorOp : public ServerOp, scheduled = true; } } + + void show(std::ostream& strm) const override final + { + strm<<"MONITOR\n"; + } }; struct ServerMonitorSetup; diff --git a/src/sharedpv.cpp b/src/sharedpv.cpp index 52fbd76..77354ad 100644 --- a/src/sharedpv.cpp +++ b/src/sharedpv.cpp @@ -441,7 +441,7 @@ Value SharedPV::fetch() const struct StaticSource::Impl : public Source { - RWLock lock; + mutable RWLock lock; list_t pvs; decltype (List::names) list; @@ -488,6 +488,17 @@ struct StaticSource::Impl : public Source return ret; } + + virtual void show(std::ostream& strm) override final + { + strm<<"StaticProvider"; + + auto G(lock.lockReader()); + for(auto& pair : pvs) { + strm<<"\n"<