Named locked pattern and some small things for beacon emitter and handler

This commit is contained in:
Gasper Jansa
2011-01-04 18:43:20 +01:00
parent a2798bb3b7
commit 547a648e76
8 changed files with 98 additions and 14 deletions

View File

@@ -19,12 +19,16 @@ INC += inetAddressUtil.h
INC += logger.h
INC += introspectionRegistry.h
INC += transportRegistry.h
INC += namedLockPattern.h
INC += referenceCountingLock.h
LIBSRCS += hexDump.cpp
LIBSRCS += wildcharMatcher.cpp
LIBSRCS += inetAddressUtil.cpp
LIBSRCS += logger.cpp
LIBSRCS += introspectionRegistry.cpp
LIBSRCS += transportRegistry.cpp
LIBSRCS += namedLockPattern.cpp
LIBSRCS += referenceCountingLock.cpp
SRC_DIRS += $(PVACCESS)/client

View File

@@ -69,7 +69,7 @@ bool BeaconHandler::updateBeacon(int8 remoteTransportRevision, int64 timestamp,
void BeaconHandler::beaconArrivalNotify()
{
int32 size;
int32 size = 0;
//TODO TCP name must be get from somewhere not hardcoded
//TODO
Transport** transports = NULL;//_context->getTransportRegistry().get("TCP", _responseFrom, size);
@@ -83,12 +83,12 @@ void BeaconHandler::beaconArrivalNotify()
{
transports[i]->aliveNotification();
}
delete transports;
delete[] transports;
}
void BeaconHandler::changedTransport()
{
int32 size;
int32 size = 0;
//TODO TCP name must be get from somewhere not hardcoded
//TODO
Transport** transports = NULL;//_context->getTransportRegistry().get("TCP", _responseFrom, size);
@@ -102,7 +102,7 @@ void BeaconHandler::changedTransport()
{
transports[i]->changedTransport();
}
delete transports;
delete[] transports;
}
}}

View File

@@ -67,7 +67,6 @@ namespace epics { namespace pvAccess {
* Mutex
*/
Mutex _mutex;
/**
* Update beacon.
* @param remoteTransportRevision encoded (major, minor) revision.

View File

@@ -24,7 +24,7 @@ namespace epics { namespace pvAccess {
*/
BeaconServerStatusProvider(ServerContext* context);
/**
* Test Constructor (ohne context)
* Test Constructor (without context)
*/
BeaconServerStatusProvider();
/**

View File

@@ -18,6 +18,9 @@ PROD_HOST += testBeaconEmitter
testBeaconEmitter_SRCS += testBeaconEmitter.cpp
testBeaconEmitter_LIBS += pvData pvAccess Com
PROD_HOST += testBeaconHandler
testBeaconHandler_SRCS += testBeaconHandler.cpp
testBeaconHandler_LIBS += pvData pvAccess Com
include $(TOP)/configure/RULES
#----------------------------------------

View File

@@ -42,9 +42,9 @@ void testBeaconEmitter()
osiSockAddr* addr = new osiSockAddr;
addr->ia.sin_family = AF_INET;
addr->ia.sin_port = htons(5067);
if(inet_aton("92.50.75.255",&addr->ia.sin_addr)==0) {
cout<<"error in inet_aton()"<<endl;
return;
if(inet_aton("255.255.255.255",&addr->ia.sin_addr)==0)
{
assert(false);
}
broadcastAddresses->push_back(addr);
BlockingUDPConnector connector(true, broadcastAddresses, true);

View File

@@ -6,6 +6,7 @@
#include "blockingUDP.h"
#include "beaconHandler.h"
#include "inetAddressUtil.h"
#include "introspectionRegistry.h"
#include <osiSock.h>
@@ -14,32 +15,105 @@
using namespace epics::pvAccess;
using namespace epics::pvData;
using namespace std;
void decodeFromIPv6Address(ByteBuffer* buffer, osiSockAddr* address)
{
// IPv4 compatible IPv6 address
// first 80-bit are 0
buffer->getLong();
buffer->getShort();
// next 16-bits are 1
buffer->getShort();
// following IPv4 address in big-endian (network) byte order
in_addr_t ipv4Addr = 0;
ipv4Addr |= (uint32)buffer->getByte() << 24;
ipv4Addr |= (uint32)buffer->getByte() << 16;
ipv4Addr |= (uint32)buffer->getByte() << 8;
ipv4Addr |= (uint32)buffer->getByte() << 0;
address->ia.sin_addr.s_addr = ipv4Addr;
}
class BeaconResponseHandler : public ResponseHandler
{
public:
BeaconResponseHandler()
{
_pvDataCreate = getPVDataCreate();
}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command, int payloadSize,
ByteBuffer* payloadBuffer)
{
cout << "DummyResponseHandler::handleResponse" << endl;
cout << "BeaconResponseHandler::handleResponse" << endl;
// reception timestamp
TimeStamp timestamp;
timestamp.getCurrent();
//TODO
//super.handleResponse(responseFrom, transport, version, command, payloadSize, payloadBuffer);
transport->ensureData((2*sizeof(int16)+2*sizeof(int32)+128)/sizeof(int8));
const int32 sequentalID = payloadBuffer->getShort() & 0x0000FFFF;
const TimeStamp startupTimestamp(payloadBuffer->getInt() & 0x00000000FFFFFFFFL,(int32)(payloadBuffer->getInt() & 0x00000000FFFFFFFFL));
// 128-bit IPv6 address
osiSockAddr address;
decodeFromIPv6Address(payloadBuffer, &address);
// get port
const int32 port = payloadBuffer->getShort() & 0xFFFF;
address.ia.sin_port = ntohs(port);
// accept given address if explicitly specified by sender
if (!ipv4AddressToInt(address))
{
responseFrom->ia.sin_port = port;
}
else
{
responseFrom->ia.sin_port = port;
responseFrom->ia.sin_addr.s_addr = address.ia.sin_addr.s_addr;
}
//org.epics.ca.client.impl.remote.BeaconHandler beaconHandler = context.getBeaconHandler(responseFrom);
// currently we care only for servers used by this context
//if (beaconHandler == null)
// return;
// extra data
PVFieldPtr data = NULL;
const FieldConstPtr field = IntrospectionRegistry::deserializeFull(payloadBuffer, transport);
if (field != NULL)
{
data = _pvDataCreate->createPVField(NULL, field);
data->deserialize(payloadBuffer, transport);
}
// notify beacon handler
//beaconHandler.beaconNotify(responseFrom, version, timestamp, startupTimestamp, sequentalID, data);
}
private:
PVDataCreate* _pvDataCreate;
BeaconHandler* _beaconHandler;
};
void testBeaconHandler()
{
BeacondResponseHandler brh;
BeaconResponseHandler brh;
BlockingUDPConnector connector(false, NULL, true);
DummyClientContext context;
osiSockAddr bindAddr;
bindAddr.ia.sin_family = AF_INET;
bindAddr.ia.sin_port = htons(5067);
bindAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
Transport* transport = connector.connect(NULL, &brh, &bindAddr, 1, 50);
((BlockingUDPTransport*)transport)->start();
(static_cast<BlockingUDPTransport*>(transport))->start();
while(1) sleep(1);

View File

@@ -34,6 +34,10 @@ PROD_HOST += transportRegisterTest
transportRegisterTest_SRCS += transportRegistryTest.cpp
transportRegisterTest_LIBS += pvAccess Com pvData
PROD_HOST += namedLockPatternTest
namedLockPatternTest_SRCS += namedLockPatternTest.cpp
namedLockPatternTest_LIBS += pvAccess Com pvData
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE