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:
+6
-6
@@ -151,11 +151,11 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
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());
|
||||
// send busCommand
|
||||
m_ebusloop->addBusCommand(busCommand);
|
||||
busCommand = m_ebusloop->getBusCommand();
|
||||
busCommand->waitSignal();
|
||||
|
||||
if (!busCommand->isErrorResult()) {
|
||||
// decode data
|
||||
@@ -204,11 +204,11 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
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());
|
||||
// send busCommand
|
||||
m_ebusloop->addBusCommand(busCommand);
|
||||
busCommand = m_ebusloop->getBusCommand();
|
||||
busCommand->waitSignal();
|
||||
|
||||
if (!busCommand->isErrorResult()) {
|
||||
// decode result
|
||||
@@ -273,11 +273,11 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
ebusCommand += cmd[1];
|
||||
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());
|
||||
// send busCommand
|
||||
m_ebusloop->addBusCommand(busCommand);
|
||||
busCommand = m_ebusloop->getBusCommand();
|
||||
busCommand->waitSignal();
|
||||
|
||||
if (busCommand->isErrorResult()) {
|
||||
L.log(bas, error, " %s", busCommand->getResultCodeCStr());
|
||||
|
||||
+10
-6
@@ -148,7 +148,7 @@ void* EBusLoop::run()
|
||||
ebusCommand += m_commands->getEbusCommand(index);
|
||||
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());
|
||||
|
||||
m_bus->addCommand(busCommand);
|
||||
@@ -165,8 +165,7 @@ void* EBusLoop::run()
|
||||
if (busResult == RESULT_BUS_ACQUIRED && busCommandActive == true) {
|
||||
L.log(bus, trace, " getBus success");
|
||||
lookbusretries = 0;
|
||||
m_bus->sendCommand();
|
||||
BusCommand* busCommand = m_bus->recvCommand();
|
||||
BusCommand* busCommand = m_bus->sendCommand();
|
||||
L.log(bus, trace, " %s", busCommand->getMessageStr().c_str());
|
||||
|
||||
if (busCommand->isErrorResult() == true && retries < m_retries) {
|
||||
@@ -176,7 +175,7 @@ void* EBusLoop::run()
|
||||
m_bus->addCommand(busCommand);
|
||||
} else {
|
||||
retries = 0;
|
||||
if (pollCommandActive == true) {
|
||||
if (busCommand->isPoll() == true) {
|
||||
// only save correct results
|
||||
if (busCommand->isErrorResult() == false)
|
||||
m_commands->storePolData(busCommand->getMessageStr().c_str()); // TODO use getResult()
|
||||
@@ -184,7 +183,7 @@ void* EBusLoop::run()
|
||||
delete busCommand;
|
||||
pollCommandActive = false;
|
||||
} else {
|
||||
m_recvBuffer.add(busCommand);
|
||||
busCommand->sendSignal();
|
||||
}
|
||||
|
||||
busCommandActive = false;
|
||||
@@ -199,7 +198,12 @@ void* EBusLoop::run()
|
||||
L.log(bus, trace, " getBus failure");
|
||||
if (lookbusretries >= m_lookbusretries) {
|
||||
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;
|
||||
busCommandActive = false;
|
||||
pollCommandActive = false;
|
||||
|
||||
@@ -38,7 +38,6 @@ public:
|
||||
void stop() { m_stop = true; }
|
||||
|
||||
void addBusCommand(BusCommand* busCommand) { m_sendBuffer.add(busCommand); }
|
||||
BusCommand* getBusCommand() { return m_recvBuffer.remove(); }
|
||||
|
||||
void dump(const bool dumpState) { m_bus->setDumpState(dumpState); }
|
||||
|
||||
@@ -50,7 +49,6 @@ private:
|
||||
Bus* m_bus;
|
||||
bool m_stop;
|
||||
WQueue<BusCommand*> m_sendBuffer;
|
||||
WQueue<BusCommand*> m_recvBuffer;
|
||||
int m_retries;
|
||||
int m_lookbusretries;
|
||||
double m_pollInterval;
|
||||
|
||||
Reference in New Issue
Block a user