header cleanup
This commit is contained in:
@@ -1,157 +0,0 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* pvAccessCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#include <pv/transportRegistry.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
TransportRegistry::TransportRegistry(): _transports(), _transportCount(0), _mutex()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TransportRegistry::~TransportRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
void TransportRegistry::put(Transport::shared_pointer const & transport)
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
//const String type = transport.getType();
|
||||
const int16 priority = transport->getPriority();
|
||||
const osiSockAddr* address = transport->getRemoteAddress();
|
||||
|
||||
transportsMap_t::iterator transportsIter = _transports.find(address);
|
||||
prioritiesMapSharedPtr_t priorities;
|
||||
if(transportsIter == _transports.end())
|
||||
{
|
||||
priorities.reset(new prioritiesMap_t());
|
||||
_transports[address] = priorities;
|
||||
_transportCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
priorities = transportsIter->second;
|
||||
prioritiesMap_t::iterator prioritiesIter = priorities->find(priority);
|
||||
if(prioritiesIter == priorities->end()) //only increase transportCount if not replacing
|
||||
{
|
||||
_transportCount++;
|
||||
}
|
||||
}
|
||||
(*priorities)[priority] = transport;
|
||||
}
|
||||
|
||||
Transport::shared_pointer TransportRegistry::get(String type, const osiSockAddr* address, const int16 priority)
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
transportsMap_t::iterator transportsIter = _transports.find(address);
|
||||
if(transportsIter != _transports.end())
|
||||
{
|
||||
prioritiesMapSharedPtr_t priorities = transportsIter->second;
|
||||
prioritiesMap_t::iterator prioritiesIter = priorities->find(priority);
|
||||
if(prioritiesIter != priorities->end())
|
||||
{
|
||||
return prioritiesIter->second;
|
||||
}
|
||||
}
|
||||
return Transport::shared_pointer();
|
||||
}
|
||||
|
||||
auto_ptr<TransportRegistry::transportVector_t> TransportRegistry::get(String type, const osiSockAddr* address)
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
transportsMap_t::iterator transportsIter = _transports.find(address);
|
||||
if(transportsIter != _transports.end())
|
||||
{
|
||||
prioritiesMapSharedPtr_t priorities = transportsIter->second;
|
||||
auto_ptr<transportVector_t> transportArray(new transportVector_t(priorities->size()));
|
||||
int32 i = 0;
|
||||
for(prioritiesMap_t::iterator prioritiesIter = priorities->begin();
|
||||
prioritiesIter != priorities->end();
|
||||
prioritiesIter++, i++)
|
||||
{
|
||||
transportArray->at(i) = prioritiesIter->second;
|
||||
}
|
||||
return transportArray;
|
||||
}
|
||||
return auto_ptr<transportVector_t>();
|
||||
}
|
||||
|
||||
Transport::shared_pointer TransportRegistry::remove(Transport::shared_pointer const & transport)
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
const int16 priority = transport->getPriority();
|
||||
const osiSockAddr* address = transport->getRemoteAddress();
|
||||
Transport::shared_pointer retTransport;
|
||||
transportsMap_t::iterator transportsIter = _transports.find(address);
|
||||
if(transportsIter != _transports.end())
|
||||
{
|
||||
prioritiesMapSharedPtr_t priorities = transportsIter->second;
|
||||
prioritiesMap_t::iterator prioritiesIter = priorities->find(priority);
|
||||
if(prioritiesIter != priorities->end())
|
||||
{
|
||||
retTransport = prioritiesIter->second;
|
||||
priorities->erase(prioritiesIter);
|
||||
_transportCount--;
|
||||
if(priorities->size() == 0)
|
||||
{
|
||||
_transports.erase(transportsIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retTransport;
|
||||
}
|
||||
|
||||
void TransportRegistry::clear()
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
_transports.clear();
|
||||
_transportCount = 0;
|
||||
}
|
||||
|
||||
int32 TransportRegistry::numberOfActiveTransports()
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
return _transportCount;
|
||||
}
|
||||
|
||||
auto_ptr<TransportRegistry::transportVector_t> TransportRegistry::toArray(String type)
|
||||
{
|
||||
// TODO support type
|
||||
return toArray();
|
||||
}
|
||||
|
||||
auto_ptr<TransportRegistry::transportVector_t> TransportRegistry::toArray()
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
if (_transportCount == 0)
|
||||
return auto_ptr<transportVector_t>(0);
|
||||
|
||||
auto_ptr<transportVector_t> transportArray(new transportVector_t(_transportCount));
|
||||
|
||||
int32 i = 0;
|
||||
for (transportsMap_t::iterator transportsIter = _transports.begin();
|
||||
transportsIter != _transports.end();
|
||||
transportsIter++)
|
||||
{
|
||||
prioritiesMapSharedPtr_t priorities = transportsIter->second;
|
||||
for (prioritiesMap_t::iterator prioritiesIter = priorities->begin();
|
||||
prioritiesIter != priorities->end();
|
||||
prioritiesIter++, i++)
|
||||
{
|
||||
transportArray->at(i) = prioritiesIter->second;
|
||||
}
|
||||
}
|
||||
|
||||
return transportArray;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* pvAccessCPP is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
|
||||
#ifndef TRANSPORTREGISTRY_H
|
||||
#define TRANSPORTREGISTRY_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <osiSock.h>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvType.h>
|
||||
#include <pv/epicsException.h>
|
||||
#include <pv/remote.h>
|
||||
#include <pv/inetAddressUtil.h>
|
||||
#include <pv/sharedPtr.h>
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
class TransportRegistry {
|
||||
public:
|
||||
typedef std::tr1::shared_ptr<TransportRegistry> shared_pointer;
|
||||
typedef std::tr1::shared_ptr<const TransportRegistry> const_shared_pointer;
|
||||
|
||||
typedef std::vector<Transport::shared_pointer> transportVector_t;
|
||||
|
||||
TransportRegistry();
|
||||
virtual ~TransportRegistry();
|
||||
|
||||
void put(Transport::shared_pointer const & transport);
|
||||
Transport::shared_pointer get(epics::pvData::String type, const osiSockAddr* address, const epics::pvData::int16 priority);
|
||||
std::auto_ptr<transportVector_t> get(epics::pvData::String type, const osiSockAddr* address);
|
||||
Transport::shared_pointer remove(Transport::shared_pointer const & transport);
|
||||
void clear();
|
||||
epics::pvData::int32 numberOfActiveTransports();
|
||||
std::auto_ptr<transportVector_t> toArray(epics::pvData::String type);
|
||||
std::auto_ptr<transportVector_t> toArray();
|
||||
|
||||
private:
|
||||
//TODO if unordered map is used instead of map we can use sockAddrAreIdentical routine from osiSock.h
|
||||
// NOTE: pointers are used to osiSockAddr (to save memory), since it guaranteed that their reference is valid as long as Transport
|
||||
typedef std::map<const epics::pvData::int16,Transport::shared_pointer> prioritiesMap_t;
|
||||
typedef std::tr1::shared_ptr<prioritiesMap_t> prioritiesMapSharedPtr_t;
|
||||
typedef std::map<const osiSockAddr*,prioritiesMapSharedPtr_t,comp_osiSockAddrPtr> transportsMap_t;
|
||||
|
||||
transportsMap_t _transports;
|
||||
epics::pvData::int32 _transportCount;
|
||||
epics::pvData::Mutex _mutex;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* INTROSPECTIONREGISTRY_H */
|
||||
Reference in New Issue
Block a user