diff --git a/pvAccessApp/Makefile b/pvAccessApp/Makefile index b6071bd..fb1b425 100644 --- a/pvAccessApp/Makefile +++ b/pvAccessApp/Makefile @@ -53,6 +53,7 @@ INC += beaconEmitter.h INC += beaconServerStatusProvider.h INC += beaconHandler.h INC += blockingTCP.h +INC += channelSearchManager.h LIBSRCS += blockingUDPTransport.cpp LIBSRCS += blockingUDPConnector.cpp LIBSRCS += beaconEmitter.cpp @@ -63,6 +64,7 @@ LIBSRCS += blockingClientTCPTransport.cpp LIBSRCS += blockingTCPConnector.cpp LIBSRCS += blockingServerTCPTransport.cpp LIBSRCS += blockingTCPAcceptor.cpp +LIBSRCS += channelSearchManager.cpp LIBRARY = pvAccess pvAccess_LIBS += Com diff --git a/pvAccessApp/remote/channelSearchManager.cpp b/pvAccessApp/remote/channelSearchManager.cpp index 033ff00..1c6110c 100644 --- a/pvAccessApp/remote/channelSearchManager.cpp +++ b/pvAccessApp/remote/channelSearchManager.cpp @@ -440,6 +440,8 @@ ChannelSearchManager::ChannelSearchManager(ClientContextImpl* context): _timers[i] = new SearchTimer(this, i, i > _beaconAnomalyTimerIndex, i != (numberOfTimers-1)); } _numberOfTimers = numberOfTimers; + + _mockTransportSendControl = new MockTransportSendControl(); } ChannelSearchManager::~ChannelSearchManager() @@ -450,6 +452,7 @@ ChannelSearchManager::~ChannelSearchManager() } if(_timers) delete[] _timers; if(_sendBuffer) delete _sendBuffer; + if(_mockTransportSendControl) delete _mockTransportSendControl; } void ChannelSearchManager::cancel() @@ -511,7 +514,7 @@ void ChannelSearchManager::searchResponse(int32 cid, int32 seqNo, int8 minorRevi else { // minor hack to enable duplicate reports - si = static_cast(_context->getChannel(cid)); + si = reinterpret_cast(_context->getChannel(cid)); if(si != NULL) { si->searchResponse(minorRevision, serverAddress); @@ -556,8 +559,7 @@ void ChannelSearchManager::initializeSendBuffer() sendBuffer.put(REQUIRE_REPLY ? (byte)QoS.REPLY_REQUIRED.getMaskValue() : (byte)QoS.DEFAULT.getMaskValue()); */ - //TODO implement Qos - //_sendBuffer->put((int8)QoS.DEFAULT.getMaskValue()); + _sendBuffer->putByte((int8)DEFAULT); _sendBuffer->putShort((int16)0); // count } @@ -567,8 +569,7 @@ void ChannelSearchManager::flushSendBuffer() TimeStamp now; now.getCurrent(); _timeAtLastSend = now.getMilliseconds(); - //TODO - //_context->getSearchTransport()->send(sendBuffer); + _context->getSearchTransport()->send(_sendBuffer); initializeSendBuffer(); } diff --git a/pvAccessApp/remote/channelSearchManager.h b/pvAccessApp/remote/channelSearchManager.h index b58a9ef..b180e71 100644 --- a/pvAccessApp/remote/channelSearchManager.h +++ b/pvAccessApp/remote/channelSearchManager.h @@ -9,7 +9,7 @@ #include "pvAccess.h" #include "arrayFIFO.h" #include "caConstants.h" -#include "clientContextImpl.h" +#include "blockingUDP.h" #include #include @@ -26,6 +26,212 @@ namespace epics { namespace pvAccess { typedef int32 pvAccessID; +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 +}; + + +//TODO this will be deleted +class ChannelImpl; +class ChannelSearchManager; +class ClientContextImpl : public ClientContext +{ + public: + + ClientContextImpl() + { + + } + + virtual Version* getVersion() { + return NULL; + } + + virtual ChannelProvider* getProvider() { + return NULL; + } + + Timer* getTimer() + { + return NULL; + } + + virtual void initialize() { + + } + + virtual void printInfo() { + + } + + virtual void printInfo(epics::pvData::StringBuilder out) { + + } + + virtual void destroy() + { + + } + + virtual void dispose() + { + + } + + BlockingUDPTransport* getSearchTransport() + { + return NULL; + } + + /** + * Searches for a channel with given channel ID. + * @param channelID CID. + * @return channel with given CID, 0 if non-existent. + */ + ChannelImpl* getChannel(pvAccessID channelID) + { + return NULL; + } + + + private: + ~ClientContextImpl() {}; + + void loadConfiguration() { + + } + + void internalInitialize() { + + + } + + void initializeUDPTransport() { + + } + + void internalDestroy() { + + } + + void destroyAllChannels() { + + } + + /** + * Check channel name. + */ + void checkChannelName(String& name) { + + } + + /** + * Check context state and tries to establish necessary state. + */ + void checkState() { + + } + + + + /** + * Generate Client channel ID (CID). + * @return Client channel ID (CID). + */ + pvAccessID generateCID() + { + return 0; + } + + /** + * Free generated channel ID (CID). + */ + void freeCID(int cid) + { + + } + + + /** + * Get, or create if necessary, transport of given server address. + * @param serverAddress required transport address + * @param priority process priority. + * @return transport for given address + */ + Transport* getTransport(TransportClient* client, osiSockAddr* serverAddress, int16 minorRevision, int16 priority) + { + + return NULL; + } + + /** + * Internal create channel. + */ + // TODO no minor version with the addresses + // TODO what if there is an channel with the same name, but on different host! + Channel* createChannelInternal(String name, ChannelRequester* requester, short priority, + InetAddrVector* addresses) { + return NULL; + } + + /** + * Destroy channel. + * @param channel + * @param force + * @throws CAException + * @throws IllegalStateException + */ + void destroyChannel(ChannelImpl* channel, bool force) { + + + } + + /** + * Get channel search manager. + * @return channel search manager. + */ + ChannelSearchManager* getChannelSearchManager() { + return NULL; + } +}; + + + //TODO check the const of paramerers /** @@ -207,6 +413,18 @@ private: static const int32 MAX_FRAMES_PER_TRY; }; +class MockTransportSendControl: public TransportSendControl +{ +public: + void endMessage() {} + void flush(bool lastMessageCompleted) {} + void setRecipient(const osiSockAddr* sendTo) {} + void startMessage(int8 command, int32 ensureCapacity) {} + void ensureBuffer(int32 size) {} + void flushSerializeBuffer() {} +}; + + class ChannelSearchManager { public: @@ -333,7 +551,7 @@ private: /** * Mock transport send control */ - TransportSendControl* _mockTransportSendControl; + MockTransportSendControl* _mockTransportSendControl; /** * SearchTimer is a friend. */ @@ -387,7 +605,6 @@ private: int64 getTimeAtLastSend(); }; - }} #endif /* CHANNELSEARCHMANAGER_H */ diff --git a/pvAccessApp/utils/referenceCountingLock.cpp b/pvAccessApp/utils/referenceCountingLock.cpp index abd2250..5699502 100644 --- a/pvAccessApp/utils/referenceCountingLock.cpp +++ b/pvAccessApp/utils/referenceCountingLock.cpp @@ -13,7 +13,7 @@ ReferenceCountingLock::ReferenceCountingLock(): _references(1) if(retval != 0) { //string errMsg = "Error: pthread_mutexattr_init failed: " + string(strerror(retval)); - assert(true); + assert(false); } retval = pthread_mutexattr_settype(&mutexAttribute, PTHREAD_MUTEX_RECURSIVE); if(retval == 0) @@ -22,13 +22,13 @@ ReferenceCountingLock::ReferenceCountingLock(): _references(1) if(retval != 0) { //string errMsg = "Error: pthread_mutex_init failed: " + string(strerror(retval)); - assert(true); + assert(false); } } else { //string errMsg = "Error: pthread_mutexattr_settype failed: " + string(strerror(retval)); - assert(true); + assert(false); } pthread_mutexattr_destroy(&mutexAttribute); @@ -58,7 +58,7 @@ void ReferenceCountingLock::release() int retval = pthread_mutex_unlock(&_mutex); if(retval != 0) { - string errMsg = "Error: pthread_mutex_unlock failed: " + string(strerror(retval)); + //string errMsg = "Error: pthread_mutex_unlock failed: " + string(strerror(retval)); //TODO do something? } } diff --git a/pvAccessApp/utils/referenceCountingLock.h b/pvAccessApp/utils/referenceCountingLock.h index 2825cae..4153b50 100644 --- a/pvAccessApp/utils/referenceCountingLock.h +++ b/pvAccessApp/utils/referenceCountingLock.h @@ -71,4 +71,4 @@ private: }} -#endif /* NAMEDLOCKPATTERN_H */ +#endif /* REFERENCECOUNTINGLOCK_H */ diff --git a/testApp/remote/Makefile b/testApp/remote/Makefile index 0ddd4f4..620b69c 100644 --- a/testApp/remote/Makefile +++ b/testApp/remote/Makefile @@ -22,6 +22,10 @@ PROD_HOST += testBeaconHandler testBeaconHandler_SRCS += testBeaconHandler.cpp testBeaconHandler_LIBS += pvData pvAccess Com +PROD_HOST += testChannelSearchManager +testChannelSearchManager_SRCS += testChannelSearchManager.cpp +testChannelSearchManager_LIBS += pvData pvAccess Com + include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE