Cutelyst  1.6.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
[legend]

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...
 
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)
 
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)
 

Friends

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 
)
explicit

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)
inlinestaticprotected
static QString Cutelyst::Engine::camelCaseHeader ( const QString &  headerKey)
inlinestaticprotected

Returns the header key in camel case form

Definition at line 213 of file engine.h.

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

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 writting to the client

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

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

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

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

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

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)
protectedvirtual

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)
protectedvirtual

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 
)
staticprotected

Returns the HTTP status message for the give status.

bool Cutelyst::Engine::initApplication ( )
protected

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

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

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

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

Definition at line 301 of file engine.h.

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

Returns a QVariantMap with the INI parsed from filename.

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

Returns a QVariantMap with the JSON parsed from filename.

QVariantMap Cutelyst::Engine::opts ( ) const

Engine options

bool Cutelyst::Engine::postForkApplication ( )
protected

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.

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

Process the 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 
)
protected

Deprecated

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

Sets the configuration to be used by Application

virtual quint64 Cutelyst::Engine::time ( )
virtual
Returns
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 
)
protected

Called by Response to manually write data