consolidate TransportClient and ChannelImpl as ClientChannelImpl

This commit is contained in:
Michael Davidsaver
2017-11-06 15:51:43 -06:00
parent 7118e34222
commit 576b241faa
11 changed files with 71 additions and 99 deletions

View File

@@ -68,7 +68,7 @@ SOCKET BlockingTCPConnector::tryConnect(osiSockAddr& address, int tries) {
return INVALID_SOCKET;
}
Transport::shared_pointer BlockingTCPConnector::connect(TransportClient::shared_pointer const & client,
Transport::shared_pointer BlockingTCPConnector::connect(std::tr1::shared_ptr<ClientChannelImpl> const & client,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& address,
int8 transportRevision, int16 priority) {

View File

@@ -35,7 +35,7 @@ struct closer {
namespace epics {
namespace pvAccess {
Transport::shared_pointer BlockingUDPConnector::connect(TransportClient::shared_pointer const & /*client*/,
Transport::shared_pointer BlockingUDPConnector::connect(std::tr1::shared_ptr<ClientChannelImpl> const & /*client*/,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& bindAddress,
int8 transportRevision, int16 /*priority*/) {

View File

@@ -558,7 +558,7 @@ void initializeUDPTransports(bool serverFlag,
const std::string& addressList,
const std::string& ignoreAddressList)
{
TransportClient::shared_pointer nullTransportClient;
std::tr1::shared_ptr<ClientChannelImpl> nullTransportClient;
epics::auto_ptr<BlockingUDPConnector> connector(new BlockingUDPConnector(serverFlag, true, true));
//

View File

@@ -40,6 +40,7 @@
#include <pv/codec.h>
#include <pv/serializationHelper.h>
#include <pv/serverChannelImpl.h>
#include <pv/clientContextImpl.h>
using namespace std;
using namespace epics::pvData;
@@ -1671,7 +1672,7 @@ BlockingClientTCPTransportCodec::BlockingClientTCPTransportCodec(
ResponseHandler::shared_pointer const & responseHandler,
int32_t sendBufferSize,
int32_t receiveBufferSize,
TransportClient::shared_pointer const & client,
ClientChannelImpl::shared_pointer const & client,
epics::pvData::int8 /*remoteTransportRevision*/,
float heartbeatInterval,
int16_t priority ) :
@@ -1740,7 +1741,7 @@ void BlockingClientTCPTransportCodec::unresponsiveTransport() {
TransportClientMap_t::iterator it = _owners.begin();
for(; it!=_owners.end(); it++) {
TransportClient::shared_pointer client = it->second.lock();
ClientChannelImpl::shared_pointer client = it->second.lock();
if (client)
{
EXCEPTION_GUARD(client->transportUnresponsive());
@@ -1749,7 +1750,7 @@ void BlockingClientTCPTransportCodec::unresponsiveTransport() {
}
}
bool BlockingClientTCPTransportCodec::acquire(TransportClient::shared_pointer const & client) {
bool BlockingClientTCPTransportCodec::acquire(ClientChannelImpl::shared_pointer const & client) {
Lock lock(_mutex);
if(isClosed()) return false;
@@ -1758,8 +1759,8 @@ bool BlockingClientTCPTransportCodec::acquire(TransportClient::shared_pointer co
LOG(logLevelDebug, "Acquiring transport to %s.", _socketName.c_str());
}
_owners[client->getID()] = TransportClient::weak_pointer(client);
//_owners.insert(TransportClient::weak_pointer(client));
_owners[client->getID()] = ClientChannelImpl::weak_pointer(client);
//_owners.insert(ClientChannelImpl::weak_pointer(client));
return true;
}
@@ -1798,7 +1799,7 @@ void BlockingClientTCPTransportCodec::closedNotifyClients() {
TransportClientMap_t::iterator it = _owners.begin();
for(; it!=_owners.end(); it++) {
TransportClient::shared_pointer client = it->second.lock();
ClientChannelImpl::shared_pointer client = it->second.lock();
if (client)
{
EXCEPTION_GUARD(client->transportClosed());
@@ -1810,7 +1811,7 @@ void BlockingClientTCPTransportCodec::closedNotifyClients() {
_owners.clear();
}
//void BlockingClientTCPTransportCodec::release(TransportClient::shared_pointer const & client) {
//void BlockingClientTCPTransportCodec::release(ClientChannelImpl::shared_pointer const & client) {
void BlockingClientTCPTransportCodec::release(pvAccessID clientID) {
Lock lock(_mutex);
if(isClosed()) return;
@@ -1821,7 +1822,7 @@ void BlockingClientTCPTransportCodec::release(pvAccessID clientID) {
}
_owners.erase(clientID);
//_owners.erase(TransportClient::weak_pointer(client));
//_owners.erase(ClientChannelImpl::weak_pointer(client));
// not used anymore, close it
// TODO consider delayed destruction (can improve performance!!!)
@@ -1845,7 +1846,7 @@ void BlockingClientTCPTransportCodec::responsiveTransport() {
Transport::shared_pointer thisSharedPtr = shared_from_this();
TransportClientMap_t::iterator it = _owners.begin();
for(; it!=_owners.end(); it++) {
TransportClient::shared_pointer client = it->second.lock();
ClientChannelImpl::shared_pointer client = it->second.lock();
if (client)
{
EXCEPTION_GUARD(client->transportResponsive(thisSharedPtr));
@@ -1860,7 +1861,7 @@ void BlockingClientTCPTransportCodec::changedTransport() {
Lock lock(_mutex);
TransportClientMap_t::iterator it = _owners.begin();
for(; it!=_owners.end(); it++) {
TransportClient::shared_pointer client = it->second.lock();
ClientChannelImpl::shared_pointer client = it->second.lock();
if (client)
{
EXCEPTION_GUARD(client->transportChanged());

View File

@@ -42,6 +42,8 @@
namespace epics {
namespace pvAccess {
class ClientChannelImpl;
/**
* Channel Access TCP connector.
* @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
@@ -56,7 +58,7 @@ public:
virtual ~BlockingTCPConnector();
virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client,
virtual Transport::shared_pointer connect(std::tr1::shared_ptr<ClientChannelImpl> const & client,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& address,
epics::pvData::int8 transportRevision, epics::pvData::int16 priority);
private:

View File

@@ -36,6 +36,7 @@
namespace epics {
namespace pvAccess {
class ClientChannelImpl;
class BlockingUDPConnector;
enum InetAddressType { inetAddressType_all, inetAddressType_unicast, inetAddressType_broadcast_multicast };
@@ -238,7 +239,7 @@ public:
return epics::pvData::getFieldCreate()->deserialize(buffer, this);
}
virtual bool acquire(std::tr1::shared_ptr<TransportClient> const & /*client*/)
virtual bool acquire(std::tr1::shared_ptr<ClientChannelImpl> const & /*client*/)
{
return false;
}
@@ -447,7 +448,7 @@ public:
/**
* NOTE: transport client is ignored for broadcast (UDP).
*/
virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client,
virtual Transport::shared_pointer connect(std::tr1::shared_ptr<ClientChannelImpl> const & client,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& bindAddress,
epics::pvData::int8 transportRevision, epics::pvData::int16 priority);

View File

@@ -528,7 +528,7 @@ public:
public:
virtual bool acquire(std::tr1::shared_ptr<TransportClient> const & /*client*/) OVERRIDE FINAL
virtual bool acquire(std::tr1::shared_ptr<ClientChannelImpl> const & /*client*/) OVERRIDE FINAL
{
return false;
}
@@ -633,7 +633,7 @@ protected:
ResponseHandler::shared_pointer const & responseHandler,
int32_t sendBufferSize,
int32_t receiveBufferSize,
TransportClient::shared_pointer const & client,
std::tr1::shared_ptr<ClientChannelImpl> const & client,
epics::pvData::int8 remoteTransportRevision,
float heartbeatInterval,
int16_t priority);
@@ -645,7 +645,7 @@ public:
ResponseHandler::shared_pointer const & responseHandler,
int32_t sendBufferSize,
int32_t receiveBufferSize,
TransportClient::shared_pointer const & client,
std::tr1::shared_ptr<ClientChannelImpl> const & client,
int8_t remoteTransportRevision,
float heartbeatInterval,
int16_t priority )
@@ -673,7 +673,7 @@ public:
virtual void callback() OVERRIDE FINAL;
virtual bool acquire(TransportClient::shared_pointer const & client) OVERRIDE FINAL;
virtual bool acquire(std::tr1::shared_ptr<ClientChannelImpl> const & client) OVERRIDE FINAL;
virtual void release(pvAccessID clientId) OVERRIDE FINAL;
@@ -699,7 +699,7 @@ private:
* Owners (users) of the transport.
*/
// TODO consider using TR1 hash map
typedef std::map<pvAccessID, TransportClient::weak_pointer> TransportClientMap_t;
typedef std::map<pvAccessID, std::tr1::weak_ptr<ClientChannelImpl> > TransportClientMap_t;
TransportClientMap_t _owners;
/**

View File

@@ -41,6 +41,7 @@ namespace epics {
namespace pvAccess {
class TransportRegistry;
class ClientChannelImpl;
enum QoS {
/**
@@ -150,7 +151,7 @@ public:
virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) = 0;
};
class TransportClient;
class ClientChannelImpl;
class SecuritySession;
/**
@@ -167,15 +168,15 @@ public:
* @param client client (channel) acquiring the transport
* @return <code>true</code> if transport was granted, <code>false</code> otherwise.
*/
//virtual bool acquire(TransportClient::shared_pointer const & client) = 0;
virtual bool acquire(std::tr1::shared_ptr<TransportClient> const & client) = 0;
//virtual bool acquire(ClientChannelImpl::shared_pointer const & client) = 0;
virtual bool acquire(std::tr1::shared_ptr<ClientChannelImpl> const & client) = 0;
/**
* Releases transport.
* @param client client (channel) releasing the transport
*/
virtual void release(pvAccessID clientId) = 0;
//virtual void release(TransportClient::shared_pointer const & client) = 0;
//virtual void release(ClientChannelImpl::shared_pointer const & client) = 0;
/**
* Get protocol type (tcp, udp, ssl, etc.).
@@ -376,43 +377,6 @@ protected:
epics::pvData::int32 _debugLevel;
};
/**
* Client (user) of the transport.
*/
class TransportClient {
public:
POINTER_DEFINITIONS(TransportClient);
virtual ~TransportClient() {
}
// ID used to allow fast/efficient lookup
virtual pvAccessID getID() = 0;
/**
* Notification of unresponsive transport (e.g. no heartbeat detected) .
*/
virtual void transportUnresponsive() = 0;
/**
* Notification of responsive transport (e.g. heartbeat detected again),
* called to discard <code>transportUnresponsive</code> notification.
* @param transport responsive transport.
*/
virtual void transportResponsive(Transport::shared_pointer const & transport) = 0;
/**
* Notification of network change (server restarted).
*/
virtual void transportChanged() = 0;
/**
* Notification of forcefully closed transport.
*/
virtual void transportClosed() = 0;
};
/**
* Interface defining socket connector (Connector-Transport pattern).
*/
@@ -429,7 +393,7 @@ public:
* @param[in] priority process priority.
* @return transport instance.
*/
virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client,
virtual Transport::shared_pointer connect(std::tr1::shared_ptr<ClientChannelImpl> const & client,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& address,
epics::pvData::int8 transportRevision, epics::pvData::int16 priority) = 0;

View File

@@ -48,9 +48,9 @@ using namespace epics::pvData;
namespace epics {
namespace pvAccess {
Status ChannelImpl::channelDestroyed(
Status ClientChannelImpl::channelDestroyed(
Status::STATUSTYPE_WARNING, "channel destroyed");
Status ChannelImpl::channelDisconnected(
Status ClientChannelImpl::channelDisconnected(
Status::STATUSTYPE_WARNING, "channel disconnected");
string emptyString;
@@ -125,7 +125,7 @@ public:
protected:
ChannelImpl::shared_pointer m_channel;
ClientChannelImpl::shared_pointer m_channel;
/* negative... */
static const int NULL_REQUEST = -1;
@@ -172,7 +172,7 @@ public:
template<class subklass>
static
typename std::tr1::shared_ptr<subklass>
build(ChannelImpl::shared_pointer const & channel,
build(ClientChannelImpl::shared_pointer const & channel,
const typename subklass::requester_type::shared_pointer& requester,
const epics::pvData::PVStructure::shared_pointer& pvRequest)
{
@@ -195,7 +195,7 @@ protected:
AtomicBoolean m_subscribed;
BaseRequestImpl(ChannelImpl::shared_pointer const & channel) :
BaseRequestImpl(ClientChannelImpl::shared_pointer const & channel) :
m_channel(channel),
m_ioid(INVALID_IOID),
m_pendingRequest(NULL_REQUEST),
@@ -430,7 +430,7 @@ public:
requester_type::weak_pointer m_callback;
PVStructure::shared_pointer m_pvRequest;
ChannelProcessRequestImpl(ChannelImpl::shared_pointer const & channel, ChannelProcessRequester::shared_pointer const & callback, PVStructure::shared_pointer const & pvRequest) :
ChannelProcessRequestImpl(ClientChannelImpl::shared_pointer const & channel, ChannelProcessRequester::shared_pointer const & callback, PVStructure::shared_pointer const & pvRequest) :
BaseRequestImpl(channel),
m_callback(callback),
m_pvRequest(pvRequest)
@@ -560,7 +560,7 @@ public:
Mutex m_structureMutex;
ChannelGetImpl(ChannelImpl::shared_pointer const & channel,
ChannelGetImpl(ClientChannelImpl::shared_pointer const & channel,
ChannelGetRequester::shared_pointer const & requester,
PVStructure::shared_pointer const & pvRequest) :
BaseRequestImpl(channel),
@@ -750,7 +750,7 @@ public:
Mutex m_structureMutex;
ChannelPutImpl(ChannelImpl::shared_pointer const & channel,
ChannelPutImpl(ClientChannelImpl::shared_pointer const & channel,
ChannelPutRequester::shared_pointer const & requester,
PVStructure::shared_pointer const & pvRequest) :
BaseRequestImpl(channel),
@@ -995,7 +995,7 @@ public:
Mutex m_structureMutex;
ChannelPutGetImpl(ChannelImpl::shared_pointer const & channel,
ChannelPutGetImpl(ClientChannelImpl::shared_pointer const & channel,
ChannelPutGetRequester::shared_pointer const & requester,
PVStructure::shared_pointer const & pvRequest) :
BaseRequestImpl(channel),
@@ -1301,7 +1301,7 @@ public:
Mutex m_structureMutex;
ChannelRPCImpl(ChannelImpl::shared_pointer const & channel,
ChannelRPCImpl(ClientChannelImpl::shared_pointer const & channel,
ChannelRPCRequester::shared_pointer const & requester,
PVStructure::shared_pointer const & pvRequest) :
BaseRequestImpl(channel),
@@ -1488,7 +1488,7 @@ public:
Mutex m_structureMutex;
ChannelArrayImpl(ChannelImpl::shared_pointer const & channel,
ChannelArrayImpl(ClientChannelImpl::shared_pointer const & channel,
ChannelArrayRequester::shared_pointer const & requester,
PVStructure::shared_pointer const & pvRequest) :
BaseRequestImpl(channel),
@@ -1853,7 +1853,7 @@ private:
bool m_reportQueueStateInProgress;
// TODO check for cyclic-ref
ChannelImpl::shared_pointer m_channel;
ClientChannelImpl::shared_pointer m_channel;
pvAccessID m_ioid;
bool m_pipeline;
@@ -1863,7 +1863,7 @@ private:
public:
MonitorStrategyQueue(ChannelImpl::shared_pointer channel, pvAccessID ioid,
MonitorStrategyQueue(ClientChannelImpl::shared_pointer channel, pvAccessID ioid,
MonitorRequester::weak_pointer const & callback,
int32 queueSize,
bool pipeline, int32 ackAny) :
@@ -2133,7 +2133,7 @@ public:
int32 m_ackAny;
ChannelMonitorImpl(
ChannelImpl::shared_pointer const & channel,
ClientChannelImpl::shared_pointer const & channel,
MonitorRequester::shared_pointer const & requester,
PVStructure::shared_pointer const & pvRequest)
:
@@ -2885,7 +2885,7 @@ public:
status.deserialize(payloadBuffer, transport.get());
// TODO optimize
ChannelImpl::shared_pointer channel = static_pointer_cast<ChannelImpl>(_context.lock()->getChannel(cid));
ClientChannelImpl::shared_pointer channel = static_pointer_cast<ClientChannelImpl>(_context.lock()->getChannel(cid));
if (channel.get())
{
// failed check
@@ -2934,7 +2934,7 @@ public:
/*pvAccessID sid =*/ payloadBuffer->getInt();
// TODO optimize
ChannelImpl::shared_pointer channel = static_pointer_cast<ChannelImpl>(_context.lock()->getChannel(cid));
ClientChannelImpl::shared_pointer channel = static_pointer_cast<ClientChannelImpl>(_context.lock()->getChannel(cid));
if (channel.get())
channel->channelDestroyedOnServer();
}
@@ -3110,7 +3110,7 @@ public:
* Implementation of <code>Channel</code>.
*/
class InternalChannelImpl :
public ChannelImpl,
public ClientChannelImpl,
public TimerCallback
{
InternalChannelImpl(InternalChannelImpl&);
@@ -3271,7 +3271,7 @@ private:
public:
static ChannelImpl::shared_pointer create(InternalClientContextImpl::shared_pointer context,
static ClientChannelImpl::shared_pointer create(InternalClientContextImpl::shared_pointer context,
pvAccessID channelID,
string const & name,
ChannelRequester::shared_pointer requester,
@@ -3756,7 +3756,7 @@ public:
}
}
void transportUnresponsive() OVERRIDE FINAL {
virtual void transportUnresponsive() OVERRIDE FINAL {
/*
{
Lock guard(m_channelMutex);
@@ -4250,7 +4250,7 @@ private:
Lock guard(m_cidMapMutex);
int count = 0;
std::vector<ChannelImpl::weak_pointer> channels(m_channelsByCID.size());
std::vector<ClientChannelImpl::weak_pointer> channels(m_channelsByCID.size());
for (CIDChannelMap::iterator iter = m_channelsByCID.begin();
iter != m_channelsByCID.end();
iter++)
@@ -4261,7 +4261,7 @@ private:
guard.unlock();
ChannelImpl::shared_pointer ptr;
ClientChannelImpl::shared_pointer ptr;
for (int i = 0; i < count; i++)
{
ptr = channels[i].lock();
@@ -4298,17 +4298,17 @@ private:
* Register channel.
* @param channel
*/
void registerChannel(ChannelImpl::shared_pointer const & channel) OVERRIDE FINAL
void registerChannel(ClientChannelImpl::shared_pointer const & channel) OVERRIDE FINAL
{
Lock guard(m_cidMapMutex);
m_channelsByCID[channel->getChannelID()] = ChannelImpl::weak_pointer(channel);
m_channelsByCID[channel->getChannelID()] = ClientChannelImpl::weak_pointer(channel);
}
/**
* Unregister channel.
* @param channel
*/
void unregisterChannel(ChannelImpl::shared_pointer const & channel) OVERRIDE FINAL
void unregisterChannel(ClientChannelImpl::shared_pointer const & channel) OVERRIDE FINAL
{
Lock guard(m_cidMapMutex);
m_channelsByCID.erase(channel->getChannelID());
@@ -4455,7 +4455,7 @@ private:
* @param priority process priority.
* @return transport for given address
*/
Transport::shared_pointer getTransport(TransportClient::shared_pointer const & client, osiSockAddr* serverAddress, int8 minorRevision, int16 priority) OVERRIDE FINAL
Transport::shared_pointer getTransport(ClientChannelImpl::shared_pointer const & client, osiSockAddr* serverAddress, int8 minorRevision, int16 priority) OVERRIDE FINAL
{
try
{
@@ -4476,7 +4476,7 @@ private:
*/
// TODO no minor version with the addresses
// TODO what if there is an channel with the same name, but on different host!
ChannelImpl::shared_pointer createChannelInternal(std::string const & name, ChannelRequester::shared_pointer const & requester, short priority,
ClientChannelImpl::shared_pointer createChannelInternal(std::string const & name, ChannelRequester::shared_pointer const & requester, short priority,
const InetAddrVector& addresses) OVERRIDE FINAL { // TODO addresses
checkState();
@@ -4503,7 +4503,7 @@ private:
}
catch(std::exception& e) {
LOG(logLevelError, "createChannelInternal() exception: %s\n", e.what());
return ChannelImpl::shared_pointer();
return ClientChannelImpl::shared_pointer();
}
// TODO namedLocker.releaseSynchronizationObject(name);
}
@@ -4629,7 +4629,7 @@ private:
* Map of channels (keys are CIDs).
*/
// TODO consider std::unordered_map
typedef std::map<pvAccessID, ChannelImpl::weak_pointer> CIDChannelMap;
typedef std::map<pvAccessID, ClientChannelImpl::weak_pointer> CIDChannelMap;
CIDChannelMap m_channelsByCID;
/**

View File

@@ -32,14 +32,13 @@ namespace pvAccess {
class BeaconHandler;
class ClientContextImpl;
class ChannelImpl :
class ClientChannelImpl :
public Channel,
public TransportClient,
public TransportSender,
public SearchInstance
{
public:
POINTER_DEFINITIONS(ChannelImpl);
POINTER_DEFINITIONS(ClientChannelImpl);
virtual pvAccessID getChannelID() = 0;
virtual void destroyChannel(bool force) = 0;
@@ -48,12 +47,17 @@ public:
virtual ClientContextImpl* getContext() = 0;
virtual void channelDestroyedOnServer() = 0;
virtual pvAccessID getID() =0;
virtual pvAccessID getServerChannelID() = 0;
virtual void registerResponseRequest(ResponseRequest::shared_pointer const & responseRequest) = 0;
virtual void unregisterResponseRequest(pvAccessID ioid) = 0;
virtual Transport::shared_pointer checkAndGetTransport() = 0;
virtual Transport::shared_pointer checkDestroyedAndGetTransport() = 0;
virtual Transport::shared_pointer getTransport() = 0;
virtual void transportUnresponsive() =0;
virtual void transportChanged() =0;
virtual void transportClosed() =0;
virtual void transportResponsive(Transport::shared_pointer const & /*transport*/) =0;
static epics::pvData::Status channelDestroyed;
static epics::pvData::Status channelDisconnected;
@@ -97,10 +101,10 @@ public:
virtual ChannelSearchManager::shared_pointer getChannelSearchManager() = 0;
virtual void checkChannelName(std::string const & name) = 0;
virtual void registerChannel(ChannelImpl::shared_pointer const & channel) = 0;
virtual void unregisterChannel(ChannelImpl::shared_pointer const & channel) = 0;
virtual void registerChannel(ClientChannelImpl::shared_pointer const & channel) = 0;
virtual void unregisterChannel(ClientChannelImpl::shared_pointer const & channel) = 0;
virtual ChannelImpl::shared_pointer createChannelInternal(std::string const &name,
virtual ClientChannelImpl::shared_pointer createChannelInternal(std::string const &name,
ChannelRequester::shared_pointer const & requester,
short priority,
const InetAddrVector& addresses) = 0;
@@ -110,7 +114,7 @@ public:
virtual ResponseRequest::shared_pointer unregisterResponseRequest(pvAccessID ioid) = 0;
virtual Transport::shared_pointer getTransport(TransportClient::shared_pointer const & client, osiSockAddr* serverAddress, epics::pvData::int8 minorRevision, epics::pvData::int16 priority) = 0;
virtual Transport::shared_pointer getTransport(ClientChannelImpl::shared_pointer const & client, osiSockAddr* serverAddress, epics::pvData::int8 minorRevision, epics::pvData::int16 priority) = 0;
virtual void newServerDetected() = 0;

View File

@@ -318,7 +318,7 @@ public:
}
bool acquire(
std::tr1::shared_ptr<TransportClient> const & client)
std::tr1::shared_ptr<ClientChannelImpl> const & client)
{
return false;
}