Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DobbyIPCUtils Class Reference

Utility methods for IPC in Dobby. More...

#include <DobbyIPCUtils.h>

Inheritance diagram for DobbyIPCUtils:
Inheritance graph
[legend]
Collaboration diagram for DobbyIPCUtils:
Collaboration graph
[legend]

Public Member Functions

 DobbyIPCUtils (const std::string &systemDbusAddress, const std::shared_ptr< AI_IPC::IIpcService > &systemIpcService)
 
std::shared_ptr< AI_IPC::IAsyncReplyGetteripcInvokeMethod (const BusType &bus, const AI_IPC::Method &method, const AI_IPC::VariantList &args, int timeoutMs) const override
 Invokes the ipc method. More...
 
bool ipcInvokeMethod (const BusType &bus, const AI_IPC::Method &method, const AI_IPC::VariantList &args, AI_IPC::VariantList &replyArgs) const override
 Invokes the ipc method. More...
 
bool ipcEmitSignal (const BusType &bus, const AI_IPC::Signal &signal, const AI_IPC::VariantList &args) const override
 Sends out a signal over dbus. More...
 
bool ipcServiceAvailable (const BusType &bus, const std::string &serviceName) const override
 Queries if the given service is available on the bus. More...
 
int ipcRegisterServiceHandler (const BusType &bus, const std::string &serviceName, const std::function< void(bool)> &handlerFunc) override
 Registers a callback function that will be called when the given service is added or removed from the bus. More...
 
int ipcRegisterSignalHandler (const BusType &bus, const AI_IPC::Signal &signal, const AI_IPC::SignalHandler &handlerFunc) override
 Registers a callback function that will be called when the given signal is received on the bus. More...
 
void ipcUnregisterHandler (const BusType &bus, int handlerId) override
 Unregisters either a service or signal handler. More...
 
std::string ipcDbusAddress (const BusType &bus) const override
 Returns complete address to the dbus daemon. More...
 
std::string ipcDbusSocketPath (const BusType &bus) const override
 Returns just the path to the socket for the dbus daemon. More...
 
bool setAIDbusAddress (bool privateBus, const std::string &address)
 Sets the dbus address for one of the AI dbus-daemons. More...
 

Private Member Functions

std::shared_ptr< DobbyIpcBusgetIpcBus (const BusType &bus) const
 Utility function to simply return the bus object associated with the given bus id. More...
 

Private Attributes

std::map< BusType, std::shared_ptr< DobbyIpcBus > > mIpcBuses
 

Additional Inherited Members

- Public Types inherited from IDobbyIPCUtils
enum class  BusType { NoneBus , SystemBus , AIPrivateBus , AIPublicBus }
 The type of dbus to call methods on / emit signals.
 

Detailed Description

Utility methods for IPC in Dobby.

See also
IDobbyUtils

Member Function Documentation

◆ getIpcBus()

std::shared_ptr< DobbyIpcBus > DobbyIPCUtils::getIpcBus ( const BusType bus) const
private

Utility function to simply return the bus object associated with the given bus id.

Note no need for locking in this method as the bus objects should have been created in the construction and only deleted in the destructor. The only thing we need to check is if the bus param is valid.

Parameters
[in]busThe bus to get.
Returns
on success a shared_ptr to the bus object, on failure a nullptr.

◆ ipcDbusAddress()

std::string DobbyIPCUtils::ipcDbusAddress ( const BusType bus) const
overridevirtual

Returns complete address to the dbus daemon.

Parameters
[in]busThe bus to get the socket path for.
Returns
the path to the socket, or an empty string if no socket is available.

Implements IDobbyIPCUtils.

◆ ipcDbusSocketPath()

std::string DobbyIPCUtils::ipcDbusSocketPath ( const BusType bus) const
overridevirtual

Returns just the path to the socket for the dbus daemon.

Parameters
[in]busThe bus to get the socket path for.
Returns
the path to the socket, or an empty string if no socket is available.

Implements IDobbyIPCUtils.

◆ ipcEmitSignal()

bool DobbyIPCUtils::ipcEmitSignal ( const BusType bus,
const AI_IPC::Signal signal,
const AI_IPC::VariantList &  args 
) const
overridevirtual

Sends out a signal over dbus.

This is a pure wrapper around the IpcService::emitSignal function.

