Added configuration to Context and fixed all the users.

This commit is contained in:
miha_vitorovic
2011-01-10 14:09:58 +01:00
parent 4b8bb07d61
commit df7a9fa073
12 changed files with 532 additions and 407 deletions

View File

@@ -67,6 +67,7 @@ LIBSRCS += blockingTCPConnector.cpp
LIBSRCS += blockingServerTCPTransport.cpp
LIBSRCS += blockingTCPAcceptor.cpp
LIBSRCS += channelSearchManager.cpp
LIBSRCS += abstractResponseHandler.cpp
LIBRARY = pvAccess
pvAccess_LIBS += Com

View File

@@ -11,7 +11,7 @@
#include "caConstants.h"
#include "transportRegistry.h"
#include "introspectionRegistry.h"
#include "serverContext.h"
#include "configuration.h"
#include <serialize.h>
#include <pvType.h>
@@ -32,42 +32,42 @@ namespace epics {
};
enum QoS {
/**
* Default behavior.
*/
DEFAULT = 0x00,
/**
* Require reply (acknowledgment for reliable operation).
*/
REPLY_REQUIRED = 0x01,
/**
* Best-effort option (no reply).
*/
BESY_EFFORT = 0x02,
/**
* Process option.
*/
PROCESS = 0x04,
/**
* Initialize option.
*/
INIT = 0x08,
/**
* Destroy option.
*/
DESTROY = 0x10,
/**
* Share data option.
*/
SHARE = 0x20,
/**
* Get.
*/
GET = 0x40,
/**
* Get-put.
*/
GET_PUT =0x80
/**
* Default behavior.
*/
DEFAULT = 0x00,
/**
* Require reply (acknowledgment for reliable operation).
*/
REPLY_REQUIRED = 0x01,
/**
* Best-effort option (no reply).
*/
BESY_EFFORT = 0x02,
/**
* Process option.
*/
PROCESS = 0x04,
/**
* Initialize option.
*/
INIT = 0x08,
/**
* Destroy option.
*/
DESTROY = 0x10,
/**
* Share data option.
*/
SHARE = 0x20,
/**
* Get.
*/
GET = 0x40,
/**
* Get-put.
*/
GET_PUT = 0x80
};
typedef int32 pvAccessID;
@@ -253,6 +253,35 @@ namespace epics {
};
class Channel;
/**
* Not public IF, used by Transports, etc.
*/
class Context {
public:
virtual ~Context() {
}
/**
* Get timer.
* @return timer.
*/
virtual Timer* getTimer() = 0;
/**
* Get transport (virtual circuit) registry.
* @return transport (virtual circuit) registry.
*/
virtual TransportRegistry* getTransportRegistry() = 0;
virtual Channel* getChannel(pvAccessID id) = 0;
virtual Transport* getSearchTransport() = 0;
virtual Configuration* getConfiguration() = 0;
};
/**
* Interface defining response handler.
* @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
@@ -260,6 +289,10 @@ namespace epics {
*/
class ResponseHandler {
public:
ResponseHandler(Context* context) :
_context(context) {
}
virtual ~ResponseHandler() {
}
@@ -277,6 +310,9 @@ namespace epics {
handleResponse(osiSockAddr* responseFrom, Transport* transport,
int8 version, int8 command, int payloadSize,
epics::pvData::ByteBuffer* payloadBuffer) =0;
protected:
Context* _context;
};
/**
@@ -289,9 +325,10 @@ namespace epics {
/**
* @param description
*/
AbstractResponseHandler(String description) :
_description(description), _debug(true) {
//debug = System.getProperties().containsKey(CAConstants.CAJ_DEBUG);
AbstractResponseHandler(Context* context, String description) :
ResponseHandler(context), _description(description), _debug(
_context->getConfiguration()->getPropertyAsBoolean(
"PVACCESS_DEBUG", false)) {
}
virtual ~AbstractResponseHandler() {
@@ -373,33 +410,6 @@ namespace epics {
};
class Channel;
/**
* Not public IF, used by Transports, etc.
*/
class Context {
public:
virtual ~Context() {
}
/**
* Get timer.
* @return timer.
*/
virtual Timer* getTimer() =0;
/**
* Get transport (virtual circuit) registry.
* @return transport (virtual circuit) registry.
*/
virtual TransportRegistry* getTransportRegistry() =0;
virtual Channel* getChannel(pvAccessID id) = 0;
virtual Transport* getSearchTransport() = 0;
};
/**
* Interface defining reference counting transport IF.
* @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
@@ -474,7 +484,8 @@ namespace epics {
* @param sid preallocated channel SID.
* @param channel channel to register.
*/
virtual void registerChannel(pvAccessID sid, ServerChannel* channel) =0;
virtual void
registerChannel(pvAccessID sid, ServerChannel* channel) =0;
/**
* Unregister a new channel (and deallocates its handle).
@@ -495,44 +506,44 @@ namespace epics {
*/
virtual int getChannelCount() =0;
};
/**
* A request that expects an response.
* Responses identified by its I/O ID.
* Responses identified by its I/O ID.
* This interface needs to be extended (to provide method called on response).
* @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
*/
class ResponseRequest {
public:
/**
* Get I/O ID.
* @return ioid
*/
virtual pvAccessID getIOID() = 0;
/**
* Timeout notification.
*/
virtual void timeout() = 0;
/**
* Cancel response request (always to be called to complete/destroy).
*/
virtual void cancel() = 0;
/**
* Report status to clients (e.g. disconnected).
* @param status to report.
*/
virtual void reportStatus(epics::pvData::Status* status) = 0;
/**
* Get request requester.
* @return request requester.
*/
virtual epics::pvData::Requester* getRequester() = 0;
};
public:
/**
* Get I/O ID.
* @return ioid
*/
virtual pvAccessID getIOID() = 0;
/**
* Timeout notification.
*/
virtual void timeout() = 0;
/**
* Cancel response request (always to be called to complete/destroy).
*/
virtual void cancel() = 0;
/**
* Report status to clients (e.g. disconnected).
* @param status to report.
*/
virtual void reportStatus(epics::pvData::Status* status) = 0;
/**
* Get request requester.
* @return request requester.
*/
virtual epics::pvData::Requester* getRequester() = 0;
};
}
}

