ChannelProviderFactory, eget support for it
This commit is contained in:
+53
-6
@@ -2,6 +2,8 @@
|
||||
#include <pv/clientFactory.h>
|
||||
#include <pv/pvAccess.h>
|
||||
|
||||
#include <caProvider.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <epicsStdlib.h>
|
||||
#include <epicsGetopt.h>
|
||||
@@ -1270,15 +1272,16 @@ int main (int argc, char *argv[])
|
||||
if (!serviceRequest)
|
||||
{
|
||||
vector<string> pvs;
|
||||
vector<string> providerNames;
|
||||
|
||||
if (validURI)
|
||||
{
|
||||
// standard get request
|
||||
// for now only pva schema is supported, without authroity
|
||||
// for now no only pva/ca schema is supported, without authority
|
||||
// TODO
|
||||
if (uri.protocol != "pva")
|
||||
if (uri.protocol != "pva" && uri.protocol != "ca")
|
||||
{
|
||||
std::cerr << "invalid URI scheme '" << uri.protocol << "', only 'pva' is supported" << std::endl;
|
||||
std::cerr << "invalid URI scheme '" << uri.protocol << "', only 'pva' and 'ca' is supported" << std::endl;
|
||||
// TODO
|
||||
return 1;
|
||||
}
|
||||
@@ -1294,12 +1297,47 @@ int main (int argc, char *argv[])
|
||||
|
||||
// skip trailing '/'
|
||||
pvs.push_back(uri.path.substr(1));
|
||||
providerNames.push_back(uri.protocol);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO URI support
|
||||
for (int n = 0; optind < argc; n++, optind++)
|
||||
pvs.push_back(argv[optind]);
|
||||
{
|
||||
URI uri;
|
||||
bool validURI = URI::parse(argv[optind], uri);
|
||||
if (validURI)
|
||||
{
|
||||
// TODO this is copy&pase code from above, clean it up
|
||||
// for now no only pva/ca schema is supported, without authority
|
||||
// TODO
|
||||
if (uri.protocol != "pva" && uri.protocol != "ca")
|
||||
{
|
||||
std::cerr << "invalid URI scheme '" << uri.protocol << "', only 'pva' and 'ca' is supported" << std::endl;
|
||||
// TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
// authority = uri.host;
|
||||
|
||||
if (uri.path.length() <= 1)
|
||||
{
|
||||
std::cerr << "invalid URI, empty path" << std::endl;
|
||||
// TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
// skip trailing '/'
|
||||
pvs.push_back(uri.path.substr(1));
|
||||
providerNames.push_back(uri.protocol);
|
||||
}
|
||||
else
|
||||
{
|
||||
// defaults to "pva"
|
||||
pvs.push_back(argv[optind]);
|
||||
providerNames.push_back("pva");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PVStructure::shared_pointer pvRequest =
|
||||
@@ -1309,15 +1347,23 @@ int main (int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
// register "pva" and "ca" providers
|
||||
ClientFactory::start();
|
||||
ChannelProvider::shared_pointer provider = getChannelAccess()->getProvider("pvAccess");
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
// first connect to all, this allows resource (e.g. TCP connection) sharing
|
||||
vector<Channel::shared_pointer> channels(nPvs);
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
{
|
||||
shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl());
|
||||
channels[n] = provider->createChannel(pvs[n], channelRequesterImpl);
|
||||
|
||||
// TODO to be removed
|
||||
String providerName = providerNames[n];
|
||||
if (providerName == "pva")
|
||||
providerName = "pvAccess";
|
||||
|
||||
// TODO no privder check
|
||||
channels[n] = getChannelAccess()->getProvider(providerName)->createChannel(pvs[n], channelRequesterImpl);
|
||||
}
|
||||
|
||||
// TODO maybe unify for nPvs == 1?!
|
||||
@@ -1590,6 +1636,7 @@ int main (int argc, char *argv[])
|
||||
|
||||
channel->destroy();
|
||||
|
||||
epics::pvAccess::ca::CAClientFactory::stop();
|
||||
ClientFactory::stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "pvutils.cpp"
|
||||
|
||||
#include <pv/caProvider.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::tr1;
|
||||
using namespace epics::pvData;
|
||||
@@ -426,7 +428,10 @@ int main (int argc, char *argv[])
|
||||
|
||||
ClientFactory::start();
|
||||
ChannelProvider::shared_pointer provider = getChannelAccess()->getProvider("pvAccess");
|
||||
|
||||
|
||||
//epics::pvAccess::ca::CAClientFactory::start();
|
||||
//ChannelProvider::shared_pointer provider = getChannelAccess()->getProvider("ca");
|
||||
|
||||
// first connect to all, this allows resource (e.g. TCP connection) sharing
|
||||
vector<Channel::shared_pointer> channels(nPvs);
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "pvutils.cpp"
|
||||
#include <pv/convert.h>
|
||||
|
||||
#include <pv/caProvider.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::tr1;
|
||||
using namespace epics::pvData;
|
||||
@@ -714,7 +716,7 @@ class ChannelPutRequesterImpl : public ChannelPutRequester
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "[" << m_channelName << "] failed to get: " << status.toString() << std::endl;
|
||||
std::cerr << "[" << m_channelName << "] failed to put: " << status.toString() << std::endl;
|
||||
}
|
||||
|
||||
m_event->signal();
|
||||
@@ -854,6 +856,9 @@ int main (int argc, char *argv[])
|
||||
ClientFactory::start();
|
||||
ChannelProvider::shared_pointer provider = getChannelAccess()->getProvider("pvAccess");
|
||||
|
||||
//epics::pvAccess::ca::CAClientFactory::start();
|
||||
//ChannelProvider::shared_pointer provider = getChannelAccess()->getProvider("ca");
|
||||
|
||||
bool allOK = true;
|
||||
|
||||
try
|
||||
@@ -863,7 +868,7 @@ int main (int argc, char *argv[])
|
||||
// first connect
|
||||
shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl());
|
||||
Channel::shared_pointer channel = provider->createChannel(pvName, channelRequesterImpl);
|
||||
|
||||
|
||||
if (channelRequesterImpl->waitUntilConnected(timeOut))
|
||||
{
|
||||
shared_ptr<ChannelPutRequesterImpl> putRequesterImpl(new ChannelPutRequesterImpl(channel->getChannelName()));
|
||||
|
||||
@@ -1874,6 +1874,7 @@ public:
|
||||
typedef std::tr1::shared_ptr<MockServerChannelProvider> shared_pointer;
|
||||
typedef std::tr1::shared_ptr<const MockServerChannelProvider> const_shared_pointer;
|
||||
|
||||
static String PROVIDER_NAME;
|
||||
|
||||
MockServerChannelProvider() :
|
||||
m_mockChannelFind(),
|
||||
@@ -1936,7 +1937,7 @@ public:
|
||||
|
||||
virtual epics::pvData::String getProviderName()
|
||||
{
|
||||
return "local";
|
||||
return PROVIDER_NAME;
|
||||
}
|
||||
|
||||
virtual void destroy()
|
||||
@@ -2020,17 +2021,41 @@ private:
|
||||
auto_ptr<Thread> m_imgThread;
|
||||
};
|
||||
|
||||
String MockServerChannelProvider::PROVIDER_NAME = "local";
|
||||
|
||||
class MockChannelProviderFactory : public ChannelProviderFactory
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(MockChannelProviderFactory);
|
||||
|
||||
virtual epics::pvData::String getFactoryName()
|
||||
{
|
||||
return MockServerChannelProvider::PROVIDER_NAME;
|
||||
}
|
||||
|
||||
virtual ChannelProvider::shared_pointer sharedInstance()
|
||||
{
|
||||
// no shared instance support for mock...
|
||||
return newInstance();
|
||||
}
|
||||
|
||||
virtual ChannelProvider::shared_pointer newInstance()
|
||||
{
|
||||
MockServerChannelProvider::shared_pointer channelProvider(new MockServerChannelProvider());
|
||||
channelProvider->initialize();
|
||||
return channelProvider;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
static ServerContextImpl::shared_pointer ctx;
|
||||
|
||||
void testServer(int timeToRun)
|
||||
{
|
||||
|
||||
MockServerChannelProvider::shared_pointer channelProvider(new MockServerChannelProvider());
|
||||
channelProvider->initialize();
|
||||
|
||||
ChannelProvider::shared_pointer ptr = channelProvider;
|
||||
registerChannelProvider(ptr);
|
||||
MockChannelProviderFactory::shared_pointer factory(new MockChannelProviderFactory());
|
||||
registerChannelProviderFactory(factory);
|
||||
|
||||
//ServerContextImpl::shared_pointer ctx = ServerContextImpl::create();
|
||||
ctx = ServerContextImpl::create();
|
||||
@@ -2043,7 +2068,7 @@ void testServer(int timeToRun)
|
||||
|
||||
ctx->destroy();
|
||||
|
||||
unregisterChannelProvider(ptr);
|
||||
unregisterChannelProviderFactory(factory);
|
||||
|
||||
structureChangedListeners.clear();
|
||||
structureStore.clear();
|
||||
|
||||
@@ -63,6 +63,11 @@ public:
|
||||
return ChannelProvider::shared_pointer();
|
||||
}
|
||||
|
||||
ChannelProvider::shared_pointer createProvider(epics::pvData::String const & providerName)
|
||||
{
|
||||
return getProvider(providerName);
|
||||
}
|
||||
|
||||
std::auto_ptr<stringVector_t> getProviderNames()
|
||||
{
|
||||
std::auto_ptr<stringVector_t> pn(new stringVector_t());
|
||||
|
||||
Reference in New Issue
Block a user