From 7bd9446f13963442e3c1a54477dfafd1b0f5b628 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 14 Jan 2017 15:28:41 +0100 Subject: [PATCH 1/4] spacing --- src/lib/ebus/test/test_data.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/ebus/test/test_data.cpp b/src/lib/ebus/test/test_data.cpp index 3adf2e3f..ea1eba81 100644 --- a/src/lib/ebus/test/test_data.cpp +++ b/src/lib/ebus/test/test_data.cpp @@ -264,9 +264,9 @@ int main() { {"x,,uch,10", "3.8", "10feffff0126", "00", ""}, {"x,,uch,-10", "380", "10feffff0126", "00", ""}, {"x,,uch,=48", "", "10feffff01ab", "00", "W"}, - {"x,,uch,==48", "", "10feffff01ab", "00", "rW"}, + {"x,,uch,==48", "", "10feffff01ab", "00", "rW"}, {"x,,uch,=48", "", "10feffff0130", "00", ""}, - {"x,,uch,==48", "", "10feffff0130", "00", ""}, + {"x,,uch,==48", "", "10feffff0130", "00", ""}, {"x,,sch", "-90", "10feffff01a6", "00", ""}, {"x,,sch", "0", "10feffff0100", "00", ""}, {"x,,sch", "-1", "10feffff01ff", "00", ""}, From 774e01e9375cffc0b0523c3a592e88fcb1422c1e Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 14 Jan 2017 16:41:54 +0100 Subject: [PATCH 2/4] use own namespace --- src/ebusd/bushandler.cpp | 9 ++++++++- src/ebusd/bushandler.h | 6 +++++- src/ebusd/datahandler.cpp | 6 +++++- src/ebusd/datahandler.h | 7 ++++++- src/ebusd/main.cpp | 12 ++++++++++++ src/ebusd/main.h | 4 ++++ src/ebusd/mainloop.cpp | 9 ++++++++- src/ebusd/mainloop.h | 4 +++- src/ebusd/mqtthandler.cpp | 6 +++++- src/ebusd/mqtthandler.h | 10 ++++++++-- src/ebusd/network.cpp | 3 ++- src/ebusd/network.h | 5 +++-- src/lib/ebus/contrib/contrib.cpp | 4 +++- src/lib/ebus/contrib/contrib.h | 4 +++- src/lib/ebus/contrib/tem.cpp | 8 +++++++- src/lib/ebus/contrib/tem.h | 4 +++- src/lib/ebus/contrib/test/test_tem.cpp | 2 +- src/lib/ebus/data.cpp | 8 +++++++- src/lib/ebus/data.h | 5 ++++- src/lib/ebus/datatype.cpp | 11 ++++++++++- src/lib/ebus/datatype.h | 7 ++++++- src/lib/ebus/device.cpp | 4 +++- src/lib/ebus/device.h | 4 +++- src/lib/ebus/filereader.h | 13 ++++++++++++- src/lib/ebus/message.cpp | 10 +++++++++- src/lib/ebus/message.h | 10 ++++++++-- src/lib/ebus/result.cpp | 3 ++- src/lib/ebus/result.h | 4 ++++ src/lib/ebus/symbol.cpp | 11 +++++++++-- src/lib/ebus/symbol.h | 9 +++++++-- src/lib/ebus/test/test_data.cpp | 2 +- src/lib/ebus/test/test_device.cpp | 2 +- src/lib/ebus/test/test_filereader.cpp | 1 + src/lib/ebus/test/test_message.cpp | 4 +++- src/lib/ebus/test/test_symbol.cpp | 2 +- src/lib/utils/log.cpp | 2 -- src/lib/utils/queue.h | 2 +- src/lib/utils/rotatefile.cpp | 2 +- src/lib/utils/rotatefile.h | 2 +- src/lib/utils/tcpsocket.cpp | 2 -- src/lib/utils/tcpsocket.h | 2 +- src/tools/ebusctl.cpp | 6 ++++-- src/tools/ebusfeed.cpp | 13 +++++++++++-- 43 files changed, 196 insertions(+), 48 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 76d90434..d8881e24 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -34,7 +34,12 @@ #include "symbol.h" #include "log.h" -using namespace std; +namespace ebusd { + +using std::dec; +using std::hex; +using std::setfill; +using std::setw; // the string used for answering to a scan request (07h 04h) #define SCAN_ANSWER ("ebusd.eu;" PACKAGE_NAME ";" SCAN_VERSION ";100") @@ -1141,3 +1146,5 @@ void BusHandler::setScanConfigLoaded(unsigned char address, string file) { m_messages->addLoadedFile(address, file, ""); } } + +} // namespace ebusd diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index 9c33f24e..6765b951 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -40,7 +40,9 @@ * @image html states.png "ebusd BusHandler states" */ -using namespace std; +namespace ebusd { + +using std::string; /** the default time [us] for retrieving a symbol from an addressed slave. */ #define SLAVE_RECV_TIMEOUT 15000 @@ -650,4 +652,6 @@ class BusHandler : public WaitThread { map m_grabbedMessages; }; +} // namespace ebusd + #endif // EBUSD_BUSHANDLER_H_ diff --git a/src/ebusd/datahandler.cpp b/src/ebusd/datahandler.cpp index f9b24be5..7d5fa679 100644 --- a/src/ebusd/datahandler.cpp +++ b/src/ebusd/datahandler.cpp @@ -26,7 +26,9 @@ # include "mqtthandler.h" #endif -using namespace std; +namespace ebusd { + +using std::string; /** the final @a argp_child structure. */ static const struct argp_child g_last_argp_child = {NULL, 0, NULL, 0}; @@ -67,3 +69,5 @@ bool datahandler_register(BusHandler* busHandler, MessageMap* messages, list &args, bool& connected) { connected = false; return result.str(); } + +} // namespace ebusd diff --git a/src/ebusd/mainloop.h b/src/ebusd/mainloop.h index 0420195b..237ac0e3 100644 --- a/src/ebusd/mainloop.h +++ b/src/ebusd/mainloop.h @@ -30,7 +30,7 @@ /** \file mainloop.h */ -using namespace std; +namespace ebusd { /** * The main loop handling requests from connected clients. @@ -252,4 +252,6 @@ class MainLoop : public Thread, DeviceListener { list m_dataHandlers; }; +} // namespace ebusd + #endif // EBUSD_MAINLOOP_H_ diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 39967060..62dc70e1 100644 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -23,7 +23,9 @@ #include "mqtthandler.h" #include "log.h" -using namespace std; +namespace ebusd { + +using std::dec; /** the definition of the MQTT arguments. */ static const struct argp_option g_mqtt_argp_options[] = { @@ -455,3 +457,5 @@ void MqttHandler::publishTopic(string topic, string data, bool retain) { logOtherDebug("mqtt", "publish %s %s", topic.c_str(), data.c_str()); mosquitto_publish(m_mosquitto, NULL, topic.c_str(), (uint32_t)data.size(), (uint8_t*)(data.c_str()), 0, retain); } + +} // namespace ebusd diff --git a/src/ebusd/mqtthandler.h b/src/ebusd/mqtthandler.h index 65e35ccb..3e26d73b 100644 --- a/src/ebusd/mqtthandler.h +++ b/src/ebusd/mqtthandler.h @@ -20,9 +20,9 @@ #define EBUSD_MQTTHANDLER_H_ #include +#include #include #include -#include #include "datahandler.h" #include "bushandler.h" #include "message.h" @@ -31,7 +31,11 @@ * A data handler enabling MQTT support via mosquitto. */ -using namespace std; +namespace ebusd { + +using std::map; +using std::string; +using std::vector; /** * Helper function for getting the argp definition for MQTT. @@ -128,4 +132,6 @@ class MqttHandler : public DataSink, public DataSource, public Thread { struct mosquitto* m_mosquitto; }; +} // namespace ebusd + #endif // EBUSD_MQTTHANDLER_H_ diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index b21097c1..9dd66995 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -27,7 +27,7 @@ #include #include "log.h" -using namespace std; +namespace ebusd { int Connection::m_ids = 0; @@ -299,3 +299,4 @@ void Network::cleanConnections() { } } +} // namespace ebusd diff --git a/src/ebusd/network.h b/src/ebusd/network.h index 8071ad64..b79654fb 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -30,7 +30,7 @@ /** \file network.h */ -using namespace std; +namespace ebusd { /** Forward declaration for @a Connection. */ class Connection; @@ -306,5 +306,6 @@ class Network : public Thread { void cleanConnections(); }; -#endif // EBUSD_NETWORK_H_ +} // namespace ebusd +#endif // EBUSD_NETWORK_H_ diff --git a/src/lib/ebus/contrib/contrib.cpp b/src/lib/ebus/contrib/contrib.cpp index b79c654e..0af485d1 100644 --- a/src/lib/ebus/contrib/contrib.cpp +++ b/src/lib/ebus/contrib/contrib.cpp @@ -19,9 +19,11 @@ #include "contrib.h" #include "tem.h" -using namespace std; +namespace ebusd { bool libebus_contrib_register() { contrib_tem_register(); return true; } + +} // namespace ebusd diff --git a/src/lib/ebus/contrib/contrib.h b/src/lib/ebus/contrib/contrib.h index 08986a00..8bb0ca2a 100644 --- a/src/lib/ebus/contrib/contrib.h +++ b/src/lib/ebus/contrib/contrib.h @@ -24,7 +24,7 @@ * configure switch: --without-contrib */ -using namespace std; +namespace ebusd { /** * Registration function that is called once during initialization. @@ -32,4 +32,6 @@ using namespace std; */ bool libebus_contrib_register(); +} // namespace ebusd + #endif // LIB_EBUS_CONTRIB_CONTRIB_H_ diff --git a/src/lib/ebus/contrib/tem.cpp b/src/lib/ebus/contrib/tem.cpp index 2f9aed0f..adec6d55 100644 --- a/src/lib/ebus/contrib/tem.cpp +++ b/src/lib/ebus/contrib/tem.cpp @@ -29,7 +29,11 @@ #include #include "datatype.h" -using namespace std; +namespace ebusd { + +using std::setfill; +using std::setw; +using std::dec; void contrib_tem_register() { DataTypeList::getInstance()->add(new TemParamDataType("TEM_P")); @@ -135,3 +139,5 @@ result_t TemParamDataType::writeSymbols(istringstream& input, } return writeRawValue(value, offset, length, output, usedLength); } + +} // namespace ebusd diff --git a/src/lib/ebus/contrib/tem.h b/src/lib/ebus/contrib/tem.h index 2f0bafb9..5f412cfe 100644 --- a/src/lib/ebus/contrib/tem.h +++ b/src/lib/ebus/contrib/tem.h @@ -34,7 +34,7 @@ * Contributed data types for TEM devices not part of regular releases. */ -using namespace std; +namespace ebusd { /** * A special variant of @a NumberDataType for TEM/Dungs ParamID in master/slave @@ -68,4 +68,6 @@ class TemParamDataType : public NumberDataType { */ void contrib_tem_register(); +} // namespace ebusd + #endif // LIB_EBUS_CONTRIB_TEM_H_ diff --git a/src/lib/ebus/contrib/test/test_tem.cpp b/src/lib/ebus/contrib/test/test_tem.cpp index 3e08063a..12216b46 100644 --- a/src/lib/ebus/contrib/test/test_tem.cpp +++ b/src/lib/ebus/contrib/test/test_tem.cpp @@ -23,7 +23,7 @@ #include "tem.h" #include "data.h" -using namespace std; +using namespace ebusd; static bool error = false; diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index ecf55a20..44380ebf 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -29,7 +29,11 @@ #include #include -using namespace std; +namespace ebusd { + +using std::dec; +using std::hex; +using std::setw; /** the week day names. */ static const char* dayNames[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; @@ -1057,3 +1061,5 @@ DataField* DataFieldTemplates::get(const string name) { } return ref->second; } + +} // namespace ebusd diff --git a/src/lib/ebus/data.h b/src/lib/ebus/data.h index 0469a1cd..d3dd09dd 100644 --- a/src/lib/ebus/data.h +++ b/src/lib/ebus/data.h @@ -45,7 +45,8 @@ * instances from configuration files by inheriting the @a FileReader template * class. */ -using namespace std; + +namespace ebusd { class DataFieldTemplates; class SingleDataField; @@ -656,4 +657,6 @@ class DataFieldTemplates : public FileReader { map m_fieldsByName; }; +} // namespace ebusd + #endif // LIB_EBUS_DATA_H_ diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 21870f2d..7f73856a 100644 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -31,7 +31,14 @@ # include "contrib/contrib.h" #endif -using namespace std; +namespace ebusd { + +using std::dec; +using std::hex; +using std::fixed; +using std::setfill; +using std::setprecision; +using std::setw; unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue, result_t& result, unsigned int* length) { char* strEnd = NULL; @@ -1073,3 +1080,5 @@ DataType* DataTypeList::get(const string id, const unsigned char length) { } return dataType; } + +} // namespace ebusd diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index 202c6f38..ed083b0f 100644 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -46,7 +46,10 @@ * an @a istringstream to a @a SymbolString (see @a DataType#writeSymbols()). */ -using namespace std; +namespace ebusd { + +using std::map; +using std::list; /** the separator character used between base type name and length (in CSV only). */ #define LENGTH_SEPARATOR ':' @@ -584,4 +587,6 @@ class DataTypeList { #endif }; +} // namespace ebusd + #endif // LIB_EBUS_DATATYPE_H_ diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index a135661e..e721a8ce 100644 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -36,7 +36,7 @@ #include #include "data.h" -using namespace std; +namespace ebusd { Device::~Device() { close(); @@ -323,3 +323,5 @@ ssize_t NetworkDevice::read(unsigned char& value) { } return Device::read(value); } + +} // namespace ebusd diff --git a/src/lib/ebus/device.h b/src/lib/ebus/device.h index f6b18ca7..9381f3c1 100644 --- a/src/lib/ebus/device.h +++ b/src/lib/ebus/device.h @@ -36,7 +36,7 @@ * to a file and/or forwarding it to a logging function. */ -using namespace std; +namespace ebusd { /** * Interface for listening to data received on/sent to a device. @@ -284,4 +284,6 @@ class NetworkDevice : public Device { unsigned char m_bufPos; }; +} // namespace ebusd + #endif // LIB_EBUS_DEVICE_H_ diff --git a/src/lib/ebus/filereader.h b/src/lib/ebus/filereader.h index 843e0e9a..ae31255d 100644 --- a/src/lib/ebus/filereader.h +++ b/src/lib/ebus/filereader.h @@ -39,7 +39,16 @@ * with a "*" symbol. */ -using namespace std; +namespace ebusd { + +using std::string; +using std::ostream; +using std::ostringstream; +using std::istream; +using std::istringstream; +using std::ifstream; +using std::cout; +using std::endl; /** the separator character used between fields. */ #define FIELD_SEPARATOR ',' @@ -376,4 +385,6 @@ class FileReader { string m_lastError; }; +} // namespace ebusd + #endif // LIB_EBUS_FILEREADER_H_ diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index e41f008c..eb4ad0ec 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -27,7 +27,13 @@ #include "result.h" #include "symbol.h" -using namespace std; +namespace ebusd { + +using std::dec; +using std::hex; +using std::nouppercase; +using std::setfill; +using std::setw; /** the maximum length of the command ID bytes (in addition to PB/SB) for which the key is distinct. */ #define MAX_ID_KEYLEN 4 @@ -2197,3 +2203,5 @@ void MessageMap::dump(ostream& output, bool withConditions) { output << endl; } } + +} // namespace ebusd diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 6363bb98..4f373cc0 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -56,7 +56,11 @@ * template class. */ -using namespace std; +namespace ebusd { + +using std::binary_function; +using std::priority_queue; +using std::deque; class Condition; class SimpleCondition; @@ -702,7 +706,7 @@ class ChainedMessage : public Message { /** * A function that compares the weighted poll priority of two @a Message instances. */ -struct compareMessagePriority : binary_function { +struct compareMessagePriority : binary_function { /** * Compare the weighted poll priority of the two @a Message instances. * @param x the first @a Message. @@ -1377,4 +1381,6 @@ class MessageMap : public FileReader { map > m_instructions; }; +} // namespace ebusd + #endif // LIB_EBUS_MESSAGE_H_ diff --git a/src/lib/ebus/result.cpp b/src/lib/ebus/result.cpp index 7530198a..c2e8bc1e 100644 --- a/src/lib/ebus/result.cpp +++ b/src/lib/ebus/result.cpp @@ -19,7 +19,7 @@ #include "result.h" #include -using namespace std; +namespace ebusd { const char* getResultCode(result_t resultCode) { switch (resultCode) { @@ -58,3 +58,4 @@ const char* getResultCode(result_t resultCode) { } } +} // namespace ebusd diff --git a/src/lib/ebus/result.h b/src/lib/ebus/result.h index 3daa050b..4ca373a7 100644 --- a/src/lib/ebus/result.h +++ b/src/lib/ebus/result.h @@ -27,6 +27,8 @@ * whereas negative values indicate failure. */ +namespace ebusd { + /** type for result code. */ enum result_t { RESULT_OK = 0, //!< success @@ -70,4 +72,6 @@ enum result_t { */ const char* getResultCode(result_t resultCode); +} // namespace ebusd + #endif // LIB_EBUS_RESULT_H_ diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index 0dc7933c..f402a9ba 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -23,7 +23,13 @@ #include #include "result.h" -using namespace std; +namespace ebusd { + +using std::ostringstream; +using std::nouppercase; +using std::setw; +using std::hex; +using std::setfill; /** * CRC8 lookup table for the polynom 0x9b = x^8 + x^7 + x^4 + x^3 + x^1 + 1. @@ -83,7 +89,7 @@ result_t SymbolString::parseHex(const string& str, const bool isEscaped) { } const string SymbolString::getDataStr(const bool unescape, const bool skipLastSymbol) { - stringstream sstr; + ostringstream sstr; bool previousEscape = false; for (size_t i = 0; i < m_data.size(); i++) { @@ -255,3 +261,4 @@ bool isValidAddress(unsigned char addr, bool allowBroadcast) { return addr != SYN && addr != ESC && (allowBroadcast || addr != BROADCAST); } +} // namespace ebusd diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index d284c99c..c43b6dbf 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -27,8 +27,6 @@ #include #include "result.h" -using namespace std; - /** @file symbol.h * Classes, functions, and constants related to symbols on the eBUS. * @@ -65,6 +63,11 @@ using namespace std; * non-acknowledge, the receiving slave has to repeat its data once. */ +namespace ebusd { + +using std::string; +using std::vector; + static const unsigned char ESC = 0xA9; //!< escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA static const unsigned char SYN = 0xAA; //!< synchronization symbol static const unsigned char ACK = 0x00; //!< positive acknowledge @@ -257,4 +260,6 @@ unsigned char getMasterNumber(unsigned char addr); */ bool isValidAddress(unsigned char addr, bool allowBroadcast = true); +} // namespace ebusd + #endif // LIB_EBUS_SYMBOL_H_ diff --git a/src/lib/ebus/test/test_data.cpp b/src/lib/ebus/test/test_data.cpp index ea1eba81..977274ae 100644 --- a/src/lib/ebus/test/test_data.cpp +++ b/src/lib/ebus/test/test_data.cpp @@ -22,7 +22,7 @@ #include #include "data.h" -using namespace std; +using namespace ebusd; static bool error = false; diff --git a/src/lib/ebus/test/test_device.cpp b/src/lib/ebus/test/test_device.cpp index f38bd48c..7c79127f 100644 --- a/src/lib/ebus/test/test_device.cpp +++ b/src/lib/ebus/test/test_device.cpp @@ -20,7 +20,7 @@ #include #include "device.h" -using namespace std; +using namespace ebusd; int main() { Device* device = Device::create("/dev/ttyUSB20", true, false, false); diff --git a/src/lib/ebus/test/test_filereader.cpp b/src/lib/ebus/test/test_filereader.cpp index 462fade2..6f722611 100644 --- a/src/lib/ebus/test/test_filereader.cpp +++ b/src/lib/ebus/test/test_filereader.cpp @@ -23,6 +23,7 @@ #include "filereader.h" using namespace std; +using namespace ebusd; static bool error = false; diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index f1d982fa..880b1c21 100644 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -24,7 +24,7 @@ #include #include "message.h" -using namespace std; +using namespace ebusd; void verify(bool expectFailMatch, string type, string input, bool match, string expectStr, string gotStr) { @@ -45,12 +45,14 @@ void verify(bool expectFailMatch, string type, string input, DataFieldTemplates* templates = NULL; +namespace ebusd { DataFieldTemplates* getTemplates(const string filename) { if (filename == "") { // avoid compiler warning return templates; } return templates; } +} int main() { // message: [type],[circuit],name,[comment],[QQ[;QQ]*],[ZZ],[PBSB],[ID],fields... diff --git a/src/lib/ebus/test/test_symbol.cpp b/src/lib/ebus/test/test_symbol.cpp index 78f92cc7..bb191cd0 100644 --- a/src/lib/ebus/test/test_symbol.cpp +++ b/src/lib/ebus/test/test_symbol.cpp @@ -21,7 +21,7 @@ #include #include "symbol.h" -using namespace std; +using namespace ebusd; static bool error = false; diff --git a/src/lib/utils/log.cpp b/src/lib/utils/log.cpp index edc63e01..aecc4f34 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -25,8 +25,6 @@ #include #include "clock.h" -using namespace std; - /** the name of each @a LogFacility. */ static const char *facilityNames[] = { "main", diff --git a/src/lib/utils/queue.h b/src/lib/utils/queue.h index 1a6d8a85..36d66f0c 100644 --- a/src/lib/utils/queue.h +++ b/src/lib/utils/queue.h @@ -26,7 +26,7 @@ /** \file queue.h */ -using namespace std; +using std::list; /** * Thread safe template class for queuing items. diff --git a/src/lib/utils/rotatefile.cpp b/src/lib/utils/rotatefile.cpp index 527cc0a2..49de8e3f 100644 --- a/src/lib/utils/rotatefile.cpp +++ b/src/lib/utils/rotatefile.cpp @@ -27,7 +27,7 @@ #include #include "clock.h" -using namespace std; +using std::streamsize; RotateFile::~RotateFile() { if (m_stream) { diff --git a/src/lib/utils/rotatefile.h b/src/lib/utils/rotatefile.h index 6a4c6a3d..5abfc38d 100644 --- a/src/lib/utils/rotatefile.h +++ b/src/lib/utils/rotatefile.h @@ -28,7 +28,7 @@ * Helpers for writing to rotating files. */ -using namespace std; +using std::string; /** * Helper class for writing to a rotating file with maximum size. diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index c8f2d321..69a9d045 100644 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -23,8 +23,6 @@ #include #include -using namespace std; - TCPSocket::TCPSocket(int sfd, struct sockaddr_in* address) : m_sfd(sfd) { char ip[17]; inet_ntop(AF_INET, (struct in_addr*)&(address->sin_addr.s_addr), ip, (socklen_t)sizeof(ip)-1); diff --git a/src/lib/utils/tcpsocket.h b/src/lib/utils/tcpsocket.h index e16f5eea..b0dc1879 100644 --- a/src/lib/utils/tcpsocket.h +++ b/src/lib/utils/tcpsocket.h @@ -26,7 +26,7 @@ /** \file tcpsocket.h */ -using namespace std; +using std::string; #ifdef __MACH__ #ifndef MSG_NOSIGNAL diff --git a/src/tools/ebusctl.cpp b/src/tools/ebusctl.cpp index 828ee8e1..ebbd5b9c 100644 --- a/src/tools/ebusctl.cpp +++ b/src/tools/ebusctl.cpp @@ -32,8 +32,10 @@ #include #include "tcpsocket.h" - -using namespace std; +using std::ostringstream; +using std::cin; +using std::cout; +using std::endl; /** A structure holding all program options. */ struct options { diff --git a/src/tools/ebusfeed.cpp b/src/tools/ebusfeed.cpp index 48fd6156..4d68e07f 100644 --- a/src/tools/ebusfeed.cpp +++ b/src/tools/ebusfeed.cpp @@ -28,8 +28,17 @@ #include #include #include "device.h" +#include "result.h" -using namespace std; +using std::hex; +using std::fstream; +using std::cout; +using std::endl; +using std::setw; +using std::setfill; +using std::ios; +using ebusd::result_t; +using ebusd::Device; /** A structure holding all program options. */ struct options { @@ -133,7 +142,7 @@ int main(int argc, char* argv[]) { return EINVAL; } result_t result = device->open(); - if (result != RESULT_OK) { + if (result != ebusd::RESULT_OK) { cout << "unable to open " << opt.device << ": " << getResultCode(result) << endl; } if (!device->isValid()) { From 0217096b6b5e62cc1611b4ca67f2ed229772f46c Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 14 Jan 2017 17:34:02 +0100 Subject: [PATCH 3/4] code style --- src/ebusd/bushandler.cpp | 6 +-- src/ebusd/bushandler.h | 5 ++- src/ebusd/datahandler.cpp | 1 + src/ebusd/main.cpp | 2 +- src/ebusd/mainloop.cpp | 4 +- src/ebusd/mqtthandler.cpp | 8 ++-- src/ebusd/network.h | 2 +- src/lib/ebus/data.cpp | 29 +++++++----- src/lib/ebus/datatype.cpp | 48 ++++++++++---------- src/lib/ebus/datatype.h | 25 ++++++----- src/lib/ebus/device.cpp | 8 ++-- src/lib/ebus/device.h | 2 +- src/lib/ebus/message.cpp | 74 +++++++++++++++---------------- src/lib/ebus/message.h | 17 +++---- src/lib/ebus/symbol.cpp | 2 +- src/lib/ebus/test/test_device.cpp | 1 + src/lib/ebus/test/test_symbol.cpp | 1 + src/lib/utils/log.cpp | 4 +- src/lib/utils/rotatefile.cpp | 2 +- src/lib/utils/rotatefile.h | 7 +-- src/lib/utils/tcpsocket.cpp | 2 +- src/lib/utils/thread.cpp | 2 +- 22 files changed, 132 insertions(+), 120 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index d8881e24..23ab2058 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -320,7 +320,7 @@ void BusHandler::run() { } result_t BusHandler::handleSymbol() { - long timeout = SYN_TIMEOUT; + unsigned int timeout = SYN_TIMEOUT; unsigned char sendSymbol = ESC; bool sending = false; BusRequest* startRequest = NULL; @@ -879,7 +879,7 @@ void BusHandler::receiveCompleted() { } Message* message = m_messages->find(m_command); if (m_grabMessages) { - unsigned long long key; + uint64_t key; if (message) { key = message->getKey(); } else { @@ -1110,7 +1110,7 @@ void BusHandler::formatGrabResult(const bool unknown, ostringstream& output) { output << "grab disabled"; } else { bool first = true; - for (map::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end(); it++) { + for (map::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end(); it++) { if (it->second.dump(unknown, m_messages, first, output)) { first = false; } diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index 6765b951..be93e07e 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -20,6 +20,7 @@ #define EBUSD_BUSHANDLER_H_ #include +#include #include #include #include @@ -588,7 +589,7 @@ class BusHandler : public WaitThread { unsigned int m_remainLockCount; /** the interval in microseconds after which to generate an AUTO-SYN symbol, or 0 if disabled. */ - long m_generateSynInterval; + unsigned int m_generateSynInterval; /** the interval in seconds in which poll messages are cycled, or 0 if disabled. */ const unsigned int m_pollInterval; @@ -649,7 +650,7 @@ class BusHandler : public WaitThread { bool m_grabMessages; /** the grabbed messages by key.*/ - map m_grabbedMessages; + map m_grabbedMessages; }; } // namespace ebusd diff --git a/src/ebusd/datahandler.cpp b/src/ebusd/datahandler.cpp index 7d5fa679..f3020182 100644 --- a/src/ebusd/datahandler.cpp +++ b/src/ebusd/datahandler.cpp @@ -22,6 +22,7 @@ #include "datahandler.h" #include +#include #ifdef HAVE_MQTT # include "mqtthandler.h" #endif diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index d203c8d1..9c7e61b1 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -861,7 +861,7 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolS if (::isspace(*it)) { ident.erase(it--); } else { - *it = (char)::tolower(*it); + *it = static_cast(::tolower(*it)); } } // complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 8a023d7a..abfc1150 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -615,14 +615,14 @@ string MainLoop::executeRead(vector &args) { " Dx data byte(s) to send"; } string fieldName; - signed char fieldIndex = -2; + char fieldIndex = -2; if (args.size() == argPos + 2) { fieldName = args[argPos + 1]; fieldIndex = -1; size_t pos = fieldName.find_last_of('.'); if (pos != string::npos) { result_t result = RESULT_OK; - fieldIndex = (char)parseInt(fieldName.substr(pos+1).c_str(), 10, 0, MAX_POS, result); + fieldIndex = static_cast(parseInt(fieldName.substr(pos+1).c_str(), 10, 0, MAX_POS, result)); if (result == RESULT_OK) { fieldName = fieldName.substr(0, pos); } diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 62dc70e1..1b6e4725 100644 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -215,7 +215,7 @@ MqttHandler::MqttHandler(BusHandler* busHandler, MessageMap* messages) #if (LIBMOSQUITTO_MAJOR < 1) true, #endif - willTopic.c_str(), (uint32_t)len, (uint8_t*)(willData.c_str()), 0, true); + willTopic.c_str(), (uint32_t)len, reinterpret_cast(willData.c_str()), 0, true); if (mosquitto_connect(m_mosquitto, g_host, g_port, 60 #if (LIBMOSQUITTO_MAJOR < 1) , true @@ -250,12 +250,12 @@ void on_message( struct mosquitto *mosq, #endif void *obj, const struct mosquitto_message *message) { - MqttHandler* handler = (MqttHandler*)obj; + MqttHandler* handler = reinterpret_cast(obj); if (!handler || !message || !handler->isRunning()) { return; } string topic(message->topic); - string data(message->payloadlen > 0 ? (char*)message->payload : ""); + string data(message->payloadlen > 0 ? reinterpret_cast(message->payload) : ""); handler->notifyTopic(topic, data); } @@ -455,7 +455,7 @@ void MqttHandler::publishMessage(Message* message, ostringstream& updates) { void MqttHandler::publishTopic(string topic, string data, bool retain) { logOtherDebug("mqtt", "publish %s %s", topic.c_str(), data.c_str()); - mosquitto_publish(m_mosquitto, NULL, topic.c_str(), (uint32_t)data.size(), (uint8_t*)(data.c_str()), 0, retain); + mosquitto_publish(m_mosquitto, NULL, topic.c_str(), (uint32_t)data.size(), reinterpret_cast(data.c_str()), 0, retain); } } // namespace ebusd diff --git a/src/ebusd/network.h b/src/ebusd/network.h index b79654fb..aa0e0029 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -94,7 +94,7 @@ class NetMessage { if (sscanf("%1x%1x", m_request.c_str()+pos+1, &value1, &value2) < 2) { break; } - m_request[pos] = (char)(((value1&0x0f)<<4) | (value2&0x0f)); + m_request[pos] = static_cast(((value1&0x0f)<<4) | (value2&0x0f)); m_request.erase(pos+1, 2); } } else if (pos+1 == m_request.length()) { diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 44380ebf..acd96ca5 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -128,7 +128,7 @@ result_t DataField::create(vector::iterator& it, FileReader::trim(token); const char* str = token.c_str(); char* strEnd = NULL; - unsigned long int id; + unsigned long id; if (strncasecmp(str, "0x", 2) == 0) { str += 2; id = strtoul(str, &strEnd, 16); // hexadecimal @@ -296,7 +296,7 @@ result_t SingleDataField::create(const string id, const unsigned char length, return RESULT_OK; } if (dataType->isNumeric()) { - NumberDataType* numType = (NumberDataType*)dataType; + NumberDataType* numType = reinterpret_cast(dataType); if (values.empty() && numType->hasFlag(DAY)) { for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++) values[numType->getMinValue() + i] = dayNames[i]; @@ -318,7 +318,7 @@ result_t SingleDataField::create(const string id, const unsigned char length, if (divisor != 0 || !values.empty()) { return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field } - returnField = new SingleDataField(name, comment, unit, (StringDataType*)dataType, partType, byteCount); + returnField = new SingleDataField(name, comment, unit, dataType, partType, byteCount); return RESULT_OK; } @@ -488,7 +488,7 @@ result_t SingleDataField::derive(string name, string comment, } DataType* dataType = m_dataType; if (numeric) { - NumberDataType* numType = (NumberDataType*)m_dataType; + NumberDataType* numType = reinterpret_cast(dataType); result_t result = numType->derive(divisor, 0, numType); if (result != RESULT_OK) { return result; @@ -497,8 +497,10 @@ result_t SingleDataField::derive(string name, string comment, } if (values.empty()) { fields.push_back(new SingleDataField(name, comment, unit, dataType, partType, m_length)); + } else if (numeric) { + fields.push_back(new ValueListDataField(name, comment, unit, reinterpret_cast(dataType), partType, m_length, values)); } else { - fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)dataType, partType, m_length, values)); + return RESULT_ERR_INVALID_ARG; } return RESULT_OK; } @@ -520,7 +522,7 @@ bool SingleDataField::hasFullByteOffset(bool after) { if (m_length > 1 || !m_dataType->isNumeric()) { return true; } - NumberDataType* num = (NumberDataType*)m_dataType; + NumberDataType* num = reinterpret_cast(m_dataType); return (num->getBitCount() % 8) == 0 || (after && num->getFirstBit() + (num->getBitCount() % 8) >= 8); } @@ -549,15 +551,18 @@ result_t ValueListDataField::derive(string name, string comment, if (divisor != 0 && divisor != 1) { return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field } + if (!m_dataType->isNumeric()) { + return RESULT_ERR_INVALID_ARG; + } if (!values.empty()) { - NumberDataType* num = (NumberDataType*)m_dataType; + NumberDataType* num = reinterpret_cast(m_dataType); if (values.begin()->first < num->getMinValue() || values.rbegin()->first > num->getMaxValue()) { return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field } } else { values = m_values; } - fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)m_dataType, partType, m_length, values)); + fields.push_back(new ValueListDataField(name, comment, unit, reinterpret_cast(m_dataType), partType, m_length, values)); return RESULT_OK; } @@ -617,7 +622,7 @@ result_t ValueListDataField::readSymbols(SymbolString& input, const bool isMaste result_t ValueListDataField::writeSymbols(istringstream& input, const unsigned char offset, SymbolString& output, const bool isMaster, unsigned char* usedLength) { - NumberDataType* numType = (NumberDataType*)m_dataType; + NumberDataType* numType = reinterpret_cast(m_dataType); if (isIgnored()) { return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value } @@ -721,9 +726,9 @@ DataFieldSet* DataFieldSet::s_identFields = NULL; DataFieldSet* DataFieldSet::getIdentFields() { if (s_identFields == NULL) { - NumberDataType* uchDataType = (NumberDataType*)DataTypeList::getInstance()->get("UCH"); - StringDataType* stringDataType = (StringDataType*)DataTypeList::getInstance()->get("STR"); - NumberDataType* pinDataType = (NumberDataType*)DataTypeList::getInstance()->get("PIN"); + NumberDataType* uchDataType = reinterpret_cast(DataTypeList::getInstance()->get("UCH")); + StringDataType* stringDataType = reinterpret_cast(DataTypeList::getInstance()->get("STR")); + NumberDataType* pinDataType = reinterpret_cast(DataTypeList::getInstance()->get("PIN")); map manufacturers; manufacturers[0x06] = "Dungs"; manufacturers[0x0f] = "FH Ostfalia"; diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 7f73856a..2828232e 100644 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -43,7 +43,7 @@ using std::setw; unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue, result_t& result, unsigned int* length) { char* strEnd = NULL; - unsigned long int ret = strtoul(str, &strEnd, base); + unsigned long ret = strtoul(str, &strEnd, base); if (strEnd == NULL || strEnd == str || *strEnd != 0) { result = RESULT_ERR_INVALID_NUM; // invalid value @@ -64,7 +64,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result, unsigned int* length) { char* strEnd = NULL; - long int ret = strtol(str, &strEnd, base); + long ret = strtol(str, &strEnd, base); if (strEnd == NULL || *strEnd != 0) { result = RESULT_ERR_INVALID_NUM; // invalid value @@ -79,7 +79,7 @@ int parseSignedInt(const char* str, int base, const int minValue, const int maxV *length = (unsigned int)(strEnd - str); } result = RESULT_OK; - return (int)ret; + return static_cast(ret); } void printErrorPos(ostream& out, vector::iterator begin, const vector::iterator end, vector::iterator pos, string filename, size_t lineNo, result_t result) { @@ -337,9 +337,9 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster, break; } int mjd = last + ch*256 + 15020; // 01.01.1900 - int y = (int)((mjd-15078.2)/365.25); - int m = (int)((mjd-14956.1-(int)(y*365.25))/30.6001); - int d = mjd-14956-(int)(y*365.25)-(int)(m*30.6001); + int y = static_cast((mjd-15078.2)/365.25); + int m = static_cast((mjd-14956.1-static_cast(y*365.25))/30.6001); + int d = mjd-14956-static_cast(y*365.25)-static_cast(m*30.6001); m--; if (m >= 13) { y++; @@ -470,7 +470,7 @@ result_t DateTimeDataType::writeSymbols(istringstream& input, } else if (i + 1 == count) { int y = (value < 100 ? value + 2000 : value) - 1900; int l = last <= 2 ? 1 : 0; - int mjd = 14956 + lastLast + (int)((y-l)*365.25) + (int)((last+1+l*12)*30.6001); + int mjd = 14956 + lastLast + static_cast((y-l)*365.25) + static_cast((last+1+l*12)*30.6001); value = mjd - 15020; // 01.01.1900 output[baseOffset + offset] = (unsigned char)(value&0xff); value >>= 8; @@ -484,7 +484,7 @@ result_t DateTimeDataType::writeSymbols(istringstream& input, // calculate local week day int y = (value < 100 ? value + 2000 : value) - 1900; int l = last <= 2 ? 1 : 0; - int mjd = 14956 + lastLast + (int)((y-l)*365.25) + (int)((last+1+l*12)*30.6001); + int mjd = 14956 + lastLast + static_cast((y-l)*365.25) + static_cast((last+1+l*12)*30.6001); int daysSinceSunday = (mjd+3) % 7; // Sun=0 if (hasFlag(BCD)) { output[baseOffset + offset - incr] = (unsigned char)((6+daysSinceSunday) % 7); // Sun=0x06 @@ -737,7 +737,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster, value = __builtin_bswap32(value); # endif unsigned char* pval = (unsigned char*)&value; - val = *((float*)pval); + val = *reinterpret_cast(pval); #else int exp = (value >> 23) & 0xff; // 8 bits, signed if (exp == 0) { @@ -745,7 +745,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster, } else { exp -= 127; unsigned int sig = value & ((1 << 23) - 1); - val = (1.0f + (float)(sig / exp2(23))) * (float)exp2(exp); + val = (1.0f + static_cast(sig / exp2(23))) * static_cast(exp2(exp)); if (negative) { val = -val; } @@ -753,9 +753,9 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster, #endif if (val != 0.0) { if (m_divisor < 0) { - val *= (float)-m_divisor; + val *= static_cast(-m_divisor); } else if (m_divisor > 1) { - val /= (float)m_divisor; + val /= static_cast(m_divisor); } } if (m_precision != 0) { @@ -768,24 +768,24 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster, } if (!negative) { if (m_divisor < 0) { - output << static_cast((float)value * (float)(-m_divisor)); + output << (static_cast(value) * static_cast(-m_divisor)); } else if (m_divisor <= 1) { output << static_cast(value); } else { output << setprecision(m_precision) - << fixed << static_cast((float)value / (float)m_divisor); + << fixed << (static_cast(value) / static_cast(m_divisor)); } return RESULT_OK; } - signedValue = (int)value; // negative signed value + signedValue = static_cast(value); // negative signed value } else if (negative) { // negative signed value - signedValue = (int)value - (1 << m_bitCount); + signedValue = static_cast(value) - (1 << m_bitCount); } else { - signedValue = (int)value; + signedValue = static_cast(value); } if (m_divisor < 0) { output << fixed << setprecision(0) - << static_cast((float)signedValue * (float)(-m_divisor)); + << (static_cast(signedValue) * static_cast(-m_divisor)); } else if (m_divisor <= 1) { if (hasFlag(FIX) && hasFlag(BCD)) { if (outputFormat & OF_JSON) { @@ -800,7 +800,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster, output << static_cast(signedValue) << setw(0); } else { output << setprecision(m_precision) - << fixed << static_cast((float)signedValue / (float)m_divisor); + << fixed << (static_cast(signedValue) / static_cast(m_divisor)); } return RESULT_OK; } @@ -873,9 +873,9 @@ result_t NumberDataType::writeSymbols(istringstream& input, dvalue *= m_divisor; } #ifdef HAVE_DIRECT_FLOAT_FORMAT - float val = (float)dvalue; + float val = static_cast(dvalue); unsigned char* pval = (unsigned char*)&val; - value = *((int32_t*)pval); + value = *reinterpret_cast(pval); # if HAVE_DIRECT_FLOAT_FORMAT == 2 value = __builtin_bswap32(value); # endif @@ -903,7 +903,7 @@ result_t NumberDataType::writeSymbols(istringstream& input, char* strEnd = NULL; if (m_divisor == 1) { if (hasFlag(SIG)) { - long int signedValue = strtol(str, &strEnd, 10); + long signedValue = strtol(str, &strEnd, 10); if (signedValue < 0 && m_bitCount != 32) { value = (unsigned int)(signedValue + (1 << m_bitCount)); } else { @@ -931,9 +931,9 @@ result_t NumberDataType::writeSymbols(istringstream& input, return RESULT_ERR_OUT_OF_RANGE; // value out of range } if (dvalue < 0 && m_bitCount != 32) { - value = (int)(dvalue + (1 << m_bitCount)); + value = static_cast(dvalue + (1 << m_bitCount)); } else { - value = (int)dvalue; + value = static_cast(dvalue); } } else { if (dvalue < 0.0 || dvalue >= (1LL << (8 * length))) { diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index ed083b0f..3d4608e5 100644 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -19,6 +19,7 @@ #ifndef LIB_EBUS_DATATYPE_H_ #define LIB_EBUS_DATATYPE_H_ +#include #include #include #include @@ -158,7 +159,7 @@ class DataType { * @param flags the combination of flags (like #BCD). * @param replacement the replacement value (fill-up value for @a StringDataType, no replacement if equal to @a NumberDataType#minValue). */ - DataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement) + DataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement) : m_id(id), m_bitCount(bitCount), m_flags(flags), m_replacement(replacement) {} /** @@ -261,7 +262,7 @@ class DataType { const unsigned char m_bitCount; /** the combination of flags (like #BCD). */ - const unsigned short m_flags; + const uint16_t m_flags; /** the replacement value (fill-up value for @a StringDataType, no replacement if equal to @a NumberDataType#minValue). */ const unsigned int m_replacement; @@ -281,7 +282,7 @@ class StringDataType : public DataType { * @param replacement the replacement value (fill-up value). * @param isHex true for hex digits instead of characters. */ - StringDataType(const string id, const unsigned char bitCount, const unsigned short flags, + StringDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement, bool isHex = false) : DataType(id, bitCount, flags, replacement), m_isHex(isHex) {} @@ -327,8 +328,8 @@ class DateTimeDataType : public DataType { * @param hasTime true if time part is present. * @param resolution the the resolution in minutes for time types, or 1. */ - DateTimeDataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement, - const bool hasDate, const bool hasTime, const short resolution) + DateTimeDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement, + const bool hasDate, const bool hasTime, const int16_t resolution) : DataType(id, bitCount, flags, replacement), m_hasDate(hasDate), m_hasTime(hasTime), m_resolution(resolution) {} /** @@ -349,7 +350,7 @@ class DateTimeDataType : public DataType { /** * @return the resolution in minutes for time types, or 1. */ - short getResolution() const { return m_resolution; } + int16_t getResolution() const { return m_resolution; } // @copydoc virtual result_t readRawValue(SymbolString& input, @@ -375,7 +376,7 @@ class DateTimeDataType : public DataType { const bool m_hasTime; /** the resolution in minutes for time types, or 1. */ - const short m_resolution; + const int16_t m_resolution; }; @@ -394,7 +395,7 @@ class NumberDataType : public DataType { * @param maxValue the maximum raw value. * @param divisor the divisor (negative for reciprocal). */ - NumberDataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement, + NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement, const unsigned int minValue, const unsigned int maxValue, const int divisor) : DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue), m_divisor(divisor), m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(NULL) {} @@ -407,8 +408,8 @@ class NumberDataType : public DataType { * @param firstBit the offset to the first bit. * @param divisor the divisor (negative for reciprocal). */ - NumberDataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement, - const short firstBit, const int divisor) + NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement, + const int16_t firstBit, const int divisor) : DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1<(&address), 0, sizeof(address)); *portpos = 0; if (inet_aton(addrpos, &address.sin_addr) == 0) { struct hostent* h = gethostbyname(addrpos); @@ -111,7 +111,7 @@ result_t Device::send(const unsigned char value) { return RESULT_OK; } -result_t Device::recv(const long timeout, unsigned char& value) { +result_t Device::recv(const unsigned int timeout, unsigned char& value) { if (!isValid()) { return RESULT_ERR_DEVICE; } @@ -254,9 +254,9 @@ result_t NetworkDevice::open() { ret = bind(m_fd, (struct sockaddr*)&address, sizeof(address)); } else { int value = 1; - ret = setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, (void*)&value, sizeof(value)); + ret = setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&value), sizeof(value)); value = 1; - setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&value, sizeof(value)); + setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast(&value), sizeof(value)); } if (ret == 0) { ret = connect(m_fd, (struct sockaddr*)&m_address, sizeof(m_address)); diff --git a/src/lib/ebus/device.h b/src/lib/ebus/device.h index 9381f3c1..cb17d7d8 100644 --- a/src/lib/ebus/device.h +++ b/src/lib/ebus/device.h @@ -119,7 +119,7 @@ class Device { * @param value the reference in which the received byte value is stored. * @return the result_t code. */ - result_t recv(const long timeout, unsigned char& value); + result_t recv(const unsigned int timeout, unsigned char& value); /** * Return the device name. diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index eb4ad0ec..e799bf2b 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -92,13 +92,13 @@ Message::Message(const string circuit, const string name, m_lastUpdateTime(0), m_lastChangeTime(0), m_pollCount(0), m_lastPollTime(0) { m_id.push_back(pb); m_id.push_back(sb); - unsigned long long key = 0; + uint64_t key = 0; if (!isPassive) { key |= (isWrite ? 0x1fLL : 0x1eLL) << (8 * 7); // special values for active } - key |= (unsigned long long)SYN << (8 * 6); - key |= (unsigned long long)pb << (8 * 5); - key |= (unsigned long long)sb << (8 * 4); + key |= (uint64_t)SYN << (8 * 6); + key |= (uint64_t)pb << (8 * 5); + key |= (uint64_t)sb << (8 * 4); m_key = key; setScanMessage(); } @@ -134,19 +134,19 @@ string getDefault(const string value, vector* defaults, size_t pos, bool return defaultStr.substr(0, insertPos)+value+defaultStr.substr(insertPos+1); } -unsigned long long Message::createKey(const vector id, +uint64_t Message::createKey(const vector id, const bool isWrite, const bool isPassive, const unsigned char srcAddress, const unsigned char dstAddress) { - unsigned long long key = (unsigned long long)(id.size()-2) << (8 * 7 + 5); + uint64_t key = (uint64_t)(id.size()-2) << (8 * 7 + 5); if (isPassive) { - key |= (unsigned long long)getMasterNumber(srcAddress) << (8 * 7); // 0..25 + key |= (uint64_t)getMasterNumber(srcAddress) << (8 * 7); // 0..25 } else { key |= (isWrite ? 0x1fLL : 0x1eLL) << (8 * 7); // special values for active } - key |= (unsigned long long)dstAddress << (8 * 6); + key |= (uint64_t)dstAddress << (8 * 6); int exp = 5; for (vector::const_iterator it = id.begin(); it < id.end(); it++) { - key ^= (unsigned long long)*it << (8 * exp--); + key ^= (uint64_t)*it << (8 * exp--); if (exp == 0) { exp = 3; } @@ -154,7 +154,7 @@ unsigned long long Message::createKey(const vector id, return key; } -unsigned long long Message::createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination) { +uint64_t Message::createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination) { if (master.size() < 5) { return INVALID_KEY; } @@ -165,14 +165,14 @@ unsigned long long Message::createKey(SymbolString& master, unsigned char maxIdL if (master.size() < 5+idLength) { return INVALID_KEY; } - unsigned long long key = (unsigned long long)idLength << (8 * 7 + 5); - key |= (unsigned long long)getMasterNumber(master[0]) << (8 * 7); // QQ address for passive message - key |= (unsigned long long)(anyDestination ? SYN : master[1]) << (8 * 6); // ZZ address - key |= (unsigned long long)master[2] << (8 * 5); // PB - key |= (unsigned long long)master[3] << (8 * 4); // SB + uint64_t key = (uint64_t)idLength << (8 * 7 + 5); + key |= (uint64_t)getMasterNumber(master[0]) << (8 * 7); // QQ address for passive message + key |= (uint64_t)(anyDestination ? SYN : master[1]) << (8 * 6); // ZZ address + key |= (uint64_t)master[2] << (8 * 5); // PB + key |= (uint64_t)master[3] << (8 * 4); // SB int exp = 3; for (unsigned char i = 0; i < idLength; i++) { - key ^= (unsigned long long)master[5 + i] << (8 * exp--); + key ^= (uint64_t)master[5 + i] << (8 * exp--); if (exp == 0) { exp = 3; } @@ -190,11 +190,11 @@ result_t Message::parseId(string input, vector& id) { break; } input.clear(); - input.push_back((char)in.get()); + input.push_back(static_cast(in.get())); if (in.eof()) { return RESULT_ERR_INVALID_ARG; // too short hex } - input.push_back((char)in.get()); + input.push_back(static_cast(in.get())); result_t result; unsigned char value = (unsigned char)parseInt(input.c_str(), 16, 0, 0xff, result); @@ -522,8 +522,8 @@ bool Message::checkId(Message& other) { return other.checkIdPrefix(m_id); } -unsigned long long Message::getDerivedKey(const unsigned char dstAddress) { - return (m_key & ~(0xffLL << (8*6))) | (unsigned long long)dstAddress << (8*6); +uint64_t Message::getDerivedKey(const unsigned char dstAddress) { + return (m_key & ~(0xffLL << (8*6))) | (uint64_t)dstAddress << (8*6); } bool Message::setPollPriority(unsigned char priority) { @@ -842,10 +842,10 @@ ChainedMessage::ChainedMessage(const string circuit, const string name, m_ids(ids), m_lengths(lengths), m_maxTimeDiff(m_ids.size()*15) { // 15 seconds per message size_t cnt = ids.size(); - m_lastMasterDatas = (SymbolString**)calloc(cnt, sizeof(SymbolString*)); - m_lastSlaveDatas = (SymbolString**)calloc(cnt, sizeof(SymbolString*)); - m_lastMasterUpdateTimes = (time_t*)calloc(cnt, sizeof(time_t)); - m_lastSlaveUpdateTimes = (time_t*)calloc(cnt, sizeof(time_t)); + m_lastMasterDatas = reinterpret_cast(calloc(cnt, sizeof(SymbolString*))); + m_lastSlaveDatas = reinterpret_cast(calloc(cnt, sizeof(SymbolString*))); + m_lastMasterUpdateTimes = reinterpret_cast(calloc(cnt, sizeof(time_t))); + m_lastSlaveUpdateTimes = reinterpret_cast(calloc(cnt, sizeof(time_t))); for (size_t index = 0; index < cnt; index++) { m_lastMasterDatas[index] = new SymbolString(); m_lastSlaveDatas[index] = new SymbolString(); @@ -1331,7 +1331,7 @@ result_t SimpleCondition::resolve(MessageMap* messages, ostringstream& errorMess return RESULT_ERR_INVALID_ADDR; } // clone the message with dedicated dstAddress if necessary - unsigned long long key = message->getDerivedKey(m_dstAddress); + uint64_t key = message->getDerivedKey(m_dstAddress); vector* derived = messages->getByKey(key); if (derived == NULL) { message = message->derive(m_dstAddress, true); @@ -1524,10 +1524,10 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond result_t MessageMap::add(Message* message, bool storeByName) { - unsigned long long key = message->getKey(); + uint64_t key = message->getKey(); bool conditional = message->isConditional(); if (!m_addAll) { - map >::iterator keyIt = m_messagesByKey.find(key); + map >::iterator keyIt = m_messagesByKey.find(key); if (keyIt != m_messagesByKey.end()) { Message* other = getFirstAvailable(keyIt->second, message); if (other != NULL) { @@ -1768,7 +1768,7 @@ Message* MessageMap::getScanMessage(const unsigned char dstAddress) { if (!isValidAddress(dstAddress, false) || isMaster(dstAddress)) { return NULL; } - unsigned long long key = m_scanMessage->getDerivedKey(dstAddress); + uint64_t key = m_scanMessage->getDerivedKey(dstAddress); vector* msgs = getByKey(key); if (msgs != NULL) { return msgs->front(); @@ -1888,8 +1888,8 @@ string MessageMap::getLoadedFiles(unsigned char address) { return m_loadedFiles[address]; } -vector* MessageMap::getByKey(const unsigned long long key) { - map >::iterator it = m_messagesByKey.find(key); +vector* MessageMap::getByKey(const uint64_t key) { + map >::iterator it = m_messagesByKey.find(key); if (it != m_messagesByKey.end()) { return &it->second; } @@ -2002,26 +2002,26 @@ Message* MessageMap::find(SymbolString& master, bool anyDestination, if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) { return m_scanMessage; } - unsigned long long baseKey = Message::createKey(master, m_maxIdLength, anyDestination); + uint64_t baseKey = Message::createKey(master, m_maxIdLength, anyDestination); if (baseKey == INVALID_KEY) { return NULL; } unsigned char maxIdLength = Message::getKeyLength(baseKey); for (unsigned char idLength = maxIdLength; true; idLength--) { - unsigned long long key = baseKey; + uint64_t key = baseKey; if (idLength == maxIdLength) { baseKey &= ~ID_LENGTH_AND_IDS_MASK; } else { - key |= (unsigned long long)idLength << (8 * 7 + 5); + key |= (uint64_t)idLength << (8 * 7 + 5); int exp = 3; for (unsigned char i = 0; i < idLength; i++) { - key ^= (unsigned long long)master[5 + i] << (8 * exp--); + key ^= (uint64_t)master[5 + i] << (8 * exp--); if (exp == 0) { exp = 3; } } } - map >::iterator it; + map >::iterator it; if (withPassive) { it = m_messagesByKey.find(key); if (it != m_messagesByKey.end()) { @@ -2105,7 +2105,7 @@ void MessageMap::clear() { if (it->first[0] != '-') { // avoid double free: instances stored multiple times have a key starting with "-" for (vector::iterator nit = nameMessages.begin(); nit != nameMessages.end(); nit++) { Message* message = *nit; - map >::iterator keyIt = m_messagesByKey.find(message->getKey()); + map >::iterator keyIt = m_messagesByKey.find(message->getKey()); if (keyIt != m_messagesByKey.end()) { vector* keyMessages = &keyIt->second; if (!keyMessages->empty()) { @@ -2122,7 +2122,7 @@ void MessageMap::clear() { nameMessages.clear(); } // free remaining message instances by key - for (map >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) { + for (map >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) { vector keyMessages = it->second; for (vector::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) { Message* message = *kit; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 4f373cc0..4baa25f4 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -19,6 +19,7 @@ #ifndef LIB_EBUS_MESSAGE_H_ #define LIB_EBUS_MESSAGE_H_ +#include #include #include #include @@ -160,7 +161,7 @@ class Message { * @param dstAddress the destination address, or @a SYN for any (set later). * @return the key for the ID. */ - static unsigned long long createKey(const vector id, + static uint64_t createKey(const vector id, const bool isWrite, const bool isPassive, const unsigned char srcAddress, const unsigned char dstAddress); @@ -171,7 +172,7 @@ class Message { * @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 unsigned long long createKey(SymbolString& master, + static uint64_t createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination = false); /** @@ -179,7 +180,7 @@ class Message { * @param key the key. * @return the length field from the key. */ - static unsigned char getKeyLength(unsigned long long key) { return (unsigned char)(key >> (8 * 7 + 5)); } + static unsigned char getKeyLength(uint64_t key) { return (unsigned char)(key >> (8 * 7 + 5)); } /** * Parse an ID part from the input @a string. @@ -332,14 +333,14 @@ class Message { * Return the key for storing in @a MessageMap. * @return the key for storing in @a MessageMap. */ - unsigned long long getKey() { return m_key; } + uint64_t getKey() { return m_key; } /** * Return the derived key for storing in @a MessageMap. * @param dstAddress the destination address for the derivation. * @return the derived key for storing in @a MessageMap. */ - unsigned long long getDerivedKey(const unsigned char dstAddress); + uint64_t getDerivedKey(const unsigned char dstAddress); /** * Get the polling priority, or 0 for no polling at all. @@ -573,7 +574,7 @@ class Message { *
  • bytes 3-0: ID bytes (with cyclic xor if more than 4)
  • * */ - unsigned long long m_key; + uint64_t m_key; /** the @a DataField for encoding/decoding the message. */ DataField* m_data; @@ -1228,7 +1229,7 @@ class MessageMap : public FileReader { * @return the found @a Message instances, or NULL. * Note: the caller may not free the returned instances. */ - vector* getByKey(const unsigned long long key); + vector* getByKey(const uint64_t key); /** * Find the @a Message instance for the specified circuit and name. @@ -1369,7 +1370,7 @@ class MessageMap : public FileReader { map > m_messagesByName; /** the known @a Message instances by key. */ - map > m_messagesByKey; + map > m_messagesByKey; /** the known @a Message instances to poll, by priority. */ MessagePriorityQueue m_pollMessages; diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index f402a9ba..cf76d060 100644 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -75,7 +75,7 @@ result_t SymbolString::parseHex(const string& str, const bool isEscaped) { for (size_t i = 0; i < str.size(); i += 2) { char* strEnd = NULL; const char* strBegin = str.substr(i, 2).c_str(); - unsigned long int value = strtoul(strBegin, &strEnd, 16); + unsigned long value = strtoul(strBegin, &strEnd, 16); if (strEnd == NULL || strEnd != strBegin+2 || value > 0xff) { return RESULT_ERR_INVALID_NUM; // invalid value diff --git a/src/lib/ebus/test/test_device.cpp b/src/lib/ebus/test/test_device.cpp index 7c79127f..b32e0005 100644 --- a/src/lib/ebus/test/test_device.cpp +++ b/src/lib/ebus/test/test_device.cpp @@ -20,6 +20,7 @@ #include #include "device.h" +using namespace std; using namespace ebusd; int main() { diff --git a/src/lib/ebus/test/test_symbol.cpp b/src/lib/ebus/test/test_symbol.cpp index bb191cd0..d168c62f 100644 --- a/src/lib/ebus/test/test_symbol.cpp +++ b/src/lib/ebus/test/test_symbol.cpp @@ -21,6 +21,7 @@ #include #include "symbol.h" +using namespace std; using namespace ebusd; static bool error = false; diff --git a/src/lib/utils/log.cpp b/src/lib/utils/log.cpp index aecc4f34..49cc25ab 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -57,7 +57,7 @@ static FILE* s_logFile = stdout; bool setLogFacilities(const char* facilities) { char *input = strdup(facilities); - char *opt = (char*)input, *value = NULL; + char *opt = reinterpret_cast(input), *value = NULL; int newFacilites = 0; while (*opt) { int val = getsubopt(&opt, (char *const *)facilityNames, &value); @@ -97,7 +97,7 @@ bool getLogFacilities(char* buffer) { bool setLogLevel(const char* level) { char *input = strdup(level); - char *opt = (char*)input, *value = NULL; + char *opt = reinterpret_cast(input), *value = NULL; int newLevel = 0; if (*opt) { int val = getsubopt(&opt, (char *const *)levelNames, &value); diff --git a/src/lib/utils/rotatefile.cpp b/src/lib/utils/rotatefile.cpp index 49de8e3f..3eafe6e8 100644 --- a/src/lib/utils/rotatefile.cpp +++ b/src/lib/utils/rotatefile.cpp @@ -77,7 +77,7 @@ void RotateFile::write(unsigned char* value, unsigned int size, bool received) { if ((m_fileSize%1024) == 0) { fflush(m_stream); } - if (m_fileSize >= m_maxSize * 1024) { + if (m_fileSize >= m_maxSize * 1024LL) { string oldfile = string(m_fileName)+".old"; if (rename(m_fileName.c_str(), oldfile.c_str()) == 0) { fclose(m_stream); diff --git a/src/lib/utils/rotatefile.h b/src/lib/utils/rotatefile.h index 5abfc38d..75d75eb2 100644 --- a/src/lib/utils/rotatefile.h +++ b/src/lib/utils/rotatefile.h @@ -20,6 +20,7 @@ #define LIB_UTILS_ROTATEFILE_H_ #include +#include #include #include #include @@ -41,7 +42,7 @@ class RotateFile { * @param maxSize the maximum size of the file to write to. * @param textMode whether to write each byte with prefixed timestamp and direction as text. */ - RotateFile(const string fileName, const unsigned long maxSize, const bool textMode = false) + RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false) : m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0) {} /** @@ -79,7 +80,7 @@ class RotateFile { const string m_fileName; /** the maximum size of @a m_file, or 0 for infinite. */ - const unsigned long m_maxSize; + const unsigned int m_maxSize; /** whether to write each byte with prefixed timestamp and direction as text. */ const bool m_textMode; @@ -88,7 +89,7 @@ class RotateFile { FILE* m_stream; /** the number of bytes already written to the @a m_file. */ - unsigned long m_fileSize; + uint64_t m_fileSize; }; #endif // LIB_UTILS_ROTATEFILE_H_ diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index 69a9d045..47b1cf80 100644 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -39,7 +39,7 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port) { struct sockaddr_in address; int ret; - memset((char*) &address, 0, sizeof(address)); + memset(reinterpret_cast(&address), 0, sizeof(address)); if (inet_addr(server.c_str()) == INADDR_NONE) { struct hostent* he; diff --git a/src/lib/utils/thread.cpp b/src/lib/utils/thread.cpp index 3132c0cc..197d3014 100644 --- a/src/lib/utils/thread.cpp +++ b/src/lib/utils/thread.cpp @@ -24,7 +24,7 @@ #include "clock.h" void* Thread::runThread(void* arg) { - ((Thread*)arg)->enter(); + reinterpret_cast(arg)->enter(); return NULL; } From 917414a6f825618dffcb173ab09922f520995aff Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 14 Jan 2017 17:58:47 +0100 Subject: [PATCH 4/4] code style --- src/ebusd/bushandler.h | 2 +- src/ebusd/datahandler.h | 2 +- src/ebusd/mainloop.cpp | 18 ++++++++++-------- src/ebusd/network.h | 4 ++-- src/lib/ebus/contrib/tem.cpp | 4 ++-- src/lib/ebus/contrib/tem.h | 2 +- src/lib/ebus/datatype.h | 2 +- src/lib/ebus/filereader.h | 2 +- src/lib/ebus/message.cpp | 4 ++-- src/lib/ebus/message.h | 2 +- src/lib/ebus/symbol.h | 2 +- src/lib/utils/log.cpp | 21 +++++++++++---------- src/lib/utils/log.h | 4 ++-- src/lib/utils/rotatefile.cpp | 8 ++++---- 14 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index be93e07e..6e333737 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -146,7 +146,7 @@ class PollRequest : public BusRequest { * Constructor. * @param message the associated @a Message. */ - PollRequest(Message* message) + explicit PollRequest(Message* message) : BusRequest(m_master, true), m_message(message), m_index(0) {} /** diff --git a/src/ebusd/datahandler.h b/src/ebusd/datahandler.h index c1ce33b0..3a51abab 100644 --- a/src/ebusd/datahandler.h +++ b/src/ebusd/datahandler.h @@ -128,7 +128,7 @@ class DataSource : virtual public DataHandler { * Constructor. * @param busHandler the @a BusHandler instance. */ - DataSource(BusHandler* busHandler) + explicit DataSource(BusHandler* busHandler) : m_busHandler(busHandler) {} /** diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index abfc1150..240a1343 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -1047,17 +1047,19 @@ string MainLoop::executeFind(vector &args) { if (verbosity == (OF_NAMES|OF_UNITS|OF_COMMENTS)) { unsigned char dstAddress = message->getDstAddress(); if (dstAddress != SYN) { - sprintf(str, "%02x", dstAddress); + snprintf(str, sizeof(str), "%02x", dstAddress); } else if (lastup != 0 && message->getLastMasterData().size() > 1) { - sprintf(str, "%02x", message->getLastMasterData()[1]); + snprintf(str, sizeof(str), "%02x", message->getLastMasterData()[1]); } else { - sprintf(str, "any"); + snprintf(str, sizeof(str), "any"); } if (lastup != 0) { - struct tm* td = localtime(&lastup); - sprintf(str+strlen(str), ", lastup=%04d-%02d-%02d %02d:%02d:%02d", - td->tm_year+1900, td->tm_mon+1, td->tm_mday, - td->tm_hour, td->tm_min, td->tm_sec); + struct tm td; + localtime_r(&lastup, &td); + size_t len = strlen(str); + snprintf(str+len, sizeof(str)-len, ", lastup=%04d-%02d-%02d %02d:%02d:%02d", + td.tm_year+1900, td.tm_mon+1, td.tm_mday, + td.tm_hour, td.tm_min, td.tm_sec); } result << " [ZZ=" << str; if (message->isPassive()) { @@ -1187,7 +1189,7 @@ string MainLoop::executeScan(vector &args) { string MainLoop::executeLog(vector &args) { if (args.size() == 1) { ostringstream ret; - char str[32]; + char str[48]; if (getLogFacilities(str)) { ret << str << ' '; } diff --git a/src/ebusd/network.h b/src/ebusd/network.h index aa0e0029..5ff91d13 100644 --- a/src/ebusd/network.h +++ b/src/ebusd/network.h @@ -44,7 +44,7 @@ class NetMessage { * Constructor. * @param isHttp whether this is a HTTP message. */ - NetMessage(const bool isHttp) + explicit NetMessage(const bool isHttp) : m_isHttp(isHttp), m_resultSet(false), m_disconnect(false), m_listening(false), m_listenSince(0) { pthread_mutex_init(&m_mutex, NULL); pthread_cond_init(&m_cond, NULL); @@ -94,7 +94,7 @@ class NetMessage { if (sscanf("%1x%1x", m_request.c_str()+pos+1, &value1, &value2) < 2) { break; } - m_request[pos] = static_cast(((value1&0x0f)<<4) | (value2&0x0f)); + m_request[pos] = static_cast(((value1&0x0f) << 4) | (value2&0x0f)); m_request.erase(pos+1, 2); } } else if (pos+1 == m_request.length()) { diff --git a/src/lib/ebus/contrib/tem.cpp b/src/lib/ebus/contrib/tem.cpp index adec6d55..70212851 100644 --- a/src/lib/ebus/contrib/tem.cpp +++ b/src/lib/ebus/contrib/tem.cpp @@ -129,9 +129,9 @@ result_t TemParamDataType::writeSymbols(istringstream& input, return RESULT_ERR_OUT_OF_RANGE; // value out of range } if (isMaster) { - value = grp | (num<<8); // grp in bits 0...5, num in bits 8...13 + value = grp | (num << 8); // grp in bits 0...5, num in bits 8...13 } else { - value = (grp<<7) | num; // grp in bits 7...11, num in bits 0...6 + value = (grp << 7) | num; // grp in bits 7...11, num in bits 0...6 } } if (value < getMinValue() || value > getMaxValue()) { diff --git a/src/lib/ebus/contrib/tem.h b/src/lib/ebus/contrib/tem.h index 5f412cfe..41a2b09d 100644 --- a/src/lib/ebus/contrib/tem.h +++ b/src/lib/ebus/contrib/tem.h @@ -46,7 +46,7 @@ class TemParamDataType : public NumberDataType { * Constructs a new instance. * @param id the type identifier. */ - TemParamDataType(const string id) + explicit TemParamDataType(const string id) : NumberDataType(id, 16, 0, 0xffff, 0, 0xffff, 0) {} // @copydoc diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index 3d4608e5..229b6ae3 100644 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -410,7 +410,7 @@ class NumberDataType : public DataType { */ NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement, const int16_t firstBit, const int divisor) - : DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1<::iterator& it, const vector::ite unsigned char dstAddress = *it; string useCircuit = circuit; if (multiple) { - sprintf(num, ".%d", index); + snprintf(num, sizeof(num), ".%d", index); useCircuit = useCircuit + num; } Message* message; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 4baa25f4..2b131801 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -1136,7 +1136,7 @@ class MessageMap : public FileReader { * Construct a new instance. * @param addAll whether to add all messages, even if duplicate. */ - MessageMap(const bool addAll = false) : FileReader::FileReader(true), + explicit MessageMap(const bool addAll = false) : FileReader::FileReader(true), m_addAll(addAll), m_maxIdLength(0), m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0) { m_scanMessage = Message::createScanMessage(); } diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index c43b6dbf..9789a6e6 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -84,7 +84,7 @@ class SymbolString { * Creates a new empty escaped or unescaped instance. * @param escaped whether to create an escaped instance. */ - SymbolString(const bool escaped = true) : m_unescapeState(escaped ? 0 : 1), m_crc(0) {} + explicit 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/utils/log.cpp b/src/lib/utils/log.cpp index 49cc25ab..7fa7de45 100644 --- a/src/lib/utils/log.cpp +++ b/src/lib/utils/log.cpp @@ -68,7 +68,7 @@ bool setLogFacilities(const char* facilities) { if (val == lf_COUNT) { newFacilites = LF_ALL; } else { - newFacilites |= 1<= level); } void logWrite(const char* facility, const char* level, const char* message, va_list ap) { struct timespec ts; - struct tm* tm; + struct tm td; clockGettime(&ts); - tm = localtime(&ts.tv_sec); + localtime_r(&ts.tv_sec, &td); char* buf; if (vasprintf(&buf, message, ap) >= 0 && buf) { fprintf(s_logFile, "%04d-%02d-%02d %02d:%02d:%02d.%03ld [%s %s] %s\n", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000, + td.tm_year+1900, td.tm_mon+1, td.tm_mday, + td.tm_hour, td.tm_min, td.tm_sec, ts.tv_nsec/1000000, facility, level, buf); fflush(s_logFile); } diff --git a/src/lib/utils/log.h b/src/lib/utils/log.h index 6bec2829..024be767 100644 --- a/src/lib/utils/log.h +++ b/src/lib/utils/log.h @@ -32,7 +32,7 @@ enum LogFacility { }; /** macro for enabling all log facilities. */ -#define LF_ALL ((1<tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, ts.tv_nsec/1000000, + td.tm_year+1900, td.tm_mon+1, td.tm_mday, + td.tm_hour, td.tm_min, td.tm_sec, ts.tv_nsec/1000000, received ? '<' : '>'); for (unsigned int pos = 0; pos < size; pos++) { fprintf(m_stream, "%2.2x ", value[pos]);