View File

@@ -24,23 +24,6 @@ using namespace epics::pvData;
namespace epics {
namespace pvAccess {
void AbstractResponseHandler::handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command,
int payloadSize, ByteBuffer* payloadBuffer) {
if(_debug) {
char ipAddrStr[48];
ipAddrToA(&responseFrom->ia, ipAddrStr, sizeof(ipAddrStr));
ostringstream prologue;
prologue<<"Message [0x"<<hex<<(int)command<<", v0x"<<hex;
prologue<<(int)version<<"] received from "<<ipAddrStr;
hexDump(prologue.str(), _description,
(const int8*)payloadBuffer->getArray(),
payloadBuffer->getPosition(), payloadSize);
}
}
void BadResponse::handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command,
int payloadSize, ByteBuffer* payloadBuffer) {
@@ -57,15 +40,15 @@ namespace epics {
}
ServerResponseHandler::ServerResponseHandler(ServerContextImpl* context) :
_context(context) {
ResponseHandler(context) {
BadResponse* badResponse = new BadResponse(context);
_handlerTable = new ResponseHandler*[HANDLER_TABLE_LENGTH];
// TODO add real handlers, as they are developed
_handlerTable[0] = new NoopResponse(_context, "Beacon");
_handlerTable[1] = new ConnectionValidationHandler(_context);
_handlerTable[2] = new EchoHandler(_context);
_handlerTable[0] = new NoopResponse(context, "Beacon");
_handlerTable[1] = new ConnectionValidationHandler(context);
_handlerTable[2] = new EchoHandler(context);
_handlerTable[3] = badResponse;
_handlerTable[4] = badResponse;
_handlerTable[5] = badResponse;

View File

@@ -8,6 +8,7 @@
#ifndef RESPONSEHANDLERS_H_
#define RESPONSEHANDLERS_H_
#include "serverContext.h"
#include "remote.h"
namespace epics {
@@ -25,13 +26,11 @@ namespace epics {
*/
AbstractServerResponseHandler(ServerContextImpl* context,
String description) :
AbstractResponseHandler(description), _context(context) {
AbstractResponseHandler(context, description) {
}
virtual ~AbstractServerResponseHandler() {
}
protected:
ServerContextImpl* _context;
};
/**
@@ -77,11 +76,6 @@ namespace epics {
*/
ResponseHandler** _handlerTable;
/**
* Context instance.
*/
ServerContextImpl* _context;
};
/**

View File

@@ -8,11 +8,12 @@
#ifndef SERVERCONTEXT_H_
#define SERVERCONTEXT_H_
#include "remote.h"
namespace epics {
namespace pvAccess {
class ServerContextImpl {
class ServerContextImpl : public Context {
};

View File

@@ -18,6 +18,8 @@ using namespace epics::pvData;
class DummyResponseHandler : public ResponseHandler
{
public:
DummyResponseHandler(Context* ctx) : ResponseHandler(ctx) {}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command, int payloadSize,
ByteBuffer* payloadBuffer)
@@ -27,9 +29,33 @@ public:
};
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() { return _timer; }
virtual TransportRegistry* getTransportRegistry() { return _tr; }
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Configuration* getConfiguration() { return _conf; }
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
void testBeaconEmitter()
{
DummyResponseHandler drh;
ContextImpl ctx;
DummyResponseHandler drh(&ctx);
/* SOCKET mysocket;
if ((mysocket = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
{

View File

@@ -37,7 +37,7 @@ void decodeFromIPv6Address(ByteBuffer* buffer, osiSockAddr* address)
class BeaconResponseHandler : public ResponseHandler
{
public:
BeaconResponseHandler()
BeaconResponseHandler(Context* ctx) : ResponseHandler(ctx)
{
_pvDataCreate = getPVDataCreate();
}
@@ -103,9 +103,33 @@ private:
};
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() { return _timer; }
virtual TransportRegistry* getTransportRegistry() { return _tr; }
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Configuration* getConfiguration() { return _conf; }
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
void testBeaconHandler()
{
BeaconResponseHandler brh;
ContextImpl ctx;
BeaconResponseHandler brh(&ctx);
BlockingUDPConnector connector(false, NULL, true);
osiSockAddr bindAddr;

View File

@@ -29,28 +29,30 @@ using std::sscanf;
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("client thread",
lowPriority)) {
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() {
return _timer;
}
virtual TransportRegistry* getTransportRegistry() {
return _tr;
}
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Timer* getTimer() { return _timer; }
virtual TransportRegistry* getTransportRegistry() { return _tr; }
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Configuration* getConfiguration() { return _conf; }
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
class DummyResponseHandler : public ResponseHandler {
public:
DummyResponseHandler(Context* ctx) : ResponseHandler(ctx) {
}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command, int payloadSize,
ByteBuffer* payloadBuffer) {
@@ -110,7 +112,7 @@ void testBlockingTCPSender() {
DummyTransportClient dtc;
DummyTransportSender dts;
DummyResponseHandler drh;
DummyResponseHandler drh(&ctx);
osiSockAddr srvAddr;

View File

@@ -8,6 +8,7 @@
#include "blockingTCP.h"
#include "remote.h"
#include "logger.h"
#include "configuration.h"
#include <iostream>
@@ -21,7 +22,8 @@ class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()),
_timer(new Timer("server thread", lowPriority)) {}
_timer(new Timer("server thread", lowPriority)),
_conf(new SystemConfigurationImpl()) {}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
@@ -30,10 +32,12 @@ public:
virtual TransportRegistry* getTransportRegistry() { return _tr; }
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Configuration* getConfiguration() { return _conf; }
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
void testServerConnections() {
@@ -43,7 +47,7 @@ void testServerConnections() {
1024);
cout<<"Press any key to stop the server...";
char c = cin.peek();
cin.peek();
delete srv;
}

View File

@@ -26,8 +26,44 @@ using std::sscanf;
static osiSockAddr sendTo;
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() {
return _timer;
}
virtual TransportRegistry* getTransportRegistry() {
return _tr;
}
virtual Channel* getChannel(epics::pvAccess::pvAccessID) {
return 0;
}
virtual Transport* getSearchTransport() {
return 0;
}
virtual Configuration* getConfiguration() {
return _conf;
}
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
class DummyResponseHandler : public ResponseHandler {
public:
DummyResponseHandler(Context* ctx) :
ResponseHandler(ctx) {
}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command, int payloadSize,
ByteBuffer* payloadBuffer) {
@@ -69,9 +105,10 @@ private:
void testBlockingUDPSender() {
BlockingUDPConnector connector(false, NULL, true);
ContextImpl ctx;
DummyTransportSender dts;
DummyResponseHandler drh;
DummyResponseHandler drh(&ctx);
osiSockAddr bindAddr;

View File

@@ -21,10 +21,42 @@ using std::endl;
using std::hex;
using std::dec;
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() {
return _timer;
}
virtual TransportRegistry* getTransportRegistry() {
return _tr;
}
virtual Channel* getChannel(epics::pvAccess::pvAccessID) {
return 0;
}
virtual Transport* getSearchTransport() {
return 0;
}
virtual Configuration* getConfiguration() {
return _conf;
}
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
class DummyResponseHandler : public ResponseHandler {
public:
DummyResponseHandler() :
packets(0) {
DummyResponseHandler(Context* context) :
ResponseHandler(context), packets(0) {
}
int getPackets() {
@@ -71,8 +103,9 @@ void DummyResponseHandler::handleResponse(osiSockAddr* responseFrom,
void testBlockingUDPConnector() {
BlockingUDPConnector connector(false, NULL, true);
ContextImpl ctx;
DummyResponseHandler drh;
DummyResponseHandler drh(&ctx);
osiSockAddr bindAddr;

File diff suppressed because it is too large Load Diff