client.h std::ostream printing

This commit is contained in:
Michael Davidsaver
2018-04-10 15:44:18 -07:00
parent 0d40464541
commit 61d43e498d
5 changed files with 90 additions and 0 deletions

View File

@@ -3,6 +3,8 @@
* found in the file LICENSE that is included with the distribution
*/
#include <typeinfo>
#include <epicsMutex.h>
#include <epicsGuard.h>
#include <epicsEvent.h>
@@ -197,6 +199,17 @@ void ClientChannel::removeConnectListener(ConnectCallback* cb)
}
}
void ClientChannel::show(std::ostream& strm) const
{
if(impl) {
strm<<typeid(*impl->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()<<", "
"\""<<op.impl->provider->getProviderName()<<"\")";
} else {
strm << "ClientProvider()";
}
return strm;
}
namespace detail {
void registerRefTrack()

View File

@@ -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;

View File

@@ -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()

View File

@@ -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;

View File

@@ -5,6 +5,7 @@
#ifndef PVATESTCLIENT_H
#define PVATESTCLIENT_H
#include <ostream>
#include <stdexcept>
#include <list>
@@ -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> impl;
};
@@ -161,6 +164,7 @@ public:
private:
std::tr1::shared_ptr<Impl> impl;
friend ::std::ostream& operator<<(::std::ostream& strm, const Monitor& op);
friend struct MonitorSync;
};
@@ -246,6 +250,7 @@ private:
std::tr1::shared_ptr<Impl> impl;
friend class ClientProvider;
friend void detail::registerRefTrack();
friend ::std::ostream& operator<<(::std::ostream& strm, const ClientChannel& op);
ClientChannel(const std::tr1::shared_ptr<Impl>& 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<epics::pvAccess::Channel> getChannel();
};
@@ -460,6 +466,7 @@ class epicsShareClass ClientProvider
struct Impl;
std::tr1::shared_ptr<Impl> 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