DBus::Object Class Reference

An Object represents a local object that is able to be called over the DBus. More...

#include <object.h>

Public Types

typedef std::map< std::string, std::shared_ptr< Interface > > Interfaces
 Typedef to the storage structure for an Object instance's interfaces. More...
 
typedef std::map< std::string, std::shared_ptr< Object > > Children
 Typedef to storage structure for an Object instance's children. More...
 

Public Member Functions

virtual ~Object ()
 
const Pathpath () const
 Returns the path this handler is associated with. More...
 
std::weak_ptr< Connectionconnection () const
 Returns the connection this handler is registered with. More...
 
bool unregister ()
 Unregisters the handler. More...
 
sigc::signal< void(std::shared_ptr< Connection >) > & signal_registered ()
 Emitted when this object is registered with a connection. More...
 
sigc::signal< void(std::shared_ptr< Connection >) > & signal_unregistered ()
 Emitted when this object is unregistered from a connection. More...
 
void set_connection (std::shared_ptr< Connection > conn)
 Sets the connection that this object is on. More...
 
const Interfacesinterfaces () const
 Get all the interfaces associated with this Object instance. More...
 
std::shared_ptr< Interfaceinterface_by_name (const std::string &name) const
 Returns the interface with the given name. More...
 
bool add_interface (std::shared_ptr< Interface > interface_by_name)
 Adds the interface to this object. More...
 
std::shared_ptr< Interfacecreate_interface (const std::string &name)
 Creates and adds the named interface to this object. More...
 
template<typename T_type >
std::shared_ptr< Method< T_type > > create_method (const std::string &method_name, sigc::slot< T_type > slot)
 Creates a method with a signature based on the. More...
 
template<typename T_type >
std::shared_ptr< Method< T_type > > create_method (const std::string &interface_name, const std::string &method_name, sigc::slot< T_type > slot)
 Creates a method with a signature based on the. More...
 
template<typename T_type >
std::shared_ptr< Property< T_type > > create_property (const std::string &interface_name, const std::string &property_name, PropertyAccess access_type=PropertyAccess::ReadWrite, PropertyUpdateType update_type=PropertyUpdateType::Updates)
 
void remove_interface (const std::string &name)
 Removes the interface found with the given name. More...
 
bool has_interface (const std::string &name)
 Test whether an Object has a named interface. More...
 
std::shared_ptr< Interfacedefault_interface () const
 Get the default interface associated with this object. More...
 
bool set_default_interface (const std::string &new_default_name)
 Set the default interface to a specific name. More...
 
bool set_default_interface (std::shared_ptr< Interface > interface_by_name)
 Set the default interface for handling calls to no interface. More...
 
void remove_default_interface ()
 Removes the currently set (if any) default interface. More...
 
template<class... T_type>
std::shared_ptr< Signal< T_type... > > create_signal (const std::string &name)
 Creates a signal with a return value (possibly void ) and a variable number of parameters and adds it to the default interface. More...
 
template<class... T_type>
std::shared_ptr< Signal< T_type... > > create_signal (const std::string &iface, const std::string &name)
 Creates a signal with a return value (possibly void ) and a variable number of parameters and adds it to the named interface. More...
 
const Childrenchildren () const
 Get the children associated with this object instance. More...
 
std::shared_ptr< Objectchild (const std::string &name) const
 Get a named child of this object. More...
 
bool add_child (const std::string &name, std::shared_ptr< Object > child, bool force=false)
 Add an object as a child with a specified name This method will fail if the object already has a child with the specified name and force is not set. More...
 
bool remove_child (const std::string &name)
 Remove the named child from this object. More...
 
bool has_child (const std::string &name) const
 Test whether an object has a child with a specified name. More...
 
std::string introspect (int space_depth=0) const
 Returns a DBus XML description of this interface. More...
 
sigc::signal< void(std::shared_ptr< Interface >) > signal_interface_added ()
 Signal emitted when an interface is added to this object. More...
 
sigc::signal< void(std::shared_ptr< Interface >) > signal_interface_removed ()
 Signal emitted when an interface is removed from this object. More...
 
sigc::signal< void(std::shared_ptr< Interface >, std::shared_ptr< Interface >)> signal_default_interface_changed ()
 Signal emitted when the default interface of this object is changed. More...
 
