Added getSingleMasterIndex() for command-line tool.
authorFlorian Pose <fp@igh-essen.com>
Thu, 11 Mar 2010 15:17:25 +0100
changeset 1870 0cee1fb7f0fd
parent 1869 14f634f5b613
child 1871 04ea48971eed
Added getSingleMasterIndex() for command-line tool.
tool/Command.cpp
tool/Command.h
tool/CommandAlias.cpp
tool/CommandDownload.cpp
tool/CommandFoeRead.cpp
tool/CommandFoeWrite.cpp
tool/CommandGraph.cpp
tool/CommandRegRead.cpp
tool/CommandRegWrite.cpp
tool/CommandSiiRead.cpp
tool/CommandSiiWrite.cpp
tool/CommandSoeRead.cpp
tool/CommandSoeWrite.cpp
tool/CommandUpload.cpp
tool/CommandXml.cpp
--- a/tool/Command.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/Command.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -209,6 +209,19 @@
 
 /*****************************************************************************/
 
+unsigned int Command::getSingleMasterIndex() const
+{
+	MasterIndexList masterIndices = getMasterIndices();
+    if (masterIndices.size() != 1) {
+		stringstream err;
+        err << getName() << " requires to select a single master!";
+        throwInvalidUsageException(err);
+    }
+	return masterIndices.front();
+}
+
+/*****************************************************************************/
+
 Command::SlaveList Command::selectedSlaves(MasterDevice &m)
 {
     ec_ioctl_master_t master;
--- a/tool/Command.h	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/Command.h	Thu Mar 11 15:17:25 2010 +0100
@@ -87,6 +87,7 @@
         typedef list<unsigned int> MasterIndexList;
         void setMasters(const string &);
         MasterIndexList getMasterIndices() const;
+		unsigned int getSingleMasterIndex() const;
 
         enum Verbosity {
             Quiet,
--- a/tool/CommandAlias.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandAlias.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -81,7 +81,6 @@
     uint16_t alias;
     stringstream err, strAlias;
     int number;
-	MasterIndexList masterIndices;
     SlaveList slaves;
     SlaveList::const_iterator si;
 
@@ -100,12 +99,7 @@
     }
     alias = number;
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::ReadWrite);
     slaves = selectedSlaves(m);
     
--- a/tool/CommandDownload.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandDownload.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -85,7 +85,6 @@
 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;
@@ -115,12 +114,7 @@
     }
     data.sdo_entry_subindex = number;
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::ReadWrite);
     slaves = selectedSlaves(m);
     if (slaves.size() != 1) {
--- a/tool/CommandFoeRead.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandFoeRead.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -76,7 +76,6 @@
 
 void CommandFoeRead::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     SlaveList slaves;
     ec_ioctl_slave_t *slave;
     ec_ioctl_slave_foe_t data;
@@ -88,12 +87,7 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
 
--- a/tool/CommandFoeWrite.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandFoeWrite.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -82,7 +82,6 @@
 
 void CommandFoeWrite::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     stringstream err;
     ec_ioctl_slave_foe_t data;
     ifstream file;
@@ -94,13 +93,6 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
-
     if (args[0] == "-") {
         loadFoeData(&data, cin);
         if (getOutputFile().empty()) {
@@ -128,6 +120,7 @@
         }
     }
 
+    MasterDevice m(getSingleMasterIndex());
     try {
         m.open(MasterDevice::ReadWrite);
     } catch (MasterDeviceException &e) {
--- a/tool/CommandGraph.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandGraph.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -67,7 +67,6 @@
 
 void CommandGraph::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     ec_ioctl_master_t master;
     unsigned int i;
     typedef vector<ec_ioctl_slave_t> SlaveVector;
@@ -91,13 +90,7 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        stringstream err;
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     m.getMaster(&master);
 
--- a/tool/CommandRegRead.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandRegRead.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -79,7 +79,6 @@
 
 void CommandRegRead::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     SlaveList slaves;
     ec_ioctl_slave_reg_t data;
     stringstream strOffset, err;
@@ -141,12 +140,7 @@
         throwInvalidUsageException(err);
     }
     
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
 
--- a/tool/CommandRegWrite.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandRegWrite.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -81,7 +81,6 @@
 
 void CommandRegWrite::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     stringstream strOffset, err;
     ec_ioctl_slave_reg_t data;
     ifstream file;
@@ -101,13 +100,6 @@
         throwInvalidUsageException(err);
     }
   
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
-
     if (getDataType().empty()) {
         if (args[1] == "-") {
             loadRegData(&data, cin);
@@ -157,6 +149,7 @@
         throwInvalidUsageException(err);
     }
 
+    MasterDevice m(getSingleMasterIndex());
     try {
         m.open(MasterDevice::ReadWrite);
     } catch (MasterDeviceException &e) {
--- a/tool/CommandSiiRead.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandSiiRead.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -76,7 +76,6 @@
 
 void CommandSiiRead::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     SlaveList slaves;
     ec_ioctl_slave_t *slave;
     ec_ioctl_slave_sii_t data;
@@ -90,12 +89,7 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
 
--- a/tool/CommandSiiWrite.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandSiiWrite.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -78,7 +78,6 @@
 
 void CommandSiiWrite::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     stringstream err;
     ec_ioctl_slave_sii_t data;
     ifstream file;
@@ -89,13 +88,6 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
-
     if (args[0] == "-") {
         loadSiiData(&data, cin);
     } else {
@@ -117,6 +109,7 @@
         }
     }
 
+    MasterDevice m(getSingleMasterIndex());
     try {
         m.open(MasterDevice::ReadWrite);
     } catch (MasterDeviceException &e) {
--- a/tool/CommandSoeRead.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandSoeRead.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -78,7 +78,6 @@
 
 void CommandSoeRead::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     SlaveList slaves;
     stringstream err;
     const DataType *dataType = NULL;
@@ -96,12 +95,7 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
     if (slaves.size() != 1) {
--- a/tool/CommandSoeWrite.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandSoeWrite.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -80,7 +80,6 @@
 
 void CommandSoeWrite::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     stringstream strIdn, err;
     const DataType *dataType = NULL;
     ec_ioctl_slave_soe_write_t ioctl;
@@ -99,12 +98,7 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::ReadWrite);
     slaves = selectedSlaves(m);
     if (slaves.size() != 1) {
--- a/tool/CommandUpload.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandUpload.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -82,7 +82,6 @@
 
 void CommandUpload::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     SlaveList slaves;
     stringstream err, strIndex, strSubIndex;
     ec_ioctl_slave_sdo_upload_t data;
@@ -113,12 +112,7 @@
     }
     data.sdo_entry_subindex = uval;
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
     if (slaves.size() != 1) {
--- a/tool/CommandXml.cpp	Thu Mar 11 15:03:52 2010 +0100
+++ b/tool/CommandXml.cpp	Thu Mar 11 15:17:25 2010 +0100
@@ -71,7 +71,6 @@
 
 void CommandXml::execute(const StringVector &args)
 {
-	MasterIndexList masterIndices;
     SlaveList slaves;
     SlaveList::const_iterator si;
 
@@ -81,13 +80,7 @@
         throwInvalidUsageException(err);
     }
 
-	masterIndices = getMasterIndices();
-    if (masterIndices.size() != 1) {
-        stringstream err;
-        err << getName() << " requires to select a single master!";
-        throwInvalidUsageException(err);
-    }
-    MasterDevice m(masterIndices.front());
+    MasterDevice m(getSingleMasterIndex());
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);