From 38d53f1ab6bee6ac2b2ab7ff4e1609434e14e7df Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Tue, 11 Jan 2011 00:58:12 +0100 Subject: [PATCH] cleanup cntd. --- pvAccessApp/utils/inetAddressUtil.h | 16 +++++----- pvAccessApp/utils/introspectionRegistry.h | 3 +- pvAccessApp/utils/namedLockPattern.h | 19 +++++------ pvAccessApp/utils/referenceCountingLock.cpp | 2 ++ pvAccessApp/utils/referenceCountingLock.h | 18 ++--------- pvAccessApp/utils/transportRegistry.cpp | 35 +++++---------------- pvAccessApp/utils/transportRegistry.h | 26 +++++++-------- testApp/utils/growingCircularBufferTest.cpp | 2 +- testApp/utils/inetAddressUtilsTest.cpp | 10 +++--- testApp/utils/loggerTest.cpp | 2 +- testApp/utils/namedLockPatternTest.cpp | 1 + 11 files changed, 48 insertions(+), 86 deletions(-) diff --git a/pvAccessApp/utils/inetAddressUtil.h b/pvAccessApp/utils/inetAddressUtil.h index e8ee082..c9dd871 100644 --- a/pvAccessApp/utils/inetAddressUtil.h +++ b/pvAccessApp/utils/inetAddressUtil.h @@ -8,13 +8,15 @@ #ifndef INETADDRESSUTIL_H_ #define INETADDRESSUTIL_H_ +// review this header, is it needed, use pure libCom calls? + /* uporabim lahko: * EPICSv3 osiSock.h kjer je definiran osiSockDiscoverBroadcastAddresses * * Kako se ga uporablja je v * epics/base/src/ca/iocinf.cpp funkcija configureChannelAccessAddressList * - * razišči kako se to priredi za IPv6 + * razisci kako se to priredi za IPv6 * */ @@ -23,8 +25,6 @@ #include #include -using namespace epics::pvData; - namespace epics { namespace pvAccess { @@ -46,21 +46,21 @@ namespace epics { * @param address address to encode. */ void - encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address); + encodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, const osiSockAddr* address); /** * Convert an integer into an IPv4 INET address. * @param addr integer representation of a given address. * @return IPv4 INET address. */ - osiSockAddr* intToIPv4Address(int32 addr); + osiSockAddr* intToIPv4Address(epics::pvData::int32 addr); /** * Convert an IPv4 INET address to an integer. * @param addr IPv4 INET address. * @return integer representation of a given address. */ - int32 ipv4AddressToInt(const osiSockAddr& addr); + epics::pvData::int32 ipv4AddressToInt(const osiSockAddr& addr); /** * Parse space delimited addresss[:port] string and return array of InetSocketAddress. @@ -69,10 +69,10 @@ namespace epics { * @param appendList list to be appended. * @return array of InetSocketAddress. */ - InetAddrVector* getSocketAddressList(String list, int defaultPort, + InetAddrVector* getSocketAddressList(epics::pvData::String list, int defaultPort, const InetAddrVector* appendList = NULL); - const String inetAddressToString(const osiSockAddr *addr, + const epics::pvData::String inetAddressToString(const osiSockAddr *addr, bool displayPort = true, bool displayHex = false); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ diff --git a/pvAccessApp/utils/introspectionRegistry.h b/pvAccessApp/utils/introspectionRegistry.h index ed9b739..dbbf768 100644 --- a/pvAccessApp/utils/introspectionRegistry.h +++ b/pvAccessApp/utils/introspectionRegistry.h @@ -19,7 +19,8 @@ #include #include - +// TODO check for memory leaks +// TODO to be removed out of header using namespace epics::pvData; using namespace std; diff --git a/pvAccessApp/utils/namedLockPattern.h b/pvAccessApp/utils/namedLockPattern.h index 26b6c1c..386eaa7 100644 --- a/pvAccessApp/utils/namedLockPattern.h +++ b/pvAccessApp/utils/namedLockPattern.h @@ -13,14 +13,11 @@ #include "referenceCountingLock.h" -using namespace std; -using namespace epics::pvData; - namespace epics { namespace pvAccess { /** * NamedLockPattern */ -template > +template > class NamedLockPattern { public: @@ -44,14 +41,14 @@ public: * @return true if acquired, false othwerwise. * NOTE: currently this routine always returns true. Look above for explanation. */ - bool acquireSynchronizationObject(const Key name, const int64 msec); + bool acquireSynchronizationObject(const Key name, const epics::pvData::int64 msec); /** * Release synchronization lock for named object. * @param name name of the object whose lock to release. */ void releaseSynchronizationObject(const Key name); private: - Mutex _mutex; + epics::pvData::Mutex _mutex; std::map _namedLocks; typename std::map::iterator _namedLocksIter; @@ -65,11 +62,11 @@ private: }; template -bool NamedLockPattern::acquireSynchronizationObject(const Key name, const int64 msec) +bool NamedLockPattern::acquireSynchronizationObject(const Key name, const epics::pvData::int64 msec) { ReferenceCountingLock* lock; { //due to guard - Lock guard(&_mutex); + epics::pvData::Lock guard(&_mutex); _namedLocksIter = _namedLocks.find(name); // get synchronization object @@ -107,7 +104,7 @@ void NamedLockPattern::releaseSynchronizationObject(const Key name) template void NamedLockPattern::releaseSynchronizationObject(const Key name,const bool release) { - Lock guard(&_mutex); + epics::pvData::Lock guard(&_mutex); ReferenceCountingLock* lock; _namedLocksIter = _namedLocks.find(name); @@ -133,11 +130,11 @@ void NamedLockPattern::releaseSynchronizationObject(const Key name, } template -class NamedLock : private NoDefaultMethods +class NamedLock : private epics::pvData::NoDefaultMethods { public: NamedLock(NamedLockPattern* namedLockPattern): _namedLockPattern(namedLockPattern) {} - bool acquireSynchronizationObject(const Key name, const int64 msec) {_name = name; return _namedLockPattern->acquireSynchronizationObject(name,msec);} + bool acquireSynchronizationObject(const Key name, const epics::pvData::int64 msec) {_name = name; return _namedLockPattern->acquireSynchronizationObject(name,msec);} ~NamedLock(){_namedLockPattern->releaseSynchronizationObject(_name);} private: Key _name; diff --git a/pvAccessApp/utils/referenceCountingLock.cpp b/pvAccessApp/utils/referenceCountingLock.cpp index b618a84..1f22a75 100644 --- a/pvAccessApp/utils/referenceCountingLock.cpp +++ b/pvAccessApp/utils/referenceCountingLock.cpp @@ -6,6 +6,8 @@ namespace epics { namespace pvAccess { +using namespace epics::pvData; + ReferenceCountingLock::ReferenceCountingLock(): _references(1) { /* pthread_mutexattr_t mutexAttribute; diff --git a/pvAccessApp/utils/referenceCountingLock.h b/pvAccessApp/utils/referenceCountingLock.h index c93f51b..0a0a67f 100644 --- a/pvAccessApp/utils/referenceCountingLock.h +++ b/pvAccessApp/utils/referenceCountingLock.h @@ -5,18 +5,8 @@ #ifndef REFERENCECOUNTINGLOCK_H #define REFERENCECOUNTINGLOCK_H -#include -#include -#include -#include -#include - #include #include -#include - -using namespace std; -using namespace epics::pvData; namespace epics { namespace pvAccess { @@ -53,7 +43,7 @@ public: * NOTE: currently this routine always returns true. Look above for explanation. * */ - bool acquire(int64 msecs); + bool acquire(epics::pvData::int64 msecs); /** * Release previously acquired lock. */ @@ -72,10 +62,8 @@ public: int decrement(); private: int _references; - Mutex _mutex; - Mutex _countMutex; - //pthread_mutex_t _mutex; - + epics::pvData::Mutex _mutex; + epics::pvData::Mutex _countMutex; }; }} diff --git a/pvAccessApp/utils/transportRegistry.cpp b/pvAccessApp/utils/transportRegistry.cpp index c319387..522363f 100644 --- a/pvAccessApp/utils/transportRegistry.cpp +++ b/pvAccessApp/utils/transportRegistry.cpp @@ -4,6 +4,9 @@ #include "transportRegistry.h" +using namespace epics::pvData; +using namespace std; + namespace epics { namespace pvAccess { TransportRegistry::TransportRegistry(): _mutex(Mutex()) @@ -18,14 +21,8 @@ TransportRegistry::~TransportRegistry() void TransportRegistry::put(Transport* transport) { - // TODO support type - if(transport == NULL) - { - throw EpicsException("null transport provided"); - } - Lock guard(&_mutex); - //const string type = transport.getType(); + //const String type = transport.getType(); const int16 priority = transport->getPriority(); const osiSockAddr* address = transport->getRemoteAddress(); @@ -44,14 +41,8 @@ void TransportRegistry::put(Transport* transport) _allTransports.push_back(transport); } -Transport* TransportRegistry::get(const string type, const osiSockAddr* address, const int16 priority) +Transport* TransportRegistry::get(const String type, const osiSockAddr* address, const int16 priority) { - // TODO support type - if(address == NULL) - { - throw EpicsException("null address provided"); - } - Lock guard(&_mutex); _transportsIter = _transports.find(address); if(_transportsIter != _transports.end()) @@ -66,14 +57,8 @@ Transport* TransportRegistry::get(const string type, const osiSockAddr* address, return NULL; } -Transport** TransportRegistry::get(const string type, const osiSockAddr* address, int32& size) +Transport** TransportRegistry::get(const String type, const osiSockAddr* address, int32& size) { - // TODO support type - if(address == NULL) - { - throw EpicsException("null address provided"); - } - Lock guard(&_mutex); _transportsIter = _transports.find(address); if(_transportsIter != _transports.end()) @@ -93,12 +78,6 @@ Transport** TransportRegistry::get(const string type, const osiSockAddr* address Transport* TransportRegistry::remove(Transport* transport) { - // TODO support type - if(transport == NULL) - { - throw EpicsException("null transport provided"); - } - Lock guard(&_mutex); const int16 priority = transport->getPriority(); const osiSockAddr* address = transport->getRemoteAddress(); @@ -148,7 +127,7 @@ int TransportRegistry::numberOfActiveTransports() return (int32)_allTransports.size(); } -Transport** TransportRegistry::toArray(const string type, int32& size) +Transport** TransportRegistry::toArray(const String type, int32& size) { // TODO support type Lock guard(&_mutex); diff --git a/pvAccessApp/utils/transportRegistry.h b/pvAccessApp/utils/transportRegistry.h index bf2bf0e..7cc7704 100644 --- a/pvAccessApp/utils/transportRegistry.h +++ b/pvAccessApp/utils/transportRegistry.h @@ -8,25 +8,21 @@ #include #include #include -#include #include -#include "lock.h" -#include "pvType.h" -#include "epicsException.h" +#include +#include +#include +#include #include "inetAddressUtil.h" -#include "remote.h" - -using namespace epics::pvData; -using namespace std; namespace epics { namespace pvAccess { class Transport; //TODO if unordered map is used instead of map we can use sockAddrAreIdentical routine from osiSock.h -typedef std::map prioritiesMap_t; +typedef std::map prioritiesMap_t; typedef std::map transportsMap_t; typedef std::vector allTransports_t; @@ -36,13 +32,13 @@ typedef std::vector allTransports_t; virtual ~TransportRegistry(); void put(Transport* transport); - Transport* get(const string type, const osiSockAddr* address, const int16 priority); - Transport** get(const string type, const osiSockAddr* address, int32& size); + Transport* get(const epics::pvData::String type, const osiSockAddr* address, const epics::pvData::int16 priority); + Transport** get(const epics::pvData::String type, const osiSockAddr* address, epics::pvData::int32& size); Transport* remove(Transport* transport); void clear(); - int32 numberOfActiveTransports(); - Transport** toArray(const string type, int32& size); - Transport** toArray(int32& size); + epics::pvData::int32 numberOfActiveTransports(); + Transport** toArray(const epics::pvData::String type, epics::pvData::int32& size); + Transport** toArray(epics::pvData::int32& size); private: transportsMap_t _transports; @@ -50,7 +46,7 @@ typedef std::vector allTransports_t; prioritiesMap_t::iterator _prioritiesIter; allTransports_t _allTransports; allTransports_t::iterator _allTransportsIter; - Mutex _mutex; + epics::pvData::Mutex _mutex; }; }} diff --git a/testApp/utils/growingCircularBufferTest.cpp b/testApp/utils/growingCircularBufferTest.cpp index 4264d19..dc2b669 100644 --- a/testApp/utils/growingCircularBufferTest.cpp +++ b/testApp/utils/growingCircularBufferTest.cpp @@ -5,7 +5,7 @@ * Author: Miha Vitorovic */ -#include "growingCircularBuffer.h" +#include #include #include diff --git a/testApp/utils/inetAddressUtilsTest.cpp b/testApp/utils/inetAddressUtilsTest.cpp index 3ceae49..bffa82f 100644 --- a/testApp/utils/inetAddressUtilsTest.cpp +++ b/testApp/utils/inetAddressUtilsTest.cpp @@ -5,8 +5,8 @@ * Author: user */ -#include "inetAddressUtil.h" -#include "logger.h" +#include +#include #include #include @@ -17,11 +17,9 @@ #include #include +using namespace epics::pvData; using namespace epics::pvAccess; -using std::cout; -using std::endl; -using std::stringstream; -using std::hex; +using namespace std; int main(int argc, char *argv[]) { createFileLogger("inetAddresUtils.log"); diff --git a/testApp/utils/loggerTest.cpp b/testApp/utils/loggerTest.cpp index 55fae09..b733037 100644 --- a/testApp/utils/loggerTest.cpp +++ b/testApp/utils/loggerTest.cpp @@ -5,7 +5,7 @@ * Author: Miha Vitorovic */ -#include "logger.h" +#include #include #include diff --git a/testApp/utils/namedLockPatternTest.cpp b/testApp/utils/namedLockPatternTest.cpp index 3470afa..db12951 100644 --- a/testApp/utils/namedLockPatternTest.cpp +++ b/testApp/utils/namedLockPatternTest.cpp @@ -11,6 +11,7 @@ #include +using namespace epics::pvData; using namespace epics::pvAccess; using namespace std;