HandlerResult handle_message (std::shared_ptr< const Message > msg)
 Handles the specified message on the specified connection. More...
 

Static Public Member Functions

static std::shared_ptr< Objectcreate (const std::string &path=std::string())
 Creates a named Object that will register as a primary or fallback handler. More...
 

Protected Member Functions

 Object (const std::string &path)
 This class has a protected constructor. More...
 

Private Member Functions

 DBUS_CXX_PROPAGATE_CONST (std::unique_ptr< priv_data >) m_priv
 

Detailed Description

An Object represents a local object that is able to be called over the DBus.

Interfaces, methods, and signals can be created from this Object.

Note: Because the header 'INTERFACE' is not required for method calls, use the method set_default_interface to set an interface that will handle method calls without 'INTERFACE' set. If a message is received without the 'INTERFACE' set, the following is used to determine how to handle the message:

  • If the default interface is not set, return an error org.freedesktop.DBus.Error.UnknownInterface
  • If the default interface is set, use that interface to try and handle the message. The normal message handling rules apply at this point, e.g. if the method does not exist an error org.freedesktop.DBus.Error.UnknownMethod will be returned.
Author
Rick L Vinyard Jr rviny.nosp@m.ard@.nosp@m.cs.nm.nosp@m.su.e.nosp@m.du

Member Typedef Documentation

◆ Children

typedef std::map<std::string, std::shared_ptr<Object> > DBus::Object::Children

Typedef to storage structure for an Object instance's children.

The key is the child's name and the value

Data Structure - map: an object's children must be uniquely named Key - child name Value -smart pointer to a child object.

Can access type as Object::Children

◆ Interfaces

typedef std::map<std::string, std::shared_ptr<Interface> > DBus::Object::Interfaces

Typedef to the storage structure for an Object instance's interfaces.

Key - interface name Value -smart pointer to an interface.

Can access type as Object::Interfaces

Constructor & Destructor Documentation

◆ Object()

DBus::Object::Object ( const std::string &  path)
protected

This class has a protected constructor.

Use the create() methods to obtain a smart pointer to a new instance.

References path().

Referenced by create().

◆ ~Object()

DBus::Object::~Object ( )
virtual

Member Function Documentation

◆ add_child()

bool DBus::Object::add_child ( const std::string &  name,
std::shared_ptr< Object child,
bool  force = false 
)

Add an object as a child with a specified name This method will fail if the object already has a child with the specified name and force is not set.

Returns
True if the child was successfully added, false otherwise.
Parameters
nameThe name to use for the child.
childA smart pointer to an object to add as a child.
forceIf true a child with the same name will be replaced.

References child(), connection(), and has_child().

◆ add_interface()

bool DBus::Object::add_interface ( std::shared_ptr< Interface interface_by_name)

Adds the interface to this object.

References connection(), LOGGER_NAME, path(), and SIMPLELOGGER_DEBUG.

Referenced by create_interface().

◆ child()

std::shared_ptr< Object > DBus::Object::child ( const std::string &  name) const

Get a named child of this object.

Returns
A smart pointer to a child with the specified name, or a null smart pointer if no child found.
Parameters
nameThe name of the child to return

Referenced by add_child().

◆ children()

const Object::Children & DBus::Object::children ( ) const

Get the children associated with this object instance.

◆ connection()

std::weak_ptr< Connection > DBus::Object::connection ( ) const

Returns the connection this handler is registered with.

Referenced by add_child(), add_interface(), handle_message(), and unregister().

◆ create()

std::shared_ptr< Object > DBus::Object::create ( const std::string &  path = std::string())
static

Creates a named Object that will register as a primary or fallback handler.

Parameters
pathThe path the object will handle

References Object(), and path().

Referenced by DBus::Connection::create_object().

◆ create_interface()

std::shared_ptr< Interface > DBus::Object::create_interface ( const std::string &  name)

Creates and adds the named interface to this object.

If the string is empty, and there is no default interface set, this will set the default interface.

Returns
the newly created interface

References add_interface(), DBus::Interface::create(), and set_default_interface().

Referenced by create_method(), create_property(), and create_signal().

