QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsfcgiserverresponse.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfcgiserverresponse.h
3
4 Define response wrapper for fcgi response
5 -------------------
6 begin : 2017-01-03
7 copyright : (C) 2017 by David Marteau
8 email : david dot marteau at 3liz dot com
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifndef QGSFCGISERVERRESPONSE_H
20#define QGSFCGISERVERRESPONSE_H
21
22#define SIP_NO_FILE
23
24
25#include <mutex>
26#include <thread>
27
28#include "qgsserverrequest.h"
29#include "qgsserverresponse.h"
30
31#include <QBuffer>
32
40{
41 public:
46 QgsSocketMonitoringThread( std::shared_ptr<QgsFeedback> feedback );
47
51 void run();
52
56 void stop();
57
58 private:
59 std::atomic_bool mShouldStop;
60 std::shared_ptr<QgsFeedback> mFeedback;
61 int mIpcFd = -1;
62
63 // used to synchronize socket monitoring thread and fcgi response
64 std::timed_mutex mMutex;
65};
66
72class SERVER_EXPORT QgsFcgiServerResponse : public QgsServerResponse
73{
74 public:
80
81 ~QgsFcgiServerResponse() override;
82
83 void setHeader( const QString &key, const QString &value ) override;
84
85 void removeHeader( const QString &key ) override;
86
87 QString header( const QString &key ) const override;
88
89 QMap<QString, QString> headers() const override { return mHeaders; }
90
91 bool headersSent() const override;
92
93 void setStatusCode( int code ) override;
94
95 int statusCode() const override { return mStatusCode; }
96
97 void sendError( int code, const QString &message ) override;
98
99 QIODevice *io() override;
100
101 void finish() override;
102
103 void flush() override;
104
105 void clear() override;
106
107 QByteArray data() const override;
108
109 void truncate() override;
110
114 void setDefaultHeaders();
115
120 QgsFeedback *feedback() const override { return mFeedback.get(); }
121
122 private:
123 QMap<QString, QString> mHeaders;
124 QBuffer mBuffer;
125 bool mFinished = false;
126 bool mHeadersSent = false;
128 int mStatusCode = 0;
129
130 // encapsulate thread data
131 std::unique_ptr<QgsSocketMonitoringThread> mSocketMonitoringThread;
132 // real thread object. Used to join.
133 std::thread mThread;
134 // Used to cancel rendering jobs
135 std::shared_ptr<QgsFeedback> mFeedback;
136};
137
138#endif
QgsFeedback * feedback() const override
Returns socket feedback if any.
QMap< QString, QString > headers() const override
Returns the header value.
QgsFcgiServerResponse(QgsServerRequest::Method method=QgsServerRequest::GetMethod)
Constructor for QgsFcgiServerResponse.
int statusCode() const override
Returns the http status code.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Method
HTTP Method (or equivalent) used for the request.
virtual void removeHeader(const QString &key)=0
Clear header Undo a previous 'setHeader' call.
virtual void truncate()=0
Truncate data.
virtual void flush()
Flushes the current output buffer to the network.
virtual QByteArray data() const =0
Gets the data written so far.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual void clear()=0
Reset all headers and content for this response.
QgsServerResponse()=default
virtual void finish()
Finish the response, ending the transaction.
virtual bool headersSent() const =0
Returns true if the headers have already been sent.
virtual void sendError(int code, const QString &message)=0
Send error This method delegates error handling at the server level.
virtual QIODevice * io()=0
Returns the underlying QIODevice.
virtual QString header(const QString &key) const =0
Returns the header value.
virtual void setStatusCode(int code)=0
Set the http status code.
void run()
main thread function
QgsSocketMonitoringThread(std::shared_ptr< QgsFeedback > feedback)
Constructor for QgsSocketMonitoringThread.