Command::SlaveList Command::selectedSlaves(MasterDevice &m) { ec_ioctl_master_t master; unsigned int i; ec_ioctl_slave_t slave; SlaveList list; m.getMaster(&master); if (aliases == "-") { // no alias given PositionParser pp(master.slave_count); NumberListParser::List posList = pp.parse(positions.c_str()); NumberListParser::List::const_iterator pi; for (pi = posList.begin(); pi != posList.end(); pi++) { if (*pi < master.slave_count) { m.getSlave(&slave, *pi); list.push_back(slave); } } } else { // aliases given SlaveAliasParser ap(master, m); NumberListParser::List aliasList = ap.parse(aliases.c_str()); NumberListParser::List::const_iterator ai; for (ai = aliasList.begin(); ai != aliasList.end(); ai++) { // gather slaves with that alias (and following) uint16_t lastAlias = 0; vector<ec_ioctl_slave_t> aliasSlaves; for (i = 0; i < master.slave_count; i++) { m.getSlave(&slave, i); if (slave.alias) { if (lastAlias && lastAlias == *ai && slave.alias != *ai) { // ignore multiple ocurrences of the same alias to // assure consistency for the position argument break; } lastAlias = slave.alias; } if (lastAlias == *ai) { aliasSlaves.push_back(slave); } } PositionParser pp(aliasSlaves.size()); NumberListParser::List posList = pp.parse(positions.c_str()); NumberListParser::List::const_iterator pi; for (pi = posList.begin(); pi != posList.end(); pi++) { if (*pi < aliasSlaves.size()) { list.push_back(aliasSlaves[*pi]); } } } } return list; }
Command::ConfigList Command::selectedConfigs(MasterDevice &m) { unsigned int i; ec_ioctl_master_t master; ec_ioctl_config_t config; ConfigList list; stringstream err; m.getMaster(&master); if (aliases == "-" && positions == "-") { // shortcut for (i = 0; i < master.config_count; i++) { m.getConfig(&config, i); list.push_back(config); } } else { // take the long way home... ConfigMap configs; uint16_t maxAlias = 0; // fill cascaded map structure with all configs for (i = 0; i < master.config_count; i++) { m.getConfig(&config, i); AliasMap &aliasMap = configs[config.alias]; aliasMap[config.position] = config; if (config.alias > maxAlias) { maxAlias = config.alias; } } ConfigAliasParser ap(maxAlias); NumberListParser::List aliasList = ap.parse(aliases.c_str()); NumberListParser::List::const_iterator ai; for (ai = aliasList.begin(); ai != aliasList.end(); ai++) { ConfigMap::iterator ci = configs.find(*ai); if (ci == configs.end()) { continue; } AliasMap &aliasMap = configs[*ai]; AliasPositionParser pp(aliasMap); NumberListParser::List posList = pp.parse(positions.c_str()); NumberListParser::List::const_iterator pi; for (pi = posList.begin(); pi != posList.end(); pi++) { AliasMap::const_iterator ci; ci = aliasMap.find(*pi); if (ci != aliasMap.end()) { list.push_back(ci->second); } } } } list.sort(); return list; }