some cosmetics.
This commit is contained in:
+1
-1
@@ -91,7 +91,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
ebusCommand += m_commands->getEbusCommand(index);
|
ebusCommand += m_commands->getEbusCommand(index);
|
||||||
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
|
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
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(new BusCommand(type, ebusCommand));
|
m_ebusloop->addBusCommand(new BusCommand(type, ebusCommand));
|
||||||
BusCommand* busCommand = m_ebusloop->getBusCommand();
|
BusCommand* busCommand = m_ebusloop->getBusCommand();
|
||||||
|
|||||||
+13
-10
@@ -28,13 +28,13 @@ extern Appl& A;
|
|||||||
EBusLoop::EBusLoop() : m_stop(false)
|
EBusLoop::EBusLoop() : m_stop(false)
|
||||||
{
|
{
|
||||||
m_deviceName = A.getParam<const char*>("p_device");
|
m_deviceName = A.getParam<const char*>("p_device");
|
||||||
|
|
||||||
m_bus = new Bus(m_deviceName,
|
m_bus = new Bus(m_deviceName,
|
||||||
A.getParam<bool>("p_nodevicecheck"),
|
A.getParam<bool>("p_nodevicecheck"),
|
||||||
A.getParam<const char*>("p_dumpfile"),
|
A.getParam<const char*>("p_dumpfile"),
|
||||||
A.getParam<long>("p_dumpsize"),
|
A.getParam<long>("p_dumpsize"),
|
||||||
A.getParam<bool>("p_dump"));
|
A.getParam<bool>("p_dump"));
|
||||||
|
|
||||||
m_bus->connect();
|
m_bus->connect();
|
||||||
|
|
||||||
if (m_bus->isConnected() == false)
|
if (m_bus->isConnected() == false)
|
||||||
@@ -44,10 +44,10 @@ EBusLoop::EBusLoop() : m_stop(false)
|
|||||||
EBusLoop::~EBusLoop()
|
EBusLoop::~EBusLoop()
|
||||||
{
|
{
|
||||||
m_bus->disconnect();
|
m_bus->disconnect();
|
||||||
|
|
||||||
if (m_bus->isConnected() == true)
|
if (m_bus->isConnected() == true)
|
||||||
L.log(bus, error, "error during disconnect.");
|
L.log(bus, error, "error during disconnect.");
|
||||||
|
|
||||||
delete m_bus;
|
delete m_bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ void* EBusLoop::run()
|
|||||||
{
|
{
|
||||||
int busResult;
|
int busResult;
|
||||||
bool busCommandActive = false;
|
bool busCommandActive = false;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (m_bus->isConnected() == true) {
|
if (m_bus->isConnected() == true) {
|
||||||
|
|
||||||
@@ -72,13 +72,16 @@ void* EBusLoop::run()
|
|||||||
// add new bus command to send
|
// add new bus command to send
|
||||||
if (busResult == 4 && busCommandActive == false && m_sendBuffer.size() != 0) {
|
if (busResult == 4 && busCommandActive == false && m_sendBuffer.size() != 0) {
|
||||||
BusCommand* busCommand = m_sendBuffer.remove();
|
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);
|
m_bus->addCommand(busCommand);
|
||||||
|
L.log(bus, debug, " addCommand success");
|
||||||
busCommandActive = true;
|
busCommandActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send bus command
|
// send bus command
|
||||||
if (busResult == 1 && busCommandActive == true) {
|
if (busResult == 1 && busCommandActive == true) {
|
||||||
L.log(bus, event, " getBus success");
|
L.log(bus, trace, " getBus success");
|
||||||
m_bus->sendCommand();
|
m_bus->sendCommand();
|
||||||
BusCommand* busCommand = m_bus->recvCommand();
|
BusCommand* busCommand = m_bus->recvCommand();
|
||||||
L.log(bus, trace, " %s", busCommand->getResult().c_str());
|
L.log(bus, trace, " %s", busCommand->getResult().c_str());
|
||||||
@@ -87,21 +90,21 @@ void* EBusLoop::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (busResult == 0)
|
if (busResult == 0)
|
||||||
L.log(bus, event, " getBus failure");
|
L.log(bus, trace, " getBus failure");
|
||||||
|
|
||||||
if (busResult == -1)
|
if (busResult == -1)
|
||||||
L.log(bus, event, " getBus error");
|
L.log(bus, event, " getBus error");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sleep(10);
|
sleep(10);
|
||||||
m_bus->connect();
|
m_bus->connect();
|
||||||
|
|
||||||
if (m_bus->isConnected() == false)
|
if (m_bus->isConnected() == false)
|
||||||
L.log(bus, error, "can't open %s", m_deviceName.c_str());
|
L.log(bus, error, "can't open %s", m_deviceName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_stop == true) {
|
if (m_stop == true) {
|
||||||
m_bus->disconnect();
|
m_bus->disconnect();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -38,7 +38,7 @@ void Connection::addResult(Message message)
|
|||||||
void* Connection::run()
|
void* Connection::run()
|
||||||
{
|
{
|
||||||
m_running = true;
|
m_running = true;
|
||||||
|
|
||||||
int maxfd;
|
int maxfd;
|
||||||
fd_set checkfds;
|
fd_set checkfds;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
@@ -46,7 +46,7 @@ void* Connection::run()
|
|||||||
FD_ZERO(&checkfds);
|
FD_ZERO(&checkfds);
|
||||||
FD_SET(m_notify.notifyFD(), &checkfds);
|
FD_SET(m_notify.notifyFD(), &checkfds);
|
||||||
FD_SET(m_socket->getFD(), &checkfds);
|
FD_SET(m_socket->getFD(), &checkfds);
|
||||||
|
|
||||||
(m_notify.notifyFD() > m_socket->getFD()) ?
|
(m_notify.notifyFD() > m_socket->getFD()) ?
|
||||||
(maxfd = m_notify.notifyFD()) : (maxfd = m_socket->getFD());
|
(maxfd = m_notify.notifyFD()) : (maxfd = m_socket->getFD());
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ void* Connection::run()
|
|||||||
|
|
||||||
// set select timeout 10 secs
|
// set select timeout 10 secs
|
||||||
timeout.tv_sec = 10;
|
timeout.tv_sec = 10;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
// set readfds to inital checkfds
|
// set readfds to inital checkfds
|
||||||
readfds = checkfds;
|
readfds = checkfds;
|
||||||
@@ -65,7 +65,7 @@ void* Connection::run()
|
|||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// new data from notify
|
// new data from notify
|
||||||
if (FD_ISSET(m_notify.notifyFD(), &readfds))
|
if (FD_ISSET(m_notify.notifyFD(), &readfds))
|
||||||
break;
|
break;
|
||||||
@@ -79,7 +79,7 @@ void* Connection::run()
|
|||||||
datalen = m_socket->recv(data, sizeof(data)-1);
|
datalen = m_socket->recv(data, sizeof(data)-1);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// removed closed socket
|
// removed closed socket
|
||||||
if (datalen <= 0 || strncasecmp(data, "quit", 4) == 0)
|
if (datalen <= 0 || strncasecmp(data, "quit", 4) == 0)
|
||||||
break;
|
break;
|
||||||
@@ -94,12 +94,12 @@ void* Connection::run()
|
|||||||
|
|
||||||
L.log(net, debug, "[%08x] result added", getID());
|
L.log(net, debug, "[%08x] result added", getID());
|
||||||
std::string result(message->getData());
|
std::string result(message->getData());
|
||||||
|
|
||||||
if (m_socket->isValid() == true)
|
if (m_socket->isValid() == true)
|
||||||
m_socket->send(result.c_str(), result.size());
|
m_socket->send(result.c_str(), result.size());
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
delete message;
|
delete message;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ void* Connection::run()
|
|||||||
|
|
||||||
delete m_socket;
|
delete m_socket;
|
||||||
m_running = false;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -137,10 +137,10 @@ Network::~Network()
|
|||||||
connection->join();
|
connection->join();
|
||||||
delete connection;
|
delete connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_running == true)
|
if (m_running == true)
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
delete m_Listener;
|
delete m_Listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ void* Network::run()
|
|||||||
FD_ZERO(&checkfds);
|
FD_ZERO(&checkfds);
|
||||||
FD_SET(m_notify.notifyFD(), &checkfds);
|
FD_SET(m_notify.notifyFD(), &checkfds);
|
||||||
FD_SET(m_Listener->getFD(), &checkfds);
|
FD_SET(m_Listener->getFD(), &checkfds);
|
||||||
|
|
||||||
(m_notify.notifyFD() > m_Listener->getFD()) ?
|
(m_notify.notifyFD() > m_Listener->getFD()) ?
|
||||||
(maxfd = m_notify.notifyFD()) : (maxfd = m_Listener->getFD());
|
(maxfd = m_notify.notifyFD()) : (maxfd = m_Listener->getFD());
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ void* Network::run()
|
|||||||
|
|
||||||
// set select timeout 1 secs
|
// set select timeout 1 secs
|
||||||
timeout.tv_sec = 1;
|
timeout.tv_sec = 1;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
// set readfds to inital checkfds
|
// set readfds to inital checkfds
|
||||||
readfds = checkfds;
|
readfds = checkfds;
|
||||||
@@ -178,7 +178,7 @@ void* Network::run()
|
|||||||
cleanConnections();
|
cleanConnections();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// new data from notify
|
// new data from notify
|
||||||
if (FD_ISSET(m_notify.notifyFD(), &readfds)) {
|
if (FD_ISSET(m_notify.notifyFD(), &readfds)) {
|
||||||
m_running = false;
|
m_running = false;
|
||||||
@@ -190,14 +190,14 @@ void* Network::run()
|
|||||||
TCPSocket* socket = m_Listener->newSocket();
|
TCPSocket* socket = m_Listener->newSocket();
|
||||||
if (socket == NULL)
|
if (socket == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Connection* connection = new Connection(socket, m_queue);
|
Connection* connection = new Connection(socket, m_queue);
|
||||||
if (connection == NULL)
|
if (connection == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
connection->start("netConnection");
|
connection->start("netConnection");
|
||||||
m_connections.push_back(connection);
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user