From 3cc04bf3a7ffffd91fcf670d1a2a2c2272cb6e6c Mon Sep 17 00:00:00 2001 From: Roland Jax Date: Sun, 11 May 2014 15:12:00 +0200 Subject: [PATCH] some cosmetics. --- src/baseloop.cpp | 2 +- src/ebusloop.cpp | 23 +++++++++++++---------- src/network.cpp | 32 ++++++++++++++++---------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/baseloop.cpp b/src/baseloop.cpp index ba49c233..c572ac2f 100644 --- a/src/baseloop.cpp +++ b/src/baseloop.cpp @@ -91,7 +91,7 @@ std::string BaseLoop::decodeMessage(const std::string& data) ebusCommand += m_commands->getEbusCommand(index); std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower); - L.log(bas, event, " type: %s msg: %s", type.c_str(), ebusCommand.c_str()); + L.log(bas, trace, " type: %s msg: %s", type.c_str(), ebusCommand.c_str()); // send busCommand m_ebusloop->addBusCommand(new BusCommand(type, ebusCommand)); BusCommand* busCommand = m_ebusloop->getBusCommand(); diff --git a/src/ebusloop.cpp b/src/ebusloop.cpp index d1373f2a..079c22c7 100644 --- a/src/ebusloop.cpp +++ b/src/ebusloop.cpp @@ -28,13 +28,13 @@ extern Appl& A; EBusLoop::EBusLoop() : m_stop(false) { m_deviceName = A.getParam("p_device"); - + m_bus = new Bus(m_deviceName, A.getParam("p_nodevicecheck"), A.getParam("p_dumpfile"), A.getParam("p_dumpsize"), A.getParam("p_dump")); - + m_bus->connect(); if (m_bus->isConnected() == false) @@ -44,10 +44,10 @@ EBusLoop::EBusLoop() : m_stop(false) EBusLoop::~EBusLoop() { m_bus->disconnect(); - + if (m_bus->isConnected() == true) L.log(bus, error, "error during disconnect."); - + delete m_bus; } @@ -55,7 +55,7 @@ void* EBusLoop::run() { int busResult; bool busCommandActive = false; - + for (;;) { if (m_bus->isConnected() == true) { @@ -72,13 +72,16 @@ void* EBusLoop::run() // add new bus command to send if (busResult == 4 && busCommandActive == false && m_sendBuffer.size() != 0) { BusCommand* busCommand = m_sendBuffer.remove(); + L.log(bus, debug, " type: %s msg: %s", + busCommand->getType().c_str(), busCommand->getCommand().c_str()); m_bus->addCommand(busCommand); + L.log(bus, debug, " addCommand success"); busCommandActive = true; } // send bus command if (busResult == 1 && busCommandActive == true) { - L.log(bus, event, " getBus success"); + L.log(bus, trace, " getBus success"); m_bus->sendCommand(); BusCommand* busCommand = m_bus->recvCommand(); L.log(bus, trace, " %s", busCommand->getResult().c_str()); @@ -87,21 +90,21 @@ void* EBusLoop::run() } if (busResult == 0) - L.log(bus, event, " getBus failure"); + L.log(bus, trace, " getBus failure"); if (busResult == -1) L.log(bus, event, " getBus error"); - + } else { sleep(10); m_bus->connect(); - + if (m_bus->isConnected() == false) L.log(bus, error, "can't open %s", m_deviceName.c_str()); } if (m_stop == true) { - m_bus->disconnect(); + m_bus->disconnect(); return NULL; } } diff --git a/src/network.cpp b/src/network.cpp index c4b74487..318a4695 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -38,7 +38,7 @@ void Connection::addResult(Message message) void* Connection::run() { m_running = true; - + int maxfd; fd_set checkfds; struct timeval timeout; @@ -46,7 +46,7 @@ void* Connection::run() FD_ZERO(&checkfds); FD_SET(m_notify.notifyFD(), &checkfds); FD_SET(m_socket->getFD(), &checkfds); - + (m_notify.notifyFD() > m_socket->getFD()) ? (maxfd = m_notify.notifyFD()) : (maxfd = m_socket->getFD()); @@ -56,7 +56,7 @@ void* Connection::run() // set select timeout 10 secs timeout.tv_sec = 10; - timeout.tv_usec = 0; + timeout.tv_usec = 0; // set readfds to inital checkfds readfds = checkfds; @@ -65,7 +65,7 @@ void* Connection::run() if (ret == 0) { continue; } - + // new data from notify if (FD_ISSET(m_notify.notifyFD(), &readfds)) break; @@ -79,7 +79,7 @@ void* Connection::run() datalen = m_socket->recv(data, sizeof(data)-1); else break; - + // removed closed socket if (datalen <= 0 || strncasecmp(data, "quit", 4) == 0) break; @@ -94,12 +94,12 @@ void* Connection::run() L.log(net, debug, "[%08x] result added", getID()); std::string result(message->getData()); - + if (m_socket->isValid() == true) m_socket->send(result.c_str(), result.size()); else - break; - + break; + delete message; } @@ -108,7 +108,7 @@ void* Connection::run() delete m_socket; m_running = false; - L.log(net, event, "[%08x] connection closed - active connections: %d", getID(), m_count); + L.log(net, trace, "[%08x] connection closed - active connections: %d", getID(), m_count); return NULL; } @@ -137,10 +137,10 @@ Network::~Network() connection->join(); delete connection; } - + if (m_running == true) stop(); - + delete m_Listener; } @@ -158,7 +158,7 @@ void* Network::run() FD_ZERO(&checkfds); FD_SET(m_notify.notifyFD(), &checkfds); FD_SET(m_Listener->getFD(), &checkfds); - + (m_notify.notifyFD() > m_Listener->getFD()) ? (maxfd = m_notify.notifyFD()) : (maxfd = m_Listener->getFD()); @@ -168,7 +168,7 @@ void* Network::run() // set select timeout 1 secs timeout.tv_sec = 1; - timeout.tv_usec = 0; + timeout.tv_usec = 0; // set readfds to inital checkfds readfds = checkfds; @@ -178,7 +178,7 @@ void* Network::run() cleanConnections(); continue; } - + // new data from notify if (FD_ISSET(m_notify.notifyFD(), &readfds)) { m_running = false; @@ -190,14 +190,14 @@ void* Network::run() TCPSocket* socket = m_Listener->newSocket(); if (socket == NULL) continue; - + Connection* connection = new Connection(socket, m_queue); if (connection == NULL) continue; connection->start("netConnection"); m_connections.push_back(connection); - L.log(net, event, "[%08x] connection opened %s", connection->getID(), socket->getIP().c_str()); + L.log(net, trace, "[%08x] connection opened %s", connection->getID(), socket->getIP().c_str()); } }