notify BusCommand of finished result instead of having two queues in Bus, added isPoll to BusCommand to avoid missing/unallowed deletion of poll/non-poll commands, also return BusCommand in Bus::delCommand() for cleanup

This commit is contained in:
john30
2014-10-23 22:18:11 +02:00
parent dcbe8e6157
commit 897c70c3a8
3 changed files with 16 additions and 14 deletions
+6 -6
View File
@@ -151,11 +151,11 @@ 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);
BusCommand* busCommand = new BusCommand(ebusCommand); BusCommand* busCommand = new BusCommand(ebusCommand, false);
L.log(bas, trace, " msg: %s", ebusCommand.c_str()); L.log(bas, trace, " msg: %s", ebusCommand.c_str());
// send busCommand // send busCommand
m_ebusloop->addBusCommand(busCommand); m_ebusloop->addBusCommand(busCommand);
busCommand = m_ebusloop->getBusCommand(); busCommand->waitSignal();
if (!busCommand->isErrorResult()) { if (!busCommand->isErrorResult()) {
// decode data // decode data
@@ -204,11 +204,11 @@ std::string BaseLoop::decodeMessage(const std::string& data)
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower); std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
BusCommand* busCommand = new BusCommand(ebusCommand); BusCommand* busCommand = new BusCommand(ebusCommand, false);
L.log(bas, event, " msg: %s", ebusCommand.c_str()); L.log(bas, event, " msg: %s", ebusCommand.c_str());
// send busCommand // send busCommand
m_ebusloop->addBusCommand(busCommand); m_ebusloop->addBusCommand(busCommand);
busCommand = m_ebusloop->getBusCommand(); busCommand->waitSignal();
if (!busCommand->isErrorResult()) { if (!busCommand->isErrorResult()) {
// decode result // decode result
@@ -273,11 +273,11 @@ std::string BaseLoop::decodeMessage(const std::string& data)
ebusCommand += cmd[1]; ebusCommand += cmd[1];
std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower); std::transform(ebusCommand.begin(), ebusCommand.end(), ebusCommand.begin(), tolower);
BusCommand* busCommand = new BusCommand(ebusCommand); BusCommand* busCommand = new BusCommand(ebusCommand, false);
L.log(bas, trace, " msg: %s", ebusCommand.c_str()); L.log(bas, trace, " msg: %s", ebusCommand.c_str());
// send busCommand // send busCommand
m_ebusloop->addBusCommand(busCommand); m_ebusloop->addBusCommand(busCommand);
busCommand = m_ebusloop->getBusCommand(); busCommand->waitSignal();
if (busCommand->isErrorResult()) { if (busCommand->isErrorResult()) {
L.log(bas, error, " %s", busCommand->getResultCodeCStr()); L.log(bas, error, " %s", busCommand->getResultCodeCStr());
+10 -6
View File
@@ -148,7 +148,7 @@ void* EBusLoop::run()
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);
BusCommand* busCommand = new BusCommand(ebusCommand); BusCommand* busCommand = new BusCommand(ebusCommand, true);
L.log(bus, trace, " msg: %s", ebusCommand.c_str()); L.log(bus, trace, " msg: %s", ebusCommand.c_str());
m_bus->addCommand(busCommand); m_bus->addCommand(busCommand);
@@ -165,8 +165,7 @@ void* EBusLoop::run()
if (busResult == RESULT_BUS_ACQUIRED && busCommandActive == true) { if (busResult == RESULT_BUS_ACQUIRED && busCommandActive == true) {
L.log(bus, trace, " getBus success"); L.log(bus, trace, " getBus success");
lookbusretries = 0; lookbusretries = 0;
m_bus->sendCommand(); BusCommand* busCommand = m_bus->sendCommand();
BusCommand* busCommand = m_bus->recvCommand();
L.log(bus, trace, " %s", busCommand->getMessageStr().c_str()); L.log(bus, trace, " %s", busCommand->getMessageStr().c_str());
if (busCommand->isErrorResult() == true && retries < m_retries) { if (busCommand->isErrorResult() == true && retries < m_retries) {
@@ -176,7 +175,7 @@ void* EBusLoop::run()
m_bus->addCommand(busCommand); m_bus->addCommand(busCommand);
} else { } else {
retries = 0; retries = 0;
if (pollCommandActive == true) { if (busCommand->isPoll() == true) {
// only save correct results // only save correct results
if (busCommand->isErrorResult() == false) if (busCommand->isErrorResult() == false)
m_commands->storePolData(busCommand->getMessageStr().c_str()); // TODO use getResult() m_commands->storePolData(busCommand->getMessageStr().c_str()); // TODO use getResult()
@@ -184,7 +183,7 @@ void* EBusLoop::run()
delete busCommand; delete busCommand;
pollCommandActive = false; pollCommandActive = false;
} else { } else {
m_recvBuffer.add(busCommand); busCommand->sendSignal();
} }
busCommandActive = false; busCommandActive = false;
@@ -199,7 +198,12 @@ void* EBusLoop::run()
L.log(bus, trace, " getBus failure"); L.log(bus, trace, " getBus failure");
if (lookbusretries >= m_lookbusretries) { if (lookbusretries >= m_lookbusretries) {
L.log(bus, event, " getBus failed - command deleted"); L.log(bus, event, " getBus failed - command deleted");
m_bus->delCommand(); BusCommand* busCommand = m_bus->delCommand();
if (busCommand->isPoll() == true) {
delete busCommand;
} else {
busCommand->sendSignal();
}
lookbusretries = 0; lookbusretries = 0;
busCommandActive = false; busCommandActive = false;
pollCommandActive = false; pollCommandActive = false;
-2
View File
@@ -38,7 +38,6 @@ public:
void stop() { m_stop = true; } void stop() { m_stop = true; }
void addBusCommand(BusCommand* busCommand) { m_sendBuffer.add(busCommand); } void addBusCommand(BusCommand* busCommand) { m_sendBuffer.add(busCommand); }
BusCommand* getBusCommand() { return m_recvBuffer.remove(); }
void dump(const bool dumpState) { m_bus->setDumpState(dumpState); } void dump(const bool dumpState) { m_bus->setDumpState(dumpState); }
@@ -50,7 +49,6 @@ private:
Bus* m_bus; Bus* m_bus;
bool m_stop; bool m_stop;
WQueue<BusCommand*> m_sendBuffer; WQueue<BusCommand*> m_sendBuffer;
WQueue<BusCommand*> m_recvBuffer;
int m_retries; int m_retries;
int m_lookbusretries; int m_lookbusretries;
double m_pollInterval; double m_pollInterval;