* Fixed implementation of D-Bus properties

* Added an example to demonstrate implementation of D-Bus properties
* Fixed DBus::Server (should work with the tcp transport too, see related TODO item)


git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@8158 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
pdurante 2006-10-24 11:12:29 +00:00
parent 19712668b1
commit 1b84dc5abc
30 changed files with 750 additions and 121 deletions

View file

@ -32,13 +32,14 @@
#include "connection_p.h"
#include "dispatcher_p.h"
#include "server_p.h"
#include "message_p.h"
#include "pendingcall_p.h"
using namespace DBus;
Connection::Private::Private( DBusConnection* c )
: conn(c) , dispatcher(0)
Connection::Private::Private( DBusConnection* c, Server::Private* s )
: conn(c) , dispatcher(0), server(s)
{
init();
}
@ -56,6 +57,10 @@ Connection::Private::Private( DBusBusType type )
Connection::Private::~Private()
{
debug_log("terminating connection 0x%08x", conn);
detach_server();
if(dbus_connection_get_is_connected(conn))
{
std::vector<std::string>::iterator i = names.begin();
@ -66,7 +71,7 @@ Connection::Private::~Private()
dbus_bus_release_name(conn, i->c_str(), NULL);
++i;
}
//dbus_connection_disconnect(conn);
dbus_connection_close(conn);
}
dbus_connection_unref(conn);
}
@ -74,6 +79,7 @@ Connection::Private::~Private()
void Connection::Private::init()
{
dbus_connection_ref(conn);
dbus_connection_ref(conn); //todo: the library has to own another reference
disconn_filter = new Callback<Connection::Private, bool, const Message&>(
this, &Connection::Private::disconn_filter_function
@ -85,10 +91,40 @@ void Connection::Private::init()
dbus_connection_set_exit_on_disconnect(conn, false); //why was this set to true??
}
void Connection::Private::detach_server()
{
/* Server::Private* tmp = server;
server = NULL;
if(tmp)
{
ConnectionList::iterator i;
for(i = tmp->connections.begin(); i != tmp->connections.end(); ++i)
{
if(i->_pvt.get() == this)
{
tmp->connections.erase(i);
break;
}
}
}*/
}
bool Connection::Private::do_dispatch()
{
debug_log("dispatching on %p", conn);
if(!dbus_connection_get_is_connected(conn))
{
debug_log("connection terminated");
detach_server();
return true;
}
return dbus_connection_dispatch(conn) != DBUS_DISPATCH_DATA_REMAINS;
}
@ -155,8 +191,8 @@ Connection::Connection( const char* address, bool priv )
{
InternalError e;
DBusConnection* conn = priv
? dbus_connection_open_private(address, e)
: dbus_connection_open(address,e);
? dbus_connection_open_private(address, e)
: dbus_connection_open(address, e);
if(e) throw Error(e);

View file

@ -26,6 +26,7 @@
#define __DBUSXX_CONNECTION_P_H
#include <dbus-c++/connection.h>
#include <dbus-c++/server.h>
#include <dbus-c++/dispatcher.h>
#include <dbus-c++/refptr_impl.h>
@ -39,7 +40,7 @@ struct Connection::Private
{
DBusConnection* conn;
std::vector<std::string> names;
std::vector<std::string> names;
Dispatcher* dispatcher;
bool do_dispatch();
@ -47,7 +48,10 @@ struct Connection::Private
MessageSlot disconn_filter;
bool disconn_filter_function( const Message& );
Private( DBusConnection* );
Server::Private* server;
void detach_server();
Private( DBusConnection*, Server::Private* = NULL );
Private( DBusBusType );

View file

@ -27,6 +27,7 @@
#include <dbus/dbus.h>
#include "dispatcher_p.h"
#include "server_p.h"
#include "connection_p.h"
DBus::Dispatcher* DBus::default_dispatcher = NULL;

View file

@ -88,7 +88,7 @@ Variant* InterfaceAdaptor::get_property( const std::string& name )
return NULL;
}
bool InterfaceAdaptor::set_property( const std::string& name, Variant& value )
void InterfaceAdaptor::set_property( const std::string& name, Variant& value )
{
PropertyTable::iterator pti = _properties.find(name);
@ -97,10 +97,15 @@ bool InterfaceAdaptor::set_property( const std::string& name, Variant& value )
if( !pti->second.write )
throw ErrorAccessDenied("property is not writeable");
Signature sig = value.signature();
if( pti->second.sig != sig )
throw ErrorInvalidSignature("property expects a different type");
pti->second.value = value;
return true;
return;
}
return false;
throw ErrorFailed("requested property not found");
}
InterfaceProxy* ProxyBase::find_interface( const std::string& name )

View file

@ -30,6 +30,7 @@
#include <dbus/dbus.h>
#include "message_p.h"
#include "server_p.h"
#include "connection_p.h"
using namespace DBus;

View file

@ -46,7 +46,7 @@ Message PropertiesAdaptor::Get( const CallMessage& call )
ri >> iface_name >> property_name;
debug_log("requesting property %s on interface %s\n", property_name.c_str(), iface_name.c_str());
debug_log("requesting property %s on interface %s", property_name.c_str(), iface_name.c_str());
InterfaceAdaptor* interface = (InterfaceAdaptor*) find_interface(iface_name);
@ -85,8 +85,7 @@ Message PropertiesAdaptor::Set( const CallMessage& call )
on_set_property(*interface, property_name, value);
if(!interface->set_property(property_name, value))
throw ErrorFailed("requested property not found");
interface->set_property(property_name, value);
ReturnMessage reply(call);

View file

@ -35,18 +35,23 @@ using namespace DBus;
Server::Private::Private( DBusServer* s )
: server(s)
{
dbus_server_set_new_connection_function(server, on_new_conn_cb, this, NULL);
}
Server::Private::~Private()
{
}
void Server::Private::on_new_conn_cb( DBusServer* server, DBusConnection* conn, void* data )
{
//Private* p = static_cast<Private*>(data);
Server* s = static_cast<Server*>(data);
//m->on_new_connection(nc); //TODO
Connection nc (new Connection::Private(conn, s->_pvt.get()));
Connection nc(new Connection::Private(conn));
s->_pvt->connections.push_back(nc);
debug_log("incoming connection");
s->on_new_connection(nc);
debug_log("incoming connection 0x%08x", conn);
}
Server::Server( const char* address )
@ -56,15 +61,21 @@ Server::Server( const char* address )
if(e) throw Error(e);
_pvt = new Private(server);
}
debug_log("server 0x%08x listening on %s", server, address);
_pvt = new Private(server);
dbus_server_set_new_connection_function(_pvt->server, Private::on_new_conn_cb, this, NULL);
setup(default_dispatcher);
}
/*
Server::Server( const Server& s )
: _pvt(s._pvt)
{
dbus_server_ref(_pvt->server);
}
*/
Server::~Server()
{
dbus_server_unref(_pvt->server);

View file

@ -39,8 +39,12 @@ struct Server::Private
Dispatcher* dispatcher;
ConnectionList connections;
Private( DBusServer* );
~Private();
static void on_new_conn_cb( DBusServer* server, DBusConnection* conn, void* data );
};

View file

@ -87,7 +87,8 @@ MessageIter& operator << ( MessageIter& iter, const Variant& val )
MessageIter& operator >> ( MessageIter& iter, Variant& val )
{
//TODO: check if iter really points to a variant
if(iter.type() != DBUS_TYPE_VARIANT)
throw ErrorInvalidArgs("variant type expected");
val.clear();