Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
|
Utility class to actively monitor the status of a dbus service. More...
#include <ServiceMonitor.h>
Public Types | |
enum class | State { NotRunning , Running , Ready } |
Public Member Functions | |
ServiceMonitor (const std::shared_ptr< IDobbyIPCUtils > &ipcUtils, const std::shared_ptr< IDobbyUtils > &utils, const IDobbyIPCUtils::BusType &bus, const std::string &serviceName, const AI_IPC::Signal &readySignal, const AI_IPC::Method &queryMethod, const std::function< void(State)> &stateChangeHandler) | |
State | state () const |
Returns the current state of the service. | |
void | forceReadyCheck () |
Sends out an 'is ready' method request to the service. | |
Private Member Functions | |
void | onServiceNotification (bool added) |
Callback function called when the daemon service has been added or removed from the bus. | |
void | onReadyNotification (const AI_IPC::VariantList &args) |
Callback function called when the service daemon has sent a signal saying it's ready to process requests. | |
bool | onTimer () |
Timer handler called every second, it sends out a ping request to the daemon if we think it is not alive. | |
void | sendIsReadyRequest () const |
Sends a method call over dbus asking the service daemon to reply with a ready notification / signal if it is actually there. | |
Private Attributes | |
const std::shared_ptr< IDobbyUtils > | mUtilities |
const std::shared_ptr< IDobbyIPCUtils > | mIPCUtilities |
const IDobbyIPCUtils::BusType | mBusType |
const std::string | mServiceName |
const AI_IPC::Signal | mReadySignal |
const AI_IPC::Method | mQueryMethod |
const std::function< void(State)> | mStateChangeHandler |
std::mutex | mLock |
State | mState |
int | mServiceHandlerId |
int | mSignalHandlerId |
int | mTimerId |
Utility class to actively monitor the status of a dbus service.
Previously this was implemented separately in various plugins, however the process is generic enough that it could be implemented in one object.
The class has the following requirements on the dbus service: a) The dbus service must emit a signal when it is ready b) The dbus service must implement a method to trigger the signal in a) on request.
You can think of a) as a pong message, and b) the ping. The method in b) should not return a value in the method call, instead it should trigger a signal a) if ready.
The class internally implements a timer on a one second period, it will send our feeler requests to see if the service is ready if not already in the ready state.
|
strong |
|
private |
Callback function called when the service daemon has sent a signal saying it's ready to process requests.
We use this point to adjust the mState state.
[in] | args | Arguments supplied with the signal (ignored). |
|
private |
Callback function called when the daemon service has been added or removed from the bus.
We use this point to adjust the mState state.
[in] | added | Will be true if the service arrived on the bus, false if it has left the bus. |