fixed potential iterator misuse, use auto and const where reasonable
This commit is contained in:
+20
-19
@@ -211,7 +211,7 @@ void GrabbedMessage::setLastData(MasterSymbolString& master, SlaveSymbolString&
|
|||||||
* @param firstOnly whether to read only the first non-erroneous offset.
|
* @param firstOnly whether to read only the first non-erroneous offset.
|
||||||
* @return @a RESULT_OK on success, or an error code.
|
* @return @a RESULT_OK on success, or an error code.
|
||||||
*/
|
*/
|
||||||
bool decodeType(const DataType* type, SymbolString *input, size_t length,
|
bool decodeType(const DataType* type, const SymbolString *input, size_t length,
|
||||||
size_t offsets, ostringstream& output, bool firstOnly = false) {
|
size_t offsets, ostringstream& output, bool firstOnly = false) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
string in = input->getStr(input->getDataOffset());
|
string in = input->getStr(input->getDataOffset());
|
||||||
@@ -255,7 +255,7 @@ bool decodeType(const DataType* type, SymbolString *input, size_t length,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output,
|
bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output,
|
||||||
const bool decode) {
|
const bool decode) const {
|
||||||
Message* message = messages->find(m_lastMaster);
|
Message* message = messages->find(m_lastMaster);
|
||||||
if (unknown && message) {
|
if (unknown && message) {
|
||||||
return false;
|
return false;
|
||||||
@@ -278,7 +278,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool master = isMaster(dstAddress) || dstAddress == BROADCAST || m_lastSlave.getDataSize() <= 0;
|
bool master = isMaster(dstAddress) || dstAddress == BROADCAST || m_lastSlave.getDataSize() <= 0;
|
||||||
SymbolString *input;
|
const SymbolString *input;
|
||||||
if (master) {
|
if (master) {
|
||||||
input = &m_lastMaster;
|
input = &m_lastMaster;
|
||||||
} else {
|
} else {
|
||||||
@@ -288,7 +288,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
|
|||||||
if (remain == 0) {
|
if (remain == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (auto it : *types) {
|
for (const auto it : *types) {
|
||||||
const DataType* baseType = it.second;
|
const DataType* baseType = it.second;
|
||||||
if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored()) { // skip bit and ignored types
|
if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored()) { // skip bit and ignored types
|
||||||
continue;
|
continue;
|
||||||
@@ -1143,10 +1143,13 @@ result_t BusHandler::prepareScan(symbol_t slave, bool full, string levels, bool&
|
|||||||
}
|
}
|
||||||
|
|
||||||
deque<Message*> messages = m_messages->findAll("scan", "", levels, true);
|
deque<Message*> messages = m_messages->findAll("scan", "", levels, true);
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it < messages.end(); it++) {
|
auto it = messages.begin();
|
||||||
|
while (it != messages.end()) {
|
||||||
Message* message = *it;
|
Message* message = *it;
|
||||||
if (message->getPrimaryCommand() == 0x07 && message->getSecondaryCommand() == 0x04) {
|
if (message->getPrimaryCommand() == 0x07 && message->getSecondaryCommand() == 0x04) {
|
||||||
messages.erase(it--); // query pb 0x07 / sb 0x04 only once
|
it = messages.erase(it); // query pb 0x07 / sb 0x04 only once
|
||||||
|
} else {
|
||||||
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1229,7 +1232,7 @@ void BusHandler::setScanFinished() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool BusHandler::formatScanResult(symbol_t slave, ostringstream& output, bool leadingNewline) {
|
bool BusHandler::formatScanResult(symbol_t slave, ostringstream& output, bool leadingNewline) {
|
||||||
map<symbol_t, vector<string>>::iterator it = m_scanResults.find(slave);
|
const auto it = m_scanResults.find(slave);
|
||||||
if (it == m_scanResults.end()) {
|
if (it == m_scanResults.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1237,7 +1240,7 @@ bool BusHandler::formatScanResult(symbol_t slave, ostringstream& output, bool le
|
|||||||
output << endl;
|
output << endl;
|
||||||
}
|
}
|
||||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(slave);
|
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(slave);
|
||||||
for (auto result : it->second) {
|
for (const auto result : it->second) {
|
||||||
output << result;
|
output << result;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1317,7 +1320,7 @@ void BusHandler::formatSeenInfo(ostringstream& output) {
|
|||||||
const vector<string>& loadedFiles = m_messages->getLoadedFiles(address);
|
const vector<string>& loadedFiles = m_messages->getLoadedFiles(address);
|
||||||
if (!loadedFiles.empty()) {
|
if (!loadedFiles.empty()) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& loadedFile : loadedFiles) {
|
for (const auto& loadedFile : loadedFiles) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
output << ", loaded \"";
|
output << ", loaded \"";
|
||||||
@@ -1347,9 +1350,8 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
|
|||||||
output << ",\"co\":" << (m_addressConflict ? 1 : 0);
|
output << ",\"co\":" << (m_addressConflict ? 1 : 0);
|
||||||
if (m_grabMessages) {
|
if (m_grabMessages) {
|
||||||
size_t unknownCnt = 0;
|
size_t unknownCnt = 0;
|
||||||
for (map<uint64_t, GrabbedMessage>::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end();
|
for (auto it : m_grabbedMessages) {
|
||||||
it++) {
|
Message* message = m_messages->find(it.second.getLastMasterData());
|
||||||
Message* message = m_messages->find(it->second.getLastMasterData());
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
unknownCnt++;
|
unknownCnt++;
|
||||||
}
|
}
|
||||||
@@ -1364,10 +1366,10 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
|
|||||||
}
|
}
|
||||||
output << ",\"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(address) << dec << setw(0);
|
output << ",\"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(address) << dec << setw(0);
|
||||||
output << "\":{\"o\":" << (ownAddress ? 1 : 0);
|
output << "\":{\"o\":" << (ownAddress ? 1 : 0);
|
||||||
map<symbol_t, vector<string>>::iterator it = m_scanResults.find(address);
|
const auto it = m_scanResults.find(address);
|
||||||
if (it != m_scanResults.end()) {
|
if (it != m_scanResults.end()) {
|
||||||
output << ",\"s\":\"";
|
output << ",\"s\":\"";
|
||||||
for (auto result : it->second) {
|
for (const auto result : it->second) {
|
||||||
output << result;
|
output << result;
|
||||||
}
|
}
|
||||||
output << "\"";
|
output << "\"";
|
||||||
@@ -1383,7 +1385,7 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
|
|||||||
if (!loadedFiles.empty()) {
|
if (!loadedFiles.empty()) {
|
||||||
output << ",\"f\":[";
|
output << ",\"f\":[";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& loadedFile : loadedFiles) {
|
for (const auto loadedFile : loadedFiles) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -1406,7 +1408,7 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
|
|||||||
if (!loadedFiles.empty()) {
|
if (!loadedFiles.empty()) {
|
||||||
output << ",\"l\":{";
|
output << ",\"l\":{";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& loadedFile : loadedFiles) {
|
for (const auto& loadedFile : loadedFiles) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -1489,9 +1491,8 @@ void BusHandler::formatGrabResult(const bool unknown, ostringstream& output, con
|
|||||||
output << "grab disabled";
|
output << "grab disabled";
|
||||||
} else {
|
} else {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (map<uint64_t, GrabbedMessage>::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end();
|
for (const auto& it : m_grabbedMessages) {
|
||||||
it++) {
|
if (it.second.dump(unknown, m_messages, first, output, decode)) {
|
||||||
if (it->second.dump(unknown, m_messages, first, output, decode)) {
|
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,7 +329,8 @@ class GrabbedMessage {
|
|||||||
* @param decode whether to add decoding hints.
|
* @param decode whether to add decoding hints.
|
||||||
* @return whether the message was added to the output.
|
* @return whether the message was added to the output.
|
||||||
*/
|
*/
|
||||||
bool dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output, const bool decode = false);
|
bool dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output,
|
||||||
|
const bool decode = false) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+20
-25
@@ -632,11 +632,10 @@ void shutdown() {
|
|||||||
s_messageMap = NULL;
|
s_messageMap = NULL;
|
||||||
}
|
}
|
||||||
// free templates
|
// free templates
|
||||||
for (map<string, DataFieldTemplates*>::iterator it = s_templatesByPath.begin(); it != s_templatesByPath.end(); it++) {
|
for (const auto it : s_templatesByPath) {
|
||||||
if (it->second != &s_globalTemplates) {
|
if (it.second != &s_globalTemplates) {
|
||||||
delete it->second;
|
delete it.second;
|
||||||
}
|
}
|
||||||
it->second = NULL;
|
|
||||||
}
|
}
|
||||||
s_templatesByPath.clear();
|
s_templatesByPath.clear();
|
||||||
|
|
||||||
@@ -738,7 +737,7 @@ DataFieldTemplates* getTemplates(const string filename) {
|
|||||||
if (pos != string::npos) {
|
if (pos != string::npos) {
|
||||||
path = filename.substr(0, pos);
|
path = filename.substr(0, pos);
|
||||||
}
|
}
|
||||||
map<string, DataFieldTemplates*>::iterator it = s_templatesByPath.find(path);
|
const auto it = s_templatesByPath.find(path);
|
||||||
if (it != s_templatesByPath.end()) {
|
if (it != s_templatesByPath.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
@@ -755,7 +754,7 @@ DataFieldTemplates* getTemplates(const string filename) {
|
|||||||
* @return the @a DataFieldTemplates.
|
* @return the @a DataFieldTemplates.
|
||||||
*/
|
*/
|
||||||
static bool readTemplates(const string path, const string extension, bool available, bool verbose = false) {
|
static bool readTemplates(const string path, const string extension, bool available, bool verbose = false) {
|
||||||
map<string, DataFieldTemplates*>::iterator it = s_templatesByPath.find(path);
|
const auto it = s_templatesByPath.find(path);
|
||||||
if (it != s_templatesByPath.end()) {
|
if (it != s_templatesByPath.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -799,8 +798,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
readTemplates(path, extension, hasTemplates, verbose);
|
readTemplates(path, extension, hasTemplates, verbose);
|
||||||
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
|
for (const auto& name : files) {
|
||||||
string name = *it;
|
|
||||||
logInfo(lf_main, "reading file %s", name.c_str());
|
logInfo(lf_main, "reading file %s", name.c_str());
|
||||||
result = messages->readFromFile(name, errorDescription, verbose);
|
result = messages->readFromFile(name, errorDescription, verbose);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
@@ -808,8 +806,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
for (vector<string>::iterator it = dirs.begin(); it != dirs.end(); it++) {
|
for (const auto& name : dirs) {
|
||||||
string name = *it;
|
|
||||||
logInfo(lf_main, "reading dir %s", name.c_str());
|
logInfo(lf_main, "reading dir %s", name.c_str());
|
||||||
result = readConfigFiles(name, extension, messages, true, verbose, errorDescription);
|
result = readConfigFiles(name, extension, messages, true, verbose, errorDescription);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
@@ -864,12 +861,11 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
|
|||||||
logInfo(lf_main, "loading configuration files from %s", opt.configPath);
|
logInfo(lf_main, "loading configuration files from %s", opt.configPath);
|
||||||
messages->clear();
|
messages->clear();
|
||||||
s_globalTemplates.clear();
|
s_globalTemplates.clear();
|
||||||
for (map<string, DataFieldTemplates*>::iterator it = s_templatesByPath.begin(); it != s_templatesByPath.end();
|
for (auto& it : s_templatesByPath) {
|
||||||
it++) {
|
if (it.second != &s_globalTemplates) {
|
||||||
if (it->second != &s_globalTemplates) {
|
delete it.second;
|
||||||
delete it->second;
|
|
||||||
}
|
}
|
||||||
it->second = NULL;
|
it.second = NULL;
|
||||||
}
|
}
|
||||||
s_templatesByPath.clear();
|
s_templatesByPath.clear();
|
||||||
|
|
||||||
@@ -957,19 +953,20 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, string& rela
|
|||||||
}
|
}
|
||||||
logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), path.c_str(),
|
logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), path.c_str(),
|
||||||
prefix.c_str(), getResultCode(result));
|
prefix.c_str(), getResultCode(result));
|
||||||
for (string::iterator it = ident.begin(); it != ident.end(); it++) {
|
auto it = ident.begin();
|
||||||
|
while (it != ident.end()) {
|
||||||
if (::isspace(*it)) {
|
if (::isspace(*it)) {
|
||||||
ident.erase(it--);
|
it = ident.erase(it);
|
||||||
} else {
|
} else {
|
||||||
*it = static_cast<char>(::tolower(*it));
|
*it = static_cast<char>(::tolower(*it));
|
||||||
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv
|
// complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv
|
||||||
size_t bestMatch = 0;
|
size_t bestMatch = 0;
|
||||||
string best;
|
string best;
|
||||||
map<string, string> bestDefaults;
|
map<string, string> bestDefaults;
|
||||||
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
|
for (const auto& name : files) {
|
||||||
string name = *it;
|
|
||||||
symbol_t checkDest;
|
symbol_t checkDest;
|
||||||
unsigned int checkSw, checkHw;
|
unsigned int checkSw, checkHw;
|
||||||
map<string, string> defaults;
|
map<string, string> defaults;
|
||||||
@@ -1020,14 +1017,12 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, string& rela
|
|||||||
if (readCommon) {
|
if (readCommon) {
|
||||||
result = collectConfigFiles(path, "", ".csv", files);
|
result = collectConfigFiles(path, "", ".csv", files);
|
||||||
if (result == RESULT_OK && !files.empty()) {
|
if (result == RESULT_OK && !files.empty()) {
|
||||||
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
|
for (const auto& name : files) {
|
||||||
string name = *it;
|
string baseName = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *.
|
||||||
name = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *.
|
if (baseName == "_templates.") { // skip templates
|
||||||
if (name == "_templates.") { // skip templates
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (name.length() < 3 || name.find_first_of('.') != 2) { // different from the scheme "ZZ."
|
if (baseName.length() < 3 || baseName.find_first_of('.') != 2) { // different from the scheme "ZZ."
|
||||||
name = *it;
|
|
||||||
string errorDescription;
|
string errorDescription;
|
||||||
result = messages->readFromFile(name, errorDescription, opt.checkConfig);
|
result = messages->readFromFile(name, errorDescription, opt.checkConfig);
|
||||||
if (result == RESULT_OK) {
|
if (result == RESULT_OK) {
|
||||||
|
|||||||
+19
-22
@@ -82,13 +82,13 @@ result_t UserList::addFromFile(map<string, string>& row, vector< map<string, str
|
|||||||
name = ""; // default levels
|
name = ""; // default levels
|
||||||
}
|
}
|
||||||
string levels;
|
string levels;
|
||||||
for (auto entry : subRows) {
|
for (const auto& entry : subRows) {
|
||||||
string level = entry["level"];
|
const auto it = entry.find("level");
|
||||||
if (!level.empty()) {
|
if (it != entry.end() && !it->second.empty()) {
|
||||||
if (!levels.empty()) {
|
if (!levels.empty()) {
|
||||||
levels += VALUE_SEPARATOR;
|
levels += VALUE_SEPARATOR;
|
||||||
}
|
}
|
||||||
levels += level;
|
levels += it->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_userSecrets[name] = secret;
|
m_userSecrets[name] = secret;
|
||||||
@@ -158,9 +158,10 @@ MainLoop::~MainLoop() {
|
|||||||
m_shutdown = true;
|
m_shutdown = true;
|
||||||
join();
|
join();
|
||||||
|
|
||||||
for (list<DataHandler*>::iterator it = m_dataHandlers.begin(); it != m_dataHandlers.end(); it++) {
|
for (const auto dataHandler : m_dataHandlers) {
|
||||||
delete *it;
|
delete dataHandler;
|
||||||
}
|
}
|
||||||
|
m_dataHandlers.clear();
|
||||||
if (m_dumpFile) {
|
if (m_dumpFile) {
|
||||||
delete m_dumpFile;
|
delete m_dumpFile;
|
||||||
m_dumpFile = NULL;
|
m_dumpFile = NULL;
|
||||||
@@ -206,11 +207,11 @@ void MainLoop::run() {
|
|||||||
list<DataSink*> dataSinks;
|
list<DataSink*> dataSinks;
|
||||||
deque<Message*> messages;
|
deque<Message*> messages;
|
||||||
|
|
||||||
for (list<DataHandler*>::iterator it = m_dataHandlers.begin(); it != m_dataHandlers.end(); it++) {
|
for (const auto dataHandler : m_dataHandlers) {
|
||||||
if ((*it)->isDataSink()) {
|
if (dataHandler->isDataSink()) {
|
||||||
dataSinks.push_back(dynamic_cast<DataSink*>(*it));
|
dataSinks.push_back(dynamic_cast<DataSink*>(dataHandler));
|
||||||
}
|
}
|
||||||
(*it)->start();
|
dataHandler->start();
|
||||||
}
|
}
|
||||||
while (!m_shutdown) {
|
while (!m_shutdown) {
|
||||||
// pick the next message to handle
|
// pick the next message to handle
|
||||||
@@ -362,8 +363,8 @@ void MainLoop::run() {
|
|||||||
m_updateCheck = message == "" ? "unknown" : message;
|
m_updateCheck = message == "" ? "unknown" : message;
|
||||||
logNotice(lf_main, "update check: %s", message.c_str());
|
logNotice(lf_main, "update check: %s", message.c_str());
|
||||||
if (!dataSinks.empty()) {
|
if (!dataSinks.empty()) {
|
||||||
for (list<DataSink*>::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) {
|
for (const auto dataSink : dataSinks) {
|
||||||
(*it)->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck);
|
dataSink->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -385,10 +386,9 @@ void MainLoop::run() {
|
|||||||
time(&now);
|
time(&now);
|
||||||
if (!dataSinks.empty()) {
|
if (!dataSinks.empty()) {
|
||||||
messages = m_messages->findAll("", "", "*", false, true, true, true, true, true, sinkSince, now);
|
messages = m_messages->findAll("", "", "*", false, true, true, true, true, true, sinkSince, now);
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
|
for (const auto message : messages) {
|
||||||
Message* message = *it;
|
for (const auto dataSink : dataSinks) {
|
||||||
for (list<DataSink*>::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) {
|
dataSink->notifyUpdate(message);
|
||||||
(*it)->notifyUpdate(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sinkSince = now;
|
sinkSince = now;
|
||||||
@@ -425,8 +425,7 @@ void MainLoop::run() {
|
|||||||
if (listening) {
|
if (listening) {
|
||||||
string levels = getUserLevels(user);
|
string levels = getUserLevels(user);
|
||||||
messages = m_messages->findAll("", "", levels, false, true, true, true, true, true, since, now);
|
messages = m_messages->findAll("", "", levels, false, true, true, true, true, true, since, now);
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
|
for (const auto message : messages) {
|
||||||
Message* message = *it;
|
|
||||||
ostream << message->getCircuit() << " " << message->getName() << " = " << dec;
|
ostream << message->getCircuit() << " " << message->getName() << " = " << dec;
|
||||||
message->decodeLastData(ostream);
|
message->decodeLastData(ostream);
|
||||||
ostream << endl;
|
ostream << endl;
|
||||||
@@ -1252,8 +1251,7 @@ string MainLoop::executeFind(vector<string> &args, string levels) {
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
ostringstream result;
|
ostringstream result;
|
||||||
char str[32];
|
char str[32];
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end();) {
|
for (const auto message : messages) {
|
||||||
Message* message = *it++;
|
|
||||||
if (!id.empty() && !message->checkIdPrefix(id)) {
|
if (!id.empty() && !message->checkIdPrefix(id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1649,8 +1647,7 @@ string MainLoop::executeGet(vector<string> &args, bool& connected) {
|
|||||||
deque<Message *> messages = m_messages->findAll(circuit, name, getUserLevels(user), exact, true, false, true);
|
deque<Message *> messages = m_messages->findAll(circuit, name, getUserLevels(user), exact, true, false, true);
|
||||||
bool first = true;
|
bool first = true;
|
||||||
verbosity |= (valueName ? OF_VALUENAME : numeric ? OF_NUMERIC : 0) | OF_JSON | (full ? OF_ALL_ATTRS : 0);
|
verbosity |= (valueName ? OF_VALUENAME : numeric ? OF_NUMERIC : 0) | OF_JSON | (full ? OF_ALL_ATTRS : 0);
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end();) {
|
for (const auto message : messages) {
|
||||||
Message* message = *it++;
|
|
||||||
symbol_t dstAddress = message->getDstAddress();
|
symbol_t dstAddress = message->getDstAddress();
|
||||||
if (dstAddress == SYN) {
|
if (dstAddress == SYN) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ bool parseTopic(const string topic, vector<string> &strs, vector<string> &fields
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string fieldName = knownFieldNames[idx];
|
string fieldName = knownFieldNames[idx];
|
||||||
for (auto& it : fields) {
|
for (const auto& it : fields) {
|
||||||
if (it == fieldName) {
|
if (it == fieldName) {
|
||||||
return false; // duplicate column
|
return false; // duplicate column
|
||||||
}
|
}
|
||||||
@@ -521,12 +521,11 @@ void MqttHandler::run() {
|
|||||||
time(&lastTaskRun);
|
time(&lastTaskRun);
|
||||||
}
|
}
|
||||||
if (m_connected && !m_updatedMessages.empty()) {
|
if (m_connected && !m_updatedMessages.empty()) {
|
||||||
for (map<Message*, int>::iterator it = m_updatedMessages.begin(); it != m_updatedMessages.end(); it++) {
|
for (const auto it : m_updatedMessages) {
|
||||||
Message* message = it->first;
|
|
||||||
updates.str("");
|
updates.str("");
|
||||||
updates.clear();
|
updates.clear();
|
||||||
updates << dec;
|
updates << dec;
|
||||||
publishMessage(message, updates);
|
publishMessage(it.first, updates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_updatedMessages.clear();
|
m_updatedMessages.clear();
|
||||||
|
|||||||
@@ -291,15 +291,15 @@ void Network::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Network::cleanConnections() {
|
void Network::cleanConnections() {
|
||||||
list<Connection*>::iterator c_it = m_connections.begin();
|
auto it = m_connections.begin();
|
||||||
while (c_it != m_connections.end()) {
|
while (it != m_connections.end()) {
|
||||||
if (!(*c_it)->isRunning()) {
|
if (!(*it)->isRunning()) {
|
||||||
Connection* connection = *c_it;
|
Connection* connection = *it;
|
||||||
c_it = m_connections.erase(c_it);
|
it = m_connections.erase(it);
|
||||||
delete connection;
|
delete connection;
|
||||||
logDebug(lf_network, "dead connection removed - %d", m_connections.size());
|
logDebug(lf_network, "dead connection removed - %d", m_connections.size());
|
||||||
} else {
|
} else {
|
||||||
c_it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-28
@@ -81,7 +81,7 @@ const string AttributedItem::formatInt(size_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const string AttributedItem::pluck(map<string, string>& row, string key) {
|
const string AttributedItem::pluck(map<string, string>& row, string key) {
|
||||||
map<string, string>::iterator it = row.find(key);
|
const auto it = row.find(key);
|
||||||
if (it == row.end()) {
|
if (it == row.end()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -127,8 +127,8 @@ void AttributedItem::appendJson(ostream& output, const string name, const string
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AttributedItem::mergeAttributes(map<string, string>& attributes) const {
|
void AttributedItem::mergeAttributes(map<string, string>& attributes) const {
|
||||||
for (auto& entry : m_attributes) {
|
for (const auto& entry : m_attributes) {
|
||||||
auto it = attributes.find(entry.first);
|
const auto it = attributes.find(entry.first);
|
||||||
if (it == attributes.end() || it->second.empty()) {
|
if (it == attributes.end() || it->second.empty()) {
|
||||||
attributes[entry.first] = entry.second;
|
attributes[entry.first] = entry.second;
|
||||||
}
|
}
|
||||||
@@ -140,13 +140,13 @@ void AttributedItem::dumpAttribute(ostream& output, const string name, const boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
string AttributedItem::getAttribute(const string name) const {
|
string AttributedItem::getAttribute(const string name) const {
|
||||||
auto it = m_attributes.find(name);
|
const auto it = m_attributes.find(name);
|
||||||
return it == m_attributes.end() ? "" : it->second;
|
return it == m_attributes.end() ? "" : it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AttributedItem::appendAttribute(ostringstream& output, OutputFormat outputFormat, const string name,
|
bool AttributedItem::appendAttribute(ostringstream& output, OutputFormat outputFormat, const string name,
|
||||||
const bool onlyIfNonEmpty, const string prefix, const string suffix) const {
|
const bool onlyIfNonEmpty, const string prefix, const string suffix) const {
|
||||||
auto it = m_attributes.find(name);
|
const auto it = m_attributes.find(name);
|
||||||
string value = it == m_attributes.end() ? "" : it->second;
|
string value = it == m_attributes.end() ? "" : it->second;
|
||||||
if (onlyIfNonEmpty && value.empty()) {
|
if (onlyIfNonEmpty && value.empty()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -168,7 +168,7 @@ bool AttributedItem::appendAttributes(ostringstream& output, OutputFormat output
|
|||||||
ret = appendAttribute(output, outputFormat, "comment", true, "[", "]") || ret;
|
ret = appendAttribute(output, outputFormat, "comment", true, "[", "]") || ret;
|
||||||
}
|
}
|
||||||
if (outputFormat & OF_ALL_ATTRS) {
|
if (outputFormat & OF_ALL_ATTRS) {
|
||||||
for (auto& entry : m_attributes) {
|
for (const auto entry : m_attributes) {
|
||||||
ret = true;
|
ret = true;
|
||||||
if (!entry.second.empty() && entry.first != "unit" && entry.first != "comment") {
|
if (!entry.second.empty() && entry.first != "unit" && entry.first != "comment") {
|
||||||
if (outputFormat & OF_JSON) {
|
if (outputFormat & OF_JSON) {
|
||||||
@@ -198,7 +198,7 @@ result_t DataField::create(vector< map<string, string> >& rows, string& errorDes
|
|||||||
return RESULT_ERR_EOF;
|
return RESULT_ERR_EOF;
|
||||||
}
|
}
|
||||||
size_t fieldIndex = -1;
|
size_t fieldIndex = -1;
|
||||||
for (auto row : rows) {
|
for (auto& row : rows) {
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -681,7 +681,7 @@ void ValueListDataField::dump(ostream& output) const {
|
|||||||
output << FIELD_SEPARATOR;
|
output << FIELD_SEPARATOR;
|
||||||
if (!m_dataType->dump(output, m_length)) { // no divisor appended
|
if (!m_dataType->dump(output, m_length)) { // no divisor appended
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto it : m_values) {
|
for (const auto it : m_values) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -703,7 +703,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input,
|
|||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
auto it = m_values.find(value);
|
const auto it = m_values.find(value);
|
||||||
if (it == m_values.end() && value != m_dataType->getReplacement()) {
|
if (it == m_values.end() && value != m_dataType->getReplacement()) {
|
||||||
// fall back to raw value in input
|
// fall back to raw value in input
|
||||||
output << setw(0) << dec << static_cast<unsigned>(value);
|
output << setw(0) << dec << static_cast<unsigned>(value);
|
||||||
@@ -743,7 +743,7 @@ result_t ValueListDataField::writeSymbols(istringstream& input,
|
|||||||
}
|
}
|
||||||
const char* str = input.str().c_str();
|
const char* str = input.str().c_str();
|
||||||
|
|
||||||
for (auto it : m_values) {
|
for (const auto it : m_values) {
|
||||||
if (it.second.compare(str) == 0) {
|
if (it.second.compare(str) == 0) {
|
||||||
return numType->writeRawValue(it.first, offset, m_length, output, usedLength);
|
return numType->writeRawValue(it.first, offset, m_length, output, usedLength);
|
||||||
}
|
}
|
||||||
@@ -775,7 +775,7 @@ result_t ConstantDataField::derive(const string name, map<string, string> attrib
|
|||||||
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
|
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
|
||||||
}
|
}
|
||||||
string useName = name.empty() ? m_name : name;
|
string useName = name.empty() ? m_name : name;
|
||||||
for (auto entry : m_attributes) { // merge with this attributes
|
for (const auto entry : m_attributes) { // merge with this attributes
|
||||||
if (attributes[entry.first].empty()) {
|
if (attributes[entry.first].empty()) {
|
||||||
attributes[entry.first] = entry.second;
|
attributes[entry.first] = entry.second;
|
||||||
}
|
}
|
||||||
@@ -881,15 +881,15 @@ DataFieldSet* DataFieldSet::getIdentFields() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataFieldSet::~DataFieldSet() {
|
DataFieldSet::~DataFieldSet() {
|
||||||
for (auto it : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
delete it;
|
delete field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DataFieldSet* DataFieldSet::clone() const {
|
const DataFieldSet* DataFieldSet::clone() const {
|
||||||
vector<const SingleDataField*> fields;
|
vector<const SingleDataField*> fields;
|
||||||
for (auto it : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
fields.push_back(it->clone());
|
fields.push_back(field->clone());
|
||||||
}
|
}
|
||||||
return new DataFieldSet(m_name, fields);
|
return new DataFieldSet(m_name, fields);
|
||||||
}
|
}
|
||||||
@@ -898,7 +898,7 @@ size_t DataFieldSet::getLength(PartType partType, size_t maxLength) const {
|
|||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
bool previousFullByteOffset[] = { true, true, true, true };
|
bool previousFullByteOffset[] = { true, true, true, true };
|
||||||
|
|
||||||
for (auto field : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
if (field->getPartType() == partType) {
|
if (field->getPartType() == partType) {
|
||||||
if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) {
|
if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) {
|
||||||
length--;
|
length--;
|
||||||
@@ -938,8 +938,8 @@ result_t DataFieldSet::derive(const string name, map<string, string> attributes,
|
|||||||
if (!values.empty()) {
|
if (!values.empty()) {
|
||||||
return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive
|
return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive
|
||||||
}
|
}
|
||||||
for (auto it : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
result_t result = it->derive("", attributes, partType, divisor, values, fields);
|
result_t result = field->derive("", attributes, partType, divisor, values, fields);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -951,7 +951,7 @@ result_t DataFieldSet::derive(const string name, map<string, string> attributes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DataFieldSet::hasField(const char* fieldName, bool numeric) const {
|
bool DataFieldSet::hasField(const char* fieldName, bool numeric) const {
|
||||||
for (auto field : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
if (field->hasField(fieldName, numeric) == 0) {
|
if (field->hasField(fieldName, numeric) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -961,13 +961,13 @@ bool DataFieldSet::hasField(const char* fieldName, bool numeric) const {
|
|||||||
|
|
||||||
void DataFieldSet::dump(ostream& output) const {
|
void DataFieldSet::dump(ostream& output) const {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto it : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
output << FIELD_SEPARATOR;
|
output << FIELD_SEPARATOR;
|
||||||
}
|
}
|
||||||
it->dump(output);
|
field->dump(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -975,7 +975,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset,
|
|||||||
unsigned int& output, const char* fieldName, ssize_t fieldIndex) const {
|
unsigned int& output, const char* fieldName, ssize_t fieldIndex) const {
|
||||||
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
|
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
|
||||||
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
|
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
|
||||||
for (auto field : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
if (field->getPartType() != partType) {
|
if (field->getPartType() != partType) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1017,7 +1017,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset,
|
|||||||
outputIndex = 0;
|
outputIndex = 0;
|
||||||
}
|
}
|
||||||
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
|
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
|
||||||
for (auto field : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
if (field->getPartType() != partType) {
|
if (field->getPartType() != partType) {
|
||||||
if (outputIndex >= 0 && !field->isIgnored()) {
|
if (outputIndex >= 0 && !field->isIgnored()) {
|
||||||
outputIndex++;
|
outputIndex++;
|
||||||
@@ -1064,7 +1064,7 @@ result_t DataFieldSet::write(istringstream& input, SymbolString& data,
|
|||||||
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
|
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
|
||||||
bool previousFullByteOffset = true;
|
bool previousFullByteOffset = true;
|
||||||
size_t baseOffset = offset;
|
size_t baseOffset = offset;
|
||||||
for (auto field : m_fields) {
|
for (const auto field : m_fields) {
|
||||||
if (field->getPartType() != partType) {
|
if (field->getPartType() != partType) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1100,7 +1100,7 @@ result_t DataFieldSet::write(istringstream& input, SymbolString& data,
|
|||||||
|
|
||||||
DataFieldTemplates::DataFieldTemplates(DataFieldTemplates& other)
|
DataFieldTemplates::DataFieldTemplates(DataFieldTemplates& other)
|
||||||
: MappedFileReader::MappedFileReader(false) {
|
: MappedFileReader::MappedFileReader(false) {
|
||||||
for (auto it : other.m_fieldsByName) {
|
for (const auto it : other.m_fieldsByName) {
|
||||||
m_fieldsByName[it.first] = it.second->clone();
|
m_fieldsByName[it.first] = it.second->clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1117,7 +1117,7 @@ result_t DataFieldTemplates::add(const DataField* field, string name, bool repla
|
|||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
name = field->getName();
|
name = field->getName();
|
||||||
}
|
}
|
||||||
auto it = m_fieldsByName.find(name);
|
const auto it = m_fieldsByName.find(name);
|
||||||
if (it != m_fieldsByName.end()) {
|
if (it != m_fieldsByName.end()) {
|
||||||
if (!replace) {
|
if (!replace) {
|
||||||
return RESULT_ERR_DUPLICATE_NAME; // duplicate key
|
return RESULT_ERR_DUPLICATE_NAME; // duplicate key
|
||||||
@@ -1136,7 +1136,7 @@ result_t DataFieldTemplates::getFieldMap(vector<string>& row, string& errorDescr
|
|||||||
// name[:usename],basetype[:len]|template[:usename][,[divisor|values][,[unit][,[comment]]]]
|
// name[:usename],basetype[:len]|template[:usename][,[divisor|values][,[unit][,[comment]]]]
|
||||||
if (row.empty()) {
|
if (row.empty()) {
|
||||||
// default map does not include separate field name
|
// default map does not include separate field name
|
||||||
for (auto col : defaultTemplateFieldMap) {
|
for (const auto& col : defaultTemplateFieldMap) {
|
||||||
row.push_back(col);
|
row.push_back(col);
|
||||||
}
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
@@ -1252,7 +1252,7 @@ result_t DataFieldTemplates::addFromFile(map<string, string>& row, vector< map<s
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DataField* DataFieldTemplates::get(const string name) const {
|
const DataField* DataFieldTemplates::get(const string name) const {
|
||||||
auto ref = m_fieldsByName.find(name);
|
const auto ref = m_fieldsByName.find(name);
|
||||||
if (ref == m_fieldsByName.end()) {
|
if (ref == m_fieldsByName.end()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-67
@@ -163,7 +163,7 @@ string getDefault(const string value, const map<string, string>& defaults, const
|
|||||||
if (value.length() == 0 && replaceStar && required) {
|
if (value.length() == 0 && replaceStar && required) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
auto it = defaults.find(fieldName);
|
const auto it = defaults.find(fieldName);
|
||||||
const string defaultStr = it == defaults.end() ? "" : it->second;
|
const string defaultStr = it == defaults.end() ? "" : it->second;
|
||||||
if (!replaceStar || defaultStr.empty()) {
|
if (!replaceStar || defaultStr.empty()) {
|
||||||
return value.length() > 0 ? value : defaultStr;
|
return value.length() > 0 ? value : defaultStr;
|
||||||
@@ -186,8 +186,8 @@ uint64_t Message::createKey(const vector<symbol_t> id,
|
|||||||
}
|
}
|
||||||
key |= (uint64_t)dstAddress << (8 * 6);
|
key |= (uint64_t)dstAddress << (8 * 6);
|
||||||
int exp = 5;
|
int exp = 5;
|
||||||
for (vector<symbol_t>::const_iterator it = id.begin(); it < id.end(); it++) {
|
for (const auto it : id) {
|
||||||
key ^= (uint64_t)*it << (8 * exp--);
|
key ^= (uint64_t)it << (8 * exp--);
|
||||||
if (exp == 0) {
|
if (exp == 0) {
|
||||||
exp = 3;
|
exp = 3;
|
||||||
}
|
}
|
||||||
@@ -195,7 +195,7 @@ uint64_t Message::createKey(const vector<symbol_t> id,
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Message::createKey(MasterSymbolString& master, size_t maxIdLength, bool anyDestination) {
|
uint64_t Message::createKey(const MasterSymbolString& master, size_t maxIdLength, bool anyDestination) {
|
||||||
if (master.size() < 5) {
|
if (master.size() < 5) {
|
||||||
return INVALID_KEY;
|
return INVALID_KEY;
|
||||||
}
|
}
|
||||||
@@ -473,8 +473,7 @@ result_t Message::create(map<string, string> row, vector< map<string, string> >
|
|||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
bool multiple = dstAddresses.size() > 1;
|
bool multiple = dstAddresses.size() > 1;
|
||||||
char num[10];
|
char num[10];
|
||||||
for (vector<symbol_t>::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) {
|
for (const auto dstAddress : dstAddresses) {
|
||||||
symbol_t dstAddress = *it;
|
|
||||||
string useCircuit = circuit;
|
string useCircuit = circuit;
|
||||||
if (multiple) {
|
if (multiple) {
|
||||||
snprintf(num, sizeof(num), ".%d", index);
|
snprintf(num, sizeof(num), ".%d", index);
|
||||||
@@ -489,6 +488,7 @@ result_t Message::create(map<string, string> row, vector< map<string, string> >
|
|||||||
index == 0, pollPriority, condition);
|
index == 0, pollPriority, condition);
|
||||||
}
|
}
|
||||||
messages.push_back(message);
|
messages.push_back(message);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
@@ -829,7 +829,7 @@ bool Message::isLessPollWeight(const Message* other) const {
|
|||||||
void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
|
void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
if (fieldNames == NULL) {
|
if (fieldNames == NULL) {
|
||||||
for (auto fieldName : defaultMessageFieldMap) {
|
for (const auto& fieldName : defaultMessageFieldMap) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -839,7 +839,7 @@ void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto fieldName : *fieldNames) {
|
for (const auto& fieldName : *fieldNames) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -852,7 +852,7 @@ void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
|
|||||||
void Message::dump(ostream& output, vector<string>* fieldNames, bool withConditions) const {
|
void Message::dump(ostream& output, vector<string>* fieldNames, bool withConditions) const {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
if (fieldNames == NULL) {
|
if (fieldNames == NULL) {
|
||||||
for (auto fieldName : knownFieldNamesFull) {
|
for (const auto& fieldName : knownFieldNamesFull) {
|
||||||
if (fieldName == FIELNAME_LEVEL) {
|
if (fieldName == FIELNAME_LEVEL) {
|
||||||
continue; // access level not included in default dump format
|
continue; // access level not included in default dump format
|
||||||
}
|
}
|
||||||
@@ -865,7 +865,7 @@ void Message::dump(ostream& output, vector<string>* fieldNames, bool withConditi
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto fieldName : *fieldNames) {
|
for (const auto& fieldName : *fieldNames) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -920,13 +920,13 @@ void Message::dumpField(ostream& output, string fieldName, bool withConditions)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fieldName == "pbsb") {
|
if (fieldName == "pbsb") {
|
||||||
for (vector<symbol_t>::const_iterator it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) {
|
for (auto it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) {
|
||||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
|
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fieldName == "id") {
|
if (fieldName == "id") {
|
||||||
for (vector<symbol_t>::const_iterator it = m_id.begin()+2; it < m_id.end(); it++) {
|
for (auto it = m_id.begin()+2; it < m_id.end(); it++) {
|
||||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
|
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -1218,7 +1218,7 @@ void ChainedMessage::dumpField(ostream& output, string fieldName, bool withCondi
|
|||||||
bool first = true;
|
bool first = true;
|
||||||
for (size_t index = 0; index < m_ids.size(); index++) {
|
for (size_t index = 0; index < m_ids.size(); index++) {
|
||||||
vector<symbol_t> id = m_ids[index];
|
vector<symbol_t> id = m_ids[index];
|
||||||
for (vector<symbol_t>::const_iterator it = id.begin()+2; it < id.end(); it++) {
|
for (auto it = id.begin()+2; it < id.end(); it++) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -1570,14 +1570,14 @@ bool SimpleStringCondition::checkValue(Message* message, string field) {
|
|||||||
|
|
||||||
|
|
||||||
void CombinedCondition::dump(ostream& output, bool matched) const {
|
void CombinedCondition::dump(ostream& output, bool matched) const {
|
||||||
for (auto condition : m_conditions) {
|
for (const auto condition : m_conditions) {
|
||||||
condition->dump(output, matched);
|
condition->dump(output, matched);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMessage,
|
result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMessage,
|
||||||
void (*readMessageFunc)(Message* message)) {
|
void (*readMessageFunc)(Message* message)) {
|
||||||
for (auto condition : m_conditions) {
|
for (const auto condition : m_conditions) {
|
||||||
ostringstream dummy;
|
ostringstream dummy;
|
||||||
result_t ret = condition->resolve(messages, dummy, readMessageFunc);
|
result_t ret = condition->resolve(messages, dummy, readMessageFunc);
|
||||||
if (ret != RESULT_OK) {
|
if (ret != RESULT_OK) {
|
||||||
@@ -1589,8 +1589,8 @@ result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CombinedCondition::isTrue() {
|
bool CombinedCondition::isTrue() {
|
||||||
for (vector<Condition*>::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) {
|
for (const auto condition : m_conditions) {
|
||||||
if (!(*it)->isTrue()) {
|
if (!condition->isTrue()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1616,7 +1616,7 @@ result_t Instruction::create(const string& contextPath, const string type,
|
|||||||
}
|
}
|
||||||
string arg = row["file"];
|
string arg = row["file"];
|
||||||
row.erase("file");
|
row.erase("file");
|
||||||
for (auto entry : row) { // fallback to first field
|
for (const auto entry : row) { // fallback to first field
|
||||||
if (!entry.second.empty()) {
|
if (!entry.second.empty()) {
|
||||||
arg = entry.second;
|
arg = entry.second;
|
||||||
break;
|
break;
|
||||||
@@ -1703,7 +1703,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
|
|||||||
uint64_t key = message->getKey();
|
uint64_t key = message->getKey();
|
||||||
bool conditional = message->isConditional();
|
bool conditional = message->isConditional();
|
||||||
if (!m_addAll) {
|
if (!m_addAll) {
|
||||||
map<uint64_t, vector<Message*> >::iterator keyIt = m_messagesByKey.find(key);
|
const auto keyIt = m_messagesByKey.find(key);
|
||||||
if (keyIt != m_messagesByKey.end()) {
|
if (keyIt != m_messagesByKey.end()) {
|
||||||
Message* other = getFirstAvailable(keyIt->second, message);
|
Message* other = getFirstAvailable(keyIt->second, message);
|
||||||
if (other != NULL) {
|
if (other != NULL) {
|
||||||
@@ -1729,7 +1729,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
|
|||||||
string suffix = FIELD_SEPARATOR + name + (isPassive ? "P" : (isWrite ? "W" : "R"));
|
string suffix = FIELD_SEPARATOR + name + (isPassive ? "P" : (isWrite ? "W" : "R"));
|
||||||
string nameKey = circuit + suffix;
|
string nameKey = circuit + suffix;
|
||||||
if (!m_addAll) {
|
if (!m_addAll) {
|
||||||
map<string, vector<Message*> >::iterator nameIt = m_messagesByName.find(nameKey);
|
const auto nameIt = m_messagesByName.find(nameKey);
|
||||||
if (nameIt != m_messagesByName.end()) {
|
if (nameIt != m_messagesByName.end()) {
|
||||||
vector<Message*>* messages = &nameIt->second;
|
vector<Message*>* messages = &nameIt->second;
|
||||||
if (!message->isConditional() || !messages->front()->isConditional()) {
|
if (!message->isConditional() || !messages->front()->isConditional()) {
|
||||||
@@ -1739,7 +1739,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
|
|||||||
}
|
}
|
||||||
m_messagesByName[nameKey].push_back(message);
|
m_messagesByName[nameKey].push_back(message);
|
||||||
nameKey = suffix; // also store without circuit
|
nameKey = suffix; // also store without circuit
|
||||||
map<string, vector<Message*> >::iterator nameIt = m_messagesByName.find(nameKey);
|
const auto nameIt = m_messagesByName.find(nameKey);
|
||||||
if (nameIt == m_messagesByName.end()) {
|
if (nameIt == m_messagesByName.end()) {
|
||||||
// always store first message without circuit (in order of circuit name)
|
// always store first message without circuit (in order of circuit name)
|
||||||
m_messagesByName[nameKey].push_back(message);
|
m_messagesByName[nameKey].push_back(message);
|
||||||
@@ -1779,7 +1779,7 @@ result_t MessageMap::getFieldMap(vector<string>& row, string& errorDescription,
|
|||||||
// unit,comment
|
// unit,comment
|
||||||
// minimum: type,name,PBSB,field,datatype
|
// minimum: type,name,PBSB,field,datatype
|
||||||
if (row.empty()) {
|
if (row.empty()) {
|
||||||
for (auto col : defaultMessageFieldMap) {
|
for (const auto& col : defaultMessageFieldMap) {
|
||||||
row.push_back(col);
|
row.push_back(col);
|
||||||
}
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
@@ -1881,7 +1881,7 @@ result_t MessageMap::addDefaultFromFile(map<string, string>& row, vector< map<st
|
|||||||
// check for condition in defaults
|
// check for condition in defaults
|
||||||
string type = row["type"];
|
string type = row["type"];
|
||||||
row.erase("type");
|
row.erase("type");
|
||||||
auto mainDefaults = getDefaults().find("");
|
const auto& mainDefaults = getDefaults().find("");
|
||||||
map<string, string> defaults;
|
map<string, string> defaults;
|
||||||
if (mainDefaults != getDefaults().end()) {
|
if (mainDefaults != getDefaults().end()) {
|
||||||
defaults = mainDefaults->second;
|
defaults = mainDefaults->second;
|
||||||
@@ -1894,7 +1894,7 @@ result_t MessageMap::addDefaultFromFile(map<string, string>& row, vector< map<st
|
|||||||
return RESULT_ERR_INVALID_ARG;
|
return RESULT_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
string key = filename+":"+type;
|
string key = filename+":"+type;
|
||||||
map<string, Condition*>::iterator it = m_conditions.find(key);
|
const auto it = m_conditions.find(key);
|
||||||
if (it != m_conditions.end()) {
|
if (it != m_conditions.end()) {
|
||||||
errorDescription = "condition "+type+" already defined";
|
errorDescription = "condition "+type+" already defined";
|
||||||
return RESULT_ERR_DUPLICATE_NAME;
|
return RESULT_ERR_DUPLICATE_NAME;
|
||||||
@@ -1918,7 +1918,7 @@ result_t MessageMap::addDefaultFromFile(map<string, string>& row, vector< map<st
|
|||||||
}
|
}
|
||||||
string defaultSuffix = defaults["suffix"];
|
string defaultSuffix = defaults["suffix"];
|
||||||
defaults.erase("suffix");
|
defaults.erase("suffix");
|
||||||
for (auto entry : row) {
|
for (const auto entry : row) {
|
||||||
string value = entry.second;
|
string value = entry.second;
|
||||||
if (entry.first == "circuit" && !defaultCircuit.empty()) { // TODO remove some day
|
if (entry.first == "circuit" && !defaultCircuit.empty()) { // TODO remove some day
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
@@ -1963,7 +1963,7 @@ result_t MessageMap::readConditions(string& types, const string filename, string
|
|||||||
if (types.length() > 0 && types[0] == '[' && (pos=types.find_last_of(']')) != string::npos) {
|
if (types.length() > 0 && types[0] == '[' && (pos=types.find_last_of(']')) != string::npos) {
|
||||||
// check if combined or simple condition is already known
|
// check if combined or simple condition is already known
|
||||||
const string combinedkey = filename+":"+types.substr(1, pos-1);
|
const string combinedkey = filename+":"+types.substr(1, pos-1);
|
||||||
auto it = m_conditions.find(combinedkey);
|
const auto it = m_conditions.find(combinedkey);
|
||||||
if (it != m_conditions.end()) {
|
if (it != m_conditions.end()) {
|
||||||
condition = it->second;
|
condition = it->second;
|
||||||
types = types.substr(pos+1);
|
types = types.substr(pos+1);
|
||||||
@@ -1973,7 +1973,7 @@ result_t MessageMap::readConditions(string& types, const string filename, string
|
|||||||
while ((pos=types.find(']')) != string::npos) {
|
while ((pos=types.find(']')) != string::npos) {
|
||||||
// simple condition
|
// simple condition
|
||||||
string key = filename+":"+types.substr(1, pos-1);
|
string key = filename+":"+types.substr(1, pos-1);
|
||||||
map<string, Condition*>::iterator it = m_conditions.find(key);
|
auto it = m_conditions.find(key);
|
||||||
Condition* add = NULL;
|
Condition* add = NULL;
|
||||||
if (it == m_conditions.end()) {
|
if (it == m_conditions.end()) {
|
||||||
// check for on-the-fly condition
|
// check for on-the-fly condition
|
||||||
@@ -2135,7 +2135,7 @@ result_t MessageMap::addFromFile(map<string, string>& row, vector< map<string, s
|
|||||||
errorDescription = "invalid instruction";
|
errorDescription = "invalid instruction";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
map<string, vector<Instruction*> >::iterator it = m_instructions.find(filename);
|
const auto it = m_instructions.find(filename);
|
||||||
if (it == m_instructions.end()) {
|
if (it == m_instructions.end()) {
|
||||||
vector<Instruction*> instructions;
|
vector<Instruction*> instructions;
|
||||||
instructions.push_back(instruction);
|
instructions.push_back(instruction);
|
||||||
@@ -2162,8 +2162,7 @@ result_t MessageMap::addFromFile(map<string, string>& row, vector< map<string, s
|
|||||||
row["type"] = type;
|
row["type"] = type;
|
||||||
result = Message::create(row, subRows, getDefaults(), getSubDefaults(), errorDescription, condition, filename,
|
result = Message::create(row, subRows, getDefaults(), getSubDefaults(), errorDescription, condition, filename,
|
||||||
templates, messages);
|
templates, messages);
|
||||||
for (vector<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
|
for (const auto message : messages) {
|
||||||
Message* message = *it;
|
|
||||||
if (result == RESULT_OK) {
|
if (result == RESULT_OK) {
|
||||||
result = add(message);
|
result = add(message);
|
||||||
if (result == RESULT_ERR_DUPLICATE_NAME) {
|
if (result == RESULT_ERR_DUPLICATE_NAME) {
|
||||||
@@ -2205,8 +2204,8 @@ Message* MessageMap::getScanMessage(const symbol_t dstAddress) {
|
|||||||
|
|
||||||
result_t MessageMap::resolveConditions(string& errorDescription, bool verbose) {
|
result_t MessageMap::resolveConditions(string& errorDescription, bool verbose) {
|
||||||
result_t overallResult = RESULT_OK;
|
result_t overallResult = RESULT_OK;
|
||||||
for (map<string, Condition*>::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) {
|
for (const auto it : m_conditions) {
|
||||||
Condition* condition = it->second;
|
Condition* condition = it.second;
|
||||||
result_t result = resolveCondition(condition, errorDescription);
|
result_t result = resolveCondition(condition, errorDescription);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
overallResult = result;
|
overallResult = result;
|
||||||
@@ -2234,11 +2233,11 @@ result_t MessageMap::resolveCondition(Condition* condition, string& errorDescrip
|
|||||||
result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageFunc)(Message* message)) {
|
result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageFunc)(Message* message)) {
|
||||||
result_t overallResult = RESULT_OK;
|
result_t overallResult = RESULT_OK;
|
||||||
vector<string> remove;
|
vector<string> remove;
|
||||||
for (auto& it : m_instructions) {
|
for (auto it : m_instructions) {
|
||||||
auto& instructions = it.second;
|
auto& instructions = it.second;
|
||||||
bool removeSingletons = false;
|
bool removeSingletons = false;
|
||||||
vector<Instruction*> remain;
|
vector<Instruction*> remain;
|
||||||
for (auto instruction : instructions) {
|
for (const auto instruction : instructions) {
|
||||||
if (removeSingletons && instruction->isSingleton()) {
|
if (removeSingletons && instruction->isSingleton()) {
|
||||||
delete instruction;
|
delete instruction;
|
||||||
continue;
|
continue;
|
||||||
@@ -2276,8 +2275,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
|
|||||||
if (removeSingletons && !remain.empty()) {
|
if (removeSingletons && !remain.empty()) {
|
||||||
instructions = remain;
|
instructions = remain;
|
||||||
remain.clear();
|
remain.clear();
|
||||||
for (vector<Instruction*>::iterator lit = instructions.begin(); lit != instructions.end(); lit++) {
|
for (const auto instruction : instructions) {
|
||||||
Instruction* instruction = *lit;
|
|
||||||
if (!instruction->isSingleton()) {
|
if (!instruction->isSingleton()) {
|
||||||
remain.push_back(instruction);
|
remain.push_back(instruction);
|
||||||
continue;
|
continue;
|
||||||
@@ -2291,7 +2289,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
|
|||||||
it.second = remain;
|
it.second = remain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto it : remove) {
|
for (const auto it : remove) {
|
||||||
m_instructions.erase(it);
|
m_instructions.erase(it);
|
||||||
}
|
}
|
||||||
return overallResult;
|
return overallResult;
|
||||||
@@ -2309,23 +2307,23 @@ void MessageMap::addLoadedFile(const symbol_t address, const string filename, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
const vector<string>& MessageMap::getLoadedFiles(const symbol_t address) const {
|
const vector<string>& MessageMap::getLoadedFiles(const symbol_t address) const {
|
||||||
auto files = m_loadedFiles.find(address);
|
const auto it = m_loadedFiles.find(address);
|
||||||
if (files != m_loadedFiles.end()) {
|
if (it != m_loadedFiles.end()) {
|
||||||
return files->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
return s_noFiles;
|
return s_noFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> MessageMap::getLoadedFiles() const {
|
vector<string> MessageMap::getLoadedFiles() const {
|
||||||
vector<string> ret;
|
vector<string> ret;
|
||||||
for (auto& loadedFile : m_loadedFileInfos) {
|
for (const auto& loadedFile : m_loadedFileInfos) {
|
||||||
ret.push_back(loadedFile.first);
|
ret.push_back(loadedFile.first);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageMap::getLoadedFileInfo(string filename, string& comment, size_t* hash, size_t* size, time_t* time) const {
|
bool MessageMap::getLoadedFileInfo(const string filename, string& comment, size_t* hash, size_t* size, time_t* time) const {
|
||||||
auto it = m_loadedFileInfos.find(filename);
|
const auto it = m_loadedFileInfos.find(filename);
|
||||||
if (it == m_loadedFileInfos.end()) {
|
if (it == m_loadedFileInfos.end()) {
|
||||||
comment = "";
|
comment = "";
|
||||||
hash = size = 0;
|
hash = size = 0;
|
||||||
@@ -2346,7 +2344,7 @@ bool MessageMap::getLoadedFileInfo(string filename, string& comment, size_t* has
|
|||||||
}
|
}
|
||||||
|
|
||||||
const vector<Message*>* MessageMap::getByKey(const uint64_t key) const {
|
const vector<Message*>* MessageMap::getByKey(const uint64_t key) const {
|
||||||
auto it = m_messagesByKey.find(key);
|
const auto it = m_messagesByKey.find(key);
|
||||||
if (it != m_messagesByKey.end()) {
|
if (it != m_messagesByKey.end()) {
|
||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
@@ -2369,7 +2367,7 @@ Message* MessageMap::find(const string& circuit, const string& name, const strin
|
|||||||
} else {
|
} else {
|
||||||
continue; // not allowed without circuit
|
continue; // not allowed without circuit
|
||||||
}
|
}
|
||||||
auto it = m_messagesByName.find(nameKey);
|
const auto it = m_messagesByName.find(nameKey);
|
||||||
if (it != m_messagesByName.end()) {
|
if (it != m_messagesByName.end()) {
|
||||||
Message* message = getFirstAvailable(it->second);
|
Message* message = getFirstAvailable(it->second);
|
||||||
if (message && message->hasLevel(levels)) {
|
if (message && message->hasLevel(levels)) {
|
||||||
@@ -2392,11 +2390,11 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
|
|||||||
bool checkCircuit = lcircuit.length() > 0;
|
bool checkCircuit = lcircuit.length() > 0;
|
||||||
bool checkLevel = levels != "*";
|
bool checkLevel = levels != "*";
|
||||||
bool checkName = lname.length() > 0;
|
bool checkName = lname.length() > 0;
|
||||||
for (auto it : m_messagesByName) {
|
for (const auto it : m_messagesByName) {
|
||||||
if (it.first[0] == FIELD_SEPARATOR) { // avoid duplicates: instances stored multiple times have a special key
|
if (it.first[0] == FIELD_SEPARATOR) { // avoid duplicates: instances stored multiple times have a special key
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (auto message : it.second) {
|
for (const auto message : it.second) {
|
||||||
if (checkLevel && !message->hasLevel(levels, includeEmptyLevel)) {
|
if (checkLevel && !message->hasLevel(levels, includeEmptyLevel)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2446,7 +2444,7 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message* MessageMap::find(MasterSymbolString& master, const bool anyDestination,
|
Message* MessageMap::find(const MasterSymbolString& master, const bool anyDestination,
|
||||||
const bool withRead, const bool withWrite, const bool withPassive, const bool onlyAvailable) const {
|
const bool withRead, const bool withWrite, const bool withPassive, const bool onlyAvailable) const {
|
||||||
if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) {
|
if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) {
|
||||||
return m_scanMessage;
|
return m_scanMessage;
|
||||||
@@ -2527,8 +2525,7 @@ void MessageMap::invalidateCache(Message* message) {
|
|||||||
string circuit = message->getCircuit();
|
string circuit = message->getCircuit();
|
||||||
string name = message->getName();
|
string name = message->getName();
|
||||||
deque<Message*> messages = findAll(circuit, name, "*", true, true, true, true);
|
deque<Message*> messages = findAll(circuit, name, "*", true, true, true, true);
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
|
for (auto checkMessage : messages) {
|
||||||
Message* checkMessage = *it;
|
|
||||||
if (checkMessage != message) {
|
if (checkMessage != message) {
|
||||||
checkMessage->m_lastUpdateTime = 0;
|
checkMessage->m_lastUpdateTime = 0;
|
||||||
}
|
}
|
||||||
@@ -2543,7 +2540,7 @@ void MessageMap::addPollMessage(Message* message, bool toFront) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MessageMap::decodeCircuit(const string circuit, ostringstream& output, OutputFormat outputFormat) const {
|
bool MessageMap::decodeCircuit(const string circuit, ostringstream& output, OutputFormat outputFormat) const {
|
||||||
auto it = m_circuitData.find(circuit);
|
const auto it = m_circuitData.find(circuit);
|
||||||
if (it == m_circuitData.end()) {
|
if (it == m_circuitData.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2570,13 +2567,16 @@ void MessageMap::clear() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (Message* message : it.second) {
|
for (Message* message : it.second) {
|
||||||
map<uint64_t, vector<Message*> >::iterator keyIt = m_messagesByKey.find(message->getKey());
|
const auto keyIt = m_messagesByKey.find(message->getKey());
|
||||||
if (keyIt != m_messagesByKey.end()) {
|
if (keyIt != m_messagesByKey.end()) {
|
||||||
vector<Message*>* keyMessages = &keyIt->second;
|
vector<Message*>* keyMessages = &keyIt->second;
|
||||||
if (!keyMessages->empty()) {
|
if (!keyMessages->empty()) {
|
||||||
for (vector<Message*>::iterator kit = keyMessages->begin(); kit != keyMessages->end(); kit++) {
|
auto kit = keyMessages->begin();
|
||||||
|
while (kit != keyMessages->end()) {
|
||||||
if (*kit == message) {
|
if (*kit == message) {
|
||||||
keyMessages->erase(kit--);
|
kit = keyMessages->erase(kit);
|
||||||
|
} else {
|
||||||
|
kit++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2586,23 +2586,21 @@ void MessageMap::clear() {
|
|||||||
it.second.clear();
|
it.second.clear();
|
||||||
}
|
}
|
||||||
// free remaining message instances by key
|
// free remaining message instances by key
|
||||||
for (map<uint64_t, vector<Message*> >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) {
|
for (const auto it : m_messagesByKey) {
|
||||||
vector<Message*> keyMessages = it->second;
|
vector<Message*> keyMessages = it.second;
|
||||||
for (vector<Message*>::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) {
|
for (auto message : keyMessages) {
|
||||||
Message* message = *kit;
|
|
||||||
delete message;
|
delete message;
|
||||||
}
|
}
|
||||||
keyMessages.clear();
|
keyMessages.clear();
|
||||||
}
|
}
|
||||||
// free condition instances
|
// free condition instances
|
||||||
for (map<string, Condition*>::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) {
|
for (const auto it : m_conditions) {
|
||||||
delete it->second;
|
delete it.second;
|
||||||
}
|
}
|
||||||
// free instruction instances
|
// free instruction instances
|
||||||
for (map<string, vector<Instruction*> >::iterator it = m_instructions.begin(); it != m_instructions.end(); it++) {
|
for (const auto it : m_instructions) {
|
||||||
vector<Instruction*> instructions = it->second;
|
vector<Instruction*> instructions = it.second;
|
||||||
for (vector<Instruction*>::iterator lit = instructions.begin(); lit != instructions.end(); lit++) {
|
for (const auto instruction : instructions) {
|
||||||
Instruction* instruction = *lit;
|
|
||||||
delete instruction;
|
delete instruction;
|
||||||
}
|
}
|
||||||
instructions.clear();
|
instructions.clear();
|
||||||
@@ -2616,7 +2614,7 @@ void MessageMap::clear() {
|
|||||||
m_messagesByKey.clear();
|
m_messagesByKey.clear();
|
||||||
m_conditions.clear();
|
m_conditions.clear();
|
||||||
m_instructions.clear();
|
m_instructions.clear();
|
||||||
for (auto& it : m_circuitData) {
|
for (const auto it : m_circuitData) {
|
||||||
delete it.second;
|
delete it.second;
|
||||||
}
|
}
|
||||||
m_circuitData.clear();
|
m_circuitData.clear();
|
||||||
@@ -2640,12 +2638,12 @@ void MessageMap::dump(ostream& output, bool withConditions) const {
|
|||||||
bool first = true;
|
bool first = true;
|
||||||
Message::dumpHeader(output, NULL);
|
Message::dumpHeader(output, NULL);
|
||||||
output << endl;
|
output << endl;
|
||||||
for (auto it : m_messagesByName) {
|
for (const auto it : m_messagesByName) {
|
||||||
if (it.first[0] == '-') { // skip instances stored multiple times (key starting with "-")
|
if (it.first[0] == '-') { // skip instances stored multiple times (key starting with "-")
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (m_addAll) {
|
if (m_addAll) {
|
||||||
for (auto message : it.second) {
|
for (const auto message : it.second) {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,8 +145,7 @@ class Message : public AttributedItem {
|
|||||||
* @param anyDestination @p true to use the special @a SYN as destination address in the key.
|
* @param anyDestination @p true to use the special @a SYN as destination address in the key.
|
||||||
* @return the key for the ID, or -1LL if the data is invalid.
|
* @return the key for the ID, or -1LL if the data is invalid.
|
||||||
*/
|
*/
|
||||||
static uint64_t createKey(MasterSymbolString& master,
|
static uint64_t createKey(const MasterSymbolString& master, size_t maxIdLength, bool anyDestination = false);
|
||||||
size_t maxIdLength, bool anyDestination = false);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the key for a scan message.
|
* Calculate the key for a scan message.
|
||||||
@@ -1355,7 +1354,7 @@ class MessageMap : public MappedFileReader {
|
|||||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
||||||
* @return true if the file info was found, false otherwise.
|
* @return true if the file info was found, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool getLoadedFileInfo(string filename, string& comment, size_t* hash = NULL, size_t* size = NULL,
|
bool getLoadedFileInfo(const string filename, string& comment, size_t* hash = NULL, size_t* size = NULL,
|
||||||
time_t* time = NULL) const;
|
time_t* time = NULL) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1417,7 +1416,7 @@ class MessageMap : public MappedFileReader {
|
|||||||
* @return the @a Message instance, or NULL.
|
* @return the @a Message instance, or NULL.
|
||||||
* Note: the caller may not free the returned instance.
|
* Note: the caller may not free the returned instance.
|
||||||
*/
|
*/
|
||||||
Message* find(MasterSymbolString& master, const bool anyDestination = false, const bool withRead = true,
|
Message* find(const MasterSymbolString& master, const bool anyDestination = false, const bool withRead = true,
|
||||||
const bool withWrite = true, const bool withPassive = true, const bool onlyAvailable = true) const;
|
const bool withWrite = true, const bool withPassive = true, const bool onlyAvailable = true) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user