| 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 "CReasonerEvaluationProgramLoader.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Loader { |
| 29 |
|
| 30 |
|
| 31 |
CReasonerEvaluationProgramLoader::CReasonerEvaluationProgramLoader() { |
| 32 |
mReasonerCommander = nullptr; |
| 33 |
mDeleteReasonerCommander = nullptr; |
| 34 |
mLoaderConfig = nullptr; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
CReasonerEvaluationProgramLoader::~CReasonerEvaluationProgramLoader() { |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
CLoader *CReasonerEvaluationProgramLoader::init(CLoaderFactory *loaderFactory, CConfiguration *config) { |
| 44 |
|
| 45 |
mLoaderConfig = config; |
| 46 |
|
| 47 |
CConfigurationGroup* group = mLoaderConfig->getConfigurationGroup(); |
| 48 |
|
| 49 |
CConfigData* data = mLoaderConfig->createConfig("Konclude.Execution.CommanderManager"); |
| 50 |
CCommanderManagerConfigType* rCConfig = dynamic_cast<CCommanderManagerConfigType*>(data->getConfigType()); |
| 51 |
if (rCConfig) { |
| 52 |
mReasonerCommander = dynamic_cast<CCommanderManagerThread*>(rCConfig->getCommanderManager()); |
| 53 |
} |
| 54 |
|
| 55 |
if (!mReasonerCommander) { |
| 56 |
mDeleteReasonerCommander = mReasonerCommander = new CCommanderManagerThread(); |
| 57 |
rCConfig->setCommanderManager(mReasonerCommander); |
| 58 |
} |
| 59 |
|
| 60 |
group->setConfigDefaultData(group->getConfigIndex("Konclude.Execution.CommanderManager"),data); |
| 61 |
|
| 62 |
|
| 63 |
data = config->getLastConfigChange("Konclude.Evaluation.ProgramFile"); |
| 64 |
if (data) { |
| 65 |
mProgramFileString = data->getString(); |
| 66 |
} |
| 67 |
|
| 68 |
mCloseAfterOutput = true; |
| 69 |
|
| 70 |
|
| 71 |
return this; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
CLoader *CReasonerEvaluationProgramLoader::load() { |
| 77 |
if (mReasonerCommander) { |
| 78 |
mReasonerCommander->realizeCommand(new CInitializeConfigurationCommand(mLoaderConfig)); |
| 79 |
} |
| 80 |
|
| 81 |
startProcessing(); |
| 82 |
mBlockingSem.acquire(); |
| 83 |
|
| 84 |
return this; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
COWLlinkProcessor *CReasonerEvaluationProgramLoader::initializeOWLlinkContent() { |
| 90 |
if (!mProgramFileString.isEmpty()) { |
| 91 |
QFile file(mProgramFileString); |
| 92 |
LOG(INFO,getLogDomain(),logTr("Processing evaluation program from file '%1'.").arg(mProgramFileString),this); |
| 93 |
if (file.open(QIODevice::ReadOnly)) { |
| 94 |
fileContent = file.readAll(); |
| 95 |
COWLlinkQtXMLCommandParser *owllinkCommandParser = new COWLlinkQtXMLCommandParser(mLoaderConfig); |
| 96 |
defaultCommandDelegater = preSynchronizer; |
| 97 |
|
| 98 |
CParseOWLlinkCommandsCommand *parseCommand = new CParseOWLlinkCommandsCommand(&fileContent,mProgramFileString); |
| 99 |
parseCommand->setReportErrorFromSubCommands(false); |
| 100 |
|
| 101 |
CCommandProcessedCallbackEvent *proComm = new CCommandProcessedCallbackEvent(this,parseCommand); |
| 102 |
parseCommand->addProcessedCallback(proComm); |
| 103 |
|
| 104 |
|
| 105 |
owllinkCommandParser->realizeCommand(parseCommand,defaultCommandDelegater); |
| 106 |
|
| 107 |
delete owllinkCommandParser; |
| 108 |
|
| 109 |
} else { |
| 110 |
LOG(ERROR,getLogDomain(),logTr("Evaluation program file '%1' not found.").arg(mProgramFileString),this); |
| 111 |
concludeOWLlinkContent(); |
| 112 |
} |
| 113 |
} |
| 114 |
return this; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
CConfiguration *CReasonerEvaluationProgramLoader::getConfiguration() { |
| 120 |
if (!mReasonerCommander) { |
| 121 |
return mLoaderConfig; |
| 122 |
} else { |
| 123 |
CGetDescriptionCommand *getDesComm = new CGetDescriptionCommand(); |
| 124 |
mReasonerCommander->delegateCommand(getDesComm); |
| 125 |
CCommandExecutedBlocker commExeBlocker; |
| 126 |
commExeBlocker.waitExecutedCommand(getDesComm); |
| 127 |
CConfiguration *config = getDesComm->getConfiguration(); |
| 128 |
return config; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
COWLlinkProcessor *CReasonerEvaluationProgramLoader::concludeOWLlinkContent() { |
| 134 |
mBlockingSem.release(); |
| 135 |
if (mCloseAfterOutput) { |
| 136 |
CLogger::getInstance()->waitSynchronization(); |
| 137 |
//qSleep(10); |
| 138 |
//qWait(); |
| 139 |
QCoreApplication::exit(); |
| 140 |
} |
| 141 |
return this; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
CLoader *CReasonerEvaluationProgramLoader::exit() { |
| 146 |
stopThread(); |
| 147 |
delete mDeleteReasonerCommander; |
| 148 |
return this; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
}; // end namespace Loader |
| 154 |
|
| 155 |
}; // end namespace Control |
| 156 |
|
| 157 |
}; // end namespace Konclude |