Cutelyst  2.14.2
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
Cutelyst::Engine Class Referenceabstract

The Cutelyst Engine. More...

Inheritance diagram for Cutelyst::Engine:
Inheritance graph
[legend]

Signals

void processRequestAsync (Cutelyst::EngineRequest *request)
 

Public Member Functions

 Engine (Application *app, int workerCore, const QVariantMap &opts)
 
Applicationapp () const
 application More...
 
QVariantMap config (const QString &entity) const
 user configuration for the application More...
 
bool isZeroWorker () const
 
QVariantMap opts () const
 
void processRequest (EngineRequest *request)
 
void setConfig (const QVariantMap &config)
 
virtual quint64 time ()
 
int workerCore () const
 Each worker process migth have a number of worker cores (threads), a single process with two worker threads will return 0 and 1 for each of the thread respectively. More...
 
virtual int workerId () const =0
 The id is the number of the spawned engine process, a single process workerId = 0, two process 0 for the first 1 for the second. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectList & children () const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const
 
bool disconnect (const QObject *receiver, const char *method) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const
 
bool inherits (const char *className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType)
 
QThreadthread () const
 

Static Public Member Functions

static void camelCaseByteArrayHeader (QByteArray &key)
 
static QString camelCaseHeader (const QString &headerKey)
 
static const char * httpStatusMessage (quint16 status, int *len=nullptr)
 
static QVariantMap loadIniConfig (const QString &filename)
 
static QVariantMap loadJsonConfig (const QString &filename)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

HeadersdefaultHeaders ()
 
bool initApplication ()
 initApplication More...
 
bool postForkApplication ()
 postForkApplication More...
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Friends

class Application
 
class Response
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 

Detailed Description

This class is responsible receiving the request and sending the response. It must be reimplemented by real HTTP engines due some pure virtual methods.

The subclass must create an Engine per thread (worker core), if the Application passed to the constructor has a worker core greater than 0 it will issue a new Application instance, failing to do so a fatal error is generated (usually indicating that the Application does not have a Q_INVOKABLE constructor).

Definition at line 33 of file engine.h.

Constructor & Destructor Documentation

Engine::Engine ( Cutelyst::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.

Parameters
appThe application loaded
workerCoreThe thread number
optsThe configuation options

Definition at line 57 of file engine.cpp.

References app(), QObject::connect(), QObject::metaObject(), QMetaObject::newInstance(), opts(), processRequest(), processRequestAsync(), QObject::setParent(), and workerCore().

Member Function Documentation

Application * Engine::app ( ) const

Returns the application associated with this engine.

Returns
the Application object we are dealing with

Definition at line 93 of file engine.cpp.

Referenced by Engine().

static void Cutelyst::Engine::camelCaseByteArrayHeader ( QByteArray key)
inlinestatic

Convert Header key to camel case

Definition at line 139 of file engine.h.

References QChar::isLetter(), QByteArray::size(), and QChar::toLower().

static QString Cutelyst::Engine::camelCaseHeader ( const QString headerKey)
inlinestatic

Returns the header key in camel case form

Definition at line 116 of file engine.h.

References QString::size().

QVariantMap Engine::config ( const QString entity) const
Headers & Engine::defaultHeaders ( )
protected

This is the HTTP default response headers that each request gets

Definition at line 302 of file engine.cpp.

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

Returns the HTTP status message for the given status.

Definition at line 161 of file engine.cpp.

References QByteArray::number().

bool 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

Definition at line 125 of file engine.cpp.

References QThread::currentThread(), and QObject::thread().

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 217 of file engine.h.

QVariantMap Engine::loadIniConfig ( const QString filename)
static

Returns a QVariantMap with the INI parsed from filename.

Definition at line 332 of file engine.cpp.

References QSettings::beginGroup(), QSettings::childGroups(), QSettings::childKeys(), QSettings::endGroup(), QList::insert(), QSettings::status(), and QSettings::value().

QVariantMap Engine::loadJsonConfig ( const QString filename)
static

Returns a QVariantMap with the JSON parsed from filename.

Definition at line 356 of file engine.cpp.

References QJsonDocument::fromJson(), QFile::open(), QIODevice::readAll(), QVariant::toMap(), and QJsonDocument::toVariant().

QVariantMap Engine::opts ( ) const

Engine options

Definition at line 314 of file engine.cpp.

Referenced by Engine().

bool 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

Definition at line 142 of file engine.cpp.

References QThread::currentThread(), QString::number(), and QObject::setObjectName().

void Engine::processRequest ( EngineRequest request)

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.

Definition at line 308 of file engine.cpp.

Referenced by Engine().

void Cutelyst::Engine::processRequestAsync ( Cutelyst::EngineRequest request)
signal

Process the EngineRequest req Async, 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.

Referenced by Engine().

void Engine::setConfig ( const QVariantMap &  config)

Sets the configuration to be used by Application

Definition at line 326 of file engine.cpp.

References config().

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

Definition at line 156 of file engine.cpp.

References QDateTime::currentMSecsSinceEpoch().

int Engine::workerCore ( ) const

Returns the worker core set when constructing the engine

Returns
the worker core (thread)

Definition at line 119 of file engine.cpp.

Referenced by Engine(), and Cutelyst::Application::setup().

int Engine::workerId ( ) const
pure virtual

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

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