Parameters
[in]busThe bus to emit the signal on.
[in]signalThe signal details.
[in]argsThe signal args.
Returns
true if successful, otherwise false.

Implements IDobbyIPCUtils.

◆ ipcInvokeMethod() [1/2]

bool DobbyIPCUtils::ipcInvokeMethod ( const BusType bus,
const AI_IPC::Method method,
const AI_IPC::VariantList &  args,
AI_IPC::VariantList &  replyArgs 
) const
overridevirtual

Invokes the ipc method.

This is a pure wrapper around the IpcService::invokeMethod function.

Parameters
[in]busThe bus call the method on.
[in]methodThe method to call.
[in]argsThe method args
[out]replyArgsThe reply.
Returns
true if successful, otherwise false.

Implements IDobbyIPCUtils.

◆ ipcInvokeMethod() [2/2]

std::shared_ptr< AI_IPC::IAsyncReplyGetter > DobbyIPCUtils::ipcInvokeMethod ( const BusType bus,
const AI_IPC::Method method,
const AI_IPC::VariantList &  args,
int  timeoutMs 
) const
overridevirtual

Invokes the ipc method.

This is a pure wrapper around the IpcService::invokeMethod function.

Parameters
[in]busThe bus call the method on.
[in]methodThe method to call.
[in]argsThe method args
[in]timeoutMsTimeout in milliseconds, -1 for default (5 seconds)
Returns
shared pointer pointing to a reply getter to receive reply asynchronously, or nullptr on failure.

Implements IDobbyIPCUtils.

◆ ipcRegisterServiceHandler()

int DobbyIPCUtils::ipcRegisterServiceHandler ( const BusType bus,
const std::string &  serviceName,
const std::function< void(bool)> &  handlerFunc 
)
overridevirtual

Registers a callback function that will be called when the given service is added or removed from the bus.

This in turn is useful for hooks to manage situations where the daemon they are talking to has crashed / restarted.

Case in point is the Jumper hook, it wants to know if the daemon has crashed so it doesn't block container startup by trying to talk to a nonexisting daemon. And likewise it wants to know when it's arrived back so it can re-create any state stored in the daemon.

To remove the handler call ipcUnregisterHandler with the handler id returned by this function.

Parameters
[in]busThe bus to watch the service on.
[in]serviceNameThe name of the service to look out for.
[in]handlerFuncCallback function called when the service is added or removed. If added the argument supplied will be true, if removed it will be false.
Returns
if the notifier is successifully added then a positive handler id will be returned, otherwise -1

Implements IDobbyIPCUtils.

◆ ipcRegisterSignalHandler()

int DobbyIPCUtils::ipcRegisterSignalHandler ( const BusType bus,
const AI_IPC::Signal signal,
const AI_IPC::SignalHandler &  handlerFunc 
)
overridevirtual

Registers a callback function that will be called when the given signal is received on the bus.

This is a pure wrapper around the IpcService.registerSignalHandler function.

Parameters
[in]busThe bus to watch for the signal on.
[in]signalThe signal details to watch for.
[in]handlerFuncCallback function called when the signal is received.
Returns
if the handler is successifully added then a positive handler id will be returned, otherwise -1

Implements IDobbyIPCUtils.

◆ ipcServiceAvailable()

bool DobbyIPCUtils::ipcServiceAvailable ( const BusType bus,
const std::string &  serviceName 
) const
overridevirtual

Queries if the given service is available on the bus.

This is a pure wrapper around the IpcService::serviceAvailable function.

Parameters
[in]serviceNameThe service to query.
Returns
true if the service is available, otherwise false.

Implements IDobbyIPCUtils.

◆ ipcUnregisterHandler()

void DobbyIPCUtils::ipcUnregisterHandler ( const BusType bus,
int  handlerId 
)
overridevirtual

Unregisters either a service or signal handler.

Parameters
[in]busThe bus to remove the handler for.
[in]handlerIdThe integer handler id returned by the register function.

Implements IDobbyIPCUtils.

◆ setAIDbusAddress()

bool DobbyIPCUtils::setAIDbusAddress ( bool  privateBus,
const std::string &  address 
)

Sets the dbus address for one of the AI dbus-daemons.

The address is expected to be of the form 'unix:path=<path_to_socket>'

Parameters
[in]privateBustrue if refers to the private bus.
[in]addressThe address of the bus.
Returns
true if the address was validated by opening a connection to the bus, otherwise false.

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