◆ create_method() [1/2]

template<typename T_type >
std::shared_ptr<Method<T_type> > DBus::Object::create_method ( const std::string &  interface_name,
const std::string &  method_name,
sigc::slot< T_type >  slot 
)
inline

Creates a method with a signature based on the.

Parameters
slotparameter signature and adds it to the named interface
Returns
A smart pointer to the newly created method
Parameters
interface_nameThe DBus interface, in org.example.Foo style
method_nameThe name of the method that this is for.
slotThis slot will be called with the given signature when the method is invoked

Template parameters of the sigc::slot will determine the signature of the method created.

References create_interface(), and interface_by_name().

◆ create_method() [2/2]

template<typename T_type >
std::shared_ptr<Method<T_type> > DBus::Object::create_method ( const std::string &  method_name,
sigc::slot< T_type >  slot 
)
inline

Creates a method with a signature based on the.

Parameters
slotparameter signature and adds it to the default interface
Returns
A smart pointer to the newly created method
Parameters
slotThis slot will be called with the given signature when the method is invoked

Template parameters of the sigc::slot will determine the signature of the method created.

References create_interface(), default_interface(), and set_default_interface().

◆ create_property()

template<typename T_type >
std::shared_ptr<Property<T_type> > DBus::Object::create_property ( const std::string &  interface_name,
const std::string &  property_name,
PropertyAccess  access_type = PropertyAccess::ReadWrite,
PropertyUpdateType  update_type = PropertyUpdateType::Updates 
)
inline

◆ create_signal() [1/2]

template<class... T_type>
std::shared_ptr<Signal<T_type...> > DBus::Object::create_signal ( const std::string &  iface,
const std::string &  name 
)
inline

Creates a signal with a return value (possibly void ) and a variable number of parameters and adds it to the named interface.

Template parameters for the create_signal() call will determine the signature of the signal created.

Returns
A smart pointer to the newly created signal

References create_interface(), has_interface(), and interface_by_name().

◆ create_signal() [2/2]

template<class... T_type>
std::shared_ptr<Signal<T_type...> > DBus::Object::create_signal ( const std::string &  name)
inline

Creates a signal with a return value (possibly void ) and a variable number of parameters and adds it to the default interface.

Note: This will create a default interface if it does not already exist.

Template parameters for the create_signal() call will determine the signature of the signal created.

Returns
A smart pointer to the newly created signal

References create_interface(), and default_interface().

◆ DBUS_CXX_PROPAGATE_CONST()

DBus::Object::DBUS_CXX_PROPAGATE_CONST ( std::unique_ptr< priv_data >  )
private

◆ default_interface()

std::shared_ptr< Interface > DBus::Object::default_interface ( ) const

Get the default interface associated with this object.

Returns
The default interface, or a null smart pointer if no default is set

Referenced by create_method(), and create_signal().

◆ handle_message()

HandlerResult DBus::Object::handle_message ( std::shared_ptr< const Message msg)

Handles the specified message on the specified connection.

If msg is an introspection message, the object will rely on its introspection() method to provide a reply.

Looks for interfaces specified in the message first. If the message does not specify an interface or the specified interface is not found the default interface will be used.

If the specified interface is found, all matching interfaces will be tried until an interface handler returns HandlerResult::HANDLED. Once an interface returns HandlerResult::HANDLED no further interfaces will be tried.

If no interface returns HandlerResult::HANDLED the default interface (if one is set) will be tried.

Returns
HandlerResult::HANDLED if this object handled the message, HandlerResult::NOT_HANDLED otherwise
Parameters
connThe Connection to send the reply message on
msgThe message to handle; must be a CallMessage or it will not be handled

References DBus::CALL, connection(), DBUS_CXX_INTROSPECTABLE_INTERFACE, DBUS_CXX_PEER_INTERFACE, DBUS_CXX_PROPERTIES_INTERFACE, DBUSCXX_ERROR_IO_ERROR, DBUSCXX_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE, DBus::Handled, introspect(), DBus::Invalid_Interface, DBus::Invalid_Method, LOGGER_NAME, DBus::Not_Handled, SIMPLELOGGER_DEBUG, and SIMPLELOGGER_ERROR.

