code style

This commit is contained in:
Roland Jax
2014-12-30 20:08:48 +01:00
parent df85caf71f
commit 612270f942
12 changed files with 85 additions and 53 deletions
+26 -15
View File
@@ -59,7 +59,8 @@ BaseLoop::BaseLoop()
if (pollInterval <= 0) {
m_pollActive = false;
pollInterval = 0;
} else
}
else
m_pollActive = true;
// create Port
@@ -142,7 +143,7 @@ void BaseLoop::start()
L.log(bas, event, "<<< %s", result.c_str());
// send result to client
result += '\n';
result += "\n\n";
message->setResult(result);
message->sendSignal();
@@ -177,7 +178,8 @@ string BaseLoop::decodeMessage(const string& data)
escaped = false;
}
token = previous + " " + token;
} else if (token.length() == 0) // allow multiple space chars for a single delimiter
}
else if (token.length() == 0) // allow multiple space chars for a single delimiter
continue;
else if (token[0] == '"') {
token = token.substr(1);
@@ -206,9 +208,11 @@ string BaseLoop::decodeMessage(const string& data)
while (args.size() > argPos && args[argPos][0] == '-') {
if (args[argPos] == "-f") {
maxAge = 0;
} else if (args[argPos] == "-v") {
}
else if (args[argPos] == "-v") {
verbose = true;
} else if (args[argPos] == "-m") {
}
else if (args[argPos] == "-m") {
argPos++;
if (args.size() > argPos) {
result_t result;
@@ -222,7 +226,8 @@ string BaseLoop::decodeMessage(const string& data)
argPos = 0; // print usage
break;
}
} else {
}
else {
argPos = 0; // print usage
break;
}
@@ -290,9 +295,11 @@ string BaseLoop::decodeMessage(const string& data)
L.log(bas, error, "read: %s", getResultCode(ret));
result << getResultCode(ret);
}
} else if (updateMessage != NULL) {
}
else if (updateMessage != NULL) {
result << "no data stored";
} else {
}
else {
result << "message not defined";
}
break;
@@ -379,7 +386,8 @@ string BaseLoop::decodeMessage(const string& data)
result << getResultCode(ret);
}
} else {
}
else {
result << "message not defined";
}
break;
@@ -390,22 +398,25 @@ string BaseLoop::decodeMessage(const string& data)
if (args[argPos] == "-v")
verbose = true;
else if (args[argPos] == "-r") {
if (first)
if (first == true)
first = false;
withRead = true;
} else if (args[argPos] == "-w") {
if (first) {
}
else if (args[argPos] == "-w") {
if (first == true) {
first = false;
withRead = false;
}
withWrite = true;
} else if (args[argPos] == "-p") {
if (first) {
}
else if (args[argPos] == "-p") {
if (first == true) {
first = false;
withRead = false;
}
withPassive = true;
} else {
}
else {
argPos = 0; // print usage
break;
}
+7 -4
View File
@@ -412,7 +412,8 @@ result_t BusHandler::handleSymbol()
if (isMaster(m_currentRequest->m_master[1]) == true) {
return setState(bs_sendSyn, RESULT_OK);
}
} else if (isMaster(m_command[1]) == true) {
}
else if (isMaster(m_command[1]) == true) {
receiveCompleted();
return setState(bs_skip, RESULT_OK);
}
@@ -591,7 +592,8 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
m_currentRequest->m_busLostRetries++;
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 == false)) {
LOG(bus, debug, "notify request: %s", getResultCode(result));
unsigned char dstAddress = m_currentRequest->m_master[1];
if (result == RESULT_OK && isValidAddress(dstAddress, false) == true)
@@ -630,7 +632,7 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
if (result < RESULT_OK || (result != RESULT_OK && state == bs_skip))
LOG(bus, debug, "%s during %s, switching to %s", getResultCode(result), getStateCode(m_state), getStateCode(state));
else if (m_currentRequest != NULL || state == bs_sendCmd || state==bs_sendResAck || state==bs_sendSyn)
else if (m_currentRequest != NULL || state == bs_sendCmd || state == bs_sendResAck || state == bs_sendSyn)
LOG(bus, debug, "switching from %s to %s", getStateCode(m_state), getStateCode(state));
m_state = state;
@@ -655,7 +657,8 @@ void BusHandler::receiveCompleted()
else if (master == true) {
LOG(upd, trace, "update MM cmd: %s", m_command.getDataStr().c_str());
m_seenAddresses[dstAddress] = true;
} else {
}
else {
LOG(upd, trace, "update MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
m_seenAddresses[dstAddress] = true;
}
+4 -2
View File
@@ -186,7 +186,8 @@ static result_t readConfigFiles(const string path, const string extension, DataF
if (result != RESULT_OK)
return result;
}
} else if (d->d_type == DT_REG || d->d_type == DT_LNK) {
}
else if (d->d_type == DT_REG || d->d_type == DT_LNK) {
string fn = d->d_name;
if (fn.find(extension, (fn.length() - extension.length())) != string::npos
@@ -270,7 +271,8 @@ int main(int argc, char* argv[])
L += new LogConsole(calcAreaMask(A.getOptVal<const char*>("logareas")),
calcLevel(A.getOptVal<const char*>("loglevel")),
"logconsole");
} else {
}
else {
// make me daemon
D.run("/var/run/ebusd.pid");
L += new LogFile(calcAreaMask(A.getOptVal<const char*>("logareas")),
+8 -6
View File
@@ -127,11 +127,11 @@ void printErrorPos(vector<string>::iterator begin, const vector<string>::iterato
cnt++;
}
}
if (begin < pos) {
if (begin < pos)
cnt += 1+(*begin).length()+1;
} else if (begin == pos) {
else if (begin == pos)
cnt++;
}
string item = *begin++;
cout << TEXT_SEPARATOR << item << TEXT_SEPARATOR;
}
@@ -647,7 +647,8 @@ result_t StringDataField::writeSymbols(istringstream& input,
value -= 2000;
else if (value > 99)
return RESULT_ERR_OUT_OF_RANGE; // invalid year
} else if (value < 1 || (i == 0 && value > 31) || (i == 1 && value > 12))
}
else if (value < 1 || (i == 0 && value > 31) || (i == 1 && value > 12))
return RESULT_ERR_OUT_OF_RANGE; // invalid date part
break;
case bt_tim:
@@ -898,7 +899,7 @@ result_t NumberDataField::readSymbols(SymbolString& input,
}
signedValue = (int) value; // negative signed value
}
else if (negative) // negative signed value
else if (negative == true) // negative signed value
signedValue = (int) value - (1 << m_bitCount);
else
signedValue = (int) value;
@@ -907,7 +908,8 @@ result_t NumberDataField::readSymbols(SymbolString& input,
if ((m_dataType.flags & (FIX|BCD)) == (FIX|BCD))
output << setw(m_length * 2) << setfill('0');
output << static_cast<int>(signedValue) << setw(0);
} else
}
else
output << setprecision(m_precision)
<< fixed << static_cast<float>(signedValue / (float) m_divisor);
+17 -11
View File
@@ -104,17 +104,20 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
size_t len = strlen(str);
if (len == 0) { // default: active get
defaultName = "r";
} else if (strncasecmp(str, "R", 1) == 0) { // active get
}else if (strncasecmp(str, "R", 1) == 0) { // active get
char last = str[len-1];
if (last >= '0' && last <= '9') { // poll priority (=active get)
pollPriority = last - '0';
defaultName = string(str).substr(0, len - 1); // cut off priority digit
} else
}
else
defaultName = str;
} else if (strncasecmp(str, "W", 1) == 0) { // active set
}
else if (strncasecmp(str, "W", 1) == 0) { // active set
isSet = true;
defaultName = str;
} else { // any other: passive set/get
}
else { // any other: passive set/get
isPassive = true;
isSet = strcasecmp(str+len-1, "W") == 0; // if type ends with "w" it is treated as passive set
defaultName = str;
@@ -178,11 +181,11 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
for (int pos=0, useDefaults=1; pos<2; pos++) { // message id (PBSB, optional master data)
string token = *it++;
if (useDefaults == 1) {
if (pos == 0 && token.size() > 0) {
if (pos == 0 && token.size() > 0)
useDefaults = 0;
} else {
else
token = getDefault("", defaults, defaultPos).append(token);
}
}
istringstream input(token);
if (it == end)
@@ -257,7 +260,8 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma
if (m_dstAddress == SYN)
return RESULT_ERR_INVALID_ADDR;
result = master.push_back(m_dstAddress, false, false);
} else
}
else
result = master.push_back(dstAddress, false, false);
if (result != RESULT_OK)
return result;
@@ -430,7 +434,7 @@ Message* MessageMap::find(const string& clazz, const string& name, const bool is
string lname = strtolower(name);
for (int i=0; i<2; i++) {
string key;
if (i==0)
if (i == 0)
key = string(isPassive ? "P" : (isSet ? "W" : "R")) + lclass + FIELD_SEPARATOR + lname;
else if (clazz.length() == 0)
key = string(isPassive ? "-P" : (isSet ? "-W" : "-R")) + lname; // second try: without class
@@ -473,10 +477,12 @@ deque<Message*> MessageMap::findAll(const string& clazz, const string& name, con
if (message->isPassive() == true) {
if (withPassive == false)
continue;
} else if (message->isSet() == true) {
}
else if (message->isSet() == true) {
if (withWrite == false)
continue;
} else {
}
else {
if (withRead == false)
continue;
}
+2 -1
View File
@@ -199,7 +199,8 @@ result_t DeviceNetwork::openDevice(const string deviceName, const bool noDeviceC
return RESULT_ERR_NOTFOUND;
memcpy(&sock.sin_addr, he->h_addr_list[0], he->h_length);
} else {
}
else {
ret = inet_aton(host, &sock.sin_addr);
if (ret == 0)
return RESULT_ERR_NOTFOUND;
+7 -7
View File
@@ -116,7 +116,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
if (isEscaped == false && value == ESC) {
m_data.push_back(ESC);
m_data.push_back(0x00);
if (updateCRC) {
if (updateCRC == true) {
addCRC(ESC);
addCRC(0x00);
}
@@ -124,14 +124,14 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
else if (isEscaped == false && value == SYN) {
m_data.push_back(ESC);
m_data.push_back(0x01);
if (updateCRC) {
if (updateCRC == true) {
addCRC(ESC);
addCRC(0x01);
}
}
else {
m_data.push_back(value);
if (updateCRC)
if (updateCRC == true)
addCRC(value);
}
@@ -141,7 +141,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
if (m_unescapeState != 1)
return RESULT_ERR_ESC; // invalid unescape state
m_data.push_back(value);
if (updateCRC) {
if (updateCRC == true) {
if (value == ESC) {
addCRC(ESC);
addCRC(0x00);
@@ -157,7 +157,7 @@ result_t SymbolString::push_back(const unsigned char value, const bool isEscaped
return RESULT_OK;
}
else if (m_unescapeState != 1) {
if (updateCRC)
if (updateCRC == true)
addCRC(value);
if (value == 0x00) {
@@ -173,13 +173,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)
if (updateCRC == true)
addCRC(value);
m_unescapeState = 2;
return RESULT_IN_ESC;
}
if (updateCRC)
if (updateCRC == true)
addCRC(value);
m_data.push_back(value);
+4 -2
View File
@@ -100,7 +100,8 @@ int main()
continue;
}
cout << "\"" << check[2] << "\": find OK" << endl;
} else {
}
else {
vector<string>::iterator it = entries.begin();
result = Message::create(it, entries.end(), NULL, templates, deleteMessage);
if (failedCreate == true) {
@@ -162,7 +163,8 @@ int main()
bool match = inputStr == output.str();
verify(false, "decode", check[2] + "/" + check[3], match, inputStr, output.str());
} else {
}
else {
result = message->prepareMaster(0xff, writeMstr, input);
if (failedPrepare == true) {
if (result == RESULT_OK)
+4 -2
View File
@@ -90,7 +90,8 @@ bool Appl::parseArgs(int argc, char* argv[])
lastOption = true;
// find option with short format '-'
} else if (_argv[i].rfind("-") == 0 && _argv[i].size() > 1) {
}
else if (_argv[i].rfind("-") == 0 && _argv[i].size() > 1) {
// walk through all characters
for (size_t j = 1; j < _argv[i].size(); j++) {
@@ -110,7 +111,8 @@ bool Appl::parseArgs(int argc, char* argv[])
lastOption = true;
} else {
}
else {
// break loop with command
if (lastOption == false && strlen(m_withCommand) != 0)
break;
+2 -1
View File
@@ -58,7 +58,8 @@ TCPSocket* TCPClient::connect(const string& server, const int& port)
return NULL;
memcpy(&address.sin_addr, he->h_addr_list[0], he->h_length);
} else {
}
else {
ret = inet_aton(server.c_str(), &address.sin_addr);
if (ret == 0)
return NULL;
+2 -1
View File
@@ -86,7 +86,8 @@ public:
else if (m_queue.size() > 0) {
item = m_queue.front();
m_queue.pop_front();
} else
}
else
item = NULL;
pthread_mutex_unlock(&m_mutex);
+2 -1
View File
@@ -95,7 +95,8 @@ int main(int argc, char* argv[])
port.close();
if(port.isOpen() == false)
cout << "closePort successful." << endl;
} else
}
else
cout << "error opening device " << A.getOptVal<const char*>("device") << endl;