server: cleanup handling of vector of providers

avoid keeping extra refs.  situation is confusing
enough as it is.
This commit is contained in:
Michael Davidsaver
2018-05-18 08:53:52 -07:00
parent bd88e35448
commit 6abfe9d196
4 changed files with 14 additions and 19 deletions

View File

@@ -126,9 +126,6 @@ public:
virtual void handleResponse(osiSockAddr* responseFrom,
Transport::shared_pointer const & transport, epics::pvData::int8 version, epics::pvData::int8 command,
std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
private:
std::vector<ChannelProvider::shared_pointer> _providers;
};
@@ -173,10 +170,9 @@ private:
class ServerCreateChannelHandler : public AbstractServerResponseHandler
{
public:
ServerCreateChannelHandler(ServerContextImpl::shared_pointer const & context) :
AbstractServerResponseHandler(context, "Create channel request") {
_providers = context->getChannelProviders();
}
ServerCreateChannelHandler(ServerContextImpl::shared_pointer const & context)
:AbstractServerResponseHandler(context, "Create channel request")
{}
virtual ~ServerCreateChannelHandler() {}
virtual void handleResponse(osiSockAddr* responseFrom,
@@ -184,10 +180,10 @@ public:
std::size_t payloadSize, epics::pvData::ByteBuffer* payloadBuffer) OVERRIDE FINAL;
private:
// Name of the magic "server" PV used to implement channelList() and server info
static std::string SERVER_CHANNEL_NAME;
void disconnect(Transport::shared_pointer const & transport);
std::vector<ChannelProvider::shared_pointer> _providers;
};
namespace detail {

View File

@@ -129,7 +129,7 @@ public:
* Get channel providers.
* @return channel providers.
*/
virtual std::vector<ChannelProvider::shared_pointer>& getChannelProviders() OVERRIDE FINAL;
virtual const std::vector<ChannelProvider::shared_pointer>& getChannelProviders() OVERRIDE FINAL;
/**
* Return <code>true</code> if channel provider name is provided by configuration (e.g. system env. var.).
@@ -224,9 +224,7 @@ private:
*/
ResponseHandler::shared_pointer _responseHandler;
/**
* Channel provider.
*/
// const after loadConfiguration()
std::vector<ChannelProvider::shared_pointer> _channelProviders;
/**

View File

@@ -229,7 +229,7 @@ void ServerEchoHandler::handleResponse(osiSockAddr* responseFrom,
std::string ServerSearchHandler::SUPPORTED_PROTOCOL = "tcp";
ServerSearchHandler::ServerSearchHandler(ServerContextImpl::shared_pointer const & context) :
AbstractServerResponseHandler(context, "Search request"), _providers(context->getChannelProviders())
AbstractServerResponseHandler(context, "Search request")
{
// initialize random seed with some random value
srand ( time(NULL) );
@@ -332,15 +332,14 @@ void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom,
if (allowed)
{
// TODO object pool!!!
const std::vector<ChannelProvider::shared_pointer>& _providers = _context->getChannelProviders();
int providerCount = _providers.size();
std::tr1::shared_ptr<ServerChannelFindRequesterImpl> tp(new ServerChannelFindRequesterImpl(_context, providerCount));
tp->set(name, searchSequenceId, cid, responseAddress, responseRequired, false);
// TODO use std::make_shared
ChannelFindRequester::shared_pointer spr = tp;
for (int i = 0; i < providerCount; i++)
_providers[i]->channelFind(name, spr);
_providers[i]->channelFind(name, tp);
}
}
}
@@ -575,7 +574,7 @@ public:
PVStringArray::shared_pointer allChannelNames = result->getSubFieldT<PVStringArray>("value");
ChannelListRequesterImpl::shared_pointer listListener(new ChannelListRequesterImpl());
std::vector<ChannelProvider::shared_pointer>& providers = m_serverContext->getChannelProviders();
const std::vector<ChannelProvider::shared_pointer>& providers = m_serverContext->getChannelProviders();
size_t providerCount = providers.size();
for (size_t i = 0; i < providerCount; i++)
@@ -763,6 +762,8 @@ void ServerCreateChannelHandler::handleResponse(osiSockAddr* responseFrom,
}
else
{
const std::vector<ChannelProvider::shared_pointer>& _providers(_context->getChannelProviders());
if (_providers.size() == 1)
ServerChannelRequesterImpl::create(_providers[0], transport, channelName, cid, css);
else

View File

@@ -502,7 +502,7 @@ BlockingUDPTransport::shared_pointer ServerContextImpl::getBroadcastTransport()
return _broadcastTransport;
}
std::vector<ChannelProvider::shared_pointer>& ServerContextImpl::getChannelProviders()
const std::vector<ChannelProvider::shared_pointer>& ServerContextImpl::getChannelProviders()
{
return _channelProviders;
}