Starting MockClient implementation.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <status.h>
|
||||
#include <destroyable.h>
|
||||
#include <monitor.h>
|
||||
#include <version.h>
|
||||
#include <vector>
|
||||
|
||||
namespace epics { namespace pvAccess {
|
||||
@@ -676,14 +677,14 @@ namespace epics { namespace pvAccess {
|
||||
* The class representing a CA Client Context.
|
||||
* @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
|
||||
*/
|
||||
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 <code>destroy()</code> and silently handles all exceptions.
|
||||
|
||||
@@ -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
|
||||
|
||||
132
testApp/client/MockClientImpl.cpp
Normal file
132
testApp/client/MockClientImpl.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* MockClientImpl.cpp */
|
||||
/* Author: Matej Sekoranja Date: 2010.12.18 */
|
||||
|
||||
|
||||
#include <pvAccess.h>
|
||||
#include <iostream>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "pvAccess.h"
|
||||
#include <pvAccess.h>
|
||||
|
||||
|
||||
#include <epicsAssert.h>
|
||||
|
||||
1
testApp/client/testMockClient.cpp
Normal file
1
testApp/client/testMockClient.cpp
Normal file
@@ -0,0 +1 @@
|
||||
/* testMockClient.cpp */
|
||||
Reference in New Issue
Block a user