| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CPreconditionSynchronizer.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Command { |
| 29 |
|
| 30 |
|
| 31 |
CPreconditionSynchronizer::CPreconditionSynchronizer(CCommandDelegater *commandDelegater) : CThread("CommandPreconditionSynchronizer") { |
| 32 |
delegater = commandDelegater; |
| 33 |
startThread(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
CPreconditionSynchronizer::~CPreconditionSynchronizer() { |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
CCommandDelegater *CPreconditionSynchronizer::delegateCommand(CCommand *command) { |
| 42 |
postEvent(new CCommandPreconditionChangeEvent(0,command)); |
| 43 |
return this; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
bool CPreconditionSynchronizer::processCustomsEvents(QEvent::Type type, CCustomEvent *event) { |
| 48 |
if (!CThread::processCustomsEvents(type,event)) { |
| 49 |
if (type == EVENTCOMMANDPRECONDITIONCHANGE) { |
| 50 |
CCommandPreconditionChangeEvent *commandEvent = (CCommandPreconditionChangeEvent *)event; |
| 51 |
if (commandEvent) { |
| 52 |
CCommand *command = commandEvent->getCommand(); |
| 53 |
if (command) { |
| 54 |
CPreconditionCommand *preComm = dynamic_cast<CPreconditionCommand *>(command); |
| 55 |
if (preComm) { |
| 56 |
bool processable = false; |
| 57 |
if (preComm->isProcessable()) { |
| 58 |
processable = true; |
| 59 |
} |
| 60 |
if (processable) { |
| 61 |
delegater->delegateCommand(command); |
| 62 |
} else { |
| 63 |
bool connCallback = false; |
| 64 |
CLinker<CCommandPrecondition *> *preIt = preComm->getCommandPreconditionLinker(); |
| 65 |
while (preIt) { |
| 66 |
CCommandPrecondition *pre = preIt->getData(); |
| 67 |
if (pre && !pre->isPreconditionFullfilled()) { |
| 68 |
pre->addFullfilledCallback(new CCommandPreconditionChangeEvent(this,preComm)); |
| 69 |
connCallback = true; |
| 70 |
break; |
| 71 |
} |
| 72 |
preIt = (CLinker<CCommandPrecondition *> *)preIt->getNext(); |
| 73 |
} |
| 74 |
if (!connCallback) { |
| 75 |
LOG(ERROR,"::Konclude::Command::PreconditionSynchronizer",logTr("Unprocessable commands which are not depending on their preconditions are not supported."),this); |
| 76 |
delegater->delegateCommand(command); |
| 77 |
} |
| 78 |
} |
| 79 |
} else { |
| 80 |
delegater->delegateCommand(command); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
return true; |
| 85 |
} |
| 86 |
} else { |
| 87 |
return true; |
| 88 |
} |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
}; // end namespace Command |
| 95 |
|
| 96 |
}; // end namespace Control |
| 97 |
|
| 98 |
}; // end namespace Konclude |