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 Path & | path () const |
Returns the path this handler is associated with. More... | |
std::weak_ptr< Connection > | connection () 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 Interfaces & | interfaces () const |
Get all the interfaces associated with this Object instance. More... | |
std::shared_ptr< Interface > | interface_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< Interface > | create_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< Interface > | default_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 Children & | children () const |
Get the children associated with this object instance. More... | |
std::shared_ptr< Object > | child (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< Object > | create (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 | |
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:
org.freedesktop.DBus.Error.UnknownInterface
org.freedesktop.DBus.Error.UnknownMethod
will be returned.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
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
|
protected |
|
virtual |
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.
True
if the child was successfully added, false
otherwise. name | The name to use for the child. |
child | A smart pointer to an object to add as a child. |
force | If true a child with the same name will be replaced. |
References child(), connection(), and has_child().
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().
std::shared_ptr< Object > DBus::Object::child | ( | const std::string & | name | ) | const |
Get a named child of this object.
name | The name of the child to return |
Referenced by add_child().
const Object::Children & DBus::Object::children | ( | ) | const |
Get the children associated with this object instance.
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().
|
static |
Creates a named Object that will register as a primary or fallback handler.
path | The path the object will handle |
References Object(), and path().
Referenced by DBus::Connection::create_object().
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.
References add_interface(), DBus::Interface::create(), and set_default_interface().
Referenced by create_method(), create_property(), and create_signal().
|
inline |
Creates a method with a signature based on the.
slot | parameter signature and adds it to the named interface |
interface_name | The DBus interface, in org.example.Foo style |
method_name | The name of the method that this is for. |
slot | This 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().
|
inline |
Creates a method with a signature based on the.
slot | parameter signature and adds it to the default interface |
slot | This 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().
|
inline |
References create_interface(), and interface_by_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.
References create_interface(), has_interface(), and interface_by_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.
References create_interface(), and default_interface().
|
private |
std::shared_ptr< Interface > DBus::Object::default_interface | ( | ) | const |
Get the default interface associated with this object.
Referenced by create_method(), and create_signal().
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.
HandlerResult::HANDLED
if this object handled the message, HandlerResult::NOT_HANDLED
otherwise conn | The Connection to send the reply message on |
msg | The 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.
bool DBus::Object::has_child | ( | const std::string & | name | ) | const |
Test whether an object has a child with a specified name.
True
if the object has the named child, false
otherwise. name | The name of the child to test. |
Referenced by add_child().
bool DBus::Object::has_interface | ( | const std::string & | name | ) |
Test whether an Object has a named interface.
True
if the object has the named interface, false
otherwise name | The name of the interface to look for |
Referenced by create_signal().
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().
const Object::Interfaces & DBus::Object::interfaces | ( | ) | const |
Get all the interfaces associated with this Object instance.
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().
const Path & DBus::Object::path | ( | ) | const |
Returns the path this handler is associated with.
Referenced by add_interface(), create(), introspect(), and Object().
bool DBus::Object::remove_child | ( | const std::string & | name | ) |
Remove the named child from this object.
True
if the child was found and removed, false
if no child by the name was found to remove. name | The name of the child to remove. |
void DBus::Object::remove_default_interface | ( | ) |
Removes the currently set (if any) default interface.
There wil not be a default interface set.
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
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.
conn |
References LOGGER_NAME, SIMPLELOGGER_DEBUG, and unregister().
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.
new_default_name | The name of the interface to use as the default. |
True
if an interface with the specified name was found, false
otherwise. Referenced by create_interface(), and create_method().
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
interface | True if the default interface was updated, false otherwise. |
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.
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.
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.
sigc::signal< void(std::shared_ptr< Connection >)> & DBus::Object::signal_registered | ( | ) |
Emitted when this object is registered with a connection.
sigc::signal< void(std::shared_ptr< Connection >)> & DBus::Object::signal_unregistered | ( | ) |
Emitted when this object is unregistered from a connection.
bool DBus::Object::unregister | ( | ) |