cleanup phase I

This commit is contained in:
Matej Sekoranja
2012-07-24 10:13:57 +02:00
parent 0f069c8875
commit 1b6587336e
18 changed files with 116 additions and 129 deletions

View File

@@ -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";
}
}

View File

@@ -4,7 +4,10 @@
* in file LICENSE that is included with this distribution.
*/
#include <pv/clientFactory.h>
#include <pv/clientContextImpl.h>
#include <pv/lock.h>
#include <pv/logger.h>
#include <epicsSignal.h>
@@ -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();

View File

@@ -7,9 +7,6 @@
#ifndef CLIENTFACTORY_H
#define CLIENTFACTORY_H
#include <pv/clientContextImpl.h>
#include <pv/lock.h>
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;
};
}}

View File

@@ -14,29 +14,59 @@ using epics::pvData::String;
namespace epics {
namespace pvAccess {
const String Version::getLongVersionString() const {
stringstream ret;
ret<<getProductName()<<" ["<<getImplementationLanguage();
ret<<"] v"<<getMajorVersion()<<"."<<getMinorVersion()<<".";
if(getDevelopmentVersion()>0) {
ret<<"D"<<getDevelopmentVersion();
} else
ret<<getMaintenanceVersion();
Version::Version(epics::pvData::String productName,
epics::pvData::String implementationLangugage,
int majorVersion, int minorVersion,
int maintenanceVersion, bool developmentFlag) :
_productName(productName),
_implementationLanguage(implementationLangugage),
_majorVersion(majorVersion),
_minorVersion(minorVersion),
_maintenanceVersion(maintenanceVersion),
_developmentFlag(developmentFlag)
{
}
return ret.str();
const epics::pvData::String Version::getProductName() const {
return _productName;
}
const epics::pvData::String Version::getImplementationLanguage() const {
return _implementationLanguage;
}
int Version::getMajorVersion() const {
return _majorVersion;
}
int Version::getMinorVersion() const {
return _minorVersion;
}
int Version::getMaintenanceVersion() const {
return _maintenanceVersion;
}
bool Version::isDevelopmentVersion() const {
return _developmentFlag;
}
const String Version::getVersionString() const {
stringstream ret;
ret<<getProductName()<<" v"<<getMajorVersion()<<".";
ret<<getMinorVersion()<<".";
if(getDevelopmentVersion()>0) {
ret<<"D"<<getDevelopmentVersion();
} else
ret<<getMaintenanceVersion();
ret<<getProductName()<<" v"<<getMajorVersion()<<"."<<getMinorVersion();
if (getMaintenanceVersion()>0)
ret<<'.'<<getMaintenanceVersion();
if(isDevelopmentVersion())
ret<<"-SNAPSHOT";
return ret.str();
}
std::ostream& operator<<(std::ostream& o, const Version& v) {
return o << v.getVersionString();
}
}
}

View File

@@ -9,6 +9,7 @@
#include <pv/pvType.h>
#include <pv/noDefaultMethods.h>
#include <ostream>
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:
* <ul>
* <li>a new set of functionality is to be added</li>
* <li>API or behaviour change</li>
* <li>its designated as a reference release</li>
* </ul>
*/
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 <BR/><CODE>
* "<B>ProductName </B> \[<B>ImplementationLanguage</B>\] 'v'v.r[.dd|<B>D</B>nn]"
* </CODE> <BR/>e.g. <BR/><CODE>"<B>CAJ </B> [<B>Java</B>] v1.0.1"</CODE>
* <BR/>
*
* 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 <BR/><CODE>
* "<B>ProductName </B> 'v'v.r[.dd|<B>D</B>nn]"
* </CODE> <BR/>e.g. <BR/><CODE>"<B>CAJ </B> v1.0.1"</CODE>
* <BR/>
*
* 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);
}
}

View File

@@ -280,7 +280,7 @@ public:
};
CreateRequest::shared_pointer createRequest;
static CreateRequest::shared_pointer createRequest;
CreateRequest::shared_pointer getCreateRequest() {
static Mutex mutex;

View File

@@ -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() {}

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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),

View File

@@ -275,26 +275,6 @@ public:
std::vector<ChannelProvider::shared_pointer> 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.
*/

View File

@@ -12,6 +12,7 @@
#include <pv/lock.h>
#include <pv/pvType.h>
#include <pv/sharedPtr.h>
#include <pv/referenceCountingLock.h>
@@ -54,8 +55,8 @@ public:
void releaseSynchronizationObject(const Key& name);
private:
epics::pvData::Mutex _mutex;
std::map<const Key,ReferenceCountingLock*,Compare> _namedLocks;
typename std::map<const Key,ReferenceCountingLock*,Compare>::iterator _namedLocksIter;
std::map<const Key,ReferenceCountingLock::shared_pointer,Compare> _namedLocks;
typename std::map<const Key,ReferenceCountingLock::shared_pointer,Compare>::iterator _namedLocksIter;
/**
* Release synchronization lock for named object.
@@ -69,7 +70,7 @@ private:
template <class Key, class Compare>
bool NamedLockPattern<Key,Compare>::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<Key,Compare>::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 <class Key, class Compare>
void NamedLockPattern<Key,Compare>::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<Key,Compare>::releaseSynchronizationObject(const Key& name
if (lock->decrement() <= 0)
{
_namedLocks.erase(_namedLocksIter);
delete lock;
}
}
}

View File

@@ -9,6 +9,7 @@
#include <pv/lock.h>
#include <pv/pvType.h>
#include <pv/sharedPtr.h>
namespace epics {
namespace pvAccess {
@@ -24,6 +25,8 @@ namespace pvAccess {
class ReferenceCountingLock
{
public:
POINTER_DEFINITIONS(ReferenceCountingLock);
/**
* Constructor of <code>ReferenceCountingLock</code>.
* After construction lock is free and reference count equals <code>1</code>.

View File

@@ -1,10 +1,13 @@
#include <iostream>
#include <pv/clientFactory.h>
#include <pv/pvAccess.h>
#include <stdio.h>
#include <epicsStdlib.h>
#include <epicsGetopt.h>
#include <epicsThread.h>
#include <pv/logger.h>
#include <pv/lock.h>
#include <vector>
#include <string>

View File

@@ -1,10 +1,13 @@
#include <iostream>
#include <pv/clientFactory.h>
#include <pv/pvAccess.h>
#include <stdio.h>
#include <epicsStdlib.h>
#include <epicsGetopt.h>
#include <epicsThread.h>
#include <pv/logger.h>
#include <pv/lock.h>
#include <vector>
#include <string>

View File

@@ -1,10 +1,12 @@
#include <iostream>
#include <pv/clientFactory.h>
#include <pv/pvAccess.h>
#include <stdio.h>
#include <epicsStdlib.h>
#include <epicsGetopt.h>
#include <pv/logger.h>
#include <pv/lock.h>
#include <vector>
#include <string>

View File

@@ -1,10 +1,12 @@
#include <iostream>
#include <pv/clientFactory.h>
#include <pv/pvAccess.h>
#include <stdio.h>
#include <epicsStdlib.h>
#include <epicsGetopt.h>
#include <pv/logger.h>
#include <pv/lock.h>
#include <vector>
#include <string>

View File

@@ -1,10 +1,13 @@
#include <iostream>
#include <pv/clientFactory.h>
#include <pv/pvAccess.h>
#include <stdio.h>
#include <epicsStdlib.h>
#include <epicsGetopt.h>
#include <epicsThread.h>
#include <pv/logger.h>
#include <pv/lock.h>
#include <vector>
#include <string>