| 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 |
#ifndef KONCLUDE_REASONER_ANSWERER_CANSWERERTHREAD_H |
| 22 |
#define KONCLUDE_REASONER_ANSWERER_CANSWERERTHREAD_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
|
| 26 |
|
| 27 |
// Namespace includes |
| 28 |
#include "AnswererSettings.h" |
| 29 |
#include "CAnsweringCalculationHandler.h" |
| 30 |
#include "CAnswererContext.h" |
| 31 |
#include "CAnsweringMessageData.h" |
| 32 |
#include "CAnsweringProgress.h" |
| 33 |
|
| 34 |
|
| 35 |
// Other includes |
| 36 |
#include "Reasoner/Answerer/Events/CAnsweringInitializingEvent.h" |
| 37 |
#include "Reasoner/Answerer/Events/CAnsweringMessageEvent.h" |
| 38 |
#include "Reasoner/Answerer/Events/CAnsweringCalculationCompletedEvent.h" |
| 39 |
#include "Reasoner/Answerer/Events/CAnsweringRequirementCompletedEvent.h" |
| 40 |
#include "Reasoner/Answerer/Events/CAnsweringHandlerPreparationEvent.h" |
| 41 |
|
| 42 |
#include "Reasoner/Ontology/CConcreteOntology.h" |
| 43 |
|
| 44 |
#include "Reasoner/Kernel/Manager/CReasonerManager.h" |
| 45 |
|
| 46 |
#include "Reasoner/Kernel/Cache/COccurrenceStatisticsCache.h" |
| 47 |
|
| 48 |
#include "Concurrent/CThread.h" |
| 49 |
|
| 50 |
#include "Concurrent/Callback/CBlockingCallbackData.h" |
| 51 |
|
| 52 |
// Logger includes |
| 53 |
#include "Logger/CLogger.h" |
| 54 |
|
| 55 |
|
| 56 |
namespace Konclude { |
| 57 |
|
| 58 |
using namespace Concurrent; |
| 59 |
using namespace Concurrent::Callback; |
| 60 |
|
| 61 |
namespace Reasoner { |
| 62 |
|
| 63 |
using namespace Ontology; |
| 64 |
using namespace Kernel::Manager; |
| 65 |
using namespace Kernel::Calculation; |
| 66 |
using namespace Kernel::Cache; |
| 67 |
|
| 68 |
namespace Answerer { |
| 69 |
|
| 70 |
using namespace Events; |
| 71 |
|
| 72 |
|
| 73 |
/*! |
| 74 |
* |
| 75 |
* \class CAnswererThread |
| 76 |
* \author Andreas Steigmiller |
| 77 |
* \version 0.1 |
| 78 |
* \brief TODO |
| 79 |
* |
| 80 |
*/ |
| 81 |
class CAnswererThread : public CThread, public CAnsweringCalculationHandler { |
| 82 |
// public methods |
| 83 |
public: |
| 84 |
//! Constructor |
| 85 |
CAnswererThread(CReasonerManager *reasonerManager); |
| 86 |
|
| 87 |
//! Destructor |
| 88 |
virtual ~CAnswererThread(); |
| 89 |
|
| 90 |
|
| 91 |
bool handleAnswering(CAnsweringHandler* answeringHandling, CComplexAnsweringQuery* query, CCallbackData* callback); |
| 92 |
|
| 93 |
|
| 94 |
CAnsweringCalculationHandler* postMessage(CAnsweringHandler* handler, CAnsweringMessageData* message); |
| 95 |
|
| 96 |
CAnsweringCalculationHandler* postCalculation(CAnsweringHandler* handler, CSatisfiableCalculationJob* satCalcJob, CAnsweringMessageData* finishedMessage, CCallbackDataContext* callbackContext); |
| 97 |
CAnsweringCalculationHandler* ensureRequirements(CAnsweringHandler* handler, CConcreteOntology* ontology, const QList<COntologyProcessingRequirement*>& requirementList, CAnsweringMessageData* finishedMessage); |
| 98 |
CAnsweringCalculationHandler* answerSubQuery(CAnsweringHandler* handler, CQuery* query, CAnsweringMessageData* finishedMessage); |
| 99 |
|
| 100 |
virtual CAnsweringMessageDataObserver* sendMessage(CAnsweringHandler* answeringHandler, CAnsweringMessageData* messageData, CMemoryPool* memoryPool); |
| 101 |
|
| 102 |
|
| 103 |
virtual CAnswererThread* initializeAnswerer(CConfiguration* configurationProvider); |
| 104 |
virtual CAnsweringProgress* getAnsweringProgress(); |
| 105 |
|
| 106 |
virtual CAnswererThread* addAnsweringStatistics(CAnsweringStatistics* stats); |
| 107 |
|
| 108 |
virtual COccurrenceStatisticsCacheReader* getOccurrenceStatisticsCacheReader(); |
| 109 |
|
| 110 |
virtual CAnswererThread* prepareAnswering(CAnsweringHandler* answeringHandler, CCallbackData* callback = nullptr); |
| 111 |
|
| 112 |
// protected methods |
| 113 |
protected: |
| 114 |
virtual bool processCustomsEvents(QEvent::Type type, CCustomEvent *event); |
| 115 |
|
| 116 |
bool continueCalculationCreation(); |
| 117 |
|
| 118 |
CAnswererThread* submitCalculationJobs(); |
| 119 |
|
| 120 |
// protected variables |
| 121 |
protected: |
| 122 |
qint64 mConfMaxTestParallelCount; |
| 123 |
qint64 mConfMinTestParallelCount; |
| 124 |
qint64 mConfDirectSubmission; |
| 125 |
|
| 126 |
qint64 mCurrRunningTestParallelCount; |
| 127 |
qint64 mCurrRunningRequirementParallelCount; |
| 128 |
|
| 129 |
class CAnsweringHandlerData { |
| 130 |
public: |
| 131 |
CAnsweringHandler* mAnsweringHandler; |
| 132 |
CCallbackData* mCallbackData; |
| 133 |
bool mQueued; |
| 134 |
bool mProcessing; |
| 135 |
cint64 mJobProcessingCount; |
| 136 |
cint64 mRequirmentProcessingCount; |
| 137 |
|
| 138 |
CAnsweringHandlerData(CAnsweringHandler* answeringHandling, CCallbackData* callback) { |
| 139 |
mAnsweringHandler = answeringHandling; |
| 140 |
mCallbackData = callback; |
| 141 |
mQueued = false; |
| 142 |
mProcessing = false; |
| 143 |
mJobProcessingCount = 0; |
| 144 |
mRequirmentProcessingCount = 0; |
| 145 |
} |
| 146 |
}; |
| 147 |
|
| 148 |
QList<CAnsweringHandlerData*> mQueuedAnsweringHandlerList; |
| 149 |
QSet<CAnsweringHandlerData*> mProcessingAnsweringHandlerSet; |
| 150 |
QSet<CAnsweringHandlerData*> mManagedAnsweringHandlerSet; |
| 151 |
|
| 152 |
QHash<CAnsweringHandler*, CAnsweringHandlerData*> mHandlerHandlerDataHash; |
| 153 |
|
| 154 |
CReasonerManager* mReasonerManager; |
| 155 |
CCalculationManager* mCalculationManager; |
| 156 |
COccurrenceStatisticsCacheReader* mOccStatsCacheReader; |
| 157 |
|
| 158 |
|
| 159 |
QList< QPair<CCalculationJob*, CCallbackData*> > mJobCallbackList; |
| 160 |
|
| 161 |
cint64 mStatCalculationJobsSubmitted; |
| 162 |
cint64 mStatRequirmentSubmitted; |
| 163 |
|
| 164 |
CAnswererContext* mAnswererContext; |
| 165 |
|
| 166 |
|
| 167 |
QReadWriteLock mReadWriteLock; |
| 168 |
CAnsweringProgress mAnsweringProgress; |
| 169 |
|
| 170 |
// private methods |
| 171 |
private: |
| 172 |
|
| 173 |
// private variables |
| 174 |
private: |
| 175 |
|
| 176 |
}; |
| 177 |
|
| 178 |
}; // end namespace Answerer |
| 179 |
|
| 180 |
}; // end namespace Reasoner |
| 181 |
|
| 182 |
}; // end namespace Konclude |
| 183 |
|
| 184 |
#endif // KONCLUDE_REASONER_ANSWERER_CANSWERERTHREAD_H |