diff --git a/pvAccessApp/Makefile b/pvAccessApp/Makefile index 368e322..a252a06 100644 --- a/pvAccessApp/Makefile +++ b/pvAccessApp/Makefile @@ -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 diff --git a/pvAccessApp/remote/beaconHandler.cpp b/pvAccessApp/remote/beaconHandler.cpp index 88a4392..596ace2 100644 --- a/pvAccessApp/remote/beaconHandler.cpp +++ b/pvAccessApp/remote/beaconHandler.cpp @@ -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; } }} diff --git a/pvAccessApp/remote/beaconHandler.h b/pvAccessApp/remote/beaconHandler.h index 73fa8fa..2a033a6 100644 --- a/pvAccessApp/remote/beaconHandler.h +++ b/pvAccessApp/remote/beaconHandler.h @@ -67,7 +67,6 @@ namespace epics { namespace pvAccess { * Mutex */ Mutex _mutex; - /** * Update beacon. * @param remoteTransportRevision encoded (major, minor) revision. diff --git a/pvAccessApp/remote/beaconServerStatusProvider.h b/pvAccessApp/remote/beaconServerStatusProvider.h index e6711da..5b65494 100644 --- a/pvAccessApp/remote/beaconServerStatusProvider.h +++ b/pvAccessApp/remote/beaconServerStatusProvider.h @@ -24,7 +24,7 @@ namespace epics { namespace pvAccess { */ BeaconServerStatusProvider(ServerContext* context); /** - * Test Constructor (ohne context) + * Test Constructor (without context) */ BeaconServerStatusProvider(); /** diff --git a/testApp/remote/Makefile b/testApp/remote/Makefile index 2228d16..0ddd4f4 100644 --- a/testApp/remote/Makefile +++ b/testApp/remote/Makefile @@ -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 #---------------------------------------- diff --git a/testApp/remote/testBeaconEmitter.cpp b/testApp/remote/testBeaconEmitter.cpp index ac1ec33..9ddd828 100644 --- a/testApp/remote/testBeaconEmitter.cpp +++ b/testApp/remote/testBeaconEmitter.cpp @@ -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()"<ia.sin_addr)==0) + { + assert(false); } broadcastAddresses->push_back(addr); BlockingUDPConnector connector(true, broadcastAddresses, true); diff --git a/testApp/remote/testBeaconHandler.cpp b/testApp/remote/testBeaconHandler.cpp index 435acac..30a51e2 100644 --- a/testApp/remote/testBeaconHandler.cpp +++ b/testApp/remote/testBeaconHandler.cpp @@ -6,6 +6,7 @@ #include "blockingUDP.h" #include "beaconHandler.h" #include "inetAddressUtil.h" +#include "introspectionRegistry.h" #include @@ -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(transport))->start(); while(1) sleep(1); diff --git a/testApp/utils/Makefile b/testApp/utils/Makefile index 8e364c2..ba2628e 100644 --- a/testApp/utils/Makefile +++ b/testApp/utils/Makefile @@ -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