DBus::Interface Class Reference

An Interface represents a local copy of a DBus interface. More...

#include <interface.h>

Public Types

typedef std::map< std::string, std::shared_ptr< MethodBase > > Methods
 Typedef to the storage structure for methods. More...
 
typedef std::set< std::shared_ptr< SignalBase > > Signals
 Typedef to the storage structure for signals. More...
 

Public Member Functions

virtual ~Interface ()
 
HandlerResult handle_call_message (std::shared_ptr< Connection > conn, std::shared_ptr< const CallMessage > message)
 Handles the specified call message. More...
 
HandlerResult handle_properties_message (std::shared_ptr< Connection > conn, std::shared_ptr< const CallMessage > message)
 Handle the specified properties message. More...
 
const std::string & name () const
 Get the name of this interface. More...
 
Path path () const
 Returns the path of the object associated with this interface or a null string if no object is associated. More...
 
const Methodsmethods () const
 Returns the methods associated with this interface. More...
 
std::shared_ptr< MethodBasemethod (const std::string &name) const
 Returns the method with the given name, or an invalid shared_ptr if not found. More...
 
template<typename T_type >
std::shared_ptr< Method< T_type > > create_method (const std::string &name)
 Creates a method with a return value (possibly void ) and $1 parameters. More...
 
template<typename T_type >
std::shared_ptr< Method< T_type > > create_method (const std::string &name, sigc::slot< T_type > slot)
 Creates a method with a signature equivalent to the provided. More...
 
template<typename T_type >
std::shared_ptr< Property< T_type > > create_property (const std::string &name, PropertyAccess access_type=PropertyAccess::ReadWrite, PropertyUpdateType update_type=PropertyUpdateType::Updates)
 
bool add_property (std::shared_ptr< PropertyBase > prop)
 
bool has_property (const std::string &name) const
 
bool add_method (std::shared_ptr< MethodBase > method)
 Adds the named method. More...
 
bool remove_method (const std::string &name)
 Removes the first method with the given name. More...
 
bool remove_method (std::shared_ptr< MethodBase > method)
 Removes the given method, if found. More...
 
bool has_method (const std::string &name) const
 True if the interface has a method with the given name. More...
 
bool add_signal (std::shared_ptr< SignalBase > signal)
 Adds the given signal. More...
 
bool remove_signal (std::shared_ptr< SignalBase > signal)
 Removes the given signal. More...
 
bool remove_signal (const std::string &name)
 Removes all signals with the given name. More...
 
bool has_signal (std::shared_ptr< SignalBase > signal) const
 True if the given signal is part of this interface. More...
 
bool has_signal (const std::string &name) const
 True if this interface has at least one signal with the given name. More...
 
template<class... T_type>
std::shared_ptr< Signal< T_type... > > create_signal (const std::string &member)
 Creates a signal with any number of parameters. More...
 
const Signalssignals ()
 Returns the signals associated with this interface. More...
 
const std::set< std::shared_ptr< PropertyBase > > & properties ()
 
std::shared_ptr< SignalBasesignal (const std::string &signal_name)
 Returns the first signal found with a matching name. More...
 
sigc::signal< void(std::shared_ptr< MethodBase >)> signal_method_added ()
 Signal emitted when a method of the given name is added. More...
 
sigc::signal< void(std::shared_ptr< MethodBase >)> signal_method_removed ()
 Signal emitted when a method of the given name is removed. More...
 
std::string introspect (int space_depth=0) const
 Returns a DBus XML description of this interface. More...
 

Static Public Member Functions

static std::shared_ptr< Interfacecreate (const std::string &name=std::string())
 Creates a named Interface. More...
 

Protected Member Functions

 Interface (const std::string &name)
 This class has a protected constructor. More...
 

Private Member Functions

void set_path (const std::string &new_path)
 
void property_updated (DBus::PropertyBase *prop)
 
void set_connection (std::weak_ptr< Connection > conn)
 
 DBUS_CXX_PROPAGATE_CONST (std::unique_ptr< priv_data >) m_priv
 

Friends

class Object
 
class PropertyBase
 

Detailed Description

An Interface represents a local copy of a DBus interface.

A DBus interface is an entry point that allows for object-orinted manipulation of local objects. Interfaces contain two ore more elements separated by the period ('.') character.

Author
Rick L Vinyard Jr rviny.nosp@m.ard@.nosp@m.cs.nm.nosp@m.su.e.nosp@m.du

Member Typedef Documentation

◆ Methods

typedef std::map<std::string, std::shared_ptr<MethodBase> > DBus::Interface::Methods

Typedef to the storage structure for methods.

Data Structure - map Key - method name Value -smart pointer to a method.

Can access type as Interface::Methods

◆ Signals

typedef std::set<std::shared_ptr<SignalBase> > DBus::Interface::Signals

Typedef to the storage structure for signals.

Data Structure - sets is used since signal names are not needed for the interface, but must be unique.

Can access type as Interface::Signals

Constructor & Destructor Documentation

◆ Interface()

DBus::Interface::Interface ( const std::string &  name)
protected

This class has a protected constructor.

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

References name().

Referenced by create().

◆ ~Interface()

DBus::Interface::~Interface ( )
virtual

Member Function Documentation

◆ add_method()

bool DBus::Interface::add_method ( std::shared_ptr< MethodBase method)

Adds the named method.

References has_method(), and method().

Referenced by create_method().

◆ add_property()

bool DBus::Interface::add_property ( std::shared_ptr< PropertyBase prop)

References has_property().

Referenced by create_property().

◆ add_signal()

bool DBus::Interface::add_signal ( std::shared_ptr< SignalBase signal)

Adds the given signal.

Returns
true if the signal was successfully added, false otherwise

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

Referenced by create_signal().

◆ create()

std::shared_ptr< Interface > DBus::Interface::create ( const std::string &  name = std::string())
static

Creates a named Interface.

Parameters
nameThe name of this interface

References Interface(), and name().

Referenced by DBus::Object::create_interface().

◆ create_method() [1/2]

template<typename T_type >
std::shared_ptr<Method<T_type> > DBus::Interface::create_method ( const std::string &  name)
inline

Creates a method with a return value (possibly void ) and $1 parameters.

Returns
A smart pointer to the newly created method
Parameters
nameThe name that will be associated with this method

References add_method(), DBus::Method< T_type >::create(), method(), and name().

◆ create_method() [2/2]

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

Creates a method with a signature equivalent to the provided.

Parameters
slotparameter's signature
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 add_method(), DBus::Method< T_type >::create(), method(), and name().

◆ create_property()

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

◆ create_signal()

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

Creates a signal with any number of parameters.

Returns
A smart pointer to the newly created signal
Parameters
nameThe name that will be associated with this signal

References add_signal(), name(), and path().

◆ DBUS_CXX_PROPAGATE_CONST()

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

◆ handle_call_message()

HandlerResult DBus::Interface::handle_call_message ( std::shared_ptr< Connection conn,
std::shared_ptr< const CallMessage message 
)

Handles the specified call message.

Looks for methods matching the name specified in the message, then calls handle_call_message() for each matching message.

Once a method returns HANDLED no further methods will be tried.

Returns
HANDLED if one method in this interface handled the message, NOT_HANDLED otherwise
Parameters
connThe Connection to send the reply message on
msgThe CallMessage to handle

References DBus::Invalid_Method, LOGGER_NAME, method(), and SIMPLELOGGER_DEBUG.

◆ handle_properties_message()

HandlerResult DBus::Interface::handle_properties_message ( std::shared_ptr< Connection conn,
std::shared_ptr< const CallMessage message 
)

Handle the specified properties message.

Depending on the type of properties message(Get/Set/GetAll), the appropriate response will be built up and returned.

Parameters
connThe connection this is from
messageThe message with properties information
Returns

References DBUSCXX_ERROR_PROPERTY_READ_ONLY, DBUSCXX_ERROR_UNKNOWN_PROPERTY, DBus::Handled, DBus::INVALID, LOGGER_NAME, DBus::ReadOnly, DBus::ReadWrite, SIMPLELOGGER_DEBUG, and DBus::WriteOnly.

◆ has_method()

bool DBus::Interface::has_method ( const std::string &  name) const

True if the interface has a method with the given name.

References name().

Referenced by add_method().

◆ has_property()

bool DBus::Interface::has_property ( const std::string &  name) const

References name().

Referenced by add_property().

◆ has_signal() [1/2]

bool DBus::Interface::has_signal ( const std::string &  name) const

True if this interface has at least one signal with the given name.

References name().

◆ has_signal() [2/2]

bool DBus::Interface::has_signal ( std::shared_ptr< SignalBase signal) const

True if the given signal is part of this interface.

References signal().

◆ introspect()

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

Returns a DBus XML description of this interface.

References name().

◆ method()

std::shared_ptr< MethodBase > DBus::Interface::method ( const std::string &  name) const

Returns the method with the given name, or an invalid shared_ptr if not found.

References name().

Referenced by add_method(), create_method(), handle_call_message(), and remove_method().

◆ methods()

const Interface::Methods & DBus::Interface::methods ( ) const

Returns the methods associated with this interface.

◆ name()

const std::string & DBus::Interface::name ( ) const

◆ path()

Path DBus::Interface::path ( ) const

Returns the path of the object associated with this interface or a null string if no object is associated.

Referenced by add_signal(), and create_signal().

◆ properties()

const std::set< std::shared_ptr< PropertyBase > > & DBus::Interface::properties ( )

◆ property_updated()

◆ remove_method() [1/2]

bool DBus::Interface::remove_method ( const std::string &  name)

Removes the first method with the given name.

References method(), and name().

◆ remove_method() [2/2]

bool DBus::Interface::remove_method ( std::shared_ptr< MethodBase method)

Removes the given method, if found.

Parameters
method

References method().

◆ remove_signal() [1/2]

bool DBus::Interface::remove_signal ( const std::string &  name)

Removes all signals with the given name.

References name().

◆ remove_signal() [2/2]

bool DBus::Interface::remove_signal ( std::shared_ptr< SignalBase signal)

Removes the given signal.

Returns
true if the signal was successfully removed, false otherwise

One reason a signal couldn't be removed is if it wasn't a part of the interface.

References signal().

◆ set_connection()

void DBus::Interface::set_connection ( std::weak_ptr< Connection conn)
private

References signal().

◆ set_path()

void DBus::Interface::set_path ( const std::string &  new_path)
private

◆ signal()

std::shared_ptr< SignalBase > DBus::Interface::signal ( const std::string &  signal_name)

Returns the first signal found with a matching name.

If more than one signal has a given name there are no guarantees as to which signal will be returned.

Referenced by has_signal(), remove_signal(), and set_connection().

◆ signal_method_added()

sigc::signal< void(std::shared_ptr< MethodBase >)> DBus::Interface::signal_method_added ( )

Signal emitted when a method of the given name is added.

◆ signal_method_removed()

sigc::signal< void(std::shared_ptr< MethodBase >)> DBus::Interface::signal_method_removed ( )

Signal emitted when a method of the given name is removed.

◆ signals()

const Interface::Signals & DBus::Interface::signals ( )

Returns the signals associated with this interface.

Friends And Related Function Documentation

◆ Object

friend class Object
friend

◆ PropertyBase

friend class PropertyBase
friend

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