◆ has_child()

bool DBus::Object::has_child ( const std::string &  name) const

Test whether an object has a child with a specified name.

Returns
True if the object has the named child, false otherwise.
Parameters
nameThe name of the child to test.

Referenced by add_child().

◆ has_interface()

bool DBus::Object::has_interface ( const std::string &  name)

Test whether an Object has a named interface.

Returns
True if the object has the named interface, false otherwise
Parameters
nameThe name of the interface to look for

Referenced by create_signal().

◆ interface_by_name()

std::shared_ptr< Interface > DBus::Object::interface_by_name ( const std::string &  name) const

Returns the interface with the given name.

Referenced by create_method(), create_property(), and create_signal().

◆ interfaces()

const Object::Interfaces & DBus::Object::interfaces ( ) const

Get all the interfaces associated with this Object instance.

◆ introspect()

std::string DBus::Object::introspect ( int  space_depth = 0) const

Returns a DBus XML description of this interface.

References DBUS_CXX_INTROSPECTABLE_INTERFACE, DBUS_CXX_PEER_INTERFACE, DBUS_CXX_PROPERTIES_INTERFACE, and path().

Referenced by handle_message().

◆ path()

const Path & DBus::Object::path ( ) const

Returns the path this handler is associated with.

Referenced by add_interface(), create(), introspect(), and Object().

◆ remove_child()

bool DBus::Object::remove_child ( const std::string &  name)

Remove the named child from this object.

Returns
True if the child was found and removed, false if no child by the name was found to remove.
Parameters
nameThe name of the child to remove.

◆ remove_default_interface()

void DBus::Object::remove_default_interface ( )

Removes the currently set (if any) default interface.

There wil not be a default interface set.

◆ remove_interface()

void DBus::Object::remove_interface ( const std::string &  name)

Removes the interface found with the given name.

This will not remove the default interface if the name matches - use remove_default_interface instead

◆ set_connection()

void DBus::Object::set_connection ( std::shared_ptr< Connection conn)

Sets the connection that this object is on.

Generally, you should not call this, as calling Connection::register_object will do this for you automatically.

Parameters
conn

References LOGGER_NAME, SIMPLELOGGER_DEBUG, and unregister().

◆ set_default_interface() [1/2]

bool DBus::Object::set_default_interface ( const std::string &  new_default_name)

Set the default interface to a specific name.

The currently-existing interface with the given name is used. If an interface with the given name is not found, the default interface will not be set.

Parameters
new_default_nameThe name of the interface to use as the default.
Returns
True if an interface with the specified name was found, false otherwise.

Referenced by create_interface(), and create_method().

◆ set_default_interface() [2/2]

bool DBus::Object::set_default_interface ( std::shared_ptr< Interface interface_by_name)

Set the default interface for handling calls to no interface.

If the shared pointer is invalid, this function returns false and does nothing

Parameters
interfaceTrue if the default interface was updated, false otherwise.

◆ signal_default_interface_changed()

sigc::signal< void(std::shared_ptr< Interface >, std::shared_ptr< Interface >)> DBus::Object::signal_default_interface_changed ( )

Signal emitted when the default interface of this object is changed.

The first parameter of the callback is a pointer to the old default interface, and the second parameter is a callback to the new default interface.

◆ signal_interface_added()

sigc::signal< void(std::shared_ptr< Interface >) > DBus::Object::signal_interface_added ( )

Signal emitted when an interface is added to this object.

The first parameter of the callback is a pointer to the newly added interface.

◆ signal_interface_removed()

sigc::signal< void(std::shared_ptr< Interface >)> DBus::Object::signal_interface_removed ( )

Signal emitted when an interface is removed from this object.

The first parameter of the callback is a pointer to the removed interface.

◆ signal_registered()

sigc::signal< void(std::shared_ptr< Connection >)> & DBus::Object::signal_registered ( )

Emitted when this object is registered with a connection.

◆ signal_unregistered()

sigc::signal< void(std::shared_ptr< Connection >)> & DBus::Object::signal_unregistered ( )

Emitted when this object is unregistered from a connection.

◆ unregister()

bool DBus::Object::unregister ( )

Unregisters the handler.

References connection().

Referenced by set_connection().


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