From a63374e86b51468e60e904e25b0191e27827a62f Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Thu, 3 Feb 2011 17:09:13 +0100 Subject: [PATCH] ClientFactory added --- pvAccessApp/Makefile | 2 + pvAccessApp/ca/clientFactory.cpp | 37 +++++++++++++++++++ pvAccessApp/ca/clientFactory.h | 22 +++++++++++ .../remoteClient/clientContextImpl.cpp | 3 +- testApp/remote/testRemoteClientImpl.cpp | 20 ++++++++-- 5 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 pvAccessApp/ca/clientFactory.cpp create mode 100644 pvAccessApp/ca/clientFactory.h diff --git a/pvAccessApp/Makefile b/pvAccessApp/Makefile index d76b64e..d736c71 100644 --- a/pvAccessApp/Makefile +++ b/pvAccessApp/Makefile @@ -7,7 +7,9 @@ PVACCESS = $(TOP)/pvAccessApp/ SRC_DIRS += $(PVACCESS)/ca INC += caConstants.h INC += version.h +INC += clientFactory.h LIBSRCS += version.cpp +LIBSRCS += clientFactory.cpp SRC_DIRS += $(PVACCESS)/utils diff --git a/pvAccessApp/ca/clientFactory.cpp b/pvAccessApp/ca/clientFactory.cpp new file mode 100644 index 0000000..6701b0a --- /dev/null +++ b/pvAccessApp/ca/clientFactory.cpp @@ -0,0 +1,37 @@ +/* clientFactory.cpp */ +/* Author: Matej Sekoranja Date: 2011.2.1 */ + +#include +#include + +using namespace epics::pvData; +using namespace epics::pvAccess; + +Mutex ClientFactory::m_mutex; +ClientContextImpl* ClientFactory::m_context = 0; + +void ClientFactory::start() +{ + Lock guard(&m_mutex); + + if (m_context) return; + + try { + m_context = createClientContextImpl(); + m_context->initialize(); + registerChannelProvider(m_context->getProvider()); + } catch (std::exception &e) { + errlogSevPrintf(errlogMajor, "Unhandled exception caught at %s:%d: %s", __FILE__, __LINE__, e.what()); + } catch (...) { + errlogSevPrintf(errlogMajor, "Unhandled exception caught at %s:%d.", __FILE__, __LINE__); + } +} + +void ClientFactory::stop() +{ + Lock guard(&m_mutex); + + unregisterChannelProvider(m_context->getProvider()); + m_context->dispose(); + m_context = 0; +} diff --git a/pvAccessApp/ca/clientFactory.h b/pvAccessApp/ca/clientFactory.h new file mode 100644 index 0000000..93d61bb --- /dev/null +++ b/pvAccessApp/ca/clientFactory.h @@ -0,0 +1,22 @@ +/* clientFactory.h */ +#ifndef CLIENTFACTORY_H +#define CLIENTFACTORY_H + +#include +#include + +namespace epics { namespace pvAccess { + +class ClientFactory { + public: + static void start(); + static void stop(); + + private: + static epics::pvData::Mutex m_mutex; + static ClientContextImpl* m_context; +}; + +}} + +#endif /* CLIENTFACTORY_H */ \ No newline at end of file diff --git a/pvAccessApp/remoteClient/clientContextImpl.cpp b/pvAccessApp/remoteClient/clientContextImpl.cpp index edfc307..f799a81 100644 --- a/pvAccessApp/remoteClient/clientContextImpl.cpp +++ b/pvAccessApp/remoteClient/clientContextImpl.cpp @@ -2967,7 +2967,7 @@ namespace epics { virtual epics::pvData::String getProviderName() { - return "ChannelProviderImpl"; + return "pvAccess"; } virtual void destroy() @@ -3139,6 +3139,7 @@ TODO virtual void dispose() { + // TODO try catch destroy(); } diff --git a/testApp/remote/testRemoteClientImpl.cpp b/testApp/remote/testRemoteClientImpl.cpp index 6e83e1b..17cdd61 100644 --- a/testApp/remote/testRemoteClientImpl.cpp +++ b/testApp/remote/testRemoteClientImpl.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using namespace epics::pvData; using namespace epics::pvAccess; @@ -438,6 +439,7 @@ class ChannelProcessRequesterImpl : public ChannelProcessRequester int main(int argc,char *argv[]) { + /* ClientContextImpl* context = createClientContextImpl(); context->printInfo(); @@ -445,14 +447,21 @@ int main(int argc,char *argv[]) context->printInfo(); epicsThreadSleep ( 1.0 ); + + ChannelProvider* provider = context->getProvider(); + */ + + ClientFactory::start(); + ChannelProvider* provider = getChannelAccess()->getProvider("pvAccess"); + /* ChannelFindRequesterImpl findRequester; - ChannelFind* channelFind = context->getProvider()->channelFind("something", &findRequester); + ChannelFind* channelFind = provider->channelFind("something", &findRequester); epicsThreadSleep ( 1.0 ); channelFind->destroy(); */ ChannelRequesterImpl channelRequester; - Channel* channel = context->getProvider()->createChannel("structureArrayTest", &channelRequester); + Channel* channel = provider->createChannel("structureArrayTest", &channelRequester); epicsThreadSleep ( 1.0 ); @@ -473,7 +482,7 @@ int main(int argc,char *argv[]) epicsThreadSleep ( 1.0 ); */ ChannelGetRequesterImpl channelGetRequesterImpl; - pvRequest = 0;//getCreateRequest()->createRequest("field(kiki)",&channelGetRequesterImpl); + pvRequest = getCreateRequest()->createRequest("field()",&channelGetRequesterImpl); ChannelGet* channelGet = channel->createChannelGet(&channelGetRequesterImpl, pvRequest); epicsThreadSleep ( 3.0 ); channelGet->get(false); @@ -556,10 +565,13 @@ int main(int argc,char *argv[]) epicsThreadSleep ( 3.0 ); + ClientFactory::start(); + /* printf("Destroying context... \n"); context->destroy(); printf("done.\n"); - + */ + std::cout << "-----------------------------------------------------------------------" << std::endl; epicsExitCallAtExits(); CDRMonitor::get().show(stdout);