Debian Codegraph @

Source/Network/HTTP/CQtHttpTransactionManager.h

raw
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_NETWORK_HTTP_CQTHTTPTRANSACTIONMANAGER_H
22 #define KONCLUDE_NETWORK_HTTP_CQTHTTPTRANSACTIONMANAGER_H
23
24 // Namespace includes
25 #include "HttpSettings.h"
26 #include "CHttpTransactionManager.h"
27 #include "CHttpResponseExtractor.h"
28 #include "CHttpRequestFactory.h"
29 #include "CQtHttpRequest.h"
30 #include "CQtHttpResponse.h"
31 #include "CQtHttpResponseHandler.h"
32
33 // Library includes
34 #include <QNetworkAccessManager>
35 #include <QHash>
36
37 // Other includes
38 #include "Network/HTTP/Events/CHttpRequstEvent.h"
39 #include "Network/HTTP/Events/CHttpReplyFinishedEvent.h"
40 #include "Network/HTTP/Events/CExtractResponseDataEvent.h"
41 #include "Network/HTTP/Events/CExtractResponseDataCallbackEvent.h"
42 #include "Network/HTTP/Events/CReleaseResponseEvent.h"
43 #include "Network/HTTP/Events/CAddResponseFinishedCallbackEvent.h"
44 #include "Network/HTTP/Events/CInstallRequestFinishedCallbackEvent.h"
45 #include "Network/HTTP/Events/CAbortRequestEvent.h"
46
47 #include "Concurrent/CIntervalThread.h"
48 #include "Concurrent/Callback/CBlockingCallbackData.h"
49
50 // Logger includes
51 #include "Logger/CLogger.h"
52
53
54 namespace Konclude {
55
56 using namespace Concurrent;
57 using namespace Callback;
58
59 namespace Network {
60
61 namespace HTTP {
62
63 using namespace Events;
64
65
66 /*!
67 *
68 * \class CQtHttpTransactionManager
69 * \author Andreas Steigmiller
70 * \version 0.1
71 * \brief TODO
72 *
73 */
74 class CQtHttpTransactionManager : public CIntervalThread, public CHttpTransactionManager, public CHttpRequestFactory, public CHttpResponseExtractor {
75 Q_OBJECT
76
77 // public methods
78 public:
79 //! Constructor
80 CQtHttpTransactionManager(cint64 timeoutInterval = 5*60*1000, cint64 downloadSizeLimit = -1, bool downloadLimitCancel = false);
81
82 //! Destructor
83 virtual ~CQtHttpTransactionManager();
84
85 virtual CHttpRequest* createRequest(const QString& url);
86 CHttpRequest* createRequest(const QString& url, const QByteArray& byteArray);
87 //virtual CHttpRequest* createFileDownloadRequest(const QString& url, QIODevice* openWriteFile);
88
89 virtual bool releaseResponse(CHttpResponse* response, bool releaseAlsoRequest = true);
90
91 virtual CHttpResponse* getResponse(CHttpRequest* request);
92 virtual CQtHttpResponse* getResponse(CQtHttpRequest* request);
93
94
95 virtual CQtHttpTransactionManager* setRequestHeader(CHttpRequest* request, const QString& key, const QString& value);
96
97
98 virtual bool waitFinished(CHttpResponse* response);
99
100 virtual bool callbackFinished(CHttpResponse* response, CCallbackData* callback);
101 virtual bool callbackFinished(CQtHttpResponse* response, CCallbackData* callback);
102 virtual bool callbackFinishedRequest(CHttpResponse* response, CCallbackData* callbackData);
103
104 virtual QIODevice* getResponseDataReadDevice(CHttpResponse* response);
105 virtual QString* getExtractedText(CHttpResponse* response);
106 virtual bool callbackResponseData(CHttpResponse* response, QByteArray* dataArray, CCallbackData* callback);
107 virtual QByteArray* getResponseData(CHttpResponse* response);
108 virtual bool hasFinishedSucecssfully(CHttpResponse* response);
109 virtual bool hasFinished(CHttpResponse* response);
110 virtual bool hasBeenAborted(CHttpResponse* response, ABORT_REASON* abortReason = nullptr);
111
112 virtual bool abort(CHttpRequest* request, CHttpResponse* response, ABORT_REASON abortReason = ABORT_NO_REASON);
113
114 virtual QString* getErrorString(CHttpResponse* response);
115
116 // protected slots
117 protected slots:
118 void finishedNetworkReply(QNetworkReply* reply);
119
120 virtual void threadStarted();
121 virtual void threadStopped();
122
123
124 virtual bool processCustomsEvents(QEvent::Type type, CCustomEvent *event);
125 virtual bool processTimer(qint64 timerID);
126
127 // protected methods
128 protected:
129
130 // protected variables
131 protected:
132 cint64 mTimeoutInterval;
133 cint64 mDownloadSizeLimit;
134 bool mDownloadLimitCancel;
135 QNetworkAccessManager* mQNAM;
136 QHash<QNetworkReply*,CQtHttpResponse*> mReplyResponseHash;
137 QSet<CQtHttpResponse*> mCriticalTimeoutSet;
138 QSet<CQtHttpResponse*> mNextTimeoutSet;
139 QSet<CQtHttpResponse*> mTimeoutSet;
140 QHash<CQtHttpResponse*, CQtHttpResponseHandler*> mHandlerHash;
141
142 const static qint64 TIMEOUTCHECKTIMER = 1;
143
144 // private methods
145 private:
146
147 // private variables
148 private:
149 };
150
151
152 }; // end namespace HTTP
153
154 }; // end namespace Network
155
156 }; // end namespace Konclude
157
158
159 #endif // KONCLUDE_NETWORK_HTTP_CQTHTTPTRANSACTIONMANAGER_H