From 1b6587336e1cd86acdd17dc917d4469c3e5931aa Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Tue, 24 Jul 2012 10:13:57 +0200 Subject: [PATCH] cleanup phase I --- pvAccessApp/ca/caConstants.h | 20 ++++-- pvAccessApp/ca/clientFactory.cpp | 20 +++--- pvAccessApp/ca/clientFactory.h | 7 -- pvAccessApp/ca/pvVersion.cpp | 60 ++++++++++++---- pvAccessApp/ca/pvVersion.h | 69 ++++++------------- pvAccessApp/factory/CreateRequestFactory.cpp | 2 +- pvAccessApp/remote/remote.h | 2 +- .../remoteClient/clientContextImpl.cpp | 4 +- pvAccessApp/server/responseHandlers.cpp | 2 +- pvAccessApp/server/serverContext.cpp | 11 +-- pvAccessApp/server/serverContext.h | 20 ------ pvAccessApp/utils/namedLockPattern.h | 12 ++-- pvAccessApp/utils/referenceCountingLock.h | 3 + testApp/remote/eget.cpp | 3 + testApp/remote/pvget.cpp | 3 + testApp/remote/pvput.cpp | 2 + testApp/remote/pvrpc.cpp | 2 + testApp/remote/testGetPerformance.cpp | 3 + 18 files changed, 116 insertions(+), 129 deletions(-) diff --git a/pvAccessApp/ca/caConstants.h b/pvAccessApp/ca/caConstants.h index 9c05795..d6db4a8 100644 --- a/pvAccessApp/ca/caConstants.h +++ b/pvAccessApp/ca/caConstants.h @@ -30,6 +30,9 @@ namespace pvAccess { /** CA protocol message header size. */ const epics::pvData::int16 CA_MESSAGE_HEADER_SIZE = 8; + /** All messages must be aligned to 8-bytes (64-bit). */ + const epics::pvData::int32 CA_ALIGNMENT = 1; // TODO + /** * UDP maximum send message size. * MAX_UDP: 1500 (max of ethernet and 802.{2,3} MTU) - 20/40(IPv4/IPv6) @@ -38,20 +41,23 @@ namespace pvAccess { */ const epics::pvData::int32 MAX_UDP_SEND = 1440; - /** UDP maximum receive message size. */ - const epics::pvData::int32 MAX_UDP_RECV = 0xFFFF+16; + /** + * UDP maximum receive message size. + * MAX_UDP: 65535 (max UDP packet size) - 20/40(IPv4/IPv6) - 8(UDP) + */ + const epics::pvData::int32 MAX_UDP_RECV = 65487; /** TCP maximum receive message size. */ const epics::pvData::int32 MAX_TCP_RECV = 1024*16; /** Maximum number of search requests in one search message. */ - const epics::pvData::int32 MAX_SEARCH_BATCH_COUNT = 0xFFFF; + const epics::pvData::int32 MAX_SEARCH_BATCH_COUNT = 0x7FFF; // 32767 /** Default priority (corresponds to POSIX SCHED_OTHER) */ const epics::pvData::int16 CA_DEFAULT_PRIORITY = 0; /** Unreasonable channel name length. */ - const epics::pvData::uint32 UNREASONABLE_CHANNEL_NAME_LENGTH = 500; + const epics::pvData::uint32 MAX_CHANNEL_NAME_LENGTH = 500; /** Invalid data type. */ const epics::pvData::int16 INVALID_DATA_TYPE = 0xFFFF; @@ -59,11 +65,11 @@ namespace pvAccess { /** Invalid IOID. */ const epics::pvData::int32 INVALID_IOID = 0; - /** All messages must be aligned to 8-bytes (64-bit). */ - const epics::pvData::int32 CA_ALIGNMENT = 8; - /** Default CA provider name. */ const epics::pvData::String PVACCESS_DEFAULT_PROVIDER = "local"; + + /** Name of the system env. variable to turn on debugging. */ + const epics::pvData::String PVACCESS_DEBUG = "PVACCESS_DEBUG"; } } diff --git a/pvAccessApp/ca/clientFactory.cpp b/pvAccessApp/ca/clientFactory.cpp index 91ac70d..7003eb9 100644 --- a/pvAccessApp/ca/clientFactory.cpp +++ b/pvAccessApp/ca/clientFactory.cpp @@ -4,7 +4,10 @@ * in file LICENSE that is included with this distribution. */ + #include +#include +#include #include #include @@ -12,23 +15,22 @@ using namespace epics::pvData; using namespace epics::pvAccess; -Mutex ClientFactory::m_mutex; -ClientContextImpl::shared_pointer ClientFactory::m_context; +// TODO global static variable (de/initialization order not guaranteed) +static Mutex m_mutex; +static ClientContextImpl::shared_pointer m_context; void ClientFactory::start() { - epicsSignalInstallSigAlarmIgnore (); - epicsSignalInstallSigPipeIgnore (); + epicsSignalInstallSigAlarmIgnore(); + epicsSignalInstallSigPipeIgnore(); Lock guard(m_mutex); - if (m_context.get()) return; try { m_context = createClientContextImpl(); m_context->initialize(); - ChannelProvider::shared_pointer provider = m_context->getProvider(); - registerChannelProvider(provider); + registerChannelProvider(m_context->getProvider()); } catch (std::exception &e) { LOG(logLevelError, "Unhandled exception caught at %s:%d: %s", __FILE__, __LINE__, e.what()); } catch (...) { @@ -39,11 +41,9 @@ void ClientFactory::start() void ClientFactory::stop() { Lock guard(m_mutex); - if (!m_context.get()) return; - ChannelProvider::shared_pointer provider = m_context->getProvider(); - unregisterChannelProvider(provider); + unregisterChannelProvider(m_context->getProvider()); m_context->dispose(); m_context.reset(); diff --git a/pvAccessApp/ca/clientFactory.h b/pvAccessApp/ca/clientFactory.h index c0bc9db..a36bc4b 100644 --- a/pvAccessApp/ca/clientFactory.h +++ b/pvAccessApp/ca/clientFactory.h @@ -7,9 +7,6 @@ #ifndef CLIENTFACTORY_H #define CLIENTFACTORY_H -#include -#include - namespace epics { namespace pvAccess { @@ -17,10 +14,6 @@ class ClientFactory { public: static void start(); static void stop(); - - private: - static epics::pvData::Mutex m_mutex; - static ClientContextImpl::shared_pointer m_context; }; }} diff --git a/pvAccessApp/ca/pvVersion.cpp b/pvAccessApp/ca/pvVersion.cpp index 73693e0..f04fb9d 100644 --- a/pvAccessApp/ca/pvVersion.cpp +++ b/pvAccessApp/ca/pvVersion.cpp @@ -14,29 +14,59 @@ using epics::pvData::String; namespace epics { namespace pvAccess { -const String Version::getLongVersionString() const { - stringstream ret; - ret<0) { - ret<<"D"<0) { - ret<<"D"<0) + ret<<'.'< #include +#include namespace epics { namespace pvAccess { @@ -22,30 +23,19 @@ namespace pvAccess { * @param majorVersion major version. * @param minorVersion minor version. * @param maintenanceVersion maintenance version. - * @param developmentVersion development version. + * @param developmentFlag development indicator flag. */ - Version(epics::pvData::String productName, epics::pvData::String implementationLangugage, + Version(epics::pvData::String productName, + epics::pvData::String implementationLangugage, int majorVersion, int minorVersion, - int maintenanceVersion, int developmentVersion) : - _productName(productName), - _implementationLanguage(implementationLangugage), - _majorVersion(majorVersion), - _minorVersion(minorVersion), - _maintenanceVersion(maintenanceVersion), - _developmentVersion(developmentVersion) - { - } + int maintenanceVersion, bool developmentFlag); /** The name of the product */ - inline const epics::pvData::String getProductName() const { - return _productName; - } + const epics::pvData::String getProductName() const; /** Implementation Language: C++ */ - inline const epics::pvData::String getImplementationLanguage() const { - return _implementationLanguage; - } + const epics::pvData::String getImplementationLanguage() const; /** * Major version number. This changes only when there is a @@ -55,21 +45,17 @@ namespace pvAccess { * Clients should carefully consider the implications of new versions as * external interfaces and behaviour may have changed. */ - inline int getMajorVersion() const { - return _majorVersion; - } + int getMajorVersion() const; /** - * Minor vesion number. This changes when: + * Minor version number. This changes when: *
    *
  • a new set of functionality is to be added
  • *
  • API or behaviour change
  • *
  • its designated as a reference release
  • *
*/ - inline int getMinorVersion() const { - return _minorVersion; - } + int getMinorVersion() const; /** * Maintenance version number. Optional identifier used to designate @@ -78,44 +64,27 @@ namespace pvAccess { * contains no API changes. When missing, it designates the final and * complete development drop for a release. */ - inline int getMaintenanceVersion() const { - return _maintenanceVersion; - } + int getMaintenanceVersion() const; /** - * Development drop number. Optional identifier designates development drop - * of a specific release. D01 is the first development drop of a new - * release. + * Development flag. * - * Development drops are works in progress towards a compeleted, final + * Development drops are works in progress towards a completed, final * release. A specific development drop may not completely implement all * aspects of a new feature, which may take several development drops to - * complete. At the point of the final drop for the release, the D suffix + * complete. At the point of the final drop for the release, the -SNAPSHOT suffix * will be omitted. - * - * Each 'D' drops can contain functional enhancements as well as defect - * fixes. 'D' drops may not be as stable as the final releases. */ - inline int getDevelopmentVersion() const { - return _developmentVersion; - } + bool isDevelopmentVersion() const; /** - * Get the long version string. Version epics::pvData::String formatted like
- * "ProductName \[ImplementationLanguage\] 'v'v.r[.dd|Dnn]" - *
e.g.
"CAJ [Java] v1.0.1" - *
- * + * Get the long version string. * @return epics::pvData::String denoting current version */ const epics::pvData::String getLongVersionString() const; /** - * Get the basic version string. Version epics::pvData::String formatted like
- * "ProductName 'v'v.r[.dd|Dnn]" - *
e.g.
"CAJ v1.0.1" - *
- * + * Get the basic version string. * @return epics::pvData::String denoting current version */ const epics::pvData::String getVersionString() const; @@ -126,8 +95,10 @@ namespace pvAccess { int _majorVersion; int _minorVersion; int _maintenanceVersion; - int _developmentVersion; + bool _developmentFlag; }; + + std::ostream& operator<<(std::ostream& o, const Version& v); } } diff --git a/pvAccessApp/factory/CreateRequestFactory.cpp b/pvAccessApp/factory/CreateRequestFactory.cpp index 869b74a..6b9a55f 100644 --- a/pvAccessApp/factory/CreateRequestFactory.cpp +++ b/pvAccessApp/factory/CreateRequestFactory.cpp @@ -280,7 +280,7 @@ public: }; -CreateRequest::shared_pointer createRequest; +static CreateRequest::shared_pointer createRequest; CreateRequest::shared_pointer getCreateRequest() { static Mutex mutex; diff --git a/pvAccessApp/remote/remote.h b/pvAccessApp/remote/remote.h index 105d887..2d100bb 100644 --- a/pvAccessApp/remote/remote.h +++ b/pvAccessApp/remote/remote.h @@ -329,7 +329,7 @@ namespace epics { */ AbstractResponseHandler(Context* context, epics::pvData::String description) : _description(description), - _debug(context->getConfiguration()->getPropertyAsBoolean("PVACCESS_DEBUG", false)) { + _debug(context->getConfiguration()->getPropertyAsBoolean(PVACCESS_DEBUG, false)) { } virtual ~AbstractResponseHandler() {} diff --git a/pvAccessApp/remoteClient/clientContextImpl.cpp b/pvAccessApp/remoteClient/clientContextImpl.cpp index 60ed5ba..a4b19f4 100644 --- a/pvAccessApp/remoteClient/clientContextImpl.cpp +++ b/pvAccessApp/remoteClient/clientContextImpl.cpp @@ -3738,7 +3738,7 @@ namespace epics { m_addressList(""), m_autoAddressList(true), m_connectionTimeout(30.0f), m_beaconPeriod(15.0f), m_broadcastPort(CA_BROADCAST_PORT), m_receiveBufferSize(MAX_TCP_RECV), m_namedLocker(), m_lastCID(0), m_lastIOID(0), - m_version("CA Client", "cpp", 1, 0, 0, 0), + m_version("pvAccess Client", "cpp", 1, 2, 0, true), m_contextState(CONTEXT_NOT_INITIALIZED), m_configuration(new SystemConfigurationImpl()) { @@ -4017,7 +4017,7 @@ TODO void checkChannelName(String& name) { if (name.empty()) throw std::runtime_error("0 or empty channel name"); - else if (name.length() > UNREASONABLE_CHANNEL_NAME_LENGTH) + else if (name.length() > MAX_CHANNEL_NAME_LENGTH) throw std::runtime_error("name too long"); } diff --git a/pvAccessApp/server/responseHandlers.cpp b/pvAccessApp/server/responseHandlers.cpp index 1862885..9289ea9 100644 --- a/pvAccessApp/server/responseHandlers.cpp +++ b/pvAccessApp/server/responseHandlers.cpp @@ -297,7 +297,7 @@ void ServerCreateChannelHandler::handleResponse(osiSockAddr* responseFrom, disconnect(transport); return; } - else if (channelName.size() > UNREASONABLE_CHANNEL_NAME_LENGTH) + else if (channelName.size() > MAX_CHANNEL_NAME_LENGTH) { char host[100]; sockAddrToA(&transport->getRemoteAddress()->sa,host,100); diff --git a/pvAccessApp/server/serverContext.cpp b/pvAccessApp/server/serverContext.cpp index b1762c0..cff244d 100644 --- a/pvAccessApp/server/serverContext.cpp +++ b/pvAccessApp/server/serverContext.cpp @@ -18,16 +18,7 @@ using std::tr1::static_pointer_cast; namespace epics { namespace pvAccess { const char* ServerContextImpl::StateNames[] = { "NOT_INITIALIZED", "INITIALIZED", "RUNNING", "SHUTDOWN", "DESTROYED"}; -const int32 ServerContextImpl::VERSION_MAJOR = 0; -const int32 ServerContextImpl::VERSION_MINOR = 9; -const int32 ServerContextImpl::VERSION_MAINTENANCE = 0; -const int32 ServerContextImpl::VERSION_DEVELOPMENT = 0; -const Version ServerContextImpl::VERSION("CA Server", "cpp", - ServerContextImpl::VERSION_MAJOR, - ServerContextImpl::VERSION_MINOR, - ServerContextImpl::VERSION_MAINTENANCE, - ServerContextImpl::VERSION_DEVELOPMENT); - +const Version ServerContextImpl::VERSION("pvAccess Server", "cpp", 1, 2, 0, true); ServerContextImpl::ServerContextImpl(): _state(NOT_INITIALIZED), diff --git a/pvAccessApp/server/serverContext.h b/pvAccessApp/server/serverContext.h index c5caf9f..3f74016 100644 --- a/pvAccessApp/server/serverContext.h +++ b/pvAccessApp/server/serverContext.h @@ -275,26 +275,6 @@ public: std::vector getChannelProviders(); private: - /** - * Major version. - */ - static const epics::pvData::int32 VERSION_MAJOR; - - /** - * Minor version. - */ - static const epics::pvData::int32 VERSION_MINOR; - - /** - * Maintenance version. - */ - static const epics::pvData::int32 VERSION_MAINTENANCE; - - /** - * Development version. - */ - static const epics::pvData::int32 VERSION_DEVELOPMENT; - /** * Initialization status. */ diff --git a/pvAccessApp/utils/namedLockPattern.h b/pvAccessApp/utils/namedLockPattern.h index 5de14db..77eb9bd 100644 --- a/pvAccessApp/utils/namedLockPattern.h +++ b/pvAccessApp/utils/namedLockPattern.h @@ -12,6 +12,7 @@ #include #include +#include #include @@ -54,8 +55,8 @@ public: void releaseSynchronizationObject(const Key& name); private: epics::pvData::Mutex _mutex; - std::map _namedLocks; - typename std::map::iterator _namedLocksIter; + std::map _namedLocks; + typename std::map::iterator _namedLocksIter; /** * Release synchronization lock for named object. @@ -69,7 +70,7 @@ private: template bool NamedLockPattern::acquireSynchronizationObject(const Key& name, const epics::pvData::int64 msec) { - ReferenceCountingLock* lock; + ReferenceCountingLock::shared_pointer lock; { //due to guard epics::pvData::Lock guard(_mutex); @@ -80,7 +81,7 @@ bool NamedLockPattern::acquireSynchronizationObject(const Key& name // increment references if(_namedLocksIter == _namedLocks.end()) { - lock = new ReferenceCountingLock(); + lock.reset(new ReferenceCountingLock()); _namedLocks[name] = lock; } else @@ -110,7 +111,7 @@ template void NamedLockPattern::releaseSynchronizationObject(const Key& name,const bool release) { epics::pvData::Lock guard(_mutex); - ReferenceCountingLock* lock; + ReferenceCountingLock::shared_pointer lock; _namedLocksIter = _namedLocks.find(name); // release lock @@ -129,7 +130,6 @@ void NamedLockPattern::releaseSynchronizationObject(const Key& name if (lock->decrement() <= 0) { _namedLocks.erase(_namedLocksIter); - delete lock; } } } diff --git a/pvAccessApp/utils/referenceCountingLock.h b/pvAccessApp/utils/referenceCountingLock.h index 0a15298..7b2a8aa 100644 --- a/pvAccessApp/utils/referenceCountingLock.h +++ b/pvAccessApp/utils/referenceCountingLock.h @@ -9,6 +9,7 @@ #include #include +#include namespace epics { namespace pvAccess { @@ -24,6 +25,8 @@ namespace pvAccess { class ReferenceCountingLock { public: + POINTER_DEFINITIONS(ReferenceCountingLock); + /** * Constructor of ReferenceCountingLock. * After construction lock is free and reference count equals 1. diff --git a/testApp/remote/eget.cpp b/testApp/remote/eget.cpp index 089e8c3..0cc51a6 100644 --- a/testApp/remote/eget.cpp +++ b/testApp/remote/eget.cpp @@ -1,10 +1,13 @@ #include #include +#include #include #include #include +#include #include +#include #include #include diff --git a/testApp/remote/pvget.cpp b/testApp/remote/pvget.cpp index 2db9682..306d5a8 100644 --- a/testApp/remote/pvget.cpp +++ b/testApp/remote/pvget.cpp @@ -1,10 +1,13 @@ #include #include +#include #include #include #include +#include #include +#include #include #include diff --git a/testApp/remote/pvput.cpp b/testApp/remote/pvput.cpp index 8bb66ce..70da954 100644 --- a/testApp/remote/pvput.cpp +++ b/testApp/remote/pvput.cpp @@ -1,10 +1,12 @@ #include #include +#include #include #include #include #include +#include #include #include diff --git a/testApp/remote/pvrpc.cpp b/testApp/remote/pvrpc.cpp index 4c7fb69..6677c31 100644 --- a/testApp/remote/pvrpc.cpp +++ b/testApp/remote/pvrpc.cpp @@ -1,10 +1,12 @@ #include #include +#include #include #include #include #include +#include #include #include diff --git a/testApp/remote/testGetPerformance.cpp b/testApp/remote/testGetPerformance.cpp index d5f2b2c..6c878a8 100644 --- a/testApp/remote/testGetPerformance.cpp +++ b/testApp/remote/testGetPerformance.cpp @@ -1,10 +1,13 @@ #include #include +#include #include #include #include +#include #include +#include #include #include