Utility methods for IPC in Dobby.
More...
#include <DobbyIPCUtils.h>
|
| DobbyIPCUtils (const std::string &systemDbusAddress, const std::shared_ptr< AI_IPC::IIpcService > &systemIpcService) |
|
std::shared_ptr< AI_IPC::IAsyncReplyGetter > | ipcInvokeMethod (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...
|
|
|
enum class | BusType { NoneBus
, SystemBus
, AIPrivateBus
, AIPublicBus
} |
| The type of dbus to call methods on / emit signals.
|
|
Utility methods for IPC in Dobby.
- See also
- IDobbyUtils
◆ getIpcBus()
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
-
- 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] | bus | The 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] | bus | The 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] | bus | The bus to emit the signal on. |
[in] | signal | The signal details. |
[in] | args | The 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] | bus | The bus call the method on. |
[in] | method | The method to call. |
[in] | args | The method args |
[out] | replyArgs | The reply. |
- Returns
- true if successful, otherwise false.
Implements IDobbyIPCUtils.
◆ ipcInvokeMethod() [2/2]
Invokes the ipc method.
This is a pure wrapper around the IpcService::invokeMethod function.
- Parameters
-
[in] | bus | The bus call the method on. |
[in] | method | The method to call. |
[in] | args | The method args |
[in] | timeoutMs | Timeout 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] | bus | The bus to watch the service on. |
[in] | serviceName | The name of the service to look out for. |
[in] | handlerFunc | Callback 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] | bus | The bus to watch for the signal on. |
[in] | signal | The signal details to watch for. |
[in] | handlerFunc | Callback 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] | serviceName | The 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] | bus | The bus to remove the handler for. |
[in] | handlerId | The 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] | privateBus | true if refers to the private bus. |
[in] | address | The 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: