File: COWLlinkBatchFileLoader.cpp

package info (click to toggle)
konclude 0.6.2~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 26,976 kB
  • ctags: 43,332
  • sloc: cpp: 250,898; xml: 54,573; makefile: 29; ansic: 3; sh: 3
file content (208 lines) | stat: -rw-r--r-- 6,158 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 *		Copyright (C) 2013, 2014, 2015 by the Konclude Developer Team.
 *
 *		This file is part of the reasoning system Konclude.
 *		For details and support, see <http://konclude.com/>.
 *
 *		Konclude is free software: you can redistribute it and/or modify it under
 *		the terms of version 2.1 of the GNU Lesser General Public License (LGPL2.1)
 *		as published by the Free Software Foundation.
 *
 *		You should have received a copy of the GNU Lesser General Public License
 *		along with Konclude. If not, see <http://www.gnu.org/licenses/>.
 *
 *		Konclude is distributed in the hope that it will be useful,
 *		but WITHOUT ANY WARRANTY; without even the implied warranty of
 *		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more
 *		details, see GNU Lesser General Public License.
 *
 */

#include "COWLlinkBatchFileLoader.h"


namespace Konclude {

	namespace Control {

		namespace Loader {


			COWLlinkBatchFileLoader::COWLlinkBatchFileLoader() {
				owllinkInterpreter = 0;
				loaderConfig = 0;
				mConfLogProcessingTimes = false;
			}



			COWLlinkBatchFileLoader::~COWLlinkBatchFileLoader() {
			}


			CLoader *COWLlinkBatchFileLoader::init(CLoaderFactory *loaderFactory, CConfiguration *config) {
				loaderConfig = config;
				CConfigData *data = config->getLastConfigChange("Konclude.OWLlink.RequestFile");
				if (data) {
					reqFileString = data->getString();
				}

				data = config->getLastConfigChange("Konclude.OWLlink.ResponseFile");
				if (data) {
					resFileString = data->getString();
				}


				directConsoleOutput = false;
				data = config->getLastConfigChange("Konclude.OWLlink.WriteResponseToStandardOutput");
				if (data) {
					directConsoleOutput = data->getBoolean();
				}
				directErrorOutput = false;
				data = config->getLastConfigChange("Konclude.OWLlink.WriteResponseToStandardError");
				if (data) {
					directErrorOutput = data->getBoolean();
				}
				closeAfterOutput = false;
				data = config->getLastConfigChange("Konclude.OWLlink.CloseAfterProcessedRequest");
				if (data) {
					closeAfterOutput = data->getBoolean();
				}
				blockUntilProcessed = false;
				data = config->getLastConfigChange("Konclude.OWLlink.BlockUntilProcessedRequest");
				if (data) {
					blockUntilProcessed = data->getBoolean();
				}
				mConfLogProcessingTimes = false;
				data = config->getLastConfigChange("Konclude.OWLlink.LoggingExtendedProcessingTimes");
				if (data) {
					mConfLogProcessingTimes = data->getBoolean();
				}
				data = config->getLastConfigChange("Konclude.OWLlink.SAXBasedLoadOntologiesParsing");
				if (data) {
					mConfLoadOntologiesSAXParsing = data->getBoolean();
				}

				reasonerCommander = CConfigManagerReader::readCommanderManagerConfig(config);

				return this;
			}



			CLoader *COWLlinkBatchFileLoader::load() {
				startProcessing();
				if (blockUntilProcessed) {
					blockingSem.acquire();
				}
				return this;
			}



			CConfiguration *COWLlinkBatchFileLoader::getConfiguration() {
				if (!reasonerCommander) {
					return loaderConfig;
				} else {
					CGetDescriptionCommand *getDesComm = new CGetDescriptionCommand();
					reasonerCommander->delegateCommand(getDesComm);
					CCommandExecutedBlocker commExeBlocker;
					commExeBlocker.waitExecutedCommand(getDesComm);
					CConfiguration *config = getDesComm->getConfiguration();
					return config;
				}
			}



			COWLlinkProcessor *COWLlinkBatchFileLoader::initializeOWLlinkContent() {
				mResponseTime.start();
				if (!reqFileString.isEmpty()) {
					QFile file(reqFileString);
					LOG(INFO,getLogDomain(),logTr("Processing OWLlink request from file '%1'.").arg(reqFileString),this);
					if (file.open(QIODevice::ReadOnly)) {
						fileContent = file.readAll();
						COWLlinkQtXMLCommandParser *owllinkCommandParser = new COWLlinkQtXMLCommandParser();
						owllinkInterpreter = nullptr;
						if (!resFileString.isEmpty()) {
							owllinkInterpreter = new COWLLinkRecordInterpreter(preSynchronizer,loaderConfig);
							defaultCommandDelegater = owllinkInterpreter;
						} else {
							defaultCommandDelegater = preSynchronizer;
						}

						CParseOWLlinkCommandsCommand *parseCommand = new CParseOWLlinkCommandsCommand(&fileContent,reqFileString);
						parseCommand->setRecorder(owllinkInterpreter);
						parseCommand->setReportErrorFromSubCommands(false);

						CCommandProcessedCallbackEvent *proComm = new CCommandProcessedCallbackEvent(this,parseCommand);
						parseCommand->addProcessedCallback(proComm);


						owllinkCommandParser->realizeCommand(parseCommand,defaultCommandDelegater);

						delete owllinkCommandParser;

						if (mConfLogProcessingTimes) {
							cint64 readMilliSeconds = mResponseTime.elapsed();
							LOG(INFO,getLogDomain(),logTr("Read XML content in %1 ms.").arg(readMilliSeconds),this);
						}

					} else {
						LOG(ERROR,getLogDomain(),logTr("OWLlink request file '%1' not found.").arg(reqFileString),this);
						concludeOWLlinkContent();
					}
				}	
				return this;
			}



			COWLlinkProcessor *COWLlinkBatchFileLoader::concludeOWLlinkContent() {
				if (owllinkInterpreter) {
					QByteArray fileContent(owllinkInterpreter->getByteArray());
					if (!resFileString.isEmpty()) {
						QFile file(resFileString);
						if (file.open(QIODevice::WriteOnly)) {
							file.write(fileContent);
							file.close();
						}
					}
					if (directConsoleOutput) {
						std::cout<<fileContent.data();
					}
					if (directErrorOutput) {
						std::cerr<<fileContent.data();
					}
				}
				if (mConfLogProcessingTimes) {
					cint64 responseMilliSeconds = mResponseTime.elapsed();
					LOG(INFO,getLogDomain(),logTr("OWLlink request processed in %1 ms.").arg(responseMilliSeconds),this);
				}
				if (blockUntilProcessed) {
					blockingSem.release();
				}
				if (closeAfterOutput) {
					CLogger::getInstance()->waitSynchronization();
					//qSleep(10);
					//qWait();
                    QCoreApplication::exit();
				}
				return this;
			}


			CLoader *COWLlinkBatchFileLoader::exit() {

				stopThread();

				return this;
			}



		}; // end namespace Loader

	}; // end namespace Control

}; // end namespace Konclude