Cutelyst  1.8.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
Cutelyst::Engine Class Referenceabstract
Inheritance diagram for Cutelyst::Engine:
Inheritance graph

Public Member Functions

 Engine (Application *app, int workerCore, const QVariantMap &opts)
Applicationapp () const
QVariantMap config (const QString &entity) const
 user configuration for the application More...
bool isZeroWorker () const
QVariantMap opts () const
void setConfig (const QVariantMap &config)
virtual quint64 time ()
int workerCore () const
virtual int workerId () const =0

Static Public Member Functions

static QVariantMap loadIniConfig (const QString &filename)
static QVariantMap loadJsonConfig (const QString &filename)

Protected Member Functions

HeadersdefaultHeaders ()
virtual qint64 doWrite (Context *c, const char *data, qint64 len, void *engineData)=0
void finalize (Context *c)
virtual void finalizeBody (Context *c)
virtual void finalizeCookies (Context *c)
virtual void finalizeError (Context *c)
virtual bool finalizeHeaders (Context *c)
virtual bool finalizeHeadersWrite (Context *c, quint16 status, const Headers &headers, void *engineData)=0
bool initApplication ()
 initApplication More...
bool postForkApplication ()
 postForkApplication More...
Q_DECL_DEPRECATED void processRequest (const EngineRequest &req)
Q_DECL_DEPRECATED void processRequest (const QString &method, const QString &path, const QByteArray &query, const QString &protocol, bool https, const QString &serverAddress, const QHostAddress &remoteAddress, quint16 remotePort, const QString &remoteUser, const Headers &headers, quint64 startOfRequest, QIODevice *body, void *requestPtr)
ContextprocessRequest2 (const EngineRequest &req)
virtual bool webSocketClose (Context *c, quint16 code, const QString &reason)
bool webSocketHandshake (Context *c, const QString &key, const QString &origin, const QString &protocol)
virtual bool webSocketHandshakeDo (Context *c, const QString &key, const QString &origin, const QString &protocol, void *engineData)
virtual bool webSocketSendBinaryMessage (Context *c, const QByteArray &message)
virtual bool webSocketSendPing (Context *c, const QByteArray &payload)
virtual bool webSocketSendTextMessage (Context *c, const QString &message)
qint64 write (Context *c, const char *data, qint64 len, void *engineData)

Static Protected Member Functions

static void camelCaseByteArrayHeader (QByteArray &key)
static QString camelCaseHeader (const QString &headerKey)
static const char * httpStatusMessage (quint16 status, int *len=nullptr)


class Application
class Response

Detailed Description

Definition at line 64 of file engine.h.

Constructor & Destructor Documentation

Cutelyst::Engine::Engine ( Application app,
int  workerCore,
const QVariantMap &  opts 

Constructs an Engine object, where app is the application that might be used to create new instances if workerCore is greater than 1, opts is the options loaded by the engine subclass.

Member Function Documentation

Application* Cutelyst::Engine::app ( ) const

Returns the application associated with this engine.

static void Cutelyst::Engine::camelCaseByteArrayHeader ( QByteArray &  key)
static QString Cutelyst::Engine::camelCaseHeader ( const QString &  headerKey)

Returns the header key in camel case form

Definition at line 225 of file engine.h.

QVariantMap Cutelyst::Engine::config ( const QString &  entity) const
entitythe entity you are interested in
the configuration settings
Headers& Cutelyst::Engine::defaultHeaders ( )

This is the HTTP default response headers that each request gets

virtual qint64 Cutelyst::Engine::doWrite ( Context c,
const char *  data,
qint64  len,
void *  engineData 
protectedpure virtual

Reimplement this to do the RAW writing to the client

void Cutelyst::Engine::finalize ( Context c)

Called by Application to deal with finalizing cookies, headers and body

virtual void Cutelyst::Engine::finalizeBody ( Context c)

Engines must reimplement this to write the response body back to the caller

virtual void Cutelyst::Engine::finalizeCookies ( Context c)

Reimplement if you need a custom way to Set-Cookie, the default implementation writes them to c->res()->headers()

virtual void Cutelyst::Engine::finalizeError ( Context c)

Engines should overwrite this if they want to to make custom error messages. Default implementation render an html with errors.

virtual bool Cutelyst::Engine::finalizeHeaders ( Context c)

Finalize the headers, and call doWriteHeader(), reimplemententions must call this first

virtual bool Cutelyst::Engine::finalizeHeadersWrite ( Context c,
quint16  status,
const Headers headers,
void *  engineData 
protectedpure virtual

Reimplement this to write the headers back to the client

static const char* Cutelyst::Engine::httpStatusMessage ( quint16  status,
int *  len = nullptr 

Returns the HTTP status message for the give status.

bool Cutelyst::Engine::initApplication ( )

This method inits the application and calls init on the engine. It must be called on the engine's thread

true if succeded
bool Cutelyst::Engine::isZeroWorker ( ) const

Returns true if this is the Zero worker, ie if workerId() == 0 and workerCore() == 0

the value returned from this function is only valid when postFork() is issued.

Definition at line 323 of file engine.h.

static QVariantMap Cutelyst::Engine::loadIniConfig ( const QString &  filename)

Returns a QVariantMap with the INI parsed from filename.

static QVariantMap Cutelyst::Engine::loadJsonConfig ( const QString &  filename)

Returns a QVariantMap with the JSON parsed from filename.

QVariantMap Cutelyst::Engine::opts ( ) const

Engine options

bool Cutelyst::Engine::postForkApplication ( )

Subclasses must be call after the engine forks by the worker thread, if no forking is involved it must be called once the worker thread has started.

For convenience QThread::currentThread() has it's object name set with the worker core number.

true if the engine should use this process
Q_DECL_DEPRECATED void Cutelyst::Engine::processRequest ( const EngineRequest req)


Q_DECL_DEPRECATED void Cutelyst::Engine::processRequest ( const QString &  method,
const QString &  path,
const QByteArray &  query,
const QString &  protocol,
bool  https,
const QString &  serverAddress,
const QHostAddress &  remoteAddress,
quint16  remotePort,
const QString &  remoteUser,
const Headers headers,
quint64  startOfRequest,
QIODevice *  body,
void *  requestPtr 


Context* Cutelyst::Engine::processRequest2 ( const EngineRequest req)

Process the EngineRequest req, the caller must delete the context when the request is finished.

This method allows for engines to keep the Context alive while processing websocket data.

void Cutelyst::Engine::setConfig ( const QVariantMap &  config)

Sets the configuration to be used by Application

virtual quint64 Cutelyst::Engine::time ( )
current micro seconds time to be used for stats, the default implementation returns QDateTime::currentMSecsSinceEpoch() * 1000, to become micro seconds, so if the engine supports a more precise value it can reimplement this method.
int Cutelyst::Engine::workerCore ( ) const

Returns the worker core set when constructing the engine

virtual int Cutelyst::Engine::workerId ( ) const
pure virtual

Reimplement this to get the workerId of the engine subclass, this is the same as processes id.

qint64 Cutelyst::Engine::write ( Context c,
const char *  data,
qint64  len,
void *  engineData 

Called by Response to manually write data