Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ServiceMonitor Class Reference

Utility class to actively monitor the status of a dbus service. More...

#include <ServiceMonitor.h>

Collaboration diagram for ServiceMonitor:
Collaboration graph
[legend]

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< IDobbyUtilsmUtilities
 
const std::shared_ptr< IDobbyIPCUtilsmIPCUtilities
 
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
 

Detailed Description

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.

Member Enumeration Documentation

◆ State

enum class ServiceMonitor::State
strong
Enumerator
NotRunning 

dbus service not detected on the bus

Running 

dbus service is detected but haven't received the 'ready' signal

Ready 

ready signal received

Member Function Documentation

◆ onReadyNotification()

void ServiceMonitor::onReadyNotification ( const AI_IPC::VariantList &  args)
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.

Parameters
[in]argsArguments supplied with the signal (ignored).

◆ onServiceNotification()

void ServiceMonitor::onServiceNotification ( bool  added)
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.

Parameters
[in]addedWill be true if the service arrived on the bus, false if it has left the bus.

The documentation for this class was generated from the following files: