Common message for single slave selections.
authorFlorian Pose <fp@igh-essen.com>
Mon, 28 Jul 2008 08:45:28 +0000
changeset 1155 bd4e5b544473
parent 1154 04bcd38cf8dc
child 1156 ecaf2a896ea3
Common message for single slave selections.
TODO
tool/Command.cpp
tool/Command.h
tool/CommandDownload.cpp
tool/CommandSiiRead.cpp
tool/CommandSiiWrite.cpp
tool/CommandUpload.cpp
--- a/TODO	Mon Jul 28 08:28:42 2008 +0000
+++ b/TODO	Mon Jul 28 08:45:28 2008 +0000
@@ -14,7 +14,6 @@
 * Get original driver for r8169.
 * Race in jiffies frame timeout?
 * ethercat tool:
-    - Single message for unambiguous slave in SiiRead/Write and Up/Download.
     - Implement Alias/Position selection for configs.
     - Update help for --alias and --position.
     - Show Pdos in 'ethercat slave -v'.
--- a/tool/Command.cpp	Mon Jul 28 08:28:42 2008 +0000
+++ b/tool/Command.cpp	Mon Jul 28 08:45:28 2008 +0000
@@ -80,20 +80,32 @@
 
 /*****************************************************************************/
 
-void Command::throwInvalidUsageException(const stringstream &s)
+void Command::throwInvalidUsageException(const stringstream &s) const
 {
     throw InvalidUsageException(s);
 }
 
 /*****************************************************************************/
 
-void Command::throwCommandException(const stringstream &s)
+void Command::throwCommandException(const stringstream &s) const
 {
     throw CommandException(s);
 }
 
 /*****************************************************************************/
 
+void Command::throwSingleSlaveRequired(unsigned int size) const
+{
+    stringstream err;
+
+    err << "The slave selection matches " << size << "slaves. '"
+        << name << "' requires a single slave.";
+
+    throwInvalidUsageException(err);
+}
+
+/*****************************************************************************/
+
 Command::SlaveList Command::selectedSlaves(MasterDevice &m)
 {
     unsigned int numSlaves = m.slaveCount(), i, aliasIndex;
--- a/tool/Command.h	Mon Jul 28 08:28:42 2008 +0000
+++ b/tool/Command.h	Mon Jul 28 08:45:28 2008 +0000
@@ -85,8 +85,9 @@
     protected:
 		enum {BreakAfterBytes = 16};
 
-        void throwInvalidUsageException(const stringstream &);
-        void throwCommandException(const stringstream &);
+        void throwInvalidUsageException(const stringstream &) const;
+        void throwCommandException(const stringstream &) const;
+        void throwSingleSlaveRequired(unsigned int) const;
 
         typedef list<ec_ioctl_slave_t> SlaveList;
         SlaveList selectedSlaves(MasterDevice &);
--- a/tool/CommandDownload.cpp	Mon Jul 28 08:28:42 2008 +0000
+++ b/tool/CommandDownload.cpp	Mon Jul 28 08:45:28 2008 +0000
@@ -93,8 +93,7 @@
     m.open(MasterDevice::ReadWrite);
     slaves = selectedSlaves(m);
     if (slaves.size() != 1) {
-        err << slaves.size() << " slaves selected, single slave required!";
-        throwInvalidUsageException(err);
+        throwSingleSlaveRequired(slaves.size());
     }
     data.slave_position = slaves.front().position;
 
--- a/tool/CommandSiiRead.cpp	Mon Jul 28 08:28:42 2008 +0000
+++ b/tool/CommandSiiRead.cpp	Mon Jul 28 08:45:28 2008 +0000
@@ -62,9 +62,7 @@
     slaves = selectedSlaves(m);
 
     if (slaves.size() != 1) {
-        err << "'" << getName() << "' requires a single slave ("
-            << slaves.size() << " selected).";
-        throwInvalidUsageException(err);
+        throwSingleSlaveRequired(slaves.size());
     }
     slave = &slaves.front();
     data.slave_position = slave->position;
--- a/tool/CommandSiiWrite.cpp	Mon Jul 28 08:28:42 2008 +0000
+++ b/tool/CommandSiiWrite.cpp	Mon Jul 28 08:45:28 2008 +0000
@@ -63,9 +63,7 @@
     slaves = selectedSlaves(m);
 
     if (slaves.size() != 1) {
-        err << "'" << getName() << "' requires a single slave ("
-            << slaves.size() << " selected).";
-        throwInvalidUsageException(err);
+        throwSingleSlaveRequired(slaves.size());
     }
     data.slave_position = slaves.front().position;
 
--- a/tool/CommandUpload.cpp	Mon Jul 28 08:28:42 2008 +0000
+++ b/tool/CommandUpload.cpp	Mon Jul 28 08:45:28 2008 +0000
@@ -92,8 +92,7 @@
     m.open(MasterDevice::Read);
     slaves = selectedSlaves(m);
     if (slaves.size() != 1) {
-        err << slaves.size() << " slaves selected, single slave required!";
-        throwInvalidUsageException(err);
+        throwSingleSlaveRequired(slaves.size());
     }
     data.slave_position = slaves.front().position;