| 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 "CCLIBatchProcessingLoader.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Control { |
| 27 |
|
| 28 |
namespace Loader { |
| 29 |
|
| 30 |
|
| 31 |
CCLIBatchProcessingLoader::CCLIBatchProcessingLoader() : mLogIdentifier("::Konclude::CLIBatchProcessor",this) { |
| 32 |
mOWLLinkInterpreter = nullptr; |
| 33 |
mLoaderConfig = nullptr; |
| 34 |
mConfLogProcessingTimes = false; |
| 35 |
mProcessingCommandData = nullptr; |
| 36 |
mLogTotalProcessingTime = false; |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
CCLIBatchProcessingLoader::~CCLIBatchProcessingLoader() { |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
CCommandRecorder* CCLIBatchProcessingLoader::recordData(CCommandRecordData *recData) { |
| 48 |
LOGC(recData->getRecordErrorLevel(),recData->getRecordDomain(),recData->getRecordMessage(),recData->getCommand()); |
| 49 |
return this; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
CLoader *CCLIBatchProcessingLoader::init(CLoaderFactory *loaderFactory, CConfiguration *config) { |
| 55 |
mLoaderConfig = config; |
| 56 |
reasonerCommander = CConfigManagerReader::readCommanderManagerConfig(config); |
| 57 |
|
| 58 |
mCloseAfterOutput = CConfigDataReader::readConfigBoolean(mLoaderConfig, "Konclude.CLI.CloseAfterProcessedRequest", true); |
| 59 |
mBlockUntilProcessed = CConfigDataReader::readConfigBoolean(mLoaderConfig, "Konclude.CLI.BlockUntilProcessedRequest", true); |
| 60 |
|
| 61 |
|
| 62 |
mRequestFileString = CConfigDataReader::readConfigString(config,"Konclude.CLI.RequestFile"); |
| 63 |
mResponseFileString = CConfigDataReader::readConfigString(config,"Konclude.CLI.ResponseFile"); |
| 64 |
mIRINameString = CConfigDataReader::readConfigString(config,"Konclude.CLI.IRIName"); |
| 65 |
mConfLogProcessingTimes = mLogTotalProcessingTime = CConfigDataReader::readConfigBoolean(config,"Konclude.OWLlink.LoggingExtendedProcessingTimes"); |
| 66 |
|
| 67 |
return this; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
CLoader *CCLIBatchProcessingLoader::load() { |
| 73 |
startProcessing(); |
| 74 |
if (mBlockUntilProcessed) { |
| 75 |
mBlockingSemaphore.acquire(); |
| 76 |
} |
| 77 |
return this; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
CConfiguration *CCLIBatchProcessingLoader::getConfiguration() { |
| 83 |
if (!reasonerCommander) { |
| 84 |
return mLoaderConfig; |
| 85 |
} else { |
| 86 |
CGetDescriptionCommand* getDesComm = new CGetDescriptionCommand(); |
| 87 |
reasonerCommander->delegateCommand(getDesComm); |
| 88 |
CCommandExecutedBlocker commExeBlocker; |
| 89 |
commExeBlocker.waitExecutedCommand(getDesComm); |
| 90 |
CConfiguration* config = getDesComm->getConfiguration(); |
| 91 |
return config; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
void CCLIBatchProcessingLoader::createTestingCommands() { |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
void CCLIBatchProcessingLoader::addProcessingCommand(CCommand* command) { |
| 102 |
mProcessCommandList.append(new CCommandProcessData(command)); |
| 103 |
} |
| 104 |
|
| 105 |
void CCLIBatchProcessingLoader::addProcessingCommand(CCommand* command, bool measureTime, const QString& measuredOutputString) { |
| 106 |
mProcessCommandList.append(new CCommandProcessData(command,measureTime,measuredOutputString)); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
void CCLIBatchProcessingLoader::addProcessingCommand(CCommand* command, bool measureTime, const QString& measuredOutputString, bool writeSatisfiabilityOutput, const QString& outputFileName) { |
| 111 |
mProcessCommandList.append(new CCommandProcessData(command,measureTime,measuredOutputString,writeSatisfiabilityOutput,outputFileName)); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
COWLlinkProcessor *CCLIBatchProcessingLoader::initializeOWLlinkContent() { |
| 116 |
if (mLogTotalProcessingTime) { |
| 117 |
mTotalTime.start(); |
| 118 |
} |
| 119 |
createTestingCommands(); |
| 120 |
return this; |
| 121 |
} |
| 122 |
|
| 123 |
COWLlinkProcessor *CCLIBatchProcessingLoader::concludeOWLlinkContent() { |
| 124 |
finishCommandProcessing(); |
| 125 |
if (hasMoreProcessingCommands()) { |
| 126 |
processNextCommand(); |
| 127 |
} else { |
| 128 |
finishProcessing(); |
| 129 |
terminateProcessing(); |
| 130 |
} |
| 131 |
return this; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
void CCLIBatchProcessingLoader::logOutputError(const QString& errorString) { |
| 136 |
LOG(ERROR,mLogIdentifier.getLogDomain(),errorString,this); |
| 137 |
} |
| 138 |
void CCLIBatchProcessingLoader::logOutputNotice(const QString& outputString) { |
| 139 |
LOG(NOTICE,mLogIdentifier.getLogDomain(),outputString,this); |
| 140 |
} |
| 141 |
|
| 142 |
void CCLIBatchProcessingLoader::logOutputMessage(const QString& outputString) { |
| 143 |
LOG(INFO,mLogIdentifier.getLogDomain(),outputString,this); |
| 144 |
} |
| 145 |
|
| 146 |
void CCLIBatchProcessingLoader::forcedPathCreated(const QString& filePath) { |
| 147 |
QString path = filePath; |
| 148 |
if (path.contains("/") || path.contains("\\")) { |
| 149 |
int lastSlash = path.lastIndexOf("/"); |
| 150 |
int lastBackSlash = path.lastIndexOf("\\"); |
| 151 |
int lastSeparator = qMax(lastBackSlash,lastSlash); |
| 152 |
path = path.mid(0,lastSeparator); |
| 153 |
if (!path.isEmpty()) { |
| 154 |
QDir dir; |
| 155 |
dir.mkpath(path); |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
void CCLIBatchProcessingLoader::writeCommandOutput(const QString& outputFileName, CCommand* processedCommand) { |
| 161 |
} |
| 162 |
|
| 163 |
void CCLIBatchProcessingLoader::finishCommandProcessing() { |
| 164 |
if (mProcessingCommandData) { |
| 165 |
if (mProcessingCommandData->mMeasureTime) { |
| 166 |
QString outputString = mProcessingCommandData->mMeasuredOutputString; |
| 167 |
cint64 timeElapsed = mMeasurementTime.elapsed(); |
| 168 |
if (mOutputMeasuredTimeInSeconds) { |
| 169 |
logOutputMessage(outputString.arg(timeElapsed/1000.)); |
| 170 |
} else { |
| 171 |
logOutputMessage(outputString.arg(timeElapsed)); |
| 172 |
} |
| 173 |
} |
| 174 |
if (mProcessingCommandData->mWriteOutput) { |
| 175 |
QString outputFile = mProcessingCommandData->mWriteOutputFile; |
| 176 |
writeCommandOutput(outputFile,mProcessingCommandData->mCommand); |
| 177 |
} |
| 178 |
mProcessingCommandData = nullptr; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
void CCLIBatchProcessingLoader::processNextCommand() { |
| 183 |
mProcessingCommandData = mProcessCommandList.takeFirst(); |
| 184 |
CCommand* command = mProcessingCommandData->mCommand; |
| 185 |
logOutputNotice(QString("Starting '%1' command").arg(command->getBriefCommandDescription())); |
| 186 |
command->setRecorder(this); |
| 187 |
command->setReportErrorFromSubCommands(false); |
| 188 |
CCommandProcessedCallbackEvent *proComm = new CCommandProcessedCallbackEvent(this,command); |
| 189 |
command->addProcessedCallback(proComm); |
| 190 |
mMeasurementTime.start(); |
| 191 |
preSynchronizer->delegateCommand(command); |
| 192 |
} |
| 193 |
|
| 194 |
bool CCLIBatchProcessingLoader::hasMoreProcessingCommands() { |
| 195 |
return !mProcessCommandList.isEmpty(); |
| 196 |
} |
| 197 |
|
| 198 |
void CCLIBatchProcessingLoader::finishProcessing() { |
| 199 |
} |
| 200 |
|
| 201 |
void CCLIBatchProcessingLoader::terminateProcessing() { |
| 202 |
|
| 203 |
if (mLogTotalProcessingTime) { |
| 204 |
cint64 timeElapsed = mTotalTime.elapsed(); |
| 205 |
logOutputMessage(QString("Total processing time: %1 ms.").arg(timeElapsed)); |
| 206 |
} |
| 207 |
|
| 208 |
if (mBlockUntilProcessed) { |
| 209 |
mBlockingSemaphore.release(); |
| 210 |
} |
| 211 |
|
| 212 |
if (mCloseAfterOutput) { |
| 213 |
CLogger::getInstance()->waitSynchronization(); |
| 214 |
QCoreApplication::exit(); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
CLoader *CCLIBatchProcessingLoader::exit() { |
| 221 |
stopThread(); |
| 222 |
return this; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
}; // end namespace Loader |
| 228 |
|
| 229 |
}; // end namespace Control |
| 230 |
|
| 231 |
}; // end namespace Konclude |