From 61d43e498d417f52cf09f22f67fc18aa72b32f81 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 10 Apr 2018 15:44:18 -0700 Subject: [PATCH] client.h std::ostream printing --- src/client/client.cpp | 50 ++++++++++++++++++++++++++++++++++++ src/client/clientGet.cpp | 7 +++++ src/client/clientMonitor.cpp | 14 ++++++++++ src/client/clientRPC.cpp | 7 +++++ src/client/pva/client.h | 12 +++++++++ 5 files changed, 90 insertions(+) diff --git a/src/client/client.cpp b/src/client/client.cpp index e797f1d..75d95cb 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -3,6 +3,8 @@ * found in the file LICENSE that is included with the distribution */ +#include + #include #include #include @@ -197,6 +199,17 @@ void ClientChannel::removeConnectListener(ConnectCallback* cb) } } + +void ClientChannel::show(std::ostream& strm) const +{ + if(impl) { + strm<channel.get()).name()<<" : "; + impl->channel->printInfo(strm); + } else { + strm<<"NULL Channel"; + } +} + static void register_reftrack() { @@ -305,6 +318,43 @@ void ClientProvider::disconnect() impl->channels.clear(); } +::std::ostream& operator<<(::std::ostream& strm, const Operation& op) +{ + if(op.impl) { + op.impl->show(strm); + } else { + strm << "Operation()"; + } + return strm; +} + +::std::ostream& operator<<(::std::ostream& strm, const ClientChannel& op) +{ + if(op.impl) { + strm << "ClientChannel(" + << typeid(*op.impl->channel.get()).name()<<", " + "\"" << op.impl->channel->getChannelName() <<"\", " + "\"" << op.impl->channel->getProvider()->getProviderName() <<"\", " + "connected="<<(op.impl->channel->isConnected()?"true":"false") + <<"\")"; + } else { + strm << "ClientChannel()"; + } + return strm; +} + +::std::ostream& operator<<(::std::ostream& strm, const ClientProvider& op) +{ + if(op.impl) { + strm << "ClientProvider(" + << typeid(*op.impl->provider.get()).name()<<", " + "\""<provider->getProviderName()<<"\")"; + } else { + strm << "ClientProvider()"; + } + return strm; +} + namespace detail { void registerRefTrack() diff --git a/src/client/clientGet.cpp b/src/client/clientGet.cpp index 0790a02..54051fd 100644 --- a/src/client/clientGet.cpp +++ b/src/client/clientGet.cpp @@ -177,6 +177,13 @@ struct GetPutter : public pva::ChannelPutRequester, callEvent(G, status.isSuccess()? pvac::GetEvent::Success : pvac::GetEvent::Fail); } + + virtual void show(std::ostream &strm) const + { + strm << "Operation(Get/Put" + "\"" << name() <<"\"" + ")"; + } }; size_t GetPutter::num_instances; diff --git a/src/client/clientMonitor.cpp b/src/client/clientMonitor.cpp index 8b7debd..6e19abe 100644 --- a/src/client/clientMonitor.cpp +++ b/src/client/clientMonitor.cpp @@ -248,6 +248,20 @@ ClientChannel::monitor(MonitorCallback *cb, return Monitor(ret); } +::std::ostream& operator<<(::std::ostream& strm, const Monitor& op) +{ + if(op.impl) { + strm << "Monitor(" + "\"" << op.impl->chan->getChannelName() <<"\", " + "\"" << op.impl->chan->getProvider()->getProviderName() <<"\", " + "connected="<<(op.impl->chan->isConnected()?"true":"false") + <<"\")"; + } else { + strm << "Monitor()"; + } + return strm; +} + namespace detail { void registerRefTrackMonitor() diff --git a/src/client/clientRPC.cpp b/src/client/clientRPC.cpp index 9400961..5028586 100644 --- a/src/client/clientRPC.cpp +++ b/src/client/clientRPC.cpp @@ -140,6 +140,13 @@ struct RPCer : public pva::ChannelRPCRequester, callEvent(G, status.isSuccess()? pvac::GetEvent::Success : pvac::GetEvent::Fail); } + + virtual void show(std::ostream &strm) const + { + strm << "Operation(RPC" + "\"" << name() <<"\"" + ")"; + } }; size_t RPCer::num_instances; diff --git a/src/client/pva/client.h b/src/client/pva/client.h index f4a40a7..bc2d88d 100644 --- a/src/client/pva/client.h +++ b/src/client/pva/client.h @@ -5,6 +5,7 @@ #ifndef PVATESTCLIENT_H #define PVATESTCLIENT_H +#include #include #include @@ -53,6 +54,7 @@ struct epicsShareClass Operation virtual ~Impl() {} virtual std::string name() const =0; virtual void cancel() =0; + virtual void show(std::ostream&) const =0; }; Operation() {} @@ -78,6 +80,7 @@ public: void reset() { impl.reset(); } protected: + friend ::std::ostream& operator<<(::std::ostream& strm, const Operation& op); std::tr1::shared_ptr impl; }; @@ -161,6 +164,7 @@ public: private: std::tr1::shared_ptr impl; + friend ::std::ostream& operator<<(::std::ostream& strm, const Monitor& op); friend struct MonitorSync; }; @@ -246,6 +250,7 @@ private: std::tr1::shared_ptr impl; friend class ClientProvider; friend void detail::registerRefTrack(); + friend ::std::ostream& operator<<(::std::ostream& strm, const ClientChannel& op); ClientChannel(const std::tr1::shared_ptr& i) :impl(i) {} public: @@ -397,6 +402,7 @@ public: //! Remove from list of listeners void removeConnectListener(ConnectCallback*); + void show(std::ostream& strm) const; private: std::tr1::shared_ptr getChannel(); }; @@ -460,6 +466,7 @@ class epicsShareClass ClientProvider struct Impl; std::tr1::shared_ptr impl; friend void detail::registerRefTrack(); + friend ::std::ostream& operator<<(::std::ostream& strm, const ClientProvider& op); public: /** Use named provider. @@ -512,6 +519,11 @@ ClientChannel::put(const epics::pvData::PVStructure::const_shared_pointer& pvReq return detail::PutBuilder(*this, pvRequest); } +epicsShareExtern ::std::ostream& operator<<(::std::ostream& strm, const Operation& op); +epicsShareExtern ::std::ostream& operator<<(::std::ostream& strm, const Monitor& op); +epicsShareExtern ::std::ostream& operator<<(::std::ostream& strm, const ClientChannel& op); +epicsShareExtern ::std::ostream& operator<<(::std::ostream& strm, const ClientProvider& op); + //! @} }//namespace pvac