From 3ffbf9c597e8818d672aa5725c0031c9da4fb665 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 29 Jun 2018 12:52:43 -0700 Subject: [PATCH] ServerChannel::_requests holds BaseChannelRequester Make it a bit more obvious that things are backwards here. --- src/server/pv/baseChannelRequester.h | 1 + src/server/pv/serverChannelImpl.h | 9 ++++-- src/server/responseHandlers.cpp | 44 ++++++++++++---------------- src/server/serverChannelImpl.cpp | 6 ++-- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/server/pv/baseChannelRequester.h b/src/server/pv/baseChannelRequester.h index 60a3ba0..fd79998 100644 --- a/src/server/pv/baseChannelRequester.h +++ b/src/server/pv/baseChannelRequester.h @@ -20,6 +20,7 @@ class ServerChannel; class BaseChannelRequester : virtual public epics::pvData::Requester, public Destroyable { public: + POINTER_DEFINITIONS(BaseChannelRequester); BaseChannelRequester(ServerContextImpl::shared_pointer const & context, std::tr1::shared_ptr const & channel, const pvAccessID ioid, Transport::shared_pointer const & transport); virtual ~BaseChannelRequester() {}; diff --git a/src/server/pv/serverChannelImpl.h b/src/server/pv/serverChannelImpl.h index be04967..f74c4b5 100644 --- a/src/server/pv/serverChannelImpl.h +++ b/src/server/pv/serverChannelImpl.h @@ -10,10 +10,13 @@ #include #include #include +#include namespace epics { namespace pvAccess { +class BaseChannelRequester; + class ServerChannel { public: @@ -43,7 +46,7 @@ public: ChannelSecuritySession::shared_pointer getChannelSecuritySession() const { return _channelSecuritySession; } - void registerRequest(pvAccessID id, Destroyable::shared_pointer const & request); + void registerRequest(pvAccessID id, const std::tr1::shared_ptr& request); void unregisterRequest(pvAccessID id); @@ -51,7 +54,7 @@ public: void completeGetField(GetFieldRequester *req); //! may return NULL - Destroyable::shared_pointer getRequest(pvAccessID id); + std::tr1::shared_ptr getRequest(pvAccessID id); void destroy(); @@ -68,7 +71,7 @@ private: //! keep alive in-progress GetField() GetFieldRequester::shared_pointer _active_requester; - typedef std::map _requests_t; + typedef std::map > _requests_t; _requests_t _requests; bool _destroyed; diff --git a/src/server/responseHandlers.cpp b/src/server/responseHandlers.cpp index 8dd7725..831e201 100644 --- a/src/server/responseHandlers.cpp +++ b/src/server/responseHandlers.cpp @@ -1125,9 +1125,8 @@ ChannelGetRequester::shared_pointer ServerChannelGetRequesterImpl::create(Server void ServerChannelGetRequesterImpl::activate(PVStructure::shared_pointer const & pvRequest) { startRequest(QOS_INIT); - ChannelGetRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_GET, _channelGet, _channel->getChannel()->createChannelGet(thisPointer, pvRequest)); } @@ -1385,9 +1384,8 @@ ChannelPutRequester::shared_pointer ServerChannelPutRequesterImpl::create(Server void ServerChannelPutRequesterImpl::activate(PVStructure::shared_pointer const & pvRequest) { startRequest(QOS_INIT); - ChannelPutRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_PUT, _channelPut, _channel->getChannel()->createChannelPut(thisPointer, pvRequest)); } @@ -1668,9 +1666,8 @@ ChannelPutGetRequester::shared_pointer ServerChannelPutGetRequesterImpl::create( void ServerChannelPutGetRequesterImpl::activate(PVStructure::shared_pointer const & pvRequest) { startRequest(QOS_INIT); - ChannelPutGetRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_PUT_GET, _channelPutGet, _channel->getChannel()->createChannelPutGet(thisPointer, pvRequest)); } @@ -1994,9 +1991,8 @@ void ServerMonitorRequesterImpl::activate(PVStructure::shared_pointer const & pv } } startRequest(QOS_INIT); - MonitorRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_MONITOR, _channelMonitor, _channel->getChannel()->createMonitor(thisPointer, pvRequest)); } @@ -2385,9 +2381,8 @@ ChannelArrayRequester::shared_pointer ServerChannelArrayRequesterImpl::create( void ServerChannelArrayRequesterImpl::activate(PVStructure::shared_pointer const & pvRequest) { startRequest(QOS_INIT); - ChannelArrayRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_ARRAY, _channelArray, _channel->getChannel()->createChannelArray(thisPointer, pvRequest)); } @@ -2607,25 +2602,26 @@ void ServerCancelRequestHandler::handleResponse(osiSockAddr* responseFrom, const pvAccessID ioid = payloadBuffer->getInt(); ServerChannel::shared_pointer channel = casTransport->getChannel(sid); - if (!channel.get()) + if (!channel) { failureResponse(transport, ioid, BaseChannelRequester::badCIDStatus); return; } - Destroyable::shared_pointer request = channel->getRequest(ioid); - if (!request.get()) + BaseChannelRequester::shared_pointer request(channel->getRequest(ioid)); + if (!request) { failureResponse(transport, ioid, BaseChannelRequester::badIOIDStatus); return; } ChannelRequest::shared_pointer cr = dynamic_pointer_cast(request); - if (!cr.get()) + if (!cr) { failureResponse(transport, ioid, BaseChannelRequester::notAChannelRequestStatus); return; } + // never gets here // cancel cr->cancel(); @@ -2733,9 +2729,8 @@ ChannelProcessRequester::shared_pointer ServerChannelProcessRequesterImpl::creat void ServerChannelProcessRequesterImpl::activate(PVStructure::shared_pointer const & pvRequest) { startRequest(QOS_INIT); - ChannelProcessRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_PROCESS, _channelProcess, _channel->getChannel()->createChannelProcess(thisPointer, pvRequest)); } @@ -3013,9 +3008,8 @@ ChannelRPCRequester::shared_pointer ServerChannelRPCRequesterImpl::create( void ServerChannelRPCRequesterImpl::activate(PVStructure::shared_pointer const & pvRequest) { startRequest(QOS_INIT); - ChannelRPCRequester::shared_pointer thisPointer = shared_from_this(); - Destroyable::shared_pointer thisDestroyable = shared_from_this(); - _channel->registerRequest(_ioid, thisDestroyable); + shared_pointer thisPointer(shared_from_this()); + _channel->registerRequest(_ioid, thisPointer); INIT_EXCEPTION_GUARD(CMD_RPC, _channelRPC, _channel->getChannel()->createChannelRPC(thisPointer, pvRequest)); } diff --git a/src/server/serverChannelImpl.cpp b/src/server/serverChannelImpl.cpp index c632359..f98b77c 100644 --- a/src/server/serverChannelImpl.cpp +++ b/src/server/serverChannelImpl.cpp @@ -34,7 +34,7 @@ ServerChannel::ServerChannel(Channel::shared_pointer const & channel, } } -void ServerChannel::registerRequest(const pvAccessID id, Destroyable::shared_pointer const & request) +void ServerChannel::registerRequest(const pvAccessID id, const std::tr1::shared_ptr & request) { Lock guard(_mutex); if(_destroyed) throw std::logic_error("Can't registerRequest() for destory'd server channel"); @@ -51,7 +51,7 @@ void ServerChannel::unregisterRequest(const pvAccessID id) } } -Destroyable::shared_pointer ServerChannel::getRequest(const pvAccessID id) +std::tr1::shared_ptr ServerChannel::getRequest(const pvAccessID id) { Lock guard(_mutex); _requests_t::iterator iter = _requests.find(id); @@ -59,7 +59,7 @@ Destroyable::shared_pointer ServerChannel::getRequest(const pvAccessID id) { return iter->second; } - return Destroyable::shared_pointer(); + return BaseChannelRequester::shared_pointer(); } void ServerChannel::destroy()