Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
IpcService Class Reference
Inheritance diagram for IpcService:
Inheritance graph
[legend]
Collaboration diagram for IpcService:
Collaboration graph
[legend]

Public Types

enum  BusType { SessionBus , SystemBus }
 

Public Member Functions

 IpcService (BusType busType, const std::string &serviceName, int defaultTimeoutMs=-1)
 
 IpcService (const std::string &dbusAddress, const std::string &serviceName, int defaultTimeoutMs=-1)
 
virtual bool isValid () const override
 Returns true if we initialised ourselves successfully. More...
 
virtual std::shared_ptr< AI_IPC::IAsyncReplyGetterinvokeMethod (const AI_IPC::Method &method, const AI_IPC::VariantList &args, int timeoutMs=-1) override
 Invoke a method and get reply asynchronously. More...
 
virtual bool invokeMethod (const AI_IPC::Method &method, const AI_IPC::VariantList &args, AI_IPC::VariantList &replyArgs, int timeoutMs=-1) override
 Invoke a method and get reply synchronously. More...
 
virtual bool emitSignal (const AI_IPC::Signal &signal, const AI_IPC::VariantList &args) override
 Emit a signal. More...
 
virtual std::string registerMethodHandler (const AI_IPC::Method &method, const AI_IPC::MethodHandler &handler) override
 Register a method handler. More...
 
virtual std::string registerSignalHandler (const AI_IPC::Signal &signal, const AI_IPC::SignalHandler &handler) override
 Register a signal handler. More...
 
virtual bool unregisterHandler (const std::string &regId) override
 Unregister a method or signal handler. More...
 
virtual bool enableMonitor (const std::set< std::string > &matchRules, const AI_IPC::MonitorHandler &handler) override
 Enables monitor mode on the IPC service, this will effectively disable all registered method and signal handlers. More...
 
virtual bool disableMonitor () override
 Disables monitor mode and restores normal behaviour. More...
 
virtual void flush () override
 Flushes all messages out. More...
 
virtual bool start () override
 Start IPC service. More...
 
virtual bool stop () override
 Stop IPC service. More...
 
bool isRegisteredObjectPath (const std::string &path)
 
virtual bool isServiceAvailable (const std::string &serviceName) const override
 Checks if the named service is available on the bus. More...
 
std::string getBusAddress () const override
 Returns the dbus address the service is using. More...
 

Private Member Functions

bool invokeMethodAndGetReply (DBusMessage *dbusSendMsg, AI_IPC::VariantList &replyArgs)
 
DBusHandlerResult handleDbusMessageCb (DBusMessage *message)
 
DBusHandlerResult handleDbusMessage (DBusMessage *message)
 
DBusHandlerResult handleDbusSignal (const AI_IPC::Signal &signal, const AI_IPC::VariantList &argList)
 
DBusHandlerResult handleDbusMethodCall (const AI_IPC::Method &method, const AI_IPC::VariantList &argList, DBusMessage *message)
 
void unregisterHandlers ()
 
void registerObjectPath (const std::string &path)
 
void unregisterObjectPath (const std::string &path)
 
bool isDbusMessageAllowed (const std::string &sender, const std::string &interface)
 
DBusHandlerResult handleDbusMonitorEvent (DBusMessage *dbusMsg)
 

Private Attributes

std::string mServiceName
 
std::string mBusAddress
 
std::shared_ptr< AI_IPC::DbusConnectionmDbusConnection
 
std::map< std::string, int > mObjectPaths
 
std::map< std::string, std::pair< AI_IPC::Method, AI_IPC::MethodHandler > > mMethodHandlers
 
std::map< std::string, std::pair< AI_IPC::Signal, AI_IPC::SignalHandler > > mSignalHandlers
 
AICommon::ThreadedDispatcher mHandlerDispatcher
 
std::mutex mMutex
 
std::atomic< bool > mRunning
 
int mNextSignalHandlerRegId
 
const int mDefaultTimeoutMs
 
bool mValid
 
std::atomic< bool > mInMonitorMode
 
AI_IPC::MonitorHandler mMonitorCb
 
std::set< std::string > mMonitorMatchRules
 

Member Function Documentation

◆ disableMonitor()

bool IpcService::disableMonitor ( )
overridevirtual

Disables monitor mode and restores normal behaviour.

It's recommended that flush() is called after this function to ensure that the monitor callback will no longer be called.

Implements AI_IPC::IIpcService.

◆ emitSignal()

bool IpcService::emitSignal ( const AI_IPC::Signal signal,
const AI_IPC::VariantList &  args 
)
overridevirtual

Emit a signal.

@parameter[in] signal Signal definition @parameter[in] args Signal arguments/data

Returns
On success: True.
On failure: False.

Implements AI_IPC::IIpcService.

◆ enableMonitor()

bool IpcService::enableMonitor ( const std::set< std::string > &  matchRules,
const AI_IPC::MonitorHandler &  handler 
)
overridevirtual

Enables monitor mode on the IPC service, this will effectively disable all registered method and signal handlers.

This function is for debugging only, it can be used to monitor the entire bus and the interactions between clients.

For production builds this function always returns false.

Note
As of dbus version 1.9.10 a new API was added to the daemon; org.freedesktop.DBus.Monitoring.BecomeMonitor, this is more convenient than using the magic eavesdrop=true match pattern. However currently we're still on an old dbus version that doesn't have that support.

Implements AI_IPC::IIpcService.

◆ flush()

void IpcService::flush ( )
overridevirtual

Flushes all messages out.

This method ensures that any message or signal handlers queued before this function was called are processed before the function returns.

For obvious reasons do not hold any lock that a handler might need while calling this function.

Implements AI_IPC::IIpcService.

◆ getBusAddress()

std::string IpcService::getBusAddress ( ) const
overridevirtual

Returns the dbus address the service is using.

Note the address is formatted like a dbus address and is NOT just the path to the unix socket.

Returns
The dbus address.

Implements AI_IPC::IIpcService.

◆ invokeMethod() [1/2]

bool IpcService::invokeMethod ( const AI_IPC::Method method,
const AI_IPC::VariantList &  args,
AI_IPC::VariantList &  replyArgs,
int  timeoutMs = -1 
)
overridevirtual

Invoke a method and get reply synchronously.

@parameter[in] method Method definition @parameter[in] args Method arguments @parameter[in] replyArgs Reply return by the method call @parameter[in] timeoutMs Timeout in milliseconds, -1 for default (30 seconds)

Returns
On success: True.
On failure: False.

Implements AI_IPC::IIpcService.

◆ invokeMethod() [2/2]

std::shared_ptr< IAsyncReplyGetter > IpcService::invokeMethod ( const AI_IPC::Method method,
const AI_IPC::VariantList &  args,
int  timeoutMs = -1 
)
overridevirtual

Invoke a method and get reply asynchronously.

@parameter[in] method Method definition @parameter[in] args Method arguments @parameter[in] timeoutMs Timeout in milliseconds, -1 for default (30 seconds)

Returns
On success: Shared pointer pointing to a reply getter to receive reply asynchronously.
On failure: Empty shared pointer.

Implements AI_IPC::IIpcService.

◆ isServiceAvailable()

bool IpcService::isServiceAvailable ( const std::string &  serviceName) const
overridevirtual

Checks if the named service is available on the bus.

This method is expected to be used at start to determine if the daemons are up and running.

The method doesn't wait for the service to arrive, that would be nice to have and could be done by looking for the signals dbus send when a new client arrives. We could add that in the future rather than having this polling interface.

Parameters
[in]serviceNameThe name of the service to check for.
Returns
false if an error occurried or the serviceName doesn't exist, otherwise true.

Implements AI_IPC::IIpcService.

◆ isValid()

bool IpcService::isValid ( ) const
overridevirtual

Returns true if we initialised ourselves successfully.

Returns
True if the service was initialised successfully. False if we failed to initialise

Implements AI_IPC::IIpcService.

◆ registerMethodHandler()

std::string IpcService::registerMethodHandler ( const AI_IPC::Method method,
const AI_IPC::MethodHandler &  handler 
)
overridevirtual

Register a method handler.

@parameter[in] method Method definition @parameter[in] handler Method handler

Returns
On success: Registration ID.
On failure: Empty string.

Implements AI_IPC::IIpcService.

◆ registerSignalHandler()

std::string IpcService::registerSignalHandler ( const AI_IPC::Signal signal,
const AI_IPC::SignalHandler &  handler 
)
overridevirtual

Register a signal handler.

@parameter[in] method Signal definition @parameter[in] handler Signal handler

Returns
On success: Registration ID.
On failure: Empty string.

Implements AI_IPC::IIpcService.

◆ start()

bool IpcService::start ( )
overridevirtual

Start IPC service.

It needs to be invoked to start the event dispatcher, which is required to handle method and signals, as well as to get method call reply.

Returns
On success: True.
On failure: False.

Implements AI_IPC::IIpcService.

◆ stop()

bool IpcService::stop ( )
overridevirtual

Stop IPC service.

The event dispatcher thread will be terminated.

Returns
On success: True.
On failure: False.

Implements AI_IPC::IIpcService.

◆ unregisterHandler()

bool IpcService::unregisterHandler ( const std::string &  regId)
overridevirtual

Unregister a method or signal handler.

@parameter[in] regId Registration Id

Returns
On success: True.
On failure: False.

Implements AI_IPC::IIpcService.


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