| 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_CONTROL_INTERFACE_SPARQL_CSPARQLHTTPCONNECTIONHANDLERPROCESSOR_H |
| 22 |
#define KONCLUDE_CONTROL_INTERFACE_SPARQL_CSPARQLHTTPCONNECTIONHANDLERPROCESSOR_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
#include <QTcpSocket> |
| 26 |
#include <QHostAddress> |
| 27 |
#include <QAtomicInt> |
| 28 |
|
| 29 |
// Namespace includes |
| 30 |
#include "SPARQLSettings.h" |
| 31 |
#include "CSPARQLRecordResultStreamingInterpreter.h" |
| 32 |
#include "CSPARQLStreamingWriter.h" |
| 33 |
|
| 34 |
// Other includes |
| 35 |
#include "Control/Interface/SPARQL/Events/CResultStreamingWriteEvent.h" |
| 36 |
|
| 37 |
#include "Network/HTTP/CQtHttpPooledConnectionHandler.h" |
| 38 |
#include "Network/HTTP/CQtHttpRequestBodyOnlyParser.h" |
| 39 |
#include "Network/HTTP/CQtHttpConnectionHandlerReleaser.h" |
| 40 |
|
| 41 |
#include "Network/HTTP/Events/CHandleIncomingHttpConnectionEvent.h" |
| 42 |
#include "Network/HTTP/Events/CConnectionReadyReadEvent.h" |
| 43 |
#include "Network/HTTP/Events/CConnectionDisconnectedEvent.h" |
| 44 |
|
| 45 |
#include "Control/Interface/OWLlink/COWLlinkProcessor.h" |
| 46 |
|
| 47 |
|
| 48 |
#include "Control/Command/CConfigManagerReader.h" |
| 49 |
|
| 50 |
// Logger includes |
| 51 |
#include "Logger/CLogger.h" |
| 52 |
#include "Logger/CLogIdentifier.h" |
| 53 |
|
| 54 |
|
| 55 |
namespace Konclude { |
| 56 |
|
| 57 |
using namespace Network::HTTP; |
| 58 |
using namespace Network::HTTP::Events; |
| 59 |
|
| 60 |
namespace Control { |
| 61 |
|
| 62 |
using namespace Command; |
| 63 |
|
| 64 |
namespace Interface { |
| 65 |
|
| 66 |
using namespace OWLlink; |
| 67 |
|
| 68 |
namespace SPARQL { |
| 69 |
|
| 70 |
using namespace Events; |
| 71 |
|
| 72 |
|
| 73 |
/*! |
| 74 |
* |
| 75 |
* \class CSPARQLHttpConnectionHandlerProcessor |
| 76 |
* \author Andreas Steigmiller |
| 77 |
* \version 0.1 |
| 78 |
* \brief TODO |
| 79 |
* |
| 80 |
*/ |
| 81 |
class CSPARQLHttpConnectionHandlerProcessor : public COWLlinkProcessor, public CQtHttpPooledConnectionHandler, public CSPARQLStreamingWriter { |
| 82 |
Q_OBJECT |
| 83 |
|
| 84 |
// public methods |
| 85 |
public: |
| 86 |
//! Constructor |
| 87 |
CSPARQLHttpConnectionHandlerProcessor(CConfiguration* loaderConfig, CQtHttpConnectionHandlerReleaser* releaser); |
| 88 |
|
| 89 |
//! Destructor |
| 90 |
virtual ~CSPARQLHttpConnectionHandlerProcessor(); |
| 91 |
|
| 92 |
virtual bool handleIncomingConnection(int socketDescriptor); |
| 93 |
|
| 94 |
|
| 95 |
bool isHandlerQueued(); |
| 96 |
CSPARQLHttpConnectionHandlerProcessor* setHandlerQueued(bool queued); |
| 97 |
|
| 98 |
virtual bool writeStreamData(const QList<CSPARQLResultBufferWriteData>& bufferList, bool last); |
| 99 |
virtual CSPARQLStreamingWriter* writeStreamDataToSocket(QList<CSPARQLResultBufferWriteData>* bufferList, bool last); |
| 100 |
|
| 101 |
// protected methods |
| 102 |
protected: |
| 103 |
virtual void threadStarted(); |
| 104 |
virtual void threadStopped(); |
| 105 |
|
| 106 |
bool processCustomsEvents(QEvent::Type type, CCustomEvent *event); |
| 107 |
|
| 108 |
virtual COWLlinkProcessor* initializeOWLlinkContent(); |
| 109 |
virtual COWLlinkProcessor* concludeOWLlinkContent(); |
| 110 |
|
| 111 |
|
| 112 |
virtual COWLlinkProcessor* sendData(const QByteArray& dataString); |
| 113 |
|
| 114 |
virtual CConfiguration *getConfiguration(); |
| 115 |
|
| 116 |
|
| 117 |
CSPARQLStreamingWriter* writeChunk(const QByteArray& byteArray); |
| 118 |
|
| 119 |
// protected variables |
| 120 |
protected: |
| 121 |
|
| 122 |
|
| 123 |
// private methods |
| 124 |
private: |
| 125 |
QTcpSocket* mSocket; |
| 126 |
CQtHttpRequestBodyOnlyParser* mParser; |
| 127 |
|
| 128 |
bool mProcessingRequest; |
| 129 |
bool mProcessMoreRead; |
| 130 |
QByteArray* mProcessingByteArray; |
| 131 |
|
| 132 |
CSPARQLRecordResultStreamingInterpreter* mSPARQLInterpreter; |
| 133 |
bool mWritingStarted; |
| 134 |
bool mDataWritten; |
| 135 |
bool mWritingFailed; |
| 136 |
CCommand* mProcessingCommand; |
| 137 |
|
| 138 |
CConfiguration* mLoaderConfig; |
| 139 |
QSemaphore mThreadStartedSemaphore; |
| 140 |
|
| 141 |
CQtHttpConnectionHandlerReleaser* mReleaser; |
| 142 |
bool mQueued; |
| 143 |
bool mForceDisconnect; |
| 144 |
bool mThreadedWriting; |
| 145 |
|
| 146 |
cint64 mChunkPart; |
| 147 |
CPreconditionSynchronizer* mOriginPreSynchronizer; |
| 148 |
|
| 149 |
|
| 150 |
QByteArray mStreamSPARQLHeader; |
| 151 |
QByteArray mStreamSPARQLFooter; |
| 152 |
|
| 153 |
QSemaphore* mWriteLimitSemaphore; |
| 154 |
QSemaphore* mWrittenContinueSemaphore; |
| 155 |
bool mBlockingWarned; |
| 156 |
|
| 157 |
|
| 158 |
// private slots |
| 159 |
private slots: |
| 160 |
void connectionRead(); |
| 161 |
void connectionDisconnect(); |
| 162 |
|
| 163 |
// private variables |
| 164 |
private: |
| 165 |
|
| 166 |
}; |
| 167 |
|
| 168 |
}; // end namespace SPARQL |
| 169 |
|
| 170 |
}; // end namespace Interface |
| 171 |
|
| 172 |
}; // end namespace Control |
| 173 |
|
| 174 |
}; // end namespace Konclude |
| 175 |
|
| 176 |
#endif // KONCLUDE_CONTROL_INTERFACE_SPARQL_CSPARQLHTTPCONNECTIONHANDLERPROCESSOR_H |