Open master device as late as possible.

This commit is contained in:
Florian Pose
2010-03-11 15:03:52 +01:00
parent fb8a75570d
commit ddaee8a1fc
27 changed files with 154 additions and 107 deletions
+39 -2
View File
@@ -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 @@ Command::~Command()
/*****************************************************************************/
void Command::setMasterIndices(const MasterIndexList &indices)
void Command::setMasters(const string &m)
{
masterIndices = indices;
masters = m;
};
/*****************************************************************************/
@@ -172,6 +187,28 @@ void Command::throwSingleSlaveRequired(unsigned int size) const
/*****************************************************************************/
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;