Open master device as late as possible.
--- a/tool/Command.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/Command.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -29,6 +29,21 @@
#include "Command.h"
#include "MasterDevice.h"
+#include "NumberListParser.h"
+
+/*****************************************************************************/
+
+class MasterIndexParser:
+ public NumberListParser
+{
+ unsigned int getMax()
+ {
+ MasterDevice dev;
+ dev.setIndex(0U);
+ dev.open(MasterDevice::Read);
+ return dev.getMasterCount() - 1;
+ };
+};
/*****************************************************************************/
@@ -47,9 +62,9 @@
/*****************************************************************************/
-void Command::setMasterIndices(const MasterIndexList &indices)
-{
- masterIndices = indices;
+void Command::setMasters(const string &m)
+{
+ masters = m;
};
/*****************************************************************************/
@@ -172,6 +187,28 @@
/*****************************************************************************/
+Command::MasterIndexList Command::getMasterIndices() const
+{
+ MasterIndexList indices;
+
+ try {
+ MasterIndexParser p;
+ indices = p.parse(masters.c_str());
+ } catch (MasterDeviceException &e) {
+ stringstream err;
+ err << "Failed to obtain number of masters: " << e.what();
+ throwCommandException(err);
+ } catch (runtime_error &e) {
+ stringstream err;
+ err << "Invalid master argument '" << masters << "': " << e.what();
+ throwInvalidUsageException(err);
+ }
+
+ return indices;
+}
+
+/*****************************************************************************/
+
Command::SlaveList Command::selectedSlaves(MasterDevice &m)
{
ec_ioctl_master_t master;
--- a/tool/Command.h Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/Command.h Thu Mar 11 15:03:52 2010 +0100
@@ -85,8 +85,9 @@
const string &getBriefDescription() const;
typedef list<unsigned int> MasterIndexList;
- void setMasterIndices(const MasterIndexList &);
- const MasterIndexList &getMasterIndices() const;
+ void setMasters(const string &);
+ MasterIndexList getMasterIndices() const;
+
enum Verbosity {
Quiet,
Normal,
@@ -137,7 +138,7 @@
private:
string name;
string briefDesc;
- MasterIndexList masterIndices;
+ string masters;
Verbosity verbosity;
int alias;
int position;
@@ -165,13 +166,6 @@
/****************************************************************************/
-inline const Command::MasterIndexList &Command::getMasterIndices() const
-{
- return masterIndices;
-}
-
-/****************************************************************************/
-
inline Command::Verbosity Command::getVerbosity() const
{
return verbosity;
--- a/tool/CommandAlias.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandAlias.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -81,6 +81,7 @@
uint16_t alias;
stringstream err, strAlias;
int number;
+ MasterIndexList masterIndices;
SlaveList slaves;
SlaveList::const_iterator si;
@@ -99,11 +100,12 @@
}
alias = number;
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::ReadWrite);
slaves = selectedSlaves(m);
--- a/tool/CommandCStruct.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandCStruct.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -70,6 +70,7 @@
void CommandCStruct::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
SlaveList::const_iterator si;
@@ -79,9 +80,10 @@
throwInvalidUsageException(err);
}
+ masterIndices = getMasterIndices();
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandConfig.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandConfig.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -104,8 +104,9 @@
*/
void CommandConfig::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
+ bool doIndent;
ConfigList configs;
- bool doIndent;
if (args.size()) {
stringstream err;
@@ -113,10 +114,11 @@
throwInvalidUsageException(err);
}
- doIndent = getMasterIndices().size() > 1;
+ masterIndices = getMasterIndices();
+ doIndent = masterIndices.size() > 1;
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
configs = selectedConfigs(m);
--- a/tool/CommandData.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandData.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -66,6 +66,7 @@
void CommandData::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
DomainList domains;
DomainList::const_iterator di;
@@ -75,9 +76,10 @@
throwInvalidUsageException(err);
}
+ masterIndices = getMasterIndices();
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
domains = selectedDomains(m);
--- a/tool/CommandDebug.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandDebug.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -68,6 +68,7 @@
void CommandDebug::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
stringstream str;
int debugLevel;
@@ -87,9 +88,10 @@
throwInvalidUsageException(err);
}
+ masterIndices = getMasterIndices();
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::ReadWrite);
m.setDebug(debugLevel);
--- a/tool/CommandDomains.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandDomains.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -92,9 +92,10 @@
void CommandDomains::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
+ bool doIndent;
DomainList domains;
DomainList::const_iterator di;
- bool doIndent;
if (args.size()) {
stringstream err;
@@ -102,10 +103,11 @@
throwInvalidUsageException(err);
}
- doIndent = getMasterIndices().size() > 1;
+ masterIndices = getMasterIndices();
+ doIndent = masterIndices.size() > 1;
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
domains = selectedDomains(m);
--- a/tool/CommandDownload.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandDownload.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -85,6 +85,7 @@
void CommandDownload::execute(const StringVector &args)
{
stringstream strIndex, strSubIndex, err;
+ MasterIndexList masterIndices;
ec_ioctl_slave_sdo_download_t data;
unsigned int number;
const DataType *dataType = NULL;
@@ -114,11 +115,12 @@
}
data.sdo_entry_subindex = number;
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::ReadWrite);
slaves = selectedSlaves(m);
if (slaves.size() != 1) {
--- a/tool/CommandEoe.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandEoe.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -63,6 +63,7 @@
void CommandEoe::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
ec_ioctl_master_t master;
unsigned int i;
ec_ioctl_eoe_handler_t eoe;
@@ -75,11 +76,12 @@
throwInvalidUsageException(err);
}
- doIndent = getMasterIndices().size();
+ masterIndices = getMasterIndices();
+ doIndent = masterIndices.size();
indent = doIndent ? " " : "";
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
m.getMaster(&master);
--- a/tool/CommandFoeRead.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandFoeRead.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -76,6 +76,7 @@
void CommandFoeRead::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
ec_ioctl_slave_t *slave;
ec_ioctl_slave_foe_t data;
@@ -87,11 +88,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandFoeWrite.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandFoeWrite.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -82,6 +82,7 @@
void CommandFoeWrite::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
stringstream err;
ec_ioctl_slave_foe_t data;
ifstream file;
@@ -93,11 +94,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
if (args[0] == "-") {
loadFoeData(&data, cin);
--- a/tool/CommandGraph.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandGraph.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -67,6 +67,7 @@
void CommandGraph::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
ec_ioctl_master_t master;
unsigned int i;
typedef vector<ec_ioctl_slave_t> SlaveVector;
@@ -90,12 +91,13 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
stringstream err;
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
m.getMaster(&master);
--- a/tool/CommandMaster.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandMaster.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -67,6 +67,7 @@
void CommandMaster::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
ec_ioctl_master_t data;
stringstream err;
unsigned int i, j;
@@ -79,9 +80,10 @@
throwInvalidUsageException(err);
}
+ masterIndices = getMasterIndices();
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
m.getMaster(&data);
--- a/tool/CommandPdos.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandPdos.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -91,6 +91,7 @@
void CommandPdos::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
SlaveList::const_iterator si;
bool showHeader, multiMaster;
@@ -101,10 +102,11 @@
throwInvalidUsageException(err);
}
- multiMaster = getMasterIndices().size() > 1;
+ masterIndices = getMasterIndices();
+ multiMaster = masterIndices.size() > 1;
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandRegRead.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandRegRead.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -79,6 +79,7 @@
void CommandRegRead::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
ec_ioctl_slave_reg_t data;
stringstream strOffset, err;
@@ -140,11 +141,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandRegWrite.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandRegWrite.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -81,6 +81,7 @@
void CommandRegWrite::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
stringstream strOffset, err;
ec_ioctl_slave_reg_t data;
ifstream file;
@@ -100,11 +101,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
if (getDataType().empty()) {
if (args[1] == "-") {
--- a/tool/CommandSdos.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandSdos.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -89,6 +89,7 @@
void CommandSdos::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
SlaveList::const_iterator si;
bool showHeader, multiMaster;
@@ -99,10 +100,11 @@
throwInvalidUsageException(err);
}
- multiMaster = getMasterIndices().size() > 1;
+ masterIndices = getMasterIndices();
+ multiMaster = masterIndices.size() > 1;
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandSiiRead.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandSiiRead.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -76,6 +76,7 @@
void CommandSiiRead::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
ec_ioctl_slave_t *slave;
ec_ioctl_slave_sii_t data;
@@ -89,11 +90,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandSiiWrite.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandSiiWrite.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -78,6 +78,7 @@
void CommandSiiWrite::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
stringstream err;
ec_ioctl_slave_sii_t data;
ifstream file;
@@ -88,11 +89,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
if (args[0] == "-") {
loadSiiData(&data, cin);
--- a/tool/CommandSlaves.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandSlaves.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -108,6 +108,7 @@
void CommandSlaves::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
bool doIndent;
@@ -117,10 +118,11 @@
throwInvalidUsageException(err);
}
- doIndent = getMasterIndices().size() > 1;
+ masterIndices = getMasterIndices();
+ doIndent = masterIndices.size() > 1;
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/CommandSoeRead.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandSoeRead.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -78,6 +78,7 @@
void CommandSoeRead::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
stringstream err;
const DataType *dataType = NULL;
@@ -95,11 +96,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
if (slaves.size() != 1) {
--- a/tool/CommandSoeWrite.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandSoeWrite.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -80,6 +80,7 @@
void CommandSoeWrite::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
stringstream strIdn, err;
const DataType *dataType = NULL;
ec_ioctl_slave_soe_write_t ioctl;
@@ -98,11 +99,12 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::ReadWrite);
slaves = selectedSlaves(m);
if (slaves.size() != 1) {
--- a/tool/CommandStates.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandStates.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -68,6 +68,7 @@
void CommandStates::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
SlaveList::const_iterator si;
stringstream err;
@@ -98,9 +99,10 @@
throwInvalidUsageException(err);
}
+ masterIndices = getMasterIndices();
MasterIndexList::const_iterator mi;
- for (mi = getMasterIndices().begin();
- mi != getMasterIndices().end(); mi++) {
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
MasterDevice m(*mi);
m.open(MasterDevice::ReadWrite);
slaves = selectedSlaves(m);
--- a/tool/CommandUpload.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandUpload.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -82,6 +82,7 @@
void CommandUpload::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
stringstream err, strIndex, strSubIndex;
ec_ioctl_slave_sdo_upload_t data;
@@ -112,11 +113,12 @@
}
data.sdo_entry_subindex = uval;
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
if (slaves.size() != 1) {
--- a/tool/CommandXml.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/CommandXml.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -71,6 +71,7 @@
void CommandXml::execute(const StringVector &args)
{
+ MasterIndexList masterIndices;
SlaveList slaves;
SlaveList::const_iterator si;
@@ -80,12 +81,13 @@
throwInvalidUsageException(err);
}
- if (getMasterIndices().size() != 1) {
+ masterIndices = getMasterIndices();
+ if (masterIndices.size() != 1) {
stringstream err;
err << getName() << " requires to select a single master!";
throwInvalidUsageException(err);
}
- MasterDevice m(getMasterIndices().front());
+ MasterDevice m(masterIndices.front());
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
--- a/tool/main.cpp Thu Mar 11 14:29:43 2010 +0100
+++ b/tool/main.cpp Thu Mar 11 15:03:52 2010 +0100
@@ -63,7 +63,6 @@
#include "CommandVersion.h"
#include "CommandXml.h"
-#include "NumberListParser.h"
#include "MasterDevice.h"
/*****************************************************************************/
@@ -76,8 +75,7 @@
Command::StringVector commandArgs;
// option variables
-list<unsigned int> masterIndices;
-string masterIndexList = "-"; // all masters
+string masters = "-"; // all masters
int slavePosition = -1;
int slaveAlias = -1;
int domainIndex = -1;
@@ -113,7 +111,10 @@
str << endl
<< "Global options:" << endl
- << " --master -m <master> Index of the master to use. Default: 0."
+ << " --master -m <master> Comma separated list of masters" << endl
+ << " to select, ranges are allowed." << endl
+ << " Examples: '1,3', '5-7,9', '-3'." << endl
+ << " Default: '-' (all)."
<< endl
<< " --force -f Force a command." << endl
<< " --quiet -q Output less information." << endl
@@ -132,20 +133,6 @@
/*****************************************************************************/
-class MasterIndexParser:
- public NumberListParser
-{
- unsigned int getMax()
- {
- MasterDevice dev;
- dev.setIndex(0U);
- dev.open(MasterDevice::Read);
- return dev.getMasterCount() - 1;
- };
-};
-
-/*****************************************************************************/
-
void getOptions(int argc, char **argv)
{
int c, argCount;
@@ -171,7 +158,7 @@
switch (c) {
case 'm':
- masterIndexList = optarg;
+ masters = optarg;
break;
case 'a':
@@ -261,19 +248,6 @@
}
}
- try {
- MasterIndexParser p;
- masterIndices = p.parse(masterIndexList.c_str());
- } catch (MasterDeviceException &e) {
- cerr << "Failed to obtain number of masters: " << e.what() << endl;
- exit(1);
- } catch (runtime_error &e) {
- cerr << "Invalid master argument " << masterIndexList
- << ": " << e.what() << endl
- << endl << usage();
- exit(1);
- }
-
commandName = argv[optind];
while (++optind < argc)
commandArgs.push_back(string(argv[optind]));
@@ -348,18 +322,12 @@
matchingCommands = getMatchingCommands(commandName);
- if (masterIndices.empty()) {
- cerr << "List of master indices may not be empty!" << endl
- << endl << usage();
- exit(1);
- }
-
if (matchingCommands.size()) {
if (matchingCommands.size() == 1) {
cmd = matchingCommands.front();
if (!helpRequested) {
try {
- cmd->setMasterIndices(masterIndices);
+ cmd->setMasters(masters);
cmd->setVerbosity(verbosity);
cmd->setAlias(slaveAlias);
cmd->setPosition(slavePosition);