code style

This commit is contained in:
john30
2017-01-14 17:58:47 +01:00
parent 0217096b6b
commit 917414a6f8
14 changed files with 40 additions and 37 deletions
+1 -1
View File
@@ -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) {}
/**
+1 -1
View File
@@ -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) {}
/**
+10 -8
View File
@@ -1047,17 +1047,19 @@ string MainLoop::executeFind(vector<string> &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<string> &args) {
string MainLoop::executeLog(vector<string> &args) {
if (args.size() == 1) {
ostringstream ret;
char str[32];
char str[48];
if (getLogFacilities(str)) {
ret << str << ' ';
}
+2 -2
View File
@@ -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<char>(((value1&0x0f)<<4) | (value2&0x0f));
m_request[pos] = static_cast<char>(((value1&0x0f) << 4) | (value2&0x0f));
m_request.erase(pos+1, 2);
}
} else if (pos+1 == m_request.length()) {
+2 -2
View File
@@ -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()) {
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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<<bitCount)-1), m_divisor(divisor), m_precision(0), m_firstBit(firstBit), m_baseType(NULL) {}
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1 << bitCount)-1), m_divisor(divisor), m_precision(0), m_firstBit(firstBit), m_baseType(NULL) {}
/**
* Destructor.
+1 -1
View File
@@ -74,7 +74,7 @@ class FileReader {
/**
* Construct a new instance.
*/
FileReader(bool supportsDefaults)
explicit FileReader(bool supportsDefaults)
: m_supportsDefaults(supportsDefaults) {}
/**
+2 -2
View File
@@ -42,7 +42,7 @@ using std::setw;
#define ID_SOURCE_MASK (0x1fLL << (8 * 7))
/** the bit mask for the ID length and combined ID bytes in the message key. */
#define ID_LENGTH_AND_IDS_MASK ((7LL<<(8 * 7 + 5)) | 0xffffffffLL)
#define ID_LENGTH_AND_IDS_MASK ((7LL << (8 * 7 + 5)) | 0xffffffffLL)
/** the bits in the @a ID_SOURCE_MASK for arbitrary source and active read message. */
#define ID_SOURCE_ACTIVE_WRITE (0x1fLL << (8 * 7))
@@ -447,7 +447,7 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::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;
+1 -1
View File
@@ -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();
}
+1 -1
View File
@@ -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.
+11 -10
View File
@@ -68,7 +68,7 @@ bool setLogFacilities(const char* facilities) {
if (val == lf_COUNT) {
newFacilites = LF_ALL;
} else {
newFacilites |= 1<<val;
newFacilites |= 1 << val;
}
}
//s_lastFacilities = newFacilites;
@@ -79,17 +79,18 @@ bool setLogFacilities(const char* facilities) {
bool getLogFacilities(char* buffer) {
if (s_logFacilites == LF_ALL) {
return strcpy(buffer, facilityNames[lf_COUNT]) != NULL;
return snprintf(buffer, 48, "%s", facilityNames[lf_COUNT]) != 0;
}
*buffer = 0; // for strcat to work
bool found = false;
size_t len = 0;
for (int val = 0; val < lf_COUNT; val++) {
if (s_logFacilites&(1<<val)) {
if (s_logFacilites&(1 << val)) {
if (found) {
strcat(buffer, ",");
len += snprintf(buffer+len, 48-len, ",");
}
found = true;
strcat(buffer, facilityNames[val]);
len += snprintf(buffer+len, 48-len, "%s", facilityNames[val]);
}
}
return true;
@@ -136,20 +137,20 @@ void closeLogFile() {
}
bool needsLog(const LogFacility facility, const LogLevel level) {
return ((s_logFacilites & (1<<facility)) != 0)
return ((s_logFacilites & (1 << facility)) != 0)
&& (s_logLevel >= 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);
}
+2 -2
View File
@@ -32,7 +32,7 @@ enum LogFacility {
};
/** macro for enabling all log facilities. */
#define LF_ALL ((1<<lf_main) | (1<<lf_network) | (1<<lf_bus) | (1<<lf_update) | (1<<lf_other))
#define LF_ALL ((1 << lf_main) | (1 << lf_network) | (1 << lf_bus) | (1 << lf_update) | (1 << lf_other))
/** the available log levels. */
enum LogLevel {
@@ -53,7 +53,7 @@ bool setLogFacilities(const char* facilities);
/**
* Get the log facilities.
* @param buffer the buffer into which the facilities are written to (separated by comma, buffer needs to be at last 32 characters long).
* @param buffer the buffer into which the facilities are written to (separated by comma, buffer needs to be at last 48 characters long).
* @return true on success, false on error.
*/
bool getLogFacilities(char* buffer);
+4 -4
View File
@@ -58,12 +58,12 @@ void RotateFile::write(unsigned char* value, unsigned int size, bool received) {
}
if (m_textMode) {
struct timespec ts;
struct tm* tm;
struct tm td;
clockGettime(&ts);
tm = localtime(&ts.tv_sec);
localtime_r(&ts.tv_sec, &td);
fprintf(m_stream, "%04d-%02d-%02d %02d:%02d:%02d.%03ld %c",
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,
received ? '<' : '>');
for (unsigned int pos = 0; pos < size; pos++) {
fprintf(m_stream, "%2.2x ", value[pos]);