rationalize CLI handling of providers
This commit is contained in:
@@ -1664,8 +1664,6 @@ int main (int argc, char *argv[])
|
||||
|
||||
bool allOK = true;
|
||||
|
||||
Requester::shared_pointer requester(new RequesterImpl("eget"));
|
||||
|
||||
// parse URI
|
||||
// try to parse as URI if only one nPvs
|
||||
URI uri;
|
||||
@@ -1682,14 +1680,16 @@ int main (int argc, char *argv[])
|
||||
serviceRequest = true;
|
||||
}
|
||||
|
||||
static string noAddress;
|
||||
// register "pva" and "ca" providers
|
||||
ClientFactory::start();
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
// PVs mode
|
||||
if (!serviceRequest)
|
||||
{
|
||||
vector<string> pvs;
|
||||
vector<string> pvsAddress;
|
||||
vector<string> providerNames;
|
||||
vector<ChannelProvider::shared_pointer> providers;
|
||||
vector<Destroyable::shared_pointer> operations;
|
||||
|
||||
if (validURI)
|
||||
@@ -1714,26 +1714,38 @@ int main (int argc, char *argv[])
|
||||
// skip trailing '/'
|
||||
pvs.push_back(uri.path.substr(1));
|
||||
pvsAddress.push_back(uri.host);
|
||||
providerNames.push_back(uri.protocol);
|
||||
providers.push_back(getChannelProviderRegistry()->getProvider(uri.protocol));
|
||||
if(!providers.back()) {
|
||||
std::cerr<<"Unknown provider \""<<uri.protocol<<"\" for \""<<pvs.back()<<"\n";
|
||||
allOK = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int n = 0; optind < argc; n++, optind++)
|
||||
std::vector<std::string> uris;
|
||||
|
||||
if(!fromStream) {
|
||||
for (int n = 0; optind < argc; n++, optind++)
|
||||
{
|
||||
uris.push_back(argv[optind]);
|
||||
}
|
||||
} else {
|
||||
string cn;
|
||||
while (true)
|
||||
{
|
||||
*inputStream >> cn;
|
||||
if (!(*inputStream))
|
||||
break;
|
||||
uris.push_back(cn);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t n = 0; n<uris.size(); n++)
|
||||
{
|
||||
URI uri;
|
||||
bool validURI = URI::parse(argv[optind], uri);
|
||||
bool validURI = URI::parse(uris[n], 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' are supported" << std::endl;
|
||||
// TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (uri.path.length() <= 1)
|
||||
{
|
||||
std::cerr << "invalid URI, empty path" << std::endl;
|
||||
@@ -1744,17 +1756,25 @@ int main (int argc, char *argv[])
|
||||
// skip trailing '/'
|
||||
pvs.push_back(uri.path.substr(1));
|
||||
pvsAddress.push_back(uri.host);
|
||||
providerNames.push_back(uri.protocol);
|
||||
providers.push_back(getChannelProviderRegistry()->getProvider(uri.protocol));
|
||||
}
|
||||
else
|
||||
{
|
||||
pvs.push_back(argv[optind]);
|
||||
pvsAddress.push_back(noAddress);
|
||||
providerNames.push_back(defaultProvider);
|
||||
uri.protocol = defaultProvider;
|
||||
pvs.push_back(uris[n]);
|
||||
pvsAddress.push_back(std::string());
|
||||
providers.push_back(getChannelProviderRegistry()->getProvider(defaultProvider));
|
||||
}
|
||||
|
||||
if(!providers.back()) {
|
||||
std::cerr<<"Unknown provider \""<<uri.protocol<<"\" for \""<<pvs.back()<<"\"\n";
|
||||
allOK = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nPvs = pvs.size();
|
||||
|
||||
PVStructure::shared_pointer pvRequest =
|
||||
CreateRequest::create()->createRequest(request);
|
||||
if(pvRequest.get()==0) {
|
||||
@@ -1762,20 +1782,21 @@ int main (int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
// register "pva" and "ca" providers
|
||||
ClientFactory::start();
|
||||
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++)
|
||||
{
|
||||
if(!providers[n]) continue;
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl(quiet));
|
||||
if (pvsAddress[n].empty())
|
||||
channels[n] = getChannelProviderRegistry()->getProvider(providerNames[n])->createChannel(pvs[n], channelRequesterImpl);
|
||||
channels[n] = providers[n]->createChannel(pvs[n], channelRequesterImpl);
|
||||
else
|
||||
channels[n] = getChannelProviderRegistry()->getProvider(providerNames[n])->createChannel(pvs[n], channelRequesterImpl,
|
||||
channels[n] = providers[n]->createChannel(pvs[n], channelRequesterImpl,
|
||||
ChannelProvider::PRIORITY_DEFAULT, pvsAddress[n]);
|
||||
|
||||
if(!channels[n]) {
|
||||
std::cerr<<"No such channel '"<<pvs[n]<<"'\n";
|
||||
}
|
||||
}
|
||||
|
||||
// TODO maybe unify for nPvs == 1?!
|
||||
@@ -1791,69 +1812,13 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
|
||||
// for now a simple iterating sync implementation, guarantees order
|
||||
int n = -1;
|
||||
while (true)
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
{
|
||||
Channel::shared_pointer channel;
|
||||
Channel::shared_pointer channel(channels[n]);
|
||||
|
||||
if (!fromStream)
|
||||
{
|
||||
if (++n >= nPvs)
|
||||
break;
|
||||
channel = channels[n];
|
||||
}
|
||||
else
|
||||
{
|
||||
string cn;
|
||||
string ca;
|
||||
string cp;
|
||||
|
||||
// read next channel name from stream
|
||||
*inputStream >> cn;
|
||||
if (!(*inputStream))
|
||||
break;
|
||||
|
||||
URI uri;
|
||||
bool validURI = URI::parse(cn.c_str(), 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' are supported" << std::endl;
|
||||
// TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (uri.path.length() <= 1)
|
||||
{
|
||||
std::cerr << "invalid URI, empty path" << std::endl;
|
||||
// TODO
|
||||
return 1;
|
||||
}
|
||||
|
||||
// skip trailing '/'
|
||||
cn = uri.path.substr(1);
|
||||
ca = uri.host;
|
||||
cp = uri.protocol;
|
||||
}
|
||||
else
|
||||
{
|
||||
// leave cn as it is, use default provider
|
||||
ca = noAddress;
|
||||
cp = defaultProvider;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl(quiet));
|
||||
if (ca.empty())
|
||||
channel = getChannelProviderRegistry()->getProvider(cp)->createChannel(cn, channelRequesterImpl);
|
||||
else
|
||||
channel = getChannelProviderRegistry()->getProvider(cp)->createChannel(cn, channelRequesterImpl,
|
||||
ChannelProvider::PRIORITY_DEFAULT, ca);
|
||||
if(!channel) {
|
||||
allOK = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (monitor)
|
||||
@@ -2101,6 +2066,7 @@ int main (int argc, char *argv[])
|
||||
|
||||
ClientFactory::start();
|
||||
ChannelProvider::shared_pointer provider = getChannelProviderRegistry()->getProvider("pva");
|
||||
assert(provider);
|
||||
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl(quiet));
|
||||
Channel::shared_pointer channel =
|
||||
|
||||
@@ -516,11 +516,12 @@ int main (int argc, char *argv[])
|
||||
std::cout << std::boolalpha;
|
||||
terseSeparator(fieldSeparator);
|
||||
|
||||
ClientFactory::start();
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
bool allOK = true;
|
||||
|
||||
{
|
||||
Requester::shared_pointer requester(new RequesterImpl("pvget"));
|
||||
|
||||
PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest(request);
|
||||
if(pvRequest.get()==NULL) {
|
||||
fprintf(stderr, "failed to parse request string\n");
|
||||
@@ -529,11 +530,10 @@ int main (int argc, char *argv[])
|
||||
|
||||
std::vector<std::string> pvNames;
|
||||
std::vector<std::string> pvAddresses;
|
||||
std::vector<std::string> providerNames;
|
||||
std::vector<ChannelProvider::shared_pointer> providers;
|
||||
|
||||
pvNames.reserve(nPvs);
|
||||
pvAddresses.reserve(nPvs);
|
||||
providerNames.reserve(nPvs);
|
||||
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
{
|
||||
@@ -543,7 +543,7 @@ int main (int argc, char *argv[])
|
||||
std::string providerName(defaultProvider);
|
||||
std::string pvName(pvs[n]);
|
||||
std::string address(noAddress);
|
||||
bool usingDefaultProvider = true;
|
||||
|
||||
if (validURI)
|
||||
{
|
||||
if (uri.path.length() <= 1)
|
||||
@@ -554,44 +554,41 @@ int main (int argc, char *argv[])
|
||||
providerName = uri.protocol;
|
||||
pvName = uri.path.substr(1);
|
||||
address = uri.host;
|
||||
usingDefaultProvider = false;
|
||||
}
|
||||
|
||||
if ((providerName != "pva") && (providerName != "ca"))
|
||||
{
|
||||
std::cerr << "invalid "
|
||||
<< (usingDefaultProvider ? "default provider" : "URI scheme")
|
||||
<< " '" << providerName
|
||||
<< "', only 'pva' and 'ca' are supported" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
pvNames.push_back(pvName);
|
||||
pvAddresses.push_back(address);
|
||||
providerNames.push_back(providerName);
|
||||
providers.push_back(getChannelProviderRegistry()->getProvider(providerName));
|
||||
if(!providers.back()) {
|
||||
std::cerr<<"Unknown provider \""<<providerName<<"\" for channel "<<pvs[n]<<"\n";
|
||||
allOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
ClientFactory::start();
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
// first connect to all, this allows resource (e.g. TCP connection) sharing
|
||||
vector<Channel::shared_pointer> channels(nPvs);
|
||||
vector<Destroyable::shared_pointer> operations(nPvs);
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
{
|
||||
if(!providers[n]) continue;
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl(quiet));
|
||||
if (pvAddresses[n].empty())
|
||||
channels[n] = getChannelProviderRegistry()->getProvider(
|
||||
providerNames[n])->createChannel(pvNames[n], channelRequesterImpl);
|
||||
channels[n] = providers[n]->createChannel(pvNames[n], channelRequesterImpl);
|
||||
else
|
||||
channels[n] = getChannelProviderRegistry()->getProvider(
|
||||
providerNames[n])->createChannel(pvNames[n], channelRequesterImpl,
|
||||
channels[n] = providers[n]->createChannel(pvNames[n], channelRequesterImpl,
|
||||
ChannelProvider::PRIORITY_DEFAULT, pvAddresses[n]);
|
||||
if(!channels[n]) {
|
||||
std::cerr<<"Can't create channel \""<<pvNames[n]<<"\" with provider "<<providers[n]->getProviderName()<<"\n";
|
||||
allOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
// for now a simple iterating sync implementation, guarantees order
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
{
|
||||
Channel::shared_pointer channel = channels[n];
|
||||
if(!channel) continue;
|
||||
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl = TR1::dynamic_pointer_cast<ChannelRequesterImpl>(channel->getChannelRequester());
|
||||
|
||||
if (channelRequesterImpl->waitUntilConnected(timeOut))
|
||||
|
||||
@@ -137,22 +137,22 @@ int main (int argc, char *argv[])
|
||||
|
||||
bool allOK = true;
|
||||
|
||||
ClientFactory::start();
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
{
|
||||
std::vector<std::string> pvNames;
|
||||
std::vector<std::string> pvAddresses;
|
||||
std::vector<std::string> providerNames;
|
||||
std::vector<ChannelProvider::shared_pointer> providers;
|
||||
|
||||
pvNames.reserve(nPvs);
|
||||
pvAddresses.reserve(nPvs);
|
||||
providerNames.reserve(nPvs);
|
||||
|
||||
for (int n = 0; n < nPvs; n++)
|
||||
{
|
||||
URI uri;
|
||||
bool validURI = URI::parse(pvs[n], uri);
|
||||
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl());
|
||||
|
||||
std::string providerName(defaultProvider);
|
||||
std::string pvName(pvs[n]);
|
||||
std::string address(noAddress);
|
||||
@@ -170,33 +170,27 @@ int main (int argc, char *argv[])
|
||||
usingDefaultProvider = false;
|
||||
}
|
||||
|
||||
if ((providerName != "pva") && (providerName != "ca"))
|
||||
{
|
||||
std::cerr << "invalid "
|
||||
<< (usingDefaultProvider ? "default provider" : "URI scheme")
|
||||
<< " '" << providerName
|
||||
<< "', only 'pva' and 'ca' are supported" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
pvNames.push_back(pvName);
|
||||
pvAddresses.push_back(address);
|
||||
providerNames.push_back(providerName);
|
||||
providers.push_back(getChannelProviderRegistry()->getProvider(providerName));
|
||||
if(!providers.back())
|
||||
{
|
||||
std::cerr << "unknown provider name '" << providerName
|
||||
<< "', only 'pva' and 'ca' are supported" << std::endl;
|
||||
allOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
ClientFactory::start();
|
||||
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++)
|
||||
{
|
||||
if(!providers[n]) continue;
|
||||
TR1::shared_ptr<ChannelRequesterImpl> channelRequesterImpl(new ChannelRequesterImpl());
|
||||
if (pvAddresses[n].empty())
|
||||
channels[n] = getChannelProviderRegistry()->getProvider(
|
||||
providerNames[n])->createChannel(pvNames[n], channelRequesterImpl);
|
||||
channels[n] = providers[n]->createChannel(pvNames[n], channelRequesterImpl);
|
||||
else
|
||||
channels[n] = getChannelProviderRegistry()->getProvider(
|
||||
providerNames[n])->createChannel(pvNames[n], channelRequesterImpl,
|
||||
channels[n] = providers[n]->createChannel(pvNames[n], channelRequesterImpl,
|
||||
ChannelProvider::PRIORITY_DEFAULT, pvAddresses[n]);
|
||||
}
|
||||
|
||||
|
||||
@@ -642,12 +642,12 @@ int main (int argc, char *argv[])
|
||||
usingDefaultProvider = false;
|
||||
}
|
||||
|
||||
if ((providerName != "pva") && (providerName != "ca"))
|
||||
{
|
||||
std::cerr << "invalid "
|
||||
<< (usingDefaultProvider ? "default provider" : "URI scheme")
|
||||
<< " '" << providerName
|
||||
<< "', only 'pva' and 'ca' are supported" << std::endl;
|
||||
ClientFactory::start();
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
ChannelProvider::shared_pointer provider(getChannelProviderRegistry()->getProvider(providerName));
|
||||
if(!provider) {
|
||||
std::cerr << "Unknown provider '"<<providerName<<"'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -696,9 +696,6 @@ int main (int argc, char *argv[])
|
||||
terseSeparator(fieldSeparator);
|
||||
setEnumPrintMode(enumMode);
|
||||
|
||||
ClientFactory::start();
|
||||
epics::pvAccess::ca::CAClientFactory::start();
|
||||
|
||||
bool allOK = true;
|
||||
|
||||
try
|
||||
@@ -710,11 +707,9 @@ int main (int argc, char *argv[])
|
||||
|
||||
Channel::shared_pointer channel;
|
||||
if (address.empty())
|
||||
channel = getChannelProviderRegistry()->getProvider(
|
||||
providerName)->createChannel(pvName, channelRequesterImpl);
|
||||
channel = provider->createChannel(pvName, channelRequesterImpl);
|
||||
else
|
||||
channel = getChannelProviderRegistry()->getProvider(
|
||||
providerName)->createChannel(pvName, channelRequesterImpl,
|
||||
channel = provider->createChannel(pvName, channelRequesterImpl,
|
||||
ChannelProvider::PRIORITY_DEFAULT, address);
|
||||
|
||||
if (channelRequesterImpl->waitUntilConnected(timeOut))
|
||||
|
||||
Reference in New Issue
Block a user