serverContext and beacon emitter impl
This commit is contained in:
@@ -11,52 +11,52 @@ namespace epics { namespace pvAccess {
|
||||
const float BeaconEmitter::EPICS_CA_MIN_BEACON_PERIOD = 1.0;
|
||||
const float BeaconEmitter::EPICS_CA_MIN_BEACON_COUNT_LIMIT = 3.0;
|
||||
|
||||
BeaconEmitter::BeaconEmitter(Transport* transport, ServerContext* context): _transport(transport)
|
||||
BeaconEmitter::BeaconEmitter(Transport* transport, ServerContextImpl* context): _transport(transport)
|
||||
{
|
||||
if(transport == NULL || context == NULL)
|
||||
{
|
||||
THROW_BASE_EXCEPTION("null transport or context");
|
||||
}
|
||||
|
||||
/* _timer = context->getTimer();
|
||||
_logger = context->getLogger();
|
||||
_timer = context->getTimer();
|
||||
_beaconSequenceID = 0;
|
||||
_serverAddress = context->getServerInetAddres();
|
||||
_serverAddress = context->getServerInetAddress();
|
||||
_serverPort = context->getServerPort();
|
||||
_serverStatusProvider = context->getBeaconServerStatusProvider();
|
||||
_fastBeaconPeriod = std::max(context->getBeaconPeriod(), EPICS_CA_MIN_BEACON_PERIOD);
|
||||
_slowBeaconPeriod = std::max(180.0, _fastBeaconPeriod); // TODO configurable
|
||||
_beaconCountLimit = (int16)std::max(10, EPICS_CA_MIN_BEACON_COUNT_LIMIT); // TODO configurable
|
||||
_startupTime = TimeStampFactory.create(System.currentTimeMillis());
|
||||
_timerNode = TimerFactory.createNode(this);*/
|
||||
_beaconCountLimit = (int16)std::max(10.0f, EPICS_CA_MIN_BEACON_COUNT_LIMIT); // TODO configurable
|
||||
_startupTime = new TimeStamp();
|
||||
_startupTime->getCurrent();
|
||||
_timerNode = new TimerNode(this);
|
||||
}
|
||||
|
||||
BeaconEmitter::BeaconEmitter(Transport* transport,const osiSockAddr* serverAddress): _transport(transport)
|
||||
{
|
||||
if(transport == NULL)
|
||||
{
|
||||
THROW_BASE_EXCEPTION("null transport");
|
||||
}
|
||||
{
|
||||
THROW_BASE_EXCEPTION("null transport");
|
||||
}
|
||||
|
||||
_timer = new Timer("pvAccess-server timer", lowPriority);
|
||||
//_logger = new Loger();
|
||||
_beaconSequenceID = 0;
|
||||
_serverAddress = serverAddress;
|
||||
_serverPort = serverAddress->ia.sin_port;
|
||||
_serverStatusProvider = NULL;//new BeaconServerStatusProvider();
|
||||
_fastBeaconPeriod = EPICS_CA_MIN_BEACON_PERIOD;
|
||||
_slowBeaconPeriod = 180.0;
|
||||
_beaconCountLimit = 10;
|
||||
_startupTime = new TimeStamp();
|
||||
_timerNode = new TimerNode(this);
|
||||
|
||||
_beaconSequenceID = 0;
|
||||
_serverAddress = serverAddress;
|
||||
_serverPort = serverAddress->ia.sin_port;
|
||||
_serverStatusProvider = NULL;//new BeaconServerStatusProvider();
|
||||
_fastBeaconPeriod = EPICS_CA_MIN_BEACON_PERIOD;
|
||||
_slowBeaconPeriod = 180.0;
|
||||
_beaconCountLimit = 10;
|
||||
_startupTime = new TimeStamp();
|
||||
_startupTime->getCurrent();
|
||||
_timerNode = new TimerNode(this);
|
||||
}
|
||||
|
||||
BeaconEmitter::~BeaconEmitter()
|
||||
{
|
||||
if(_timer) delete _timer;
|
||||
if(_serverStatusProvider) delete _serverStatusProvider;
|
||||
if(_startupTime) delete _startupTime;
|
||||
if(_timerNode) delete _timerNode;
|
||||
if(_startupTime) delete _startupTime;
|
||||
}
|
||||
|
||||
void BeaconEmitter::lock()
|
||||
@@ -91,7 +91,7 @@ void BeaconEmitter::send(ByteBuffer* buffer, TransportSendControl* control)
|
||||
}
|
||||
catch (...) {
|
||||
// we have to proctect internal code from external implementation...
|
||||
//logger->log(Level.WARNING, "BeaconServerStatusProvider implementation thrown an exception.", th);
|
||||
errlogSevPrintf(errlogMinor, "BeaconServerStatusProvider implementation thrown an exception.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
#include "beaconServerStatusProvider.h"
|
||||
#include "inetAddressUtil.h"
|
||||
#include "introspectionRegistry.h"
|
||||
#include "serverContext.h"
|
||||
|
||||
|
||||
#include <timeStamp.h>
|
||||
#include <osiSock.h>
|
||||
#include <errlog.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@@ -21,8 +24,7 @@ using namespace epics::pvData;
|
||||
|
||||
namespace epics { namespace pvAccess {
|
||||
|
||||
class ServerContext;
|
||||
class Logger;
|
||||
class ServerContextImpl;
|
||||
|
||||
/**
|
||||
* BeaconEmitter
|
||||
@@ -37,7 +39,7 @@ namespace epics { namespace pvAccess {
|
||||
* @param transport transport to be used to send beacons.
|
||||
* @param context CA context.
|
||||
*/
|
||||
BeaconEmitter(Transport* transport, ServerContext* context);
|
||||
BeaconEmitter(Transport* transport, ServerContextImpl* context);
|
||||
/**
|
||||
* Test Constructor (ohne context)
|
||||
* @param transport transport to be used to send beacons.
|
||||
@@ -95,11 +97,6 @@ namespace epics { namespace pvAccess {
|
||||
*/
|
||||
Timer* _timer;
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
Logger* _logger;
|
||||
|
||||
/**
|
||||
* Transport.
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ const int32 ServerContextImpl::VERSION_MAJOR = 2;
|
||||
const int32 ServerContextImpl::VERSION_MINOR = 0;
|
||||
const int32 ServerContextImpl::VERSION_MAINTENANCE = 0;
|
||||
const int32 ServerContextImpl::VERSION_DEVELOPMENT = 0;
|
||||
const Version* ServerContextImpl::VERSION = new Version("Channel Access Server in C++", "C++",
|
||||
const Version ServerContextImpl::VERSION("Channel Access Server in C++", "C++",
|
||||
ServerContextImpl::VERSION_MAJOR,
|
||||
ServerContextImpl::VERSION_MINOR,
|
||||
ServerContextImpl::VERSION_MAINTENANCE,
|
||||
@@ -30,6 +30,7 @@ ServerContextImpl::ServerContextImpl():
|
||||
_receiveBufferSize(MAX_TCP_RECV),
|
||||
_timer(NULL),
|
||||
_broadcastTransport(NULL),
|
||||
_broadcastConnector(NULL),
|
||||
_beaconEmitter(NULL),
|
||||
_acceptor(NULL),
|
||||
_transportRegistry(NULL),
|
||||
@@ -47,9 +48,15 @@ ServerContextImpl::ServerContextImpl():
|
||||
|
||||
ServerContextImpl::~ServerContextImpl()
|
||||
{
|
||||
if(_beaconEmitter) delete _beaconEmitter;
|
||||
if(_broadcastTransport) delete _broadcastTransport;
|
||||
if(_broadcastConnector) delete _broadcastConnector;
|
||||
if(_acceptor) delete _acceptor;
|
||||
if(_transportRegistry) delete _transportRegistry;
|
||||
if(_timer) delete _timer;
|
||||
}
|
||||
|
||||
const Version* ServerContextImpl::getVersion()
|
||||
const Version& ServerContextImpl::getVersion()
|
||||
{
|
||||
return ServerContextImpl::VERSION;
|
||||
}
|
||||
@@ -101,7 +108,7 @@ void ServerContextImpl::loadConfiguration()
|
||||
|
||||
void ServerContextImpl::initialize(ChannelAccess* channelAccess)
|
||||
{
|
||||
//TODO
|
||||
//TODO uncomment
|
||||
/*Lock guard(&_mutex);
|
||||
if (channelAccess == NULL)
|
||||
{
|
||||
@@ -163,14 +170,15 @@ void ServerContextImpl::initializeBroadcastTransport()
|
||||
epicsSocketDestroy(socket);
|
||||
|
||||
|
||||
BlockingUDPConnector* broadcastConnector = new BlockingUDPConnector(true, true);
|
||||
_broadcastConnector = new BlockingUDPConnector(true, true);
|
||||
|
||||
_broadcastTransport = static_cast<BlockingUDPTransport*>(broadcastConnector->connect(
|
||||
_broadcastTransport = static_cast<BlockingUDPTransport*>(_broadcastConnector->connect(
|
||||
NULL, new ServerResponseHandler(this),
|
||||
listenLocalAddress, CA_MINOR_PROTOCOL_REVISION,
|
||||
CA_DEFAULT_PRIORITY));
|
||||
|
||||
_broadcastTransport->setBroadcastAddresses(broadcasts);
|
||||
if(broadcasts) delete broadcasts;
|
||||
|
||||
// set ignore address list
|
||||
if (_ignoreAddressList.length() > 0)
|
||||
@@ -181,6 +189,8 @@ void ServerContextImpl::initializeBroadcastTransport()
|
||||
{
|
||||
_broadcastTransport->setIgnoredAddresses(list);
|
||||
}
|
||||
if(list) delete list;
|
||||
|
||||
}
|
||||
// set broadcast address list
|
||||
if (_beaconAddressList.length() > 0)
|
||||
@@ -197,6 +207,7 @@ void ServerContextImpl::initializeBroadcastTransport()
|
||||
{
|
||||
_broadcastTransport->setBroadcastAddresses(list);
|
||||
}
|
||||
if(list) delete list;
|
||||
}
|
||||
|
||||
_broadcastTransport->start();
|
||||
@@ -240,7 +251,6 @@ void ServerContextImpl::run(int32 seconds)
|
||||
// run...
|
||||
_beaconEmitter->start();
|
||||
|
||||
//TODO review how is with guards
|
||||
if(seconds == 0)
|
||||
{
|
||||
_runEvent.wait();
|
||||
@@ -367,7 +377,7 @@ void ServerContextImpl::printInfo()
|
||||
void ServerContextImpl::printInfo(ostream& str)
|
||||
{
|
||||
Lock guard(&_mutex);
|
||||
str << "VERSION : " << getVersion()->getVersionString() << endl \
|
||||
str << "VERSION : " << getVersion().getVersionString() << endl \
|
||||
<< "CHANNEL PROVIDER : " << _channelProviderName << endl \
|
||||
<< "BEACON_ADDR_LIST : " << _beaconAddressList << endl \
|
||||
<< "AUTO_BEACON_ADDR_LIST : " << _autoBeaconAddressList << endl \
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
* Get context implementation version.
|
||||
* @return version of the context implementation.
|
||||
*/
|
||||
virtual const Version* getVersion() = 0;
|
||||
virtual const Version& getVersion() = 0;
|
||||
|
||||
/**
|
||||
* Set <code>ChannelAccess</code> implementation and initialize server.
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
virtual ~ServerContextImpl();
|
||||
|
||||
//**************** derived from ServerContext ****************//
|
||||
const Version* getVersion();
|
||||
const Version& getVersion();
|
||||
void initialize(ChannelAccess* channelAccess);
|
||||
void run(int32 seconds);
|
||||
void shutdown();
|
||||
@@ -116,24 +116,16 @@ public:
|
||||
void dispose();
|
||||
void setBeaconServerStatusProvider(BeaconServerStatusProvider* beaconServerStatusProvider);
|
||||
//**************** derived from Context ****************//
|
||||
/**
|
||||
* Get timer.
|
||||
* @return timer.
|
||||
*/
|
||||
Timer* getTimer();
|
||||
Channel* getChannel(pvAccessID id);
|
||||
Transport* getSearchTransport();
|
||||
Configuration* getConfiguration();
|
||||
/**
|
||||
* Get CA transport (virtual circuit) registry.
|
||||
* @return CA transport (virtual circuit) registry.
|
||||
*/
|
||||
TransportRegistry* getTransportRegistry();
|
||||
|
||||
/**
|
||||
* Version.
|
||||
*/
|
||||
static const Version* VERSION;
|
||||
static const Version VERSION;
|
||||
|
||||
|
||||
/**
|
||||
@@ -267,7 +259,6 @@ public:
|
||||
ChannelProvider* getChannelProvider();
|
||||
|
||||
private:
|
||||
//TODO check protected members in java
|
||||
/**
|
||||
* Major version.
|
||||
*/
|
||||
@@ -291,7 +282,7 @@ private:
|
||||
/**
|
||||
* Initialization status.
|
||||
*/
|
||||
volatile State _state;
|
||||
State _state;
|
||||
|
||||
/**
|
||||
* A space-separated list of broadcast address which to send beacons.
|
||||
@@ -350,6 +341,11 @@ private:
|
||||
*/
|
||||
BlockingUDPTransport* _broadcastTransport;
|
||||
|
||||
/**
|
||||
* Broadcast connector
|
||||
*/
|
||||
BlockingUDPConnector* _broadcastConnector;
|
||||
|
||||
/**
|
||||
* Beacon emitter.
|
||||
*/
|
||||
@@ -406,18 +402,6 @@ private:
|
||||
*/
|
||||
void loadConfiguration();
|
||||
|
||||
/**
|
||||
* Check context state.
|
||||
* @throws BaseExeption if state is <code>DESTROYED</code>
|
||||
*/
|
||||
inline void checkState()
|
||||
{
|
||||
if (_state == DESTROYED)
|
||||
{
|
||||
THROW_BASE_EXCEPTION("Context destroyed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal initialization.
|
||||
*/
|
||||
|
||||
@@ -11,19 +11,21 @@ using namespace std;
|
||||
void testServerContext()
|
||||
{
|
||||
|
||||
ServerContextImpl ctx;
|
||||
ServerContextImpl ctx;
|
||||
|
||||
ctx.initialize(NULL);
|
||||
ctx.initialize(NULL);
|
||||
|
||||
ctx.printInfo();
|
||||
ctx.printInfo();
|
||||
|
||||
ctx.run(1);
|
||||
ctx.run(1);
|
||||
|
||||
ctx.destroy();
|
||||
ctx.destroy();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
testServerContext();
|
||||
|
||||
cout << "Done" << endl;
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user