CommonBackend
The class CommonBackend contains handlers and general logic for interacting with the frontend.
The class contains handlers and general logic for interacting with the frontend. To work, you need the following methods from the CommonBackend class:
- startReadAndWriteThread - Starts threads to process read and write
messages.
commonBackend.startReadAndWriteThread();
- waitForDone - Waits for the read, write, and channel-serving threads to complete. The call
of this function is necessary for the correct completion of an instance of the
CommonBackend
class.commonBackend.waitForDone();
- getConfigChannelHandlerUnprepared - Gets the config channel handler object, but it does
not make sure that it is actually in a useable
state.
commonBackend.getConfigChannelHandlerUnprepared();
- runCommonBackendWithConfigChannelOnly - Runs the configuration channel thread only for
synchronous requests to get configuration settings without triggering read-write processing.
When calling this function, you need to start the read-write processing threads using the
startReadAndWriteThread function in the future. The third parameter serverPublicKey is
optional and can be used to pass a public key for encrypted communication with the
frontend.
auto& configChannelHandler = commonBackend.runCommonBackendWithConfigChannelOnly(zmqAddress, pollingInterval,serverPublicKey);
- onConnectionLost - Sets up a callback to handle the loss of communication with the
frontend.
commonBackend.onConnectionLost([&]() { logDebug("Connection to the frontend lost, the backend will exit."); doExit = true; });
- onWriteRequest - Sets up a callback function responsible for writing. This callback function should return a write success flag (see Write handler).
- onReadRequest - Sets up a callback function responsible for reading (see Read handler).
- makeReadResponseSender - Creates an instance of the ReadResponseSender class to send the read result to the frontend (see Read handler).
- getLoggingInterface - Gets an instance of LogMessageQueue class for logging messages to
the
frontend.
LogMessageQueue& logMessageQueue = commonBackend.getLoggingInterface(); logMessageQueue.queueLogMessage(ErrorMessageFromBackend_Priority_Information, message, std::string(), 0);