Class sh::ui::web::WebServerEngineMainModule

class sh::ui::web::WebServerEngineMainModule : public QObject, public sh::ui::web::WebModule

The web serve engine main module, providing some base services like events.

Public Functions

WebServerEngineMainModule()
~WebServerEngineMainModule()
bool executeCommand(WebServerEngineRequest *request, QString command) override

Executes command as requested by the browser, if responsible.

Read parameters, check if this module is responsible for answering, and then write an answer with request.

Implementations often use executeCommand_byQObjectReflection() for convenience.

Return

If it handled (answered) the command.

bool rootCommand(WebServerEngineRequest *request, QString webadapter) override

Returns the root (‘index.html’) content. .

void triggerEvent(QString name, QString data)

Triggers an event on browser side.

void setEngine(WebServerEngine *webserver)

Assigns this web module to a sh::ui::web::WebServerEngine. .

WebServerEngine *webserver()

Returns the sh::ui::web::WebServerEngine this web module is assigned to (may be nullptr).

Public Static Functions

bool executeCommand_byQObjectReflection(QObject *o, WebServerEngineRequest *request, QString command, QString justLeftside = QString())

Convenience function often used by executeCommand().

For a QObject, it searches there for a slot with the name cmd_{command}, with `’/’s replaced by’_’s (so, for the command”foo/get_bars”, it searches for slotcmd_foo_get_bars`). If it finds one, it gets executed (in a worker thread). The request is considered as handled, if so.

If there is such a slot, but with appended __M in name, it is called in main thread!

Return

If it handled (answered) the command.

Private Functions

qint64 lastRequestTime()

Private Members

qint64 _lastRequestTime
QMutex _mutex_lastRequestTime
QList<EventEntry*> _eventEntries
quint64 _eventEntriesLastId = 0
QMutex _mutex_eventEntries
QWaitCondition _eventEntriesCondition
EventEntryCleanupThread _eventEntryCleanupThread
StopWhenIdleThread _stopWhenIdleThread

Private Slots

void cmd_dispatcher_toclient_heartbeat(WebServerEngineRequest *request)
void cmd_events_get_next(WebServerEngineRequest *request)

Private Static Attributes

QRegularExpression _restatic
class EventEntry

Data for one occurred event.

Public Functions

EventEntry(qint64 id, qint64 time, QString name, QString data)

Public Members

const qint64 id
const qint64 time
const QString name
const QString data

Friends

friend class EventEntryCleanupThread
class EventEntryCleanupThread : public QThread

Thread for cleaning up old EventEntry instances.

Public Functions

EventEntryCleanupThread(WebServerEngineMainModule *module)

Private Members

WebServerEngineMainModule *module
class StopWhenIdleThread : public QThread

Thread for stopping the application if the remote side is gone.

Public Functions

StopWhenIdleThread(WebServerEngineMainModule *module)

Private Members

WebServerEngineMainModule *module