Class sh::ui::web::WebServerEngine

class sh::ui::web::WebServerEngine

Abstract base class for a web server engine.

Such an engine implements an http server which a browser can connect to.

Public Functions

WebServerEngine(bool withMainModule, int minport, int maxport, QString externalUrl, QString dispatcherUrl, QByteArray wtoken)
~WebServerEngine()
QUrl url() = 0

Returns the home url of this engine (where the end user can point the browser to). .

QUrl externalUrl()

Returns the external root url for creating full externally valid urls (even behind reverse proxies).

Returns url() if no external root url is specified.

Change this by the cmdline parameter 'externalUrl'.

QUrl dispatcherUrl()

Returns the internal root url of the dispatcher (workers only).

QByteArray dispatcherWtoken()

Returns the wtoken got from the dispatcher (workers only).

QUrl getFullCommandUrl(QString command, WebCommandData data, bool external)

Generates a url path for a command.

Typically only needed for full url generation on server side.

void triggerEvent(QString name, QJsonObject data)

Triggers an event (at the clients).

void triggerEvent(QString name, QJsonValue data = QJsonValue::Undefined)
QString getConfigValue(QString key)

Returns the value for a runtime configuration key.

void setConfigValue(QString key, QString value)

Sets the runtime configuration key to a value (triggering a event updating the clients).

void getStaticFile(WebServerEngineRequest *request, QString path)

Returns a static file content (for the app itself) on a request.

QUrl rebaseUrl(QUrl rootUrl, QUrl url)

Returns a url rebased to another engine’s root url.

Used for dispatching to workers.

void addAndPreserveModule(std::shared_ptr<sh::ui::web::WebModule> module)

Plugs a WebModule into the engine and holds a pointer to it. Unplug it by calling removeModule().

void addModule(std::shared_ptr<sh::ui::web::WebModule> module)

Plugs a WebModule into the engine. Unplug it by either delete module (drop all pointers to it) or by calling removeModule().

void removeModule(sh::ui::web::WebModule *module)

Unplugs a WebModule from the engine.

qint64 currentTimestamp()

Returns the current engine timestamp.

It’s not related to real time, but just a value which is higher each time you query it.

This is used for coordination of some time-order sensitive operations on browser side.

Public Static Functions

WebServerEngine *createDispatcherEngine()

Creates and returns a web engine for a dispatcher.

WebServerEngine *createWorkerEngine(QString dispatcherUrl, QByteArray wtoken)

Creates and returns a web engine for a worker.

Parameters
  • dispatcherUrl: The root url of the dispatcher.

Private Members

const QJsonObject _jok
QMutex _configValuesMutex
QMutex _modulesMutex
int _minport
int _maxport
QUrl _externalurl
QUrl _dispatcherurl
QMap<QString, QString> _configValues
QList<std::weak_ptr<sh::ui::web::WebModule>> _modules
QList<std::shared_ptr<sh::ui::web::WebModule>> _smodules
std::shared_ptr<sh::ui::web::WebServerEngineMainModule> _mainmodule
QString _webstaticpath
qint64 _currentTimestamp = 1
QByteArray _wtoken

Private Static Functions

WebServerEngine *_createEngine(bool withMainModule, QString dispatcherUrl, QByteArray wtoken)

Friends

friend class WebServerEngineMainModule