QGIS API Documentation 3.43.0-Master (9e873c7bc91)
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 "qgsserverrequest.h"
26#include "qgsserverresponse.h"
27
28#include <QBuffer>
29#include <thread>
30#include <mutex>
31
39{
40 public:
45 QgsSocketMonitoringThread( std::shared_ptr<QgsFeedback> feedback );
46
50 void run();
51
55 void stop();
56
57 private:
58 std::atomic_bool mShouldStop;
59 std::shared_ptr<QgsFeedback> mFeedback;
60 int mIpcFd = -1;
61
62 // used to synchronize socket monitoring thread and fcgi response
63 std::timed_mutex mMutex;
64};
65
71class SERVER_EXPORT QgsFcgiServerResponse : public QgsServerResponse
72{
73 public:
79
80 virtual ~QgsFcgiServerResponse() override;
81
82 void setHeader( const QString &key, const QString &value ) override;
83
84 void removeHeader( const QString &key ) override;
85
86 QString header( const QString &key ) const override;
87
88 QMap<QString, QString> headers() const override { return mHeaders; }
89
90 bool headersSent() const override;
91
92 void setStatusCode( int code ) override;
93
94 int statusCode() const override { return mStatusCode; }
95
96 void sendError( int code, const QString &message ) override;
97
98 QIODevice *io() override;
99
100 void finish() override;
101
102 void flush() override;
103
104 void clear() override;
105
106 QByteArray data() const override;
107
108 void truncate() override;
109
113 void setDefaultHeaders();
114
119 QgsFeedback *feedback() const override { return mFeedback.get(); }
120
121 private:
122 QMap<QString, QString> mHeaders;
123 QBuffer mBuffer;
124 bool mFinished = false;
125 bool mHeadersSent = false;
127 int mStatusCode = 0;
128
129 // encapsulate thread data
130 std::unique_ptr<QgsSocketMonitoringThread> mSocketMonitoringThread;
131 // real thread object. Used to join.
132 std::thread mThread;
133 // Used to cancel rendering jobs
134 std::shared_ptr<QgsFeedback> mFeedback;
135};
136
137#endif
Class defining fcgi response.
QgsFeedback * feedback() const override
Returns socket feedback if any.
QMap< QString, QString > headers() const override
Returns the header value.
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.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
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.
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.
Thread used to monitor the fcgi socket.
void run()
main thread function