diff --git a/pvAccessApp/client/pvAccess.h b/pvAccessApp/client/pvAccess.h index 4b95476..2758c93 100644 --- a/pvAccessApp/client/pvAccess.h +++ b/pvAccessApp/client/pvAccess.h @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace epics { namespace pvAccess { @@ -676,14 +677,14 @@ namespace epics { namespace pvAccess { * The class representing a CA Client Context. * @author Matej Sekoranja */ - class ClientContext : private epics::pvData::NoDefaultMethods { + class ClientContext : public epics::pvData::Destroyable, private epics::pvData::NoDefaultMethods { public: /** * Get context implementation version. * @return version of the context implementation. */ - virtual epics::pvData::String getVersion() = 0; + virtual const Version* getVersion() = 0; /** * Initialize client context. This method is called immediately after instance construction (call of constructor). @@ -694,7 +695,7 @@ namespace epics { namespace pvAccess { * Get channel provider implementation. * @return the channel provider. */ - virtual ChannelProvider* getProvider() = 0; + virtual const ChannelProvider* getProvider() = 0; /** * Prints detailed information about the context to the standard output stream. @@ -707,12 +708,6 @@ namespace epics { namespace pvAccess { */ virtual void printInfo(epics::pvData::StringBuilder out) = 0; - /** - * Clear all resources attached to this Context - * @throws IllegalStateException if the context has been destroyed. - */ - virtual void destroy() = 0; - /** * Dispose (destroy) server context. * This calls destroy() and silently handles all exceptions. diff --git a/testApp/client/Makefile b/testApp/client/Makefile index b47f508..45e18ee 100644 --- a/testApp/client/Makefile +++ b/testApp/client/Makefile @@ -6,6 +6,10 @@ PROD_HOST += testChannelAccessFactory testChannelAccessFactory_SRCS += testChannelAccessFactory.cpp testChannelAccessFactory_LIBS += pvAccess Com +PROD_HOST += testMockClient +testMockClient_SRCS = testMockClient.cpp MockClientImpl.cpp +testMockClient_LIBS = pvData pvAccess Com + include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE diff --git a/testApp/client/MockClientImpl.cpp b/testApp/client/MockClientImpl.cpp new file mode 100644 index 0000000..5bb0392 --- /dev/null +++ b/testApp/client/MockClientImpl.cpp @@ -0,0 +1,132 @@ +/* MockClientImpl.cpp */ +/* Author: Matej Sekoranja Date: 2010.12.18 */ + + +#include +#include + +using namespace epics::pvData; +using namespace epics::pvAccess; + + + +class MockChannelProvider : public ChannelProvider { +public: + + virtual epics::pvData::String getProviderName() + { + return "MockChannelProvider"; + } + + virtual void destroy() + { + delete this; + } + + virtual ChannelFind* channelFind( + epics::pvData::String channelName, + ChannelFindRequester *channelFindRequester) + { + ChannelFind* channelFind = 0; // TODO + channelFindRequester->channelFindResult(getStatusCreate()->getStatusOK(), channelFind, true); + return channelFind; + } + + virtual Channel* createChannel( + epics::pvData::String channelName, + ChannelRequester *channelRequester, + short priority) + { + return createChannel(channelName, channelRequester, priority, "local"); + } + + virtual Channel* createChannel( + epics::pvData::String channelName, + ChannelRequester *channelRequester, + short priority, + epics::pvData::String address) + { + if (address == "local") + { + Channel* channel = 0; + channelRequester->channelCreated(getStatusCreate()->getStatusOK(), channel); + // TODO state change + return channel; + } + else + { + Status* errorStatus = getStatusCreate()->createStatus(STATUSTYPE_ERROR, "only local supported", 0); + channelRequester->channelCreated(errorStatus, 0); + return 0; + } + } + + private: + ~MockChannelProvider() {}; + +}; + + + + +class MockClientContext : public ClientContext +{ + public: + + MockClientContext() : m_version(new Version("Mock CA Client", "cpp", 1, 0, 0, 0)) + { + initialize(); + } + + virtual const Version* getVersion() { + return m_version; + } + + virtual const ChannelProvider* getProvider() { + return m_provider; + } + + virtual void initialize() { + m_provider = new MockChannelProvider(); + } + + virtual void printInfo() { + String info; + printInfo(&info); + std::cout << info.c_str() << std::endl; + } + + virtual void printInfo(epics::pvData::StringBuilder out) { + out->append(m_version->getVersionString()); + } + + virtual void destroy() + { + m_provider->destroy(); + delete m_version; + delete this; + } + + virtual void dispose() + { + destroy(); + } + + private: + ~MockClientContext() {}; + + Version* m_version; + MockChannelProvider* m_provider; +}; + + +int main(int argc,char *argv[]) +{ + MockClientContext* context = new MockClientContext(); + context->printInfo(); + + context->destroy(); + return(0); +} + + diff --git a/testApp/client/testChannelAccessFactory.cpp b/testApp/client/testChannelAccessFactory.cpp index 3488fda..f42958b 100644 --- a/testApp/client/testChannelAccessFactory.cpp +++ b/testApp/client/testChannelAccessFactory.cpp @@ -6,7 +6,7 @@ #include #include #include -#include "pvAccess.h" +#include #include diff --git a/testApp/client/testMockClient.cpp b/testApp/client/testMockClient.cpp new file mode 100644 index 0000000..6e39078 --- /dev/null +++ b/testApp/client/testMockClient.cpp @@ -0,0 +1 @@ +/* testMockClient.cpp */