Merge branch 'master' of github.com:john30/ebusd

This commit is contained in:
john30
2017-04-26 08:39:13 +02:00
15 changed files with 203 additions and 193 deletions
+3
View File
@@ -7,6 +7,7 @@
* added automatic check for updates (ebusd and configuration)
* use CSV header line for determining columns and picking multi-language columns by language preference
* a circuit name is now required for all message configurations
* raw logging allows logging of messages or each sent/received byte defaulting to messages
## Bug Fixes
* corrected numeric condition formatting
@@ -22,6 +23,7 @@
* corrected missing update notification on master message part
* corrected grouping of JSON output by circuit
* corrected address conflict detection when in answer mode
* fixed potential memory leaks and misused iterator
## Features
* added support for MQTT handling via libmosquitto (will be compiled in when library is available)
@@ -46,6 +48,7 @@
* allow TTQ/TTH types to use less than 8 bits
* added support for optional user-defined columns to config files
* added circuit-level attributes to config files for use in JSON
* added -N option to "read" command
# 2.4 (2016-12-17)
+9 -7
View File
@@ -20,16 +20,18 @@ The main features of the daemon are:
* regularly poll for messages
* cache all messages
* scan for bus participants
* parse messages to human readable values by using CSV message configuration files
* automatically pick CSV message configuration files by scan result
* parse messages to human readable values and vice versa via message configuration files
* automatically pick message configuration files by scan result
* automatically check for updates of daemon and configuration files
* pick preferred language for translatable message configuration parts
* grab all messages on the eBUS and provide decoding hints
* log messages and problems to a log file
* capture sent/received bytes to a log file as text
* capture messages or sent/received bytes to a log file as text
* dump received bytes to binary files for later playback/analysis
* listen for client connections on a dedicated TCP port (command line style and/or HTTP)
* optionally format messages and data in JSON on dedicated HTTP port
* listen for command line client connections on a dedicated TCP port
* optionally provide rudimentary HTML interface and allow data retrieval as JSON on HTTP port
* optionally publish received message data to MQTT topics and vice versa (if authorized)
* optional ACL and required user authentication for access to certain messages
* optional user authentication via ACL file for access to certain messages
Installation
@@ -70,7 +72,7 @@ Check the Wiki and/or the configuration repository:
Docker image
------------
A Docker image is available on the hub and it contains the latest German configuration files.
A Docker image including the latest message configuration files is available on the hub.
You can use it like this:
> docker pull john30/ebusd
> docker run -it --rm --device=/dev/ttyUSB0 -p 8888 john30/ebusd
+20 -19
View File
@@ -211,7 +211,7 @@ void GrabbedMessage::setLastData(MasterSymbolString& master, SlaveSymbolString&
* @param firstOnly whether to read only the first non-erroneous offset.
* @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) {
bool first = true;
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,
const bool decode) {
const bool decode) const {
Message* message = messages->find(m_lastMaster);
if (unknown && message) {
return false;
@@ -278,7 +278,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
return true;
}
bool master = isMaster(dstAddress) || dstAddress == BROADCAST || m_lastSlave.getDataSize() <= 0;
SymbolString *input;
const SymbolString *input;
if (master) {
input = &m_lastMaster;
} else {
@@ -288,7 +288,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first,
if (remain == 0) {
return true;
}
for (auto it : *types) {
for (const auto it : *types) {
const DataType* baseType = it.second;
if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored()) { // skip bit and ignored types
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);
for (deque<Message*>::iterator it = messages.begin(); it < messages.end(); it++) {
auto it = messages.begin();
while (it != messages.end()) {
Message* message = *it;
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) {
map<symbol_t, vector<string>>::iterator it = m_scanResults.find(slave);
const auto it = m_scanResults.find(slave);
if (it == m_scanResults.end()) {
return false;
}
@@ -1237,7 +1240,7 @@ bool BusHandler::formatScanResult(symbol_t slave, ostringstream& output, bool le
output << endl;
}
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(slave);
for (auto result : it->second) {
for (const auto result : it->second) {
output << result;
}
return true;
@@ -1317,7 +1320,7 @@ void BusHandler::formatSeenInfo(ostringstream& output) {
const vector<string>& loadedFiles = m_messages->getLoadedFiles(address);
if (!loadedFiles.empty()) {
bool first = true;
for (auto& loadedFile : loadedFiles) {
for (const auto& loadedFile : loadedFiles) {
if (first) {
first = false;
output << ", loaded \"";
@@ -1347,9 +1350,8 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
output << ",\"co\":" << (m_addressConflict ? 1 : 0);
if (m_grabMessages) {
size_t unknownCnt = 0;
for (map<uint64_t, GrabbedMessage>::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end();
it++) {
Message* message = m_messages->find(it->second.getLastMasterData());
for (auto it : m_grabbedMessages) {
Message* message = m_messages->find(it.second.getLastMasterData());
if (!message) {
unknownCnt++;
}
@@ -1364,10 +1366,10 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
}
output << ",\"" << setfill('0') << setw(2) << hex << static_cast<unsigned>(address) << dec << setw(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()) {
output << ",\"s\":\"";
for (auto result : it->second) {
for (const auto result : it->second) {
output << result;
}
output << "\"";
@@ -1383,7 +1385,7 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
if (!loadedFiles.empty()) {
output << ",\"f\":[";
bool first = true;
for (auto& loadedFile : loadedFiles) {
for (const auto loadedFile : loadedFiles) {
if (first) {
first = false;
} else {
@@ -1406,7 +1408,7 @@ void BusHandler::formatUpdateInfo(ostringstream& output) {
if (!loadedFiles.empty()) {
output << ",\"l\":{";
bool first = true;
for (auto& loadedFile : loadedFiles) {
for (const auto& loadedFile : loadedFiles) {
if (first) {
first = false;
} else {
@@ -1489,9 +1491,8 @@ void BusHandler::formatGrabResult(const bool unknown, ostringstream& output, con
output << "grab disabled";
} else {
bool first = true;
for (map<uint64_t, GrabbedMessage>::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end();
it++) {
if (it->second.dump(unknown, m_messages, first, output, decode)) {
for (const auto& it : m_grabbedMessages) {
if (it.second.dump(unknown, m_messages, first, output, decode)) {
first = false;
}
}
+2 -1
View File
@@ -329,7 +329,8 @@ class GrabbedMessage {
* @param decode whether to add decoding hints.
* @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:
+24 -28
View File
@@ -116,7 +116,7 @@ static struct options opt = {
ll_COUNT, // logLevel
false, // multiLog
false, // logRaw
0, // logRaw
PACKAGE_LOGFILE, // logRawFile
100, // logRawSize
@@ -216,7 +216,8 @@ static const struct argp_option argpoptions[] = {
" [notice]", 0 },
{NULL, 0, NULL, 0, "Raw logging options:", 6 },
{"lograwdata", O_RAW, NULL, 0, "Log each received/sent byte on the bus", 0 },
{"lograwdata", O_RAW, "bytes", OPTION_ARG_OPTIONAL,
"Log messages or all received/sent bytes on the bus", 0 },
{"lograwdatafile", O_RAWFIL, "FILE", 0, "Write raw log to FILE [" PACKAGE_LOGFILE "]", 0 },
{"lograwdatasize", O_RAWSIZ, "SIZE", 0, "Make raw log file no larger than SIZE kB [100]", 0 },
@@ -504,7 +505,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
// Raw logging options:
case O_RAW: // --lograwdata
opt->logRaw = true;
opt->logRaw = arg && strcmp("bytes", arg) == 0 ? 2 : 1;
break;
case O_RAWFIL: // --lograwdatafile=/var/log/ebusd.log
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
@@ -632,11 +633,10 @@ void shutdown() {
s_messageMap = NULL;
}
// free templates
for (map<string, DataFieldTemplates*>::iterator it = s_templatesByPath.begin(); it != s_templatesByPath.end(); it++) {
if (it->second != &s_globalTemplates) {
delete it->second;
for (const auto it : s_templatesByPath) {
if (it.second != &s_globalTemplates) {
delete it.second;
}
it->second = NULL;
}
s_templatesByPath.clear();
@@ -738,7 +738,7 @@ DataFieldTemplates* getTemplates(const string filename) {
if (pos != string::npos) {
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()) {
return it->second;
}
@@ -755,7 +755,7 @@ DataFieldTemplates* getTemplates(const string filename) {
* @return the @a DataFieldTemplates.
*/
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()) {
return false;
}
@@ -799,8 +799,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa
return result;
}
readTemplates(path, extension, hasTemplates, verbose);
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
string name = *it;
for (const auto& name : files) {
logInfo(lf_main, "reading file %s", name.c_str());
result = messages->readFromFile(name, errorDescription, verbose);
if (result != RESULT_OK) {
@@ -808,8 +807,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa
}
}
if (recursive) {
for (vector<string>::iterator it = dirs.begin(); it != dirs.end(); it++) {
string name = *it;
for (const auto& name : dirs) {
logInfo(lf_main, "reading dir %s", name.c_str());
result = readConfigFiles(name, extension, messages, true, verbose, errorDescription);
if (result != RESULT_OK) {
@@ -864,12 +862,11 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive)
logInfo(lf_main, "loading configuration files from %s", opt.configPath);
messages->clear();
s_globalTemplates.clear();
for (map<string, DataFieldTemplates*>::iterator it = s_templatesByPath.begin(); it != s_templatesByPath.end();
it++) {
if (it->second != &s_globalTemplates) {
delete it->second;
for (auto& it : s_templatesByPath) {
if (it.second != &s_globalTemplates) {
delete it.second;
}
it->second = NULL;
it.second = NULL;
}
s_templatesByPath.clear();
@@ -957,19 +954,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(),
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)) {
ident.erase(it--);
it = ident.erase(it);
} else {
*it = static_cast<char>(::tolower(*it));
it++;
}
}
// complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv
size_t bestMatch = 0;
string best;
map<string, string> bestDefaults;
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
string name = *it;
for (const auto& name : files) {
symbol_t checkDest;
unsigned int checkSw, checkHw;
map<string, string> defaults;
@@ -1020,14 +1018,12 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, string& rela
if (readCommon) {
result = collectConfigFiles(path, "", ".csv", files);
if (result == RESULT_OK && !files.empty()) {
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
string name = *it;
name = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *.
if (name == "_templates.") { // skip templates
for (const auto& name : files) {
string baseName = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *.
if (baseName == "_templates.") { // skip templates
continue;
}
if (name.length() < 3 || name.find_first_of('.') != 2) { // different from the scheme "ZZ."
name = *it;
if (baseName.length() < 3 || baseName.find_first_of('.') != 2) { // different from the scheme "ZZ."
string errorDescription;
result = messages->readFromFile(name, errorDescription, opt.checkConfig);
if (result == RESULT_OK) {
+1 -1
View File
@@ -74,7 +74,7 @@ struct options {
LogLevel logLevel; //!< log level [notice]
bool multiLog; //!< multiple log levels adjusted with --log=...
bool logRaw; //!< raw log each received/sent byte on the bus
unsigned int logRaw; //!< raw log each received/sent byte on the bus (1=messages, 2=bytes)
const char* logRawFile; //!< name of raw log file [/var/log/ebusd.log]
unsigned int logRawSize; //!< maximum size of raw log file in kB [100]
+23 -26
View File
@@ -50,7 +50,7 @@ result_t UserList::getFieldMap(vector<string>& row, string& errorDescription, co
return RESULT_OK;
}
map<string, string> seen;
for (auto &name : row) {
for (auto& name : row) {
tolower(name);
if (name == "name" || name == "secret") {
if (seen.find(name) != seen.end()) {
@@ -82,13 +82,13 @@ result_t UserList::addFromFile(map<string, string>& row, vector< map<string, str
name = ""; // default levels
}
string levels;
for (auto entry : subRows) {
string level = entry["level"];
if (!level.empty()) {
for (const auto& entry : subRows) {
const auto it = entry.find("level");
if (it != entry.end() && !it->second.empty()) {
if (!levels.empty()) {
levels += VALUE_SEPARATOR;
}
levels += level;
levels += it->second;
}
}
m_userSecrets[name] = secret;
@@ -119,8 +119,8 @@ MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* message
} else {
m_logRawFile = NULL;
}
m_logRawEnabled = opt.logRaw;
m_logRawBytes = false;
m_logRawEnabled = opt.logRaw != 0;
m_logRawBytes = opt.logRaw == 2;
m_logRawLastReceived = true;
m_logRawLastSymbol = SYN;
if (opt.aclFile[0]) {
@@ -158,9 +158,10 @@ MainLoop::~MainLoop() {
m_shutdown = true;
join();
for (list<DataHandler*>::iterator it = m_dataHandlers.begin(); it != m_dataHandlers.end(); it++) {
delete *it;
for (const auto dataHandler : m_dataHandlers) {
delete dataHandler;
}
m_dataHandlers.clear();
if (m_dumpFile) {
delete m_dumpFile;
m_dumpFile = NULL;
@@ -206,11 +207,11 @@ void MainLoop::run() {
list<DataSink*> dataSinks;
deque<Message*> messages;
for (list<DataHandler*>::iterator it = m_dataHandlers.begin(); it != m_dataHandlers.end(); it++) {
if ((*it)->isDataSink()) {
dataSinks.push_back(dynamic_cast<DataSink*>(*it));
for (const auto dataHandler : m_dataHandlers) {
if (dataHandler->isDataSink()) {
dataSinks.push_back(dynamic_cast<DataSink*>(dataHandler));
}
(*it)->start();
dataHandler->start();
}
while (!m_shutdown) {
// pick the next message to handle
@@ -362,8 +363,8 @@ void MainLoop::run() {
m_updateCheck = message == "" ? "unknown" : message;
logNotice(lf_main, "update check: %s", message.c_str());
if (!dataSinks.empty()) {
for (list<DataSink*>::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) {
(*it)->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck);
for (const auto dataSink : dataSinks) {
dataSink->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck);
}
}
} else {
@@ -385,10 +386,9 @@ void MainLoop::run() {
time(&now);
if (!dataSinks.empty()) {
messages = m_messages->findAll("", "", "*", false, true, true, true, true, true, sinkSince, now);
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
Message* message = *it;
for (list<DataSink*>::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) {
(*it)->notifyUpdate(message);
for (const auto message : messages) {
for (const auto dataSink : dataSinks) {
dataSink->notifyUpdate(message);
}
}
sinkSince = now;
@@ -425,8 +425,7 @@ void MainLoop::run() {
if (listening) {
string levels = getUserLevels(user);
messages = m_messages->findAll("", "", levels, false, true, true, true, true, true, since, now);
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
Message* message = *it;
for (const auto message : messages) {
ostream << message->getCircuit() << " " << message->getName() << " = " << dec;
message->decodeLastData(ostream);
ostream << endl;
@@ -458,7 +457,7 @@ void MainLoop::notifyDeviceData(const symbol_t symbol, bool received) {
}
if (symbol != SYN) {
if (received && !m_logRawLastReceived && symbol == m_logRawLastSymbol) {
return; // skip received echo of previously sent symbol
return; // skip received echo of previously sent symbol
}
if (m_logRawBuffer.tellp() == 0 || received != m_logRawLastReceived) {
m_logRawLastReceived = received;
@@ -1252,8 +1251,7 @@ string MainLoop::executeFind(vector<string> &args, string levels) {
bool found = false;
ostringstream result;
char str[32];
for (deque<Message*>::iterator it = messages.begin(); it != messages.end();) {
Message* message = *it++;
for (const auto message : messages) {
if (!id.empty() && !message->checkIdPrefix(id)) {
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);
bool first = true;
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();) {
Message* message = *it++;
for (const auto message : messages) {
symbol_t dstAddress = message->getDstAddress();
if (dstAddress == SYN) {
continue;
+3 -4
View File
@@ -205,7 +205,7 @@ bool parseTopic(const string topic, vector<string> &strs, vector<string> &fields
return false;
}
string fieldName = knownFieldNames[idx];
for (auto& it : fields) {
for (const auto& it : fields) {
if (it == fieldName) {
return false; // duplicate column
}
@@ -521,12 +521,11 @@ void MqttHandler::run() {
time(&lastTaskRun);
}
if (m_connected && !m_updatedMessages.empty()) {
for (map<Message*, int>::iterator it = m_updatedMessages.begin(); it != m_updatedMessages.end(); it++) {
Message* message = it->first;
for (const auto it : m_updatedMessages) {
updates.str("");
updates.clear();
updates << dec;
publishMessage(message, updates);
publishMessage(it.first, updates);
}
}
m_updatedMessages.clear();
+6 -6
View File
@@ -291,15 +291,15 @@ void Network::run() {
}
void Network::cleanConnections() {
list<Connection*>::iterator c_it = m_connections.begin();
while (c_it != m_connections.end()) {
if (!(*c_it)->isRunning()) {
Connection* connection = *c_it;
c_it = m_connections.erase(c_it);
auto it = m_connections.begin();
while (it != m_connections.end()) {
if (!(*it)->isRunning()) {
Connection* connection = *it;
it = m_connections.erase(it);
delete connection;
logDebug(lf_network, "dead connection removed - %d", m_connections.size());
} else {
c_it++;
it++;
}
}
}
+28 -28
View File
@@ -81,7 +81,7 @@ const string AttributedItem::formatInt(size_t value) {
}
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()) {
return "";
}
@@ -127,8 +127,8 @@ void AttributedItem::appendJson(ostream& output, const string name, const string
}
void AttributedItem::mergeAttributes(map<string, string>& attributes) const {
for (auto& entry : m_attributes) {
auto it = attributes.find(entry.first);
for (const auto& entry : m_attributes) {
const auto it = attributes.find(entry.first);
if (it == attributes.end() || it->second.empty()) {
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 {
auto it = m_attributes.find(name);
const auto it = m_attributes.find(name);
return it == m_attributes.end() ? "" : it->second;
}
bool AttributedItem::appendAttribute(ostringstream& output, OutputFormat outputFormat, const string name,
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;
if (onlyIfNonEmpty && value.empty()) {
return false;
@@ -168,7 +168,7 @@ bool AttributedItem::appendAttributes(ostringstream& output, OutputFormat output
ret = appendAttribute(output, outputFormat, "comment", true, "[", "]") || ret;
}
if (outputFormat & OF_ALL_ATTRS) {
for (auto& entry : m_attributes) {
for (const auto entry : m_attributes) {
ret = true;
if (!entry.second.empty() && entry.first != "unit" && entry.first != "comment") {
if (outputFormat & OF_JSON) {
@@ -198,7 +198,7 @@ result_t DataField::create(vector< map<string, string> >& rows, string& errorDes
return RESULT_ERR_EOF;
}
size_t fieldIndex = -1;
for (auto row : rows) {
for (auto& row : rows) {
if (result != RESULT_OK) {
break;
}
@@ -681,7 +681,7 @@ void ValueListDataField::dump(ostream& output) const {
output << FIELD_SEPARATOR;
if (!m_dataType->dump(output, m_length)) { // no divisor appended
bool first = true;
for (auto it : m_values) {
for (const auto it : m_values) {
if (first) {
first = false;
} else {
@@ -703,7 +703,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input,
if (result != RESULT_OK) {
return result;
}
auto it = m_values.find(value);
const auto it = m_values.find(value);
if (it == m_values.end() && value != m_dataType->getReplacement()) {
// fall back to raw value in input
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();
for (auto it : m_values) {
for (const auto it : m_values) {
if (it.second.compare(str) == 0) {
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
}
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()) {
attributes[entry.first] = entry.second;
}
@@ -881,15 +881,15 @@ DataFieldSet* DataFieldSet::getIdentFields() {
}
DataFieldSet::~DataFieldSet() {
for (auto it : m_fields) {
delete it;
for (const auto field : m_fields) {
delete field;
}
}
const DataFieldSet* DataFieldSet::clone() const {
vector<const SingleDataField*> fields;
for (auto it : m_fields) {
fields.push_back(it->clone());
for (const auto field : m_fields) {
fields.push_back(field->clone());
}
return new DataFieldSet(m_name, fields);
}
@@ -898,7 +898,7 @@ size_t DataFieldSet::getLength(PartType partType, size_t maxLength) const {
size_t length = 0;
bool previousFullByteOffset[] = { true, true, true, true };
for (auto field : m_fields) {
for (const auto field : m_fields) {
if (field->getPartType() == partType) {
if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) {
length--;
@@ -938,8 +938,8 @@ result_t DataFieldSet::derive(const string name, map<string, string> attributes,
if (!values.empty()) {
return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive
}
for (auto it : m_fields) {
result_t result = it->derive("", attributes, partType, divisor, values, fields);
for (const auto field : m_fields) {
result_t result = field->derive("", attributes, partType, divisor, values, fields);
if (result != RESULT_OK) {
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 {
for (auto field : m_fields) {
for (const auto field : m_fields) {
if (field->hasField(fieldName, numeric) == 0) {
return true;
}
@@ -961,13 +961,13 @@ bool DataFieldSet::hasField(const char* fieldName, bool numeric) const {
void DataFieldSet::dump(ostream& output) const {
bool first = true;
for (auto it : m_fields) {
for (const auto field : m_fields) {
if (first) {
first = false;
} else {
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 {
bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0;
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
for (auto field : m_fields) {
for (const auto field : m_fields) {
if (field->getPartType() != partType) {
continue;
}
@@ -1017,7 +1017,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset,
outputIndex = 0;
}
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
for (auto field : m_fields) {
for (const auto field : m_fields) {
if (field->getPartType() != partType) {
if (outputIndex >= 0 && !field->isIgnored()) {
outputIndex++;
@@ -1064,7 +1064,7 @@ result_t DataFieldSet::write(istringstream& input, SymbolString& data,
PartType partType = data.isMaster() ? pt_masterData : pt_slaveData;
bool previousFullByteOffset = true;
size_t baseOffset = offset;
for (auto field : m_fields) {
for (const auto field : m_fields) {
if (field->getPartType() != partType) {
continue;
}
@@ -1100,7 +1100,7 @@ result_t DataFieldSet::write(istringstream& input, SymbolString& data,
DataFieldTemplates::DataFieldTemplates(DataFieldTemplates& other)
: MappedFileReader::MappedFileReader(false) {
for (auto it : other.m_fieldsByName) {
for (const auto it : other.m_fieldsByName) {
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) {
name = field->getName();
}
auto it = m_fieldsByName.find(name);
const auto it = m_fieldsByName.find(name);
if (it != m_fieldsByName.end()) {
if (!replace) {
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]]]]
if (row.empty()) {
// default map does not include separate field name
for (auto col : defaultTemplateFieldMap) {
for (const auto& col : defaultTemplateFieldMap) {
row.push_back(col);
}
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 {
auto ref = m_fieldsByName.find(name);
const auto ref = m_fieldsByName.find(name);
if (ref == m_fieldsByName.end()) {
return NULL;
}
-1
View File
@@ -267,7 +267,6 @@ result_t MappedFileReader::addFromFile(vector<string>& row, string& errorDescrip
}
map<string, string> rowMapped;
vector< map<string, string> > subRowsMapped;
vector<string>::iterator it = row.begin();
bool isDefault = m_supportsDefaults && !row[0].empty() && row[0][0] == '*';
if (isDefault) {
row[0] = row[0].substr(1);
+66 -67
View File
@@ -163,7 +163,7 @@ string getDefault(const string value, const map<string, string>& defaults, const
if (value.length() == 0 && replaceStar && required) {
return value;
}
auto it = defaults.find(fieldName);
const auto it = defaults.find(fieldName);
const string defaultStr = it == defaults.end() ? "" : it->second;
if (!replaceStar || defaultStr.empty()) {
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);
int exp = 5;
for (vector<symbol_t>::const_iterator it = id.begin(); it < id.end(); it++) {
key ^= (uint64_t)*it << (8 * exp--);
for (const auto it : id) {
key ^= (uint64_t)it << (8 * exp--);
if (exp == 0) {
exp = 3;
}
@@ -195,7 +195,7 @@ uint64_t Message::createKey(const vector<symbol_t> id,
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) {
return INVALID_KEY;
}
@@ -473,8 +473,7 @@ result_t Message::create(map<string, string> row, vector< map<string, string> >
unsigned int index = 0;
bool multiple = dstAddresses.size() > 1;
char num[10];
for (vector<symbol_t>::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) {
symbol_t dstAddress = *it;
for (const auto dstAddress : dstAddresses) {
string useCircuit = circuit;
if (multiple) {
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);
}
messages.push_back(message);
index++;
}
return RESULT_OK;
}
@@ -829,7 +829,7 @@ bool Message::isLessPollWeight(const Message* other) const {
void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
bool first = true;
if (fieldNames == NULL) {
for (auto fieldName : defaultMessageFieldMap) {
for (const auto& fieldName : defaultMessageFieldMap) {
if (first) {
first = false;
} else {
@@ -839,7 +839,7 @@ void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
}
return;
}
for (auto fieldName : *fieldNames) {
for (const auto& fieldName : *fieldNames) {
if (first) {
first = false;
} else {
@@ -852,7 +852,7 @@ void Message::dumpHeader(ostream& output, vector<string>* fieldNames) {
void Message::dump(ostream& output, vector<string>* fieldNames, bool withConditions) const {
bool first = true;
if (fieldNames == NULL) {
for (auto fieldName : knownFieldNamesFull) {
for (const auto& fieldName : knownFieldNamesFull) {
if (fieldName == FIELNAME_LEVEL) {
continue; // access level not included in default dump format
}
@@ -865,7 +865,7 @@ void Message::dump(ostream& output, vector<string>* fieldNames, bool withConditi
}
return;
}
for (auto fieldName : *fieldNames) {
for (const auto& fieldName : *fieldNames) {
if (first) {
first = false;
} else {
@@ -920,13 +920,13 @@ void Message::dumpField(ostream& output, string fieldName, bool withConditions)
return;
}
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);
}
return;
}
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);
}
return;
@@ -1218,7 +1218,7 @@ void ChainedMessage::dumpField(ostream& output, string fieldName, bool withCondi
bool first = true;
for (size_t index = 0; index < m_ids.size(); 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) {
first = false;
} else {
@@ -1570,14 +1570,14 @@ bool SimpleStringCondition::checkValue(Message* message, string field) {
void CombinedCondition::dump(ostream& output, bool matched) const {
for (auto condition : m_conditions) {
for (const auto condition : m_conditions) {
condition->dump(output, matched);
}
}
result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMessage,
void (*readMessageFunc)(Message* message)) {
for (auto condition : m_conditions) {
for (const auto condition : m_conditions) {
ostringstream dummy;
result_t ret = condition->resolve(messages, dummy, readMessageFunc);
if (ret != RESULT_OK) {
@@ -1589,8 +1589,8 @@ result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMe
}
bool CombinedCondition::isTrue() {
for (vector<Condition*>::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) {
if (!(*it)->isTrue()) {
for (const auto condition : m_conditions) {
if (!condition->isTrue()) {
return false;
}
}
@@ -1616,7 +1616,7 @@ result_t Instruction::create(const string& contextPath, const string type,
}
string arg = row["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()) {
arg = entry.second;
break;
@@ -1703,7 +1703,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
uint64_t key = message->getKey();
bool conditional = message->isConditional();
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()) {
Message* other = getFirstAvailable(keyIt->second, message);
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 nameKey = circuit + suffix;
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()) {
vector<Message*>* messages = &nameIt->second;
if (!message->isConditional() || !messages->front()->isConditional()) {
@@ -1739,7 +1739,7 @@ result_t MessageMap::add(Message* message, bool storeByName) {
}
m_messagesByName[nameKey].push_back(message);
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()) {
// always store first message without circuit (in order of circuit name)
m_messagesByName[nameKey].push_back(message);
@@ -1779,7 +1779,7 @@ result_t MessageMap::getFieldMap(vector<string>& row, string& errorDescription,
// unit,comment
// minimum: type,name,PBSB,field,datatype
if (row.empty()) {
for (auto col : defaultMessageFieldMap) {
for (const auto& col : defaultMessageFieldMap) {
row.push_back(col);
}
return RESULT_OK;
@@ -1881,7 +1881,7 @@ result_t MessageMap::addDefaultFromFile(map<string, string>& row, vector< map<st
// check for condition in defaults
string type = row["type"];
row.erase("type");
auto mainDefaults = getDefaults().find("");
const auto& mainDefaults = getDefaults().find("");
map<string, string> defaults;
if (mainDefaults != getDefaults().end()) {
defaults = mainDefaults->second;
@@ -1894,7 +1894,7 @@ result_t MessageMap::addDefaultFromFile(map<string, string>& row, vector< map<st
return RESULT_ERR_INVALID_ARG;
}
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()) {
errorDescription = "condition "+type+" already defined";
return RESULT_ERR_DUPLICATE_NAME;
@@ -1918,7 +1918,7 @@ result_t MessageMap::addDefaultFromFile(map<string, string>& row, vector< map<st
}
string defaultSuffix = defaults["suffix"];
defaults.erase("suffix");
for (auto entry : row) {
for (const auto entry : row) {
string value = entry.second;
if (entry.first == "circuit" && !defaultCircuit.empty()) { // TODO remove some day
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) {
// check if combined or simple condition is already known
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()) {
condition = it->second;
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) {
// simple condition
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;
if (it == m_conditions.end()) {
// 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";
return result;
}
map<string, vector<Instruction*> >::iterator it = m_instructions.find(filename);
const auto it = m_instructions.find(filename);
if (it == m_instructions.end()) {
vector<Instruction*> instructions;
instructions.push_back(instruction);
@@ -2162,8 +2162,7 @@ result_t MessageMap::addFromFile(map<string, string>& row, vector< map<string, s
row["type"] = type;
result = Message::create(row, subRows, getDefaults(), getSubDefaults(), errorDescription, condition, filename,
templates, messages);
for (vector<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
Message* message = *it;
for (const auto message : messages) {
if (result == RESULT_OK) {
result = add(message);
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 overallResult = RESULT_OK;
for (map<string, Condition*>::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) {
Condition* condition = it->second;
for (const auto it : m_conditions) {
Condition* condition = it.second;
result_t result = resolveCondition(condition, errorDescription);
if (result != RESULT_OK) {
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 overallResult = RESULT_OK;
vector<string> remove;
for (auto& it : m_instructions) {
for (auto it : m_instructions) {
auto& instructions = it.second;
bool removeSingletons = false;
vector<Instruction*> remain;
for (auto instruction : instructions) {
for (const auto instruction : instructions) {
if (removeSingletons && instruction->isSingleton()) {
delete instruction;
continue;
@@ -2276,8 +2275,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
if (removeSingletons && !remain.empty()) {
instructions = remain;
remain.clear();
for (vector<Instruction*>::iterator lit = instructions.begin(); lit != instructions.end(); lit++) {
Instruction* instruction = *lit;
for (const auto instruction : instructions) {
if (!instruction->isSingleton()) {
remain.push_back(instruction);
continue;
@@ -2291,7 +2289,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF
it.second = remain;
}
}
for (auto it : remove) {
for (const auto it : remove) {
m_instructions.erase(it);
}
return overallResult;
@@ -2309,23 +2307,24 @@ void MessageMap::addLoadedFile(const symbol_t address, const string filename, st
}
const vector<string>& MessageMap::getLoadedFiles(const symbol_t address) const {
auto files = m_loadedFiles.find(address);
if (files != m_loadedFiles.end()) {
return files->second;
const auto it = m_loadedFiles.find(address);
if (it != m_loadedFiles.end()) {
return it->second;
}
return s_noFiles;
}
vector<string> MessageMap::getLoadedFiles() const {
vector<string> ret;
for (auto& loadedFile : m_loadedFileInfos) {
for (const auto& loadedFile : m_loadedFileInfos) {
ret.push_back(loadedFile.first);
}
return ret;
}
bool MessageMap::getLoadedFileInfo(string filename, string& comment, size_t* hash, size_t* size, time_t* time) const {
auto it = m_loadedFileInfos.find(filename);
bool MessageMap::getLoadedFileInfo(const string filename, string& comment, size_t* hash, size_t* size, time_t* time)
const {
const auto it = m_loadedFileInfos.find(filename);
if (it == m_loadedFileInfos.end()) {
comment = "";
hash = size = 0;
@@ -2346,7 +2345,7 @@ bool MessageMap::getLoadedFileInfo(string filename, string& comment, size_t* has
}
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()) {
return &it->second;
}
@@ -2369,7 +2368,7 @@ Message* MessageMap::find(const string& circuit, const string& name, const strin
} else {
continue; // not allowed without circuit
}
auto it = m_messagesByName.find(nameKey);
const auto it = m_messagesByName.find(nameKey);
if (it != m_messagesByName.end()) {
Message* message = getFirstAvailable(it->second);
if (message && message->hasLevel(levels)) {
@@ -2392,11 +2391,11 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
bool checkCircuit = lcircuit.length() > 0;
bool checkLevel = levels != "*";
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
continue;
}
for (auto message : it.second) {
for (const auto message : it.second) {
if (checkLevel && !message->hasLevel(levels, includeEmptyLevel)) {
continue;
}
@@ -2446,7 +2445,7 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
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 {
if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) {
return m_scanMessage;
@@ -2527,8 +2526,7 @@ void MessageMap::invalidateCache(Message* message) {
string circuit = message->getCircuit();
string name = message->getName();
deque<Message*> messages = findAll(circuit, name, "*", true, true, true, true);
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
Message* checkMessage = *it;
for (auto checkMessage : messages) {
if (checkMessage != message) {
checkMessage->m_lastUpdateTime = 0;
}
@@ -2543,7 +2541,7 @@ void MessageMap::addPollMessage(Message* message, bool toFront) {
}
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()) {
return false;
}
@@ -2570,13 +2568,16 @@ void MessageMap::clear() {
continue;
}
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()) {
vector<Message*>* keyMessages = &keyIt->second;
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) {
keyMessages->erase(kit--);
kit = keyMessages->erase(kit);
} else {
kit++;
}
}
}
@@ -2586,23 +2587,21 @@ void MessageMap::clear() {
it.second.clear();
}
// free remaining message instances by key
for (map<uint64_t, vector<Message*> >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) {
vector<Message*> keyMessages = it->second;
for (vector<Message*>::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) {
Message* message = *kit;
for (const auto it : m_messagesByKey) {
vector<Message*> keyMessages = it.second;
for (auto message : keyMessages) {
delete message;
}
keyMessages.clear();
}
// free condition instances
for (map<string, Condition*>::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) {
delete it->second;
for (const auto it : m_conditions) {
delete it.second;
}
// free instruction instances
for (map<string, vector<Instruction*> >::iterator it = m_instructions.begin(); it != m_instructions.end(); it++) {
vector<Instruction*> instructions = it->second;
for (vector<Instruction*>::iterator lit = instructions.begin(); lit != instructions.end(); lit++) {
Instruction* instruction = *lit;
for (const auto it : m_instructions) {
vector<Instruction*> instructions = it.second;
for (const auto instruction : instructions) {
delete instruction;
}
instructions.clear();
@@ -2616,7 +2615,7 @@ void MessageMap::clear() {
m_messagesByKey.clear();
m_conditions.clear();
m_instructions.clear();
for (auto& it : m_circuitData) {
for (const auto it : m_circuitData) {
delete it.second;
}
m_circuitData.clear();
@@ -2640,12 +2639,12 @@ void MessageMap::dump(ostream& output, bool withConditions) const {
bool first = true;
Message::dumpHeader(output, NULL);
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 "-")
continue;
}
if (m_addAll) {
for (auto message : it.second) {
for (const auto message : it.second) {
if (!message) {
continue;
}
+3 -4
View File
@@ -145,8 +145,7 @@ class Message : public AttributedItem {
* @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.
*/
static uint64_t createKey(MasterSymbolString& master,
size_t maxIdLength, bool anyDestination = false);
static uint64_t createKey(const MasterSymbolString& master, size_t maxIdLength, bool anyDestination = false);
/**
* 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.
* @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;
/**
@@ -1417,7 +1416,7 @@ class MessageMap : public MappedFileReader {
* @return the @a Message instance, or NULL.
* 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;
/**
+12
View File
@@ -170,6 +170,18 @@ class SymbolString {
return m_data[index];
}
/**
* Return a reference to the symbol at the specified index.
* @param index the index of the symbol to return.
* @return the reference to the symbol at the specified index, or SYN if not available.
*/
symbol_t operator[](const size_t index) const {
if (index >= m_data.size()) {
return SYN;
}
return m_data[index];
}
/**
* Return whether this instance is equal to the other instance.
* @param other the other instance.
+3 -1
View File
@@ -209,7 +209,7 @@ echo "ebusd: $pid"
kill -1 $pid
#client:
readarray lines <<EOF
raw
raw bytes
reload
log
log bus,update debug
@@ -219,6 +219,8 @@ grab
info
state
read -c "hallo du" ich
raw
raw
h
h r
h w