diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index e1af234f..4e84fa2e 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -98,7 +98,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave) bool append = m_scanResults != NULL && m_scanResults->find(dstAddress) != m_scanResults->end(); ostringstream scanResult; if (result == RESULT_OK) { - if (append == false) + if (!append) scanResult << hex << setw(2) << setfill('0') << static_cast(dstAddress) << UI_FIELD_SEPARATOR; result = m_message->decode(pt_slaveData, slave, scanResult, append); // decode data } @@ -110,14 +110,14 @@ bool ScanRequest::notify(result_t result, SymbolString& slave) string str = scanResult.str(); logNotice(lf_bus, "scan: %s", str.c_str()); if (m_scanResults != NULL) { - if (append == true) + if (append) (*m_scanResults)[dstAddress] += str; else (*m_scanResults)[dstAddress] = str; } // check for remaining secondary messages - if (m_messages.empty() == true) + if (m_messages.empty()) return false; m_message = m_messages.front(); @@ -151,12 +151,12 @@ result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave) for (int sendRetries=m_failedSendRetries+1; sendRetries>=0; sendRetries--) { m_nextRequests.add(&request); bool success = m_finishedRequests.waitRemove(&request); - result = success == true ? request.m_result : RESULT_ERR_TIMEOUT; + result = success ? request.m_result : RESULT_ERR_TIMEOUT; if (result == RESULT_OK) break; - if (success == false || result == RESULT_ERR_NO_SIGNAL) { + if (!success || result == RESULT_ERR_NO_SIGNAL) { logError(lf_bus, "%s, give up", getResultCode(result)); break; } @@ -174,7 +174,7 @@ void BusHandler::run() time_t lastTime; time(&lastTime); do { - if (m_device->isValid() == true) { + if (m_device->isValid()) { result_t result = handleSymbol(); if (result != RESULT_ERR_TIMEOUT) symCount++; @@ -191,7 +191,7 @@ void BusHandler::run() symCount = 0; } } else { - if (Wait(10) == false) + if (!Wait(10)) break; result_t result = m_device->open(); @@ -201,7 +201,7 @@ void BusHandler::run() logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result)); symCount = 0; } - } while (isRunning() == true); + } while (isRunning()); } result_t BusHandler::handleSymbol() @@ -306,7 +306,7 @@ result_t BusHandler::handleSymbol() // send symbol if necessary result_t result; - if (sending == true) { + if (sending) { result = m_device->send(sendSymbol); if (result == RESULT_OK) if (m_state == bs_ready) @@ -336,9 +336,9 @@ result_t BusHandler::handleSymbol() m_lastReceive = now; if (recvSymbol == SYN) { - if (sending == false && m_remainLockCount > 0 && m_command.size() != 1) + if (!sending && m_remainLockCount > 0 && m_command.size() != 1) m_remainLockCount--; - else if (sending == false && m_remainLockCount == 0 && m_command.size() == 1) + else if (!sending && m_remainLockCount == 0 && m_command.size() == 1) m_remainLockCount = 1; // wait for next AUTO-SYN after SYN / address / SYN (bus locked for own priority) return setState(bs_ready, RESULT_ERR_SYN); @@ -355,8 +355,8 @@ result_t BusHandler::handleSymbol() return RESULT_OK; case bs_ready: - if (startRequest != NULL && sending == true) { - if (m_nextRequests.remove(startRequest) == false) { + if (startRequest != NULL && sending) { + if (!m_nextRequests.remove(startRequest)) { // request already removed (e.g. due to timeout) return setState(bs_skip, RESULT_ERR_TIMEOUT); } @@ -397,7 +397,7 @@ result_t BusHandler::handleSymbol() receiveCompleted(); return setState(bs_skip, RESULT_OK); } - if (m_answer == true + if (m_answer && (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress)) return setState(bs_sendCmdAck, RESULT_OK); @@ -406,11 +406,11 @@ result_t BusHandler::handleSymbol() if (dstAddress == BROADCAST) return setState(bs_skip, RESULT_ERR_CRC); - if (m_answer == true + if (m_answer && (dstAddress == m_ownMasterAddress || dstAddress == m_ownSlaveAddress)) { return setState(bs_sendCmdAck, RESULT_ERR_CRC); } - if (m_repeat == true) + if (m_repeat) return setState(bs_skip, RESULT_ERR_CRC); return setState(bs_recvCmdAck, RESULT_ERR_CRC); } @@ -418,15 +418,15 @@ result_t BusHandler::handleSymbol() case bs_recvCmdAck: if (recvSymbol == ACK) { - if (m_commandCrcValid == false) + if (!m_commandCrcValid) return setState(bs_skip, RESULT_ERR_ACK); if (m_currentRequest != NULL) { - if (isMaster(m_currentRequest->m_master[1]) == true) { + if (isMaster(m_currentRequest->m_master[1])) { return setState(bs_sendSyn, RESULT_OK); } } - else if (isMaster(m_command[1]) == true) { // header symbols are never escaped + else if (isMaster(m_command[1])) { // header symbols are never escaped receiveCompleted(); return setState(bs_skip, RESULT_OK); } @@ -435,7 +435,7 @@ result_t BusHandler::handleSymbol() return setState(bs_recvRes, RESULT_OK); } if (recvSymbol == NAK) { - if (m_repeat == false) { + if (!m_repeat) { m_repeat = true; m_nextSendPos = 0; m_command.clear(); @@ -465,7 +465,7 @@ result_t BusHandler::handleSymbol() return setState(bs_recvResAck, RESULT_OK); } - if (m_repeat == true) { + if (m_repeat) { if (m_currentRequest != NULL) return setState(bs_sendSyn, RESULT_ERR_CRC); @@ -480,14 +480,14 @@ result_t BusHandler::handleSymbol() case bs_recvResAck: if (recvSymbol == ACK) { - if (m_responseCrcValid == false) + if (!m_responseCrcValid) return setState(bs_skip, RESULT_ERR_ACK); receiveCompleted(); return setState(bs_skip, RESULT_OK); } if (recvSymbol == NAK) { - if (m_repeat == false) { + if (!m_repeat) { m_repeat = true; m_response.clear(); return setState(bs_recvRes, RESULT_ERR_NAK, true); @@ -497,7 +497,7 @@ result_t BusHandler::handleSymbol() return setState(bs_skip, RESULT_ERR_ACK); case bs_sendCmd: - if (m_currentRequest != NULL && sending == true) { + if (m_currentRequest != NULL && sending) { if (recvSymbol == sendSymbol) { // successfully sent m_nextSendPos++; @@ -515,11 +515,11 @@ result_t BusHandler::handleSymbol() return setState(bs_skip, RESULT_ERR_INVALID_ARG); case bs_sendResAck: - if (m_currentRequest != NULL && sending == true) { + if (m_currentRequest != NULL && sending) { if (recvSymbol == sendSymbol) { // successfully sent - if (m_responseCrcValid == false) { - if (m_repeat == false) { + if (!m_responseCrcValid) { + if (!m_repeat) { m_repeat = true; m_response.clear(); return setState(bs_recvRes, RESULT_ERR_NAK, true); @@ -532,25 +532,25 @@ result_t BusHandler::handleSymbol() return setState(bs_skip, RESULT_ERR_INVALID_ARG); case bs_sendCmdAck: - if (sending == true && m_answer == true) { + if (sending && m_answer) { if (recvSymbol == sendSymbol) { // successfully sent - if (m_commandCrcValid == false) { - if (m_repeat == false) { + if (!m_commandCrcValid) { + if (!m_repeat) { m_repeat = true; m_command.clear(); return setState(bs_recvCmd, RESULT_ERR_NAK, true); } return setState(bs_skip, RESULT_ERR_ACK); } - if (isMaster(m_command[1]) == true) + if (isMaster(m_command[1])) receiveCompleted(); // decode command and store value return setState(bs_skip, RESULT_OK); m_nextSendPos = 0; m_repeat = false; Message* message = m_messages->find(m_command); - if (message == NULL || message->isPassive() == false || message->isWrite() == true) + if (message == NULL || !message->isPassive() || message->isWrite()) return setState(bs_skip, RESULT_ERR_INVALID_ARG); // don't know this request or definition has wrong direction, deny // build response and store in m_response for sending back to requesting master @@ -564,7 +564,7 @@ result_t BusHandler::handleSymbol() return setState(bs_skip, RESULT_ERR_INVALID_ARG); case bs_sendRes: - if (sending == true && m_answer == true) { + if (sending && m_answer) { if (recvSymbol == sendSymbol) { // successfully sent m_nextSendPos++; @@ -578,7 +578,7 @@ result_t BusHandler::handleSymbol() return setState(bs_skip, RESULT_ERR_INVALID_ARG); case bs_sendSyn: - if (sending == true) { + if (sending) { if (recvSymbol == sendSymbol) { // successfully sent return setState(bs_skip, RESULT_OK); @@ -600,17 +600,17 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit m_nextRequests.add(m_currentRequest); // repeat m_currentRequest = NULL; } - else if (state == bs_sendSyn || (result != RESULT_OK && firstRepetition == false)) { + else if (state == bs_sendSyn || (result != RESULT_OK && !firstRepetition)) { logDebug(lf_bus, "notify request: %s", getResultCode(result)); unsigned char dstAddress = m_currentRequest->m_master[1]; - if (result == RESULT_OK && isValidAddress(dstAddress, false) == true) + if (result == RESULT_OK && isValidAddress(dstAddress, false)) m_seenAddresses[dstAddress] = true; bool restart = m_currentRequest->notify(result, m_response); - if (restart == true) { + if (restart) { m_currentRequest->m_busLostRetries = 0; m_nextRequests.add(m_currentRequest); } - else if (m_currentRequest->m_deleteOnFinish == true) + else if (m_currentRequest->m_deleteOnFinish) delete m_currentRequest; else m_finishedRequests.add(m_currentRequest); @@ -623,11 +623,11 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit m_response.clear(false); // notify with empty response while ((m_currentRequest = m_nextRequests.remove(false)) != NULL) { bool restart = m_currentRequest->notify(RESULT_ERR_NO_SIGNAL, m_response); - if (restart == true) { // should not occur with no signal + if (restart) { // should not occur with no signal m_currentRequest->m_busLostRetries = 0; m_nextRequests.add(m_currentRequest); } - else if (m_currentRequest->m_deleteOnFinish == true) + else if (m_currentRequest->m_deleteOnFinish) delete m_currentRequest; else m_finishedRequests.add(m_currentRequest); @@ -667,7 +667,7 @@ void BusHandler::receiveCompleted() m_seenAddresses[srcAddress] = true; if (dstAddress == BROADCAST) logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str()); - else if (master == true) { + else if (master) { logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str()); m_seenAddresses[dstAddress] = true; } @@ -680,7 +680,7 @@ void BusHandler::receiveCompleted() if (message == NULL) { if (dstAddress == BROADCAST) logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str()); - else if (master == true) + else if (master) logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str()); else logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str()); @@ -694,7 +694,7 @@ void BusHandler::receiveCompleted() logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result)); else { string data = output.str(); - if (m_answer == true && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) { + if (m_answer && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) { logNotice(lf_update, "self-update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str()); // TODO store in database of internal variables } else if (message->getDstAddress() == SYN) { // any destination @@ -733,11 +733,11 @@ result_t BusHandler::startScan(bool full) m_scanResults.clear(); for (unsigned int slave=0; slave<=255; slave++) { - if (isValidAddress(slave, false) == false || isMaster(slave) == true) + if (!isValidAddress(slave, false) || isMaster(slave)) continue; - if (full == false && m_seenAddresses[slave] == false) { + if (!full && !m_seenAddresses[slave]) { unsigned int master = slave+(256-5); // check if we saw the corresponding master already - if (isMaster(master) == false || m_seenAddresses[slave] == false) + if (!isMaster(master) || !m_seenAddresses[slave]) continue; } diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 4e5d8feb..1410721d 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -501,7 +501,7 @@ result_t loadConfigFiles(DataFieldTemplates* templates, MessageMap* messages, bo */ static void logRawData(const unsigned char byte, bool received) { - if (received == true) + if (received) logNotice(lf_bus, "<%02x", byte); else logNotice(lf_bus, ">%02x", byte); @@ -522,7 +522,7 @@ int main(int argc, char* argv[]) DataFieldTemplates templates; MessageMap messages; - if (opt.checkConfig == true) { + if (opt.checkConfig) { logNotice(lf_main, "Performing configuration check..."); loadConfigFiles(&templates, &messages, true); @@ -534,13 +534,13 @@ int main(int argc, char* argv[]) } // open the device - Device *device = Device::create(opt.device, opt.noDeviceCheck==false, &logRawData); + Device *device = Device::create(opt.device, !opt.noDeviceCheck, &logRawData); if (device == NULL) { logError(lf_main, "unable to create device %s", opt.device); return EINVAL; } - if (opt.foreground == false) { + if (!opt.foreground) { setLogFile(opt.logFile); daemonize(); // make me daemon } diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 15b798b2..86104af9 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -39,7 +39,7 @@ MainLoop::MainLoop(const struct options opt, Device *device, DataFieldTemplates* result_t result = m_device->open(); if (result != RESULT_OK) logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result)); - else if (m_device->isValid() == false) + else if (!m_device->isValid()) logError(lf_bus, "device %s not available", m_device->getName()); // create BusHandler @@ -78,7 +78,7 @@ void MainLoop::run() { bool running = true; - while (running == true) { + while (running) { string result; // pick the next message to handle @@ -88,7 +88,7 @@ void MainLoop::run() time_t since, until; time(&until); bool listening = message->isListening(since); - if (listening == false) + if (!listening) since = until; bool connected = true; @@ -102,12 +102,12 @@ void MainLoop::run() logNotice(lf_main, "<<< %s", result.c_str()); result += "\n\n"; } - if (listening == true) { + if (listening) { result += getUpdates(since, until); } // send result to client - message->setResult(result, listening, until, connected == false); + message->setResult(result, listening, until, !connected); } } @@ -122,7 +122,7 @@ string MainLoop::decodeMessage(const string& data, bool& connected, bool& listen bool escaped = false; while (getline(stream, token, ' ') != 0) { - if (escaped == true) { + if (escaped) { args.pop_back(); if (token.length() > 0 && token[token.length()-1] == '"') { token = token.substr(0, token.length() - 1); @@ -245,7 +245,7 @@ string MainLoop::executeRead(vector &args) time(&now); Message* updateMessage = NULL; - if (maxAge > 0 && verbose == false) { + if (maxAge > 0 && !verbose) { updateMessage = m_messages->find(clazz, args[argPos], false, true); if (updateMessage != NULL && updateMessage->getLastUpdateTime() + maxAge > now) @@ -322,7 +322,7 @@ string MainLoop::executeWrite(vector &args) ret = master.push_back(m_address, false); if (ret == RESULT_OK) ret = master.parseHex(msg.str()); - if (ret == RESULT_OK && isValidAddress(master[1]) == false) + if (ret == RESULT_OK && !isValidAddress(master[1])) ret = RESULT_ERR_INVALID_ADDR; if (ret != RESULT_OK) return getResultCode(ret); @@ -382,7 +382,7 @@ string MainLoop::executeWrite(vector &args) return getResultCode(RESULT_OK); ret = message->decode(pt_slaveData, slave, result); // decode data - if (ret == RESULT_OK && result.str().empty() == true) + if (ret == RESULT_OK && result.str().empty()) return getResultCode(RESULT_OK); } if (ret != RESULT_OK) { @@ -401,21 +401,21 @@ string MainLoop::executeFind(vector &args) if (args[argPos] == "-v") verbose = true; else if (args[argPos] == "-r") { - if (first == true) { + if (first) { first = false; withWrite = withPassive = false; } withRead = true; } else if (args[argPos] == "-w") { - if (first == true) { + if (first) { first = false; withRead = withPassive = false; } withWrite = true; } else if (args[argPos] == "-p") { - if (first == true) { + if (first) { first = false; withRead = withWrite = false; } @@ -464,16 +464,16 @@ string MainLoop::executeFind(vector &args) if (dstAddress == SYN) continue; time_t lastup = message->getLastUpdateTime(); - if (onlyWithData == true && lastup == 0) + if (onlyWithData && lastup == 0) continue; - if (found == true) + if (found) result << endl; result << message->getClass() << " " << message->getName() << " = "; if (lastup == 0) result << "no data stored"; else result << message->getLastValue(); - if (verbose == true) { + if (verbose) { if (lastup == 0) sprintf(str, "%02x", dstAddress); else { @@ -495,7 +495,7 @@ string MainLoop::executeFind(vector &args) } found = true; } - if (found == false) + if (!found) return getResultCode(RESULT_ERR_NOTFOUND); return result.str(); @@ -504,7 +504,7 @@ string MainLoop::executeFind(vector &args) string MainLoop::executeListen(vector &args, bool& listening) { if (args.size() == 1) { - if (listening == true) + if (listening) return "listen continued"; listening = true; @@ -525,7 +525,7 @@ string MainLoop::executeState(vector &args) return "usage: 'state'\n" " Report bus state."; - if (m_busHandler->hasSignal() == true) { + if (m_busHandler->hasSignal()) { ostringstream result; result << "signal acquired, " << static_cast(m_busHandler->getSymbolRate()) << " symbols/sec, max. " @@ -579,7 +579,7 @@ string MainLoop::executeLog(vector &args) " AREA the log area to include (main|network|bus|update|all)\n" " LEVEL the log level to set (error|notice|info|debug)"; - if (result == true) + if (result) return getResultCode(RESULT_OK); return getResultCode(RESULT_ERR_INVALID_ARG); diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index 6f6fa192..3fc930fc 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -74,7 +74,7 @@ void Connection::run() time_t listenSince = 0; bool closed = false; - while (closed == false) { + while (!closed) { #ifdef HAVE_PPOLL // wait for new fd event ret = ppoll(fds, nfds, &tdiff, NULL); @@ -109,12 +109,12 @@ void Connection::run() #endif } - if (newData == true || m_listening == true) { + if (newData || m_listening) { char data[256]; size_t datalen = 0; - if (newData == true) { - if (m_socket->isValid() == false) + if (newData) { + if (!m_socket->isValid()) break; datalen = m_socket->recv(data, sizeof(data)-1); @@ -133,7 +133,7 @@ void Connection::run() logDebug(lf_network, "[%05d] wait for result", getID()); string result = message.getResult(); - if (m_socket->isValid() == false) + if (!m_socket->isValid()) break; m_socket->send(result.c_str(), result.size()); @@ -154,7 +154,7 @@ void Connection::run() Network::Network(const bool local, const int port, WQueue* netQueue) : m_netQueue(netQueue), m_listening(false) { - if (local == true) + if (local) m_tcpServer = new TCPServer(port, "127.0.0.1"); else m_tcpServer = new TCPServer(port, "0.0.0.0"); @@ -168,7 +168,7 @@ Network::~Network() { stop(); - while (m_connections.empty() == false) { + while (!m_connections.empty()) { Connection* connection = m_connections.back(); m_connections.pop_back(); connection->stop(); @@ -183,7 +183,7 @@ Network::~Network() void Network::run() { - if (m_listening == false) + if (!m_listening) return; int ret; @@ -277,7 +277,7 @@ void Network::cleanConnections() { list::iterator c_it; for (c_it = m_connections.begin(); c_it != m_connections.end(); c_it++) { - if ((*c_it)->isRunning() == false) { + if (!(*c_it)->isRunning()) { Connection* connection = *c_it; c_it = m_connections.erase(c_it); delete connection; diff --git a/src/ebusd/network.h b/src/ebusd/network.h index 60ee9c5c..ec70e3f0 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -86,7 +86,7 @@ public: { pthread_mutex_lock(&m_mutex); - while (m_resultSet == false) + while (!m_resultSet) pthread_cond_wait(&m_cond, &m_mutex); pthread_mutex_unlock(&m_mutex); diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 59783dcc..0fd7322c 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -119,7 +119,7 @@ void printErrorPos(vector::iterator begin, const vector::iterato bool first = true; int cnt = 0; while (begin != end) { - if (first == true) + if (first) first = false; else { cout << FIELD_SEPARATOR; @@ -166,22 +166,22 @@ result_t DataField::create(vector::iterator& it, if (it == end) break; - if (isTemplate == true) + if (isTemplate) partType = pt_any; else { const char* partStr = (*it++).c_str(); hasPartStr = partStr[0] != 0; if (it == end) { - if (name.empty() == false || hasPartStr == true) + if (!name.empty() || hasPartStr) result = RESULT_ERR_MISSING_TYPE; break; } - if (dstAddress == BROADCAST || isMaster(dstAddress) == true - || (isWriteMessage == true && hasPartStr == false) + if (dstAddress == BROADCAST || isMaster(dstAddress) + || (isWriteMessage && !hasPartStr) || strcasecmp(partStr, "M") == 0) { // master data partType = pt_masterData; } - else if ((isWriteMessage == false && hasPartStr == false) + else if ((!isWriteMessage && !hasPartStr) || strcasecmp(partStr, "S") == 0) { // slave data partType = pt_slaveData; } @@ -191,14 +191,14 @@ result_t DataField::create(vector::iterator& it, } } - if (fields.empty() == true) { + if (fields.empty()) { firstName = name; firstComment = comment; } const string typeStr = *it++; - if (typeStr.empty() == true) { - if (name.empty() == false || hasPartStr == true) + if (typeStr.empty()) { + if (!name.empty() || hasPartStr) result = RESULT_ERR_MISSING_TYPE; break; } @@ -206,7 +206,7 @@ result_t DataField::create(vector::iterator& it, map values; if (it != end) { const string divisorStr = *it++; - if (divisorStr.empty() == false) { + if (!divisorStr.empty()) { if (divisorStr.find('=') == string::npos) divisor = parseInt(divisorStr.c_str(), 10, 1, 10000, result); else { @@ -265,7 +265,7 @@ result_t DataField::create(vector::iterator& it, while (result == RESULT_OK && getline(stream, token, VALUE_SEPARATOR) != 0) { DataField* templ = templates->get(token); if (templ == NULL) { - if (found == false) + if (!found) break; // fallback to direct definition result = RESULT_ERR_NOTFOUND; // cannot mix reference and direct definition } @@ -276,7 +276,7 @@ result_t DataField::create(vector::iterator& it, } if (result != RESULT_OK) break; - if (found == true) + if (found) continue; // go to next definition } typeName = typeStr; @@ -329,11 +329,11 @@ result_t DataField::create(vector::iterator& it, add = new StringDataField(name, comment, unit, *dataType, partType, byteCount); break; case bt_num: - if (values.empty() == true && (dataType->flags & DAY) != 0) { + if (values.empty() && (dataType->flags & DAY) != 0) { for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++) values[dataType->minValueOrLength + i] = dayNames[i]; } - if (values.empty() == true || (dataType->flags & LST) == 0) { + if (values.empty() || (dataType->flags & LST) == 0) { if (divisor == 0) divisor = 1; if ((dataType->bitCount % 8) == 0) @@ -361,7 +361,7 @@ result_t DataField::create(vector::iterator& it, } while (it != end && result == RESULT_OK); if (result != RESULT_OK) { - while (fields.empty() == false) { // cleanup already created fields + while (!fields.empty()) { // cleanup already created fields delete fields.back(); fields.pop_back(); } @@ -407,17 +407,17 @@ result_t SingleDataField::read(const PartType partType, default: return RESULT_ERR_INVALID_PART; } - if (isIgnored() == true || (filterName != NULL && m_name != filterName)) { + if (isIgnored() || (filterName != NULL && m_name != filterName)) { if (offset + m_length > data.size()) { return RESULT_ERR_INVALID_POS; } return RESULT_EMPTY; } - if (leadingSeparator == true) + if (leadingSeparator) output << separator; - if (verbose == true) + if (verbose) output << m_name << "="; result_t result = readSymbols(data, offset, output); @@ -461,13 +461,13 @@ result_t StringDataField::derive(string name, string comment, { if (m_partType != pt_any && partType == pt_any) return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance - if (divisor != 0 || values.empty() == false) + if (divisor != 0 || !values.empty()) return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field - if (name.empty() == true) + if (name.empty()) name = m_name; - if (comment.empty() == true) + if (comment.empty()) comment = m_comment; - if (unit.empty() == true) + if (unit.empty()) unit = m_unit; fields.push_back(new StringDataField(name, comment, unit, m_dataType, partType, m_length)); @@ -590,7 +590,7 @@ result_t StringDataField::writeSymbols(istringstream& input, incr = -1; } - if (isIgnored() == true && (m_dataType.flags & REQ) == 0) { + if (isIgnored() && (m_dataType.flags & REQ) == 0) { for (size_t offset = start, i = 0; i < count; offset += incr, i++) { output[baseOffset + offset] = m_dataType.replacement; // fill up with replacement } @@ -602,17 +602,17 @@ result_t StringDataField::writeSymbols(istringstream& input, switch (m_dataType.type) { case bt_hexstr: - while (input.eof() == false && input.peek() == ' ') + while (!input.eof() && input.peek() == ' ') input.get(); - if (input.eof() == true) // no more digits + if (input.eof()) // no more digits value = m_dataType.replacement; // fill up with replacement else { token.clear(); token.push_back(input.get()); - if (input.eof() == true) + if (input.eof()) return RESULT_ERR_INVALID_NUM; // too short hex value token.push_back(input.get()); - if (input.eof() == true) + if (input.eof()) return RESULT_ERR_INVALID_NUM; // too short hex value value = parseInt(token.c_str(), 16, 0, 0xff, result); @@ -623,7 +623,7 @@ result_t StringDataField::writeSymbols(istringstream& input, case bt_dat: if (m_length == 4 && i == 2) continue; // skip weekday in between - if (input.eof() == true || getline(input, token, '.') == 0) + if (input.eof() || getline(input, token, '.') == 0) return RESULT_ERR_EOF; // incomplete if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) { value = m_dataType.replacement; @@ -659,7 +659,7 @@ result_t StringDataField::writeSymbols(istringstream& input, return RESULT_ERR_OUT_OF_RANGE; // invalid date part break; case bt_tim: - if (input.eof() == true || getline(input, token, LENGTH_SEPARATOR) == 0) + if (input.eof() || getline(input, token, LENGTH_SEPARATOR) == 0) return RESULT_ERR_EOF; // incomplete if ((m_dataType.flags & REQ) == 0 && strcmp(token.c_str(), NULL_VALUE) == 0) { value = m_dataType.replacement; @@ -695,11 +695,11 @@ result_t StringDataField::writeSymbols(istringstream& input, } break; default: - if (input.eof() == true) + if (input.eof()) value = m_dataType.replacement; else { value = input.get(); - if (input.eof() == true || value < 0x20) + if (input.eof() || value < 0x20) value = m_dataType.replacement; } break; @@ -726,7 +726,7 @@ result_t StringDataField::writeSymbols(istringstream& input, bool NumericDataField::hasFullByteOffset(bool after) { return m_length > 1 || (m_bitCount % 8) == 0 - || (after == true && m_bitOffset + (m_bitCount % 8) >= 8); + || (after && m_bitOffset + (m_bitCount % 8) >= 8); } void NumericDataField::dump(ostream& output) @@ -848,17 +848,17 @@ result_t NumberDataField::derive(string name, string comment, { if (m_partType != pt_any && partType == pt_any) return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance - if (name.empty() == true) + if (name.empty()) name = m_name; - if (comment.empty() == true) + if (comment.empty()) comment = m_comment; - if (unit.empty() == true) + if (unit.empty()) unit = m_unit; if (divisor == 0) divisor = m_divisor; else if ((m_dataType.bitCount % 8) == 0) divisor *= m_dataType.divisorOrFirstBit; - if (values.empty() == false) { + if (!values.empty()) { if (divisor != 1) return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field @@ -896,7 +896,7 @@ result_t NumberDataField::readSymbols(SymbolString& input, bool negative = (m_dataType.flags & SIG) != 0 && (value & (1 << (m_bitCount - 1))) != 0; if (m_bitCount == 32) { - if (negative == false) { + if (!negative) { if (m_divisor <= 1) output << static_cast(value); else @@ -906,7 +906,7 @@ result_t NumberDataField::readSymbols(SymbolString& input, } signedValue = (int) value; // negative signed value } - else if (negative == true) // negative signed value + else if (negative) // negative signed value signedValue = (int) value - (1 << m_bitCount); else signedValue = (int) value; @@ -929,7 +929,7 @@ result_t NumberDataField::writeSymbols(istringstream& input, unsigned int value; const char* str = input.str().c_str(); - if ((m_dataType.flags & REQ) == 0 && (isIgnored() == true || strcasecmp(str, NULL_VALUE) == 0)) + if ((m_dataType.flags & REQ) == 0 && (isIgnored() || strcasecmp(str, NULL_VALUE) == 0)) value = m_dataType.replacement; // replacement value else if (str == NULL || *str == 0) return RESULT_ERR_EOF; // input too short @@ -992,16 +992,16 @@ result_t ValueListDataField::derive(string name, string comment, { if (m_partType != pt_any && partType == pt_any) return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance - if (name.empty() == true) + if (name.empty()) name = m_name; - if (comment.empty() == true) + if (comment.empty()) comment = m_comment; - if (unit.empty() == true) + if (unit.empty()) unit = m_unit; if (divisor != 0 && divisor != 1) return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field - if (values.empty() == false) { + if (!values.empty()) { if (values.begin()->first < m_dataType.minValueOrLength || values.rbegin()->first > m_dataType.maxValueOrLength) return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field @@ -1019,7 +1019,7 @@ void ValueListDataField::dump(ostream& output) NumericDataField::dump(output); bool first = true; for (map::iterator it = m_values.begin(); it != m_values.end(); it++) { - if (first == true) + if (first) first = false; else output << VALUE_SEPARATOR; @@ -1057,7 +1057,7 @@ result_t ValueListDataField::readSymbols(SymbolString& input, result_t ValueListDataField::writeSymbols(istringstream& input, unsigned char baseOffset, SymbolString& output) { - if (isIgnored() == true) + if (isIgnored()) return writeRawValue(m_dataType.replacement, baseOffset, output); // replacement value const char* str = input.str().c_str(); @@ -1110,7 +1110,7 @@ DataFieldSet* DataFieldSet::createIdentFields() DataFieldSet::~DataFieldSet() { - while (m_fields.empty() == false) { + while (!m_fields.empty()) { delete m_fields.back(); m_fields.pop_back(); } @@ -1125,7 +1125,7 @@ unsigned char DataFieldSet::getLength(PartType partType) for (vector::iterator it = m_fields.begin(); it < m_fields.end(); it++) { SingleDataField* field = *it; if (field->getPartType() == partType) { - if (previousFullByteOffset[partType] == false && field->hasFullByteOffset(false) == false) + if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) length--; length += field->getLength(partType); @@ -1142,7 +1142,7 @@ result_t DataFieldSet::derive(string name, string comment, unsigned int divisor, map values, vector& fields) { - if (values.empty() == false) + if (!values.empty()) return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive for (vector::iterator it = m_fields.begin(); it < m_fields.end(); it++) { @@ -1172,7 +1172,7 @@ result_t DataFieldSet::read(const PartType partType, if (partType != pt_any && field->getPartType() != partType) continue; - if (previousFullByteOffset == false && field->hasFullByteOffset(false) == false) + if (!previousFullByteOffset && !field->hasFullByteOffset(false)) offset--; result_t result = field->read(partType, data, offset, output, leadingSeparator, verbose, filterName, separator); @@ -1188,12 +1188,12 @@ result_t DataFieldSet::read(const PartType partType, } } - if (verbose == true) { + if (verbose) { if (m_comment.length() > 0) output << " [" << m_comment << "]"; } - return found == true ? RESULT_OK : RESULT_EMPTY; + return found ? RESULT_OK : RESULT_EMPTY; } result_t DataFieldSet::write(istringstream& input, @@ -1208,12 +1208,12 @@ result_t DataFieldSet::write(istringstream& input, if (partType != pt_any && field->getPartType() != partType) continue; - if (previousFullByteOffset == false && field->hasFullByteOffset(false) == false) + if (!previousFullByteOffset && !field->hasFullByteOffset(false)) offset--; result_t result; if (m_fields.size() > 1) { - if (field->isIgnored() == true) + if (field->isIgnored()) token.clear(); else if (getline(input, token, separator) == 0) token.clear(); @@ -1249,7 +1249,7 @@ result_t DataFieldTemplates::add(DataField* field, bool replace) string name = field->getName(); map::iterator it = m_fieldsByName.find(name); if (it != m_fieldsByName.end()) { - if (replace == false) + if (!replace) return RESULT_ERR_DUPLICATE; // duplicate key delete it->second; diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index cfcc47bc..7fde4119 100644 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -87,7 +87,7 @@ bool Device::isValid() if (m_fd == -1) return false; - if (m_checkDevice == true) + if (m_checkDevice) checkDevice(); return m_fd != -1; @@ -95,13 +95,13 @@ bool Device::isValid() result_t Device::send(const unsigned char value) { - if (isValid() == false) + if (!isValid()) return RESULT_ERR_DEVICE; if (write(m_fd, &value, 1) != 1) return RESULT_ERR_SEND; - if (m_logRaw == true && m_logRawFunc != NULL) + if (m_logRaw && m_logRawFunc != NULL) (*m_logRawFunc)(value, false); return RESULT_OK; @@ -109,7 +109,7 @@ result_t Device::send(const unsigned char value) result_t Device::recv(const long timeout, unsigned char& value) { - if (isValid() == false) + if (!isValid()) return RESULT_ERR_DEVICE; if (timeout > 0) { @@ -153,10 +153,10 @@ result_t Device::recv(const long timeout, unsigned char& value) if (nbytes < 0) return RESULT_ERR_DEVICE; - if (m_logRaw == true && m_logRawFunc != NULL) + if (m_logRaw && m_logRawFunc != NULL) (*m_logRawFunc)(value, true); - if (m_dumpRaw == true && m_dumpRawStream.is_open() == true) { + if (m_dumpRaw && m_dumpRawStream.is_open()) { m_dumpRawStream.write((char*)&value, 1); m_dumpRawFileSize++; if ((m_dumpRawFileSize%1024) == 0) @@ -182,7 +182,7 @@ void Device::setDumpRaw(bool dumpRaw) m_dumpRaw = dumpRaw; - if (dumpRaw == false || m_dumpRawFile == NULL) + if (!dumpRaw || m_dumpRawFile == NULL) m_dumpRawStream.close(); else { m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app); @@ -197,7 +197,7 @@ void Device::setDumpRawFile(const char* dumpFile) { m_dumpRawStream.close(); m_dumpRawFile = dumpFile; - if (m_dumpRaw == true && m_dumpRawFile != NULL) { + if (m_dumpRaw && m_dumpRawFile != NULL) { m_dumpRawStream.open(m_dumpRawFile, ios::out | ios::binary | ios::app); m_dumpRawFileSize = 0; } diff --git a/src/lib/ebus/filereader.h b/src/lib/ebus/filereader.h index 722da3cb..ea6366d4 100644 --- a/src/lib/ebus/filereader.h +++ b/src/lib/ebus/filereader.h @@ -72,7 +72,7 @@ public: { ifstream ifs; ifs.open(filename.c_str(), ifstream::in); - if (ifs.is_open() == false) + if (!ifs.is_open()) return RESULT_ERR_NOTFOUND; string line; @@ -96,7 +96,7 @@ public: switch (ch) { case FIELD_SEPARATOR: - if (quotedText == true) + if (quotedText) field << ch; else { row.push_back(field.str()); @@ -104,7 +104,7 @@ public: } break; case TEXT_SEPARATOR: - if (quotedText == true) { + if (quotedText) { quotedText = false; } else if (prev == TEXT_SEPARATOR) { // double dquote @@ -130,7 +130,7 @@ public: result_t result; vector::iterator it = row.begin(); const vector::iterator end = row.end(); - if (m_supportsDefaults == true) { + if (m_supportsDefaults) { if (line[0] == '*') { row[0] = row[0].substr(1); defaults.push_back(row); @@ -142,7 +142,7 @@ public: result = addFromFile(it, end, arg, NULL, filename, lineNo); if (result != RESULT_OK) { - if (verbose == false) { + if (!verbose) { ifs.close(); return result; } diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 86286db8..cba16196 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -45,7 +45,7 @@ Message::Message(const string clazz, const string name, const bool isWrite, { int exp = 7; unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5); - if (isPassive == true) + if (isPassive) key |= (unsigned long long)getMasterNumber(srcAddress) << (8 * exp--); // 0..25 else key |= 0x1fLL << (8 * exp--); // special value for active @@ -159,7 +159,7 @@ result_t Message::create(vector::iterator& it, const vector::ite srcAddress = parseInt(str, 16, 0, 0xff, result); if (result != RESULT_OK) return result; - if (isMaster(srcAddress) == false) + if (!isMaster(srcAddress)) return RESULT_ERR_INVALID_ADDR; } @@ -173,7 +173,7 @@ result_t Message::create(vector::iterator& it, const vector::ite dstAddress = parseInt(str, 16, 0, 0xff, result); if (result != RESULT_OK) return result; - if (isValidAddress(dstAddress) == false) + if (!isValidAddress(dstAddress)) return RESULT_ERR_INVALID_ADDR; } @@ -190,14 +190,14 @@ result_t Message::create(vector::iterator& it, const vector::ite istringstream input(token); if (it == end) return RESULT_ERR_EOF; - while (input.eof() == false) { + while (!input.eof()) { while (input.peek() == ' ') input.get(); - if (input.eof() == true) // no more digits + if (input.eof()) // no more digits break; token.clear(); token.push_back(input.get()); - if (input.eof() == true) { + if (input.eof()) { return RESULT_ERR_INVALID_ARG; // too short hex } token.push_back(input.get()); @@ -249,7 +249,7 @@ result_t Message::create(vector::iterator& it, const vector::ite result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& masterData, istringstream& input, char separator, const unsigned char dstAddress) { - if (m_isPassive == true) + if (m_isPassive) return RESULT_ERR_INVALID_ARG; // prepare not possible SymbolString master(false); @@ -289,7 +289,7 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma result_t Message::prepareSlave(SymbolString& slaveData) { - if (m_isPassive == false || m_isWrite == true) + if (!m_isPassive || m_isWrite) return RESULT_ERR_INVALID_ARG; // prepare not possible SymbolString slave(false); @@ -398,7 +398,7 @@ result_t MessageMap::add(Message* message) m_messagesByName[nameKey] = message; m_messageCount++; - if (isPassive == true) + if (isPassive) m_passiveMessageCount++; nameKey = string(isPassive ? "-P" : (isWrite ? "-W" : "-R")) + name; // also store without class @@ -483,28 +483,28 @@ deque MessageMap::findAll(const string& clazz, const string& name, con if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-" continue; Message* message = it->second; - if (checkClass == true) { + if (checkClass) { string check = strtolower(message->getClass()); if (completeMatch ? (check != lclass) : (check.find(lclass) == check.npos)) continue; } - if (checkName == true) { + if (checkName) { string check = strtolower(message->getName()); if (completeMatch ? (check != lname) : (check.find(lname) == check.npos)) continue; } - if (checkPb == true && message->getId()[0] != pb) + if (checkPb && message->getId()[0] != pb) continue; - if (message->isPassive() == true) { - if (withPassive == false) + if (message->isPassive()) { + if (!withPassive) continue; } - else if (message->isWrite() == true) { - if (withWrite == false) + else if (message->isWrite()) { + if (!withWrite) continue; } else { - if (withRead == false) + if (!withRead) continue; } ret.push_back(message); @@ -556,7 +556,7 @@ Message* MessageMap::find(SymbolString& master) void MessageMap::clear() { // clear poll messages - while (m_pollMessages.empty() == false) { + while (!m_pollMessages.empty()) { m_pollMessages.top(); m_pollMessages.pop(); } @@ -578,7 +578,7 @@ void MessageMap::clear() Message* MessageMap::getNextPoll() { - if (m_pollMessages.empty() == true) + if (m_pollMessages.empty()) return NULL; Message* ret = m_pollMessages.top(); m_pollMessages.pop(); diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index 98523d19..dded2a7f 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -86,7 +86,7 @@ const string SymbolString::getDataStr(const bool unescape) for (size_t i = 0; i < m_data.size(); i++) { unsigned char value = m_data[i]; - if (m_unescapeState == 0 && unescape == true && previousEscape == true) { + if (m_unescapeState == 0 && unescape && previousEscape) { if (value == 0x00) sstr << "a9"; // ESC else if (value == 0x01) @@ -96,7 +96,7 @@ const string SymbolString::getDataStr(const bool unescape) previousEscape = false; } - else if (m_unescapeState == 0 && unescape == true && value == ESC) { + else if (m_unescapeState == 0 && unescape && value == ESC) { previousEscape = true; // escape sequence not yet finished } else { @@ -111,35 +111,35 @@ const string SymbolString::getDataStr(const bool unescape) result_t SymbolString::push_back(const unsigned char value, const bool isEscaped, const bool updateCRC) { if (m_unescapeState == 0) { // store escaped data - if (isEscaped == false && value == ESC) { + if (!isEscaped && value == ESC) { m_data.push_back(ESC); m_data.push_back(0x00); - if (updateCRC == true) { + if (updateCRC) { addCRC(ESC); addCRC(0x00); } } - else if (isEscaped == false && value == SYN) { + else if (!isEscaped && value == SYN) { m_data.push_back(ESC); m_data.push_back(0x01); - if (updateCRC == true) { + if (updateCRC) { addCRC(ESC); addCRC(0x01); } } else { m_data.push_back(value); - if (updateCRC == true) + if (updateCRC) addCRC(value); } return RESULT_OK; } - else if (isEscaped == false) { + else if (!isEscaped) { if (m_unescapeState != 1) return RESULT_ERR_ESC; // invalid unescape state m_data.push_back(value); - if (updateCRC == true) { + if (updateCRC) { if (value == ESC) { addCRC(ESC); addCRC(0x00); @@ -155,7 +155,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped return RESULT_OK; } else if (m_unescapeState != 1) { - if (updateCRC == true) + if (updateCRC) addCRC(value); if (value == 0x00) { @@ -171,13 +171,13 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped return RESULT_ERR_ESC; // invalid escape sequence } else if (value == ESC) { - if (updateCRC == true) + if (updateCRC) addCRC(value); m_unescapeState = 2; return RESULT_IN_ESC; } - if (updateCRC == true) + if (updateCRC) addCRC(value); m_data.push_back(value); @@ -242,6 +242,6 @@ unsigned char getMasterNumber(unsigned char addr) { } bool isValidAddress(unsigned char addr, bool allowBroadcast) { - return addr != SYN && addr != ESC && (allowBroadcast == true || addr != BROADCAST); + return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST); } diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index 96cc8674..69fc233d 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -48,7 +48,7 @@ public: * Creates a new empty escaped or unescaped instance. * @param escaped whether to create an escaped instance. */ - SymbolString(const bool escaped=true) : m_unescapeState(escaped == true ? 0 : 1), m_crc(0) {} + SymbolString(const bool escaped=true) : m_unescapeState(escaped ? 0 : 1), m_crc(0) {} /** * Add all symbols from the other @a SymbolString and the calculated CRC if escaped. diff --git a/src/lib/ebus/test/test_data.cpp b/src/lib/ebus/test/test_data.cpp index 307a41b2..f20ebdb9 100644 --- a/src/lib/ebus/test/test_data.cpp +++ b/src/lib/ebus/test/test_data.cpp @@ -26,14 +26,14 @@ using namespace std; void verify(bool expectFailMatch, string type, string input, bool match, string expectStr, string gotStr) { - if (expectFailMatch == true) { - if (match == true) + if (expectFailMatch) { + if (match) cout << " failed " << type << " match >" << input << "< error: unexpectedly succeeded" << endl; else cout << " failed " << type << " match >" << input << "< OK" << endl; } - else if (match == true) + else if (match) cout << " " << type << " match >" << input << "< OK" << endl; else cout << " " << type << " match >" << input << "< error: got >" @@ -248,7 +248,7 @@ int main() } vector::iterator it = entries.begin(); result = DataField::create(it, entries.end(), templates, fields, isSet, isTemplate ? SYN : mstr[1]); - if (failedCreate == true) { + if (failedCreate) { if (result == RESULT_OK) cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl; else @@ -294,9 +294,9 @@ int main() } result = fields->read(pt_masterData, mstr, 0, output, false, verbose); if (result >= RESULT_OK) { - result = fields->read(pt_slaveData, sstr, 0, output, output.str().empty() == false, verbose); + result = fields->read(pt_slaveData, sstr, 0, output, !output.str().empty(), verbose); } - if (failedRead == true) + if (failedRead) if (result >= RESULT_OK) cout << " failed read " << fields->getName() << " >" << check[2] << "< error: unexpectedly succeeded" << endl; @@ -312,12 +312,12 @@ int main() verify(failedReadMatch, "read", check[2], match, expectStr, output.str()); } - if (verbose == false) { + if (!verbose) { istringstream input(expectStr); result = fields->write(input, pt_masterData, writeMstr, 0); if (result >= RESULT_OK) result = fields->write(input, pt_slaveData, writeSstr, 0); - if (failedWrite == true) { + if (failedWrite) { if (result >= RESULT_OK) cout << " failed write " << fields->getName() << " >" << expectStr << "< error: unexpectedly succeeded" << endl; diff --git a/src/lib/ebus/test/test_device.cpp b/src/lib/ebus/test/test_device.cpp index 4333ac6a..4dea4e4e 100644 --- a/src/lib/ebus/test/test_device.cpp +++ b/src/lib/ebus/test/test_device.cpp @@ -34,7 +34,7 @@ int main () if (result != RESULT_OK) { cout << "open failed: " << getResultCode(result) << endl; } else { - if (device->isValid() == false) + if (!device->isValid()) cout << "device not available." << endl; int count = 0; @@ -52,7 +52,7 @@ int main () device->close(); - if(device->isValid() == false) + if (!device->isValid()) cout << "close successful." << endl; } diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index 762134e5..50bf3dbd 100644 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -27,14 +27,14 @@ using namespace std; void verify(bool expectFailMatch, string type, string input, bool match, string expectStr, string gotStr) { - if (expectFailMatch == true) { - if (match == true) + if (expectFailMatch) { + if (match) cout << " failed " << type << " match >" << input << "< error: unexpectedly succeeded" << endl; else cout << " failed " << type << " match >" << input << "< OK" << endl; } - else if (match == true) + else if (match) cout << " " << type << " match >" << input << "< OK" << endl; else cout << " " << type << " match >" << input << "< error: got >" @@ -104,7 +104,7 @@ int main() delete deleteMessage; deleteMessage = NULL; } - if (isTemplate == true) { + if (isTemplate) { // store new template DataField* fields = NULL; vector::iterator it = entries.begin(); @@ -136,7 +136,7 @@ int main() else { vector::iterator it = entries.begin(); result = Message::create(it, entries.end(), NULL, templates, deleteMessage); - if (failedCreate == true) { + if (failedCreate) { if (result == RESULT_OK) cout << "\"" << check[0] << "\": failed create error: unexpectedly succeeded" << endl; else @@ -158,7 +158,7 @@ int main() continue; } cout << "\"" << check[0] << "\": create OK" << endl; - if (dontMap == false) { + if (!dontMap) { result_t result = messages->add(deleteMessage); if (result != RESULT_OK) { cout << "\"" << check[0] << "\": add error: " @@ -168,7 +168,7 @@ int main() cout << " map OK" << endl; message = deleteMessage; deleteMessage = NULL; - if (onlyMap == true) + if (onlyMap) continue; Message* foundMessage = messages->find(mstr); if (foundMessage == message) @@ -182,7 +182,7 @@ int main() message = deleteMessage; } - if (message->isPassive() == true || decode == true) { + if (message->isPassive() || decode) { ostringstream output; result = message->decode(mstr, sstr, output); if (result != RESULT_OK) { @@ -199,7 +199,7 @@ int main() istringstream input(inputStr); SymbolString writeMstr; result = message->prepareMaster(0xff, writeMstr, input); - if (failedPrepare == true) { + if (failedPrepare) { if (result == RESULT_OK) cout << " \"" << inputStr << "\": failed prepare error: unexpectedly succeeded" << endl; else diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index 1fdbc2a6..0d1c119b 100644 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -82,7 +82,7 @@ TCPSocket* TCPClient::connect(const string& server, const int& port) int TCPServer::start() { - if (m_listening == true) + if (m_listening) return 0; m_lfd = socket(AF_INET, SOCK_STREAM, 0); @@ -115,7 +115,7 @@ int TCPServer::start() TCPSocket* TCPServer::newSocket() { - if (m_listening == false) + if (!m_listening) return NULL; struct sockaddr_in address; diff --git a/src/lib/utils/thread.cpp b/src/lib/utils/thread.cpp index 0c85e732..ec80ceb6 100644 --- a/src/lib/utils/thread.cpp +++ b/src/lib/utils/thread.cpp @@ -32,11 +32,12 @@ void* Thread::runThread(void* arg) Thread::~Thread() { - if (m_started == true) + if (m_started) { pthread_detach(m_threadid); - - if (m_started == true) + } + if (m_started) { pthread_cancel(m_threadid); + } } bool Thread::start(const char* name) @@ -62,7 +63,7 @@ bool Thread::join() { int result = -1; - if (m_started == true) { + if (m_started) { m_stopped = true; result = pthread_join(m_threadid, NULL); diff --git a/src/lib/utils/thread.h b/src/lib/utils/thread.h index 78078285..0c0883e3 100644 --- a/src/lib/utils/thread.h +++ b/src/lib/utils/thread.h @@ -53,7 +53,7 @@ public: * Return whether this @a Thread is still running and not yet stopped. * @return true if this @a Thread is till running and not yet stopped. */ - virtual bool isRunning() { return m_running == true && m_stopped == false; } + virtual bool isRunning() { return m_running && !m_stopped; } /** * Create the native thread and set its name. diff --git a/src/lib/utils/wqueue.h b/src/lib/utils/wqueue.h index 30eb1886..59a21b1f 100644 --- a/src/lib/utils/wqueue.h +++ b/src/lib/utils/wqueue.h @@ -87,7 +87,7 @@ public: pthread_mutex_lock(&m_mutex); T item; - if (wait == true) { + if (wait) { while (m_queue.size() == 0) pthread_cond_wait(&m_cond, &m_mutex); item = m_queue.front(); @@ -157,7 +157,7 @@ public: pthread_mutex_lock(&m_mutex); T item; - if (wait == true) { + if (wait) { while (m_queue.size() == 0) pthread_cond_wait(&m_cond, &m_mutex); item = m_queue.front(); diff --git a/src/tools/ebusctl.cpp b/src/tools/ebusctl.cpp index 3995b50f..48ba81a3 100644 --- a/src/tools/ebusctl.cpp +++ b/src/tools/ebusctl.cpp @@ -189,8 +189,8 @@ string fetchData(TCPSocket* socket, bool& listening) #endif } - if (newData == true) { - if (socket->isValid() == true) { + if (newData) { + if (socket->isValid()) { datalen = socket->recv(data, sizeof(data)); if (datalen < 0) { @@ -204,14 +204,14 @@ string fetchData(TCPSocket* socket, bool& listening) if ((ss.str().length() >= 2 && ss.str()[ss.str().length()-2] == '\n' && ss.str()[ss.str().length()-1] == '\n') - || listening == true) + || listening) break; } else break; } - else if (newInput == true) { + else if (newInput) { getline(cin, message); message += '\n'; @@ -242,7 +242,7 @@ void connect(const char* host, int port, char* const *args, int argCount) string message; bool listening = false; - if (once == false) { + if (!once) { cout << host << ": "; getline(cin, message); } @@ -270,7 +270,7 @@ void connect(const char* host, int port, char* const *args, int argCount) if (strcasecmp(message.c_str(), "L") == 0 || strcasecmp(message.c_str(), "LISTEN") == 0) { listening = true; - while (listening && cin.eof() == false) { + while (listening && !cin.eof()) { string result(fetchData(socket, listening)); cout << result; if (strcasecmp(result.c_str(), "LISTEN STOPPED") == 0) @@ -281,7 +281,7 @@ void connect(const char* host, int port, char* const *args, int argCount) cout << fetchData(socket, listening); } - } while (once == false && cin.eof() == false); + } while (!once && !cin.eof()); delete socket; diff --git a/src/tools/ebusfeed.cpp b/src/tools/ebusfeed.cpp index 37d356fc..c4d096fb 100644 --- a/src/tools/ebusfeed.cpp +++ b/src/tools/ebusfeed.cpp @@ -140,18 +140,18 @@ int main(int argc, char* argv[]) if (result != RESULT_OK) cout << "unable to open " << opt.device << ": " << getResultCode(result) << endl; - if (device->isValid() == false) + if (!device->isValid()) cout << "device " << opt.device << " not available" << endl; else { cout << "device opened" << endl; fstream file(opt.dumpFile, ios::in | ios::binary); - if (file.is_open() == true) { + if (file.is_open()) { while (true) { unsigned char byte = file.get(); - if (file.eof() == true) + if (file.eof()) break; cout << hex << setw(2) << setfill('0') << static_cast(byte) << endl;