major D-Bus code update

git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@7715 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2006-09-23 23:25:34 +00:00
parent acfeb85b87
commit 42ea920aeb
41 changed files with 958 additions and 1506 deletions

View file

@ -22,12 +22,13 @@
*/
#ifndef __DBUSXX_DBUSXX_H
#define __DBUSXX_DBUSXX_H
#ifndef __DBUSXX_DBUS_H
#define __DBUSXX_DBUS_H
#include "types.h"
#include "interface.h"
#include "object.h"
#include "property.h"
#include "connection.h"
#include "server.h"
#include "error.h"
@ -41,4 +42,4 @@
#include "xml.h"
#include "introspection.h"
#endif//__DBUSXX_DBUSXX_H
#endif//__DBUSXX_DBUS_H

View file

@ -51,16 +51,16 @@ public:
const char* what() const throw();
const char* name();
const char* name() const;
const char* message();
const char* message() const;
void set( const char* name, const char* message );
// parameters MUST be static strings
bool is_set();
bool is_set() const;
operator bool()
operator bool() const
{
return is_set();
}
@ -224,7 +224,61 @@ struct ErrorMatchRuleInvalid : public Error
{}
};
/* TODO: add the remaining error codes from dbus-protocol.h */
struct ErrorSpawnExecFailed : public Error
{
ErrorSpawnExecFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ExecFailed", message)
{}
};
struct ErrorSpawnForkFailed : public Error
{
ErrorSpawnForkFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ForkFailed", message)
{}
};
struct ErrorSpawnChildExited : public Error
{
ErrorSpawnChildExited( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ChildExited", message)
{}
};
struct ErrorSpawnChildSignaled : public Error
{
ErrorSpawnChildSignaled( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.ChildSignaled", message)
{}
};
struct ErrorSpawnFailed : public Error
{
ErrorSpawnFailed( const char* message )
: Error("org.freedesktop.DBus.Error.Spawn.Failed", message)
{}
};
struct ErrorInvalidSignature : public Error
{
ErrorInvalidSignature( const char* message )
: Error("org.freedesktop.DBus.Error.InvalidSignature", message)
{}
};
struct ErrorUnixProcessIdUnknown : public Error
{
ErrorUnixProcessIdUnknown( const char* message )
: Error("org.freedesktop.DBus.Error.UnixProcessIdUnknown", message)
{}
};
struct ErrorSELinuxSecurityContextUnknown : public Error
{
ErrorSELinuxSecurityContextUnknown( const char* message )
: Error("org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown", message)
{}
};
} /* namespace DBus */

View file

@ -28,77 +28,94 @@
#include <string>
#include <map>
#include "util.h"
#include "types.h"
#include "message.h"
namespace DBus {
class Interface;
class IfaceTracker;
//todo: this should belong to to properties.h
struct PropertyData
{
bool read;
bool write;
Variant value;
};
typedef std::map<std::string, Interface*> InterfaceTable;
class Object;
class CallMessage;
class SignalMessage;
typedef std::map<std::string, PropertyData> PropertyTable;
class IntrospectedInterface;
class IfaceTracker
class ObjectAdaptor;
class InterfaceAdaptor;
class SignalMessage;
typedef std::map<std::string, InterfaceAdaptor*> InterfaceAdaptorTable;
class AdaptorBase
{
public:
virtual const Object* object() const = 0 ;
virtual const ObjectAdaptor* object() const = 0 ;
protected:
InterfaceTable _interfaces;
InterfaceAdaptor* find_interface( const std::string& name );
virtual ~IfaceTracker()
virtual ~AdaptorBase()
{}
virtual void remit_signal( SignalMessage& )
{}
virtual void _emit_signal( SignalMessage& ) = 0;
virtual Message rinvoke_method( CallMessage& );
};
typedef std::map< std::string, Slot<Message, const CallMessage&> > MethodTable;
typedef std::map< std::string, Slot<void, const SignalMessage&> > SignalTable;
class Interface : public virtual IfaceTracker
{
public:
Interface( const char* name );
virtual ~Interface();
inline const std::string& iname() const;
virtual Message invoke_method( const CallMessage& );
virtual bool dispatch_signal( const SignalMessage& );
virtual IntrospectedInterface* const introspect() const
{
return NULL;
}
private:
void register_interface( const char* name );
private:
std::string _name;
InterfaceAdaptorTable _interfaces;
};
/*
*/
const std::string& Interface::iname() const
class ObjectProxy;
class InterfaceProxy;
class CallMessage;
typedef std::map<std::string, InterfaceProxy*> InterfaceProxyTable;
class ProxyBase
{
public:
virtual const ObjectProxy* object() const = 0 ;
protected:
InterfaceProxy* find_interface( const std::string& name );
virtual ~ProxyBase()
{}
virtual Message _invoke_method( CallMessage& ) = 0;
InterfaceProxyTable _interfaces;
};
class Interface
{
public:
Interface( const std::string& name );
virtual ~Interface();
inline const std::string& name() const;
private:
std::string _name;
};
/*
*/
const std::string& Interface::name() const
{
return _name;
}
@ -106,29 +123,43 @@ const std::string& Interface::iname() const
/*
*/
class InterfaceAdaptor : public Interface
typedef std::map< std::string, Slot<Message, const CallMessage&> > MethodTable;
class InterfaceAdaptor : public Interface, public virtual AdaptorBase
{
public:
InterfaceAdaptor( const char* name );
InterfaceAdaptor( const std::string& name );
Message invoke_method( const CallMessage& );
Message dispatch_method( const CallMessage& );
void emit_signal( const SignalMessage& );
Variant* get_property( const std::string& name );
bool set_property( const std::string& name, Variant& value );
virtual IntrospectedInterface* const introspect() const
{
return NULL;
}
protected:
MethodTable _methods;
PropertyTable _properties;
};
/*
*/
class InterfaceProxy : public Interface
typedef std::map< std::string, Slot<void, const SignalMessage&> > SignalTable;
class InterfaceProxy : public Interface, public virtual ProxyBase
{
public:
InterfaceProxy( const char* name );
InterfaceProxy( const std::string& name );
Message invoke_method( const CallMessage& );
@ -141,11 +172,16 @@ protected:
# define register_method(interface, method, callback) \
InterfaceAdaptor::_methods[ #method ] = \
new DBus::Callback< interface, DBus::Message, const DBus::CallMessage& >(this, & interface :: callback );
new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage& >(this, & interface :: callback );
# define bind_property(variable, can_read, can_write) \
InterfaceAdaptor::_properties[ #variable ].read = can_read; \
InterfaceAdaptor::_properties[ #variable ].write = can_write; \
variable.bind( InterfaceAdaptor::_properties[ #variable ] );
# define connect_signal(interface, signal) \
# define connect_signal(interface, signal, callback) \
InterfaceProxy::_signals[ #signal ] = \
new DBus::Callback< interface, void, const DBus::SignalMessage& >(this, & interface :: method );
new ::DBus::Callback< interface, void, const ::DBus::SignalMessage& >(this, & interface :: callback );
} /* namespace DBus */

View file

@ -42,11 +42,20 @@ struct IntrospectedMethod
const IntrospectedArgument* args;
};
struct IntrospectedProperty
{
const char* name;
const char* type;
const bool read;
const bool write;
};
struct IntrospectedInterface
{
const char* name;
const IntrospectedMethod* methods;
const IntrospectedMethod* signals;
const IntrospectedProperty* properties;
};
class IntrospectableAdaptor : public InterfaceAdaptor

View file

@ -125,10 +125,12 @@ public:
MessageIter new_variant( const char* sig );
MessageIter new_struct( const char* sig );
MessageIter new_struct();
void close_container( MessageIter& container );
void copy_data( MessageIter& to );
Message& msg() const
{
return *_msg;
@ -187,9 +189,9 @@ public:
bool is_signal( const char* interface, const char* member ) const;
MessageIter r_iter() const;
MessageIter reader() const;
MessageIter w_iter();
MessageIter writer();
bool append( int first_type, ... );

View file

@ -27,7 +27,6 @@
#include <string>
#include <list>
#include <map>
#include "interface.h"
#include "connection.h"
@ -36,19 +35,11 @@
namespace DBus {
class Object;
typedef std::list<Object*> ObjectPList;
class ObjectAdaptor;
class ObjectProxy;
class Object : protected virtual IfaceTracker
class Object
{
protected:
Object( Connection& conn, const char* path, const char* service );
Object( Connection& conn, const Path& path, const char* service );
public:
@ -57,15 +48,11 @@ public:
inline const DBus::Path& path() const;
inline const std::string& service() const;
inline const Object* object() const;
inline Connection& conn();
private:
//Object( const Object& );
virtual bool handle_message( const Message& ) = 0;
virtual void register_obj() = 0;
virtual void unregister_obj() = 0;
@ -80,11 +67,6 @@ private:
/*
*/
const Object* Object::object() const
{
return this;
}
Connection& Object::conn()
{
return _conn;
@ -103,21 +85,29 @@ const std::string& Object::service() const
/*
*/
class ObjectAdaptor : public Object
class ObjectAdaptor;
typedef std::list<ObjectAdaptor*> ObjectAdaptorPList;
class ObjectAdaptor : public Object, public virtual AdaptorBase
{
public:
static ObjectAdaptor* from_path( const Path& path );
static ObjectAdaptorPList from_path_prefix( const std::string& prefix );
struct Private;
ObjectAdaptor( Connection& conn, const char* path );
ObjectAdaptor( Connection& conn, const Path& path );
~ObjectAdaptor();
void remit_signal( SignalMessage& );
inline const ObjectAdaptor* object() const;
protected:
class DeferredReturn
class Continuation
{
public:
@ -127,7 +117,7 @@ protected:
private:
DeferredReturn( Connection& conn, const CallMessage& call, const void* tag );
Continuation( Connection& conn, const CallMessage& call, const void* tag );
Connection _conn;
CallMessage _call;
@ -140,31 +130,38 @@ protected:
void return_later( const void* tag );
void return_now( DeferredReturn* ret );
void return_now( Continuation* ret );
void return_error( DeferredReturn* ret, Error& error );
void return_error( Continuation* ret, const Error error );
DeferredReturn* find_return( const void* tag );
Continuation* find_continuation( const void* tag );
private:
void _emit_signal( SignalMessage& );
bool handle_message( const Message& );
void register_obj();
void unregister_obj();
typedef std::map<const void*, DeferredReturn*> DeferredReturnMap;
DeferredReturnMap _deferred_returns;
typedef std::map<const void*, Continuation*> ContinuationMap;
ContinuationMap _continuations;
friend struct Private;
};
void* ObjectAdaptor::DeferredReturn::tag()
const ObjectAdaptor* ObjectAdaptor::object() const
{
return this;
}
void* ObjectAdaptor::Continuation::tag()
{
return const_cast<void*>(_tag);
}
MessageIter& ObjectAdaptor::DeferredReturn::writer()
MessageIter& ObjectAdaptor::Continuation::writer()
{
return _writer;
}
@ -172,18 +169,24 @@ MessageIter& ObjectAdaptor::DeferredReturn::writer()
/*
*/
class ObjectProxy : public Object
class ObjectProxy;
typedef std::list<ObjectProxy*> ObjectProxyPList;
class ObjectProxy : public Object, public virtual ProxyBase
{
public:
ObjectProxy( Connection& conn, const char* path, const char* service = "" );
ObjectProxy( Connection& conn, const Path& path, const char* service = "" );
~ObjectProxy();
Message rinvoke_method( CallMessage& );
inline const ObjectProxy* object() const;
private:
Message _invoke_method( CallMessage& );
bool handle_message( const Message& );
void register_obj();
@ -194,6 +197,11 @@ private:
MessageSlot _filtered;
};
const ObjectProxy* ObjectProxy::object() const
{
return this;
}
} /* namespace DBus */
#endif//__DBUSXX_OBJECT_H

104
include/dbus-c++/property.h Normal file
View file

@ -0,0 +1,104 @@
/*
*
* D-Bus++ - C++ bindings for DBus
*
* Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __DBUSXX_PROPERTY_H
#define __DBUSXX_PROPERTY_H
#include "types.h"
#include "interface.h"
namespace DBus {
template <typename T>
class PropertyAdaptor
{
public:
PropertyAdaptor() : _data(0)
{}
void bind( PropertyData& data )
{
_data = &data;
}
T operator() (void) const
{
T t;
MessageIter ri = _data->value.reader();
ri >> t;
return t;
}
PropertyAdaptor& operator = ( const T& t )
{
_data->value.clear();
MessageIter wi = _data->value.writer();
wi << t;
return *this;
}
private:
PropertyData* _data;
};
struct IntrospectedInterface;
class PropertiesAdaptor : public InterfaceAdaptor
{
public:
PropertiesAdaptor();
Message Get( const CallMessage& );
Message Set( const CallMessage& );
protected:
virtual void on_get_property( InterfaceAdaptor& interface, const String& property, Variant& value )
{}
virtual void on_set_property( InterfaceAdaptor& interface, const String& property, const Variant& value )
{}
IntrospectedInterface* const introspect() const;
};
class PropertiesProxy : public InterfaceProxy
{
public:
PropertiesProxy();
Variant Get( const String& interface, const String& property );
void Set( const String& interface, const String& property, const Variant& value );
};
} /* namespace DBus */
#endif//__DBUSXX_PROPERTY_H

View file

@ -49,6 +49,7 @@ typedef std::string String;
struct Path : public std::string
{
Path() {}
Path( const std::string& s ) : std::string(s) {}
Path( const char* c ) : std::string(c) {}
Path& operator = ( std::string& s )
{
@ -60,6 +61,7 @@ struct Path : public std::string
struct Signature : public std::string
{
Signature() {}
Signature( const std::string& s ) : std::string(s) {}
Signature( const char* c ) : std::string(c) {}
Signature& operator = ( std::string& s )
{
@ -80,30 +82,23 @@ public:
Variant& operator = ( const Variant& v );
const char* signature() const;
const Signature signature() const;
MessageIter iter() const
void clear();
MessageIter reader() const
{
return _it;
return _msg.reader();
}
MessageIter writer()
{
return _msg.writer();
}
private:
Message _msg;
MessageIter _it;
mutable Signature _signature;
};
template <typename E>
struct Array : public std::vector<E> {};
template <typename K, typename V>
struct Dict : public std::map<K, V>
{
bool has_key( const K& key ) const
{
return this->find(key) != this->end();
}
};
template <
@ -131,19 +126,19 @@ struct type
}
};
template <> struct type<Byte> { static std::string sig(){ return "y"; } };
template <> struct type<Bool> { static std::string sig(){ return "b"; } };
template <> struct type<Int16> { static std::string sig(){ return "n"; } };
template <> struct type<UInt16> { static std::string sig(){ return "q"; } };
template <> struct type<Int32> { static std::string sig(){ return "i"; } };
template <> struct type<UInt32> { static std::string sig(){ return "u"; } };
template <> struct type<Int64> { static std::string sig(){ return "x"; } };
template <> struct type<UInt64> { static std::string sig(){ return "t"; } };
template <> struct type<Double> { static std::string sig(){ return "d"; } };
template <> struct type<String> { static std::string sig(){ return "s"; } };
template <> struct type<Path> { static std::string sig(){ return "o"; } };
template <> struct type<Signature> { static std::string sig(){ return "g"; } };
template <> struct type<Invalid> { static std::string sig(){ return ""; } };
template <> struct type<Byte> { static std::string sig(){ return "y"; } };
template <> struct type<Bool> { static std::string sig(){ return "b"; } };
template <> struct type<Int16> { static std::string sig(){ return "n"; } };
template <> struct type<UInt16> { static std::string sig(){ return "q"; } };
template <> struct type<Int32> { static std::string sig(){ return "i"; } };
template <> struct type<UInt32> { static std::string sig(){ return "u"; } };
template <> struct type<Int64> { static std::string sig(){ return "x"; } };
template <> struct type<UInt64> { static std::string sig(){ return "t"; } };
template <> struct type<Double> { static std::string sig(){ return "d"; } };
template <> struct type<String> { static std::string sig(){ return "s"; } };
template <> struct type<Path> { static std::string sig(){ return "o"; } };
template <> struct type<Signature> { static std::string sig(){ return "g"; } };
template <> struct type<Invalid> { static std::string sig(){ return ""; } };
template <typename E>
struct type< std::vector<E> >
@ -315,11 +310,11 @@ template <
>
inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Struct<T1,T2,T3,T4,T5,T6,T7,T8>& val )
{
const std::string sig =
/* const std::string sig =
DBus::type<T1>::sig() + DBus::type<T2>::sig() + DBus::type<T3>::sig() + DBus::type<T4>::sig() +
DBus::type<T5>::sig() + DBus::type<T6>::sig() + DBus::type<T7>::sig() + DBus::type<T8>::sig();
DBus::MessageIter sit = iter.new_struct(sig.c_str());
*/
DBus::MessageIter sit = iter.new_struct(/*sig.c_str()*/);
sit << val._1 << val._2 << val._3 << val._4 << val._5 << val._6 << val._7 << val._8;