tool/Command.cpp
changeset 1869 14f634f5b613
parent 1834 67fc217d7341
child 1870 0cee1fb7f0fd
equal deleted inserted replaced
1868:489ea0becd74 1869:14f634f5b613
    27  *
    27  *
    28  ****************************************************************************/
    28  ****************************************************************************/
    29 
    29 
    30 #include "Command.h"
    30 #include "Command.h"
    31 #include "MasterDevice.h"
    31 #include "MasterDevice.h"
       
    32 #include "NumberListParser.h"
       
    33 
       
    34 /*****************************************************************************/
       
    35 
       
    36 class MasterIndexParser:
       
    37     public NumberListParser
       
    38 {
       
    39     unsigned int getMax()
       
    40     {
       
    41         MasterDevice dev;
       
    42         dev.setIndex(0U);
       
    43         dev.open(MasterDevice::Read);
       
    44         return dev.getMasterCount() - 1;
       
    45     };
       
    46 };
    32 
    47 
    33 /*****************************************************************************/
    48 /*****************************************************************************/
    34 
    49 
    35 Command::Command(const string &name, const string &briefDesc):
    50 Command::Command(const string &name, const string &briefDesc):
    36     name(name),
    51     name(name),
    45 {
    60 {
    46 }
    61 }
    47 
    62 
    48 /*****************************************************************************/
    63 /*****************************************************************************/
    49 
    64 
    50 void Command::setMasterIndices(const MasterIndexList &indices)
    65 void Command::setMasters(const string &m)
    51 {
    66 {
    52     masterIndices = indices;
    67     masters = m;
    53 };
    68 };
    54 
    69 
    55 /*****************************************************************************/
    70 /*****************************************************************************/
    56 
    71 
    57 void Command::setVerbosity(Verbosity v)
    72 void Command::setVerbosity(Verbosity v)
   166 
   181 
   167     err << "The slave selection matches " << size << " slaves. '"
   182     err << "The slave selection matches " << size << " slaves. '"
   168         << name << "' requires a single slave.";
   183         << name << "' requires a single slave.";
   169 
   184 
   170     throwInvalidUsageException(err);
   185     throwInvalidUsageException(err);
       
   186 }
       
   187 
       
   188 /*****************************************************************************/
       
   189 
       
   190 Command::MasterIndexList Command::getMasterIndices() const
       
   191 {
       
   192 	MasterIndexList indices;
       
   193 
       
   194     try {
       
   195         MasterIndexParser p;
       
   196         indices = p.parse(masters.c_str());
       
   197     } catch (MasterDeviceException &e) {
       
   198 		stringstream err;
       
   199 		err << "Failed to obtain number of masters: " << e.what();
       
   200 		throwCommandException(err);
       
   201     } catch (runtime_error &e) {
       
   202 		stringstream err;
       
   203         err << "Invalid master argument '" << masters << "': " << e.what();
       
   204 		throwInvalidUsageException(err);
       
   205     }
       
   206 
       
   207 	return indices;
   171 }
   208 }
   172 
   209 
   173 /*****************************************************************************/
   210 /*****************************************************************************/
   174 
   211 
   175 Command::SlaveList Command::selectedSlaves(MasterDevice &m)
   212 Command::SlaveList Command::selectedSlaves(MasterDevice &m)