* Nested objects introspection patch (David Belser)

* More indentation in generated code (David Belser)
* Avoid redundant calls to dbus_bus_add_match (David Belser)
* Typo in HAVE_PTHREAD_H macro  (Olivier Hochreutiner)
* Allow other listeners to receive the same signal, if any (Olivier Hochreutiner)
This commit is contained in:
admin 2008-01-06 01:58:28 +01:00
parent ecd2428049
commit 68a722e6d1
10 changed files with 89 additions and 64 deletions

View file

@ -8,9 +8,11 @@ GLIB_H = $(HEADER_DIR)/glib-integration.h
GLIB_CPP = glib-integration.cpp
endif
CONFIG_H = $(top_builddir)/include/dbus-c++/config.h
HEADER_DIR = $(top_srcdir)/include/dbus-c++
HEADER_FILES = \
$(HEADER_DIR)/config.h \
$(CONFIG_H) \
$(HEADER_DIR)/dbus.h \
$(HEADER_DIR)/types.h \
$(HEADER_DIR)/connection.h \

View file

@ -74,7 +74,7 @@ DefaultWatch::~DefaultWatch()
DefaultMutex::DefaultMutex()
{
#if defined HAVE_PTHREAD
#if defined HAVE_PTHREAD_H
pthread_mutex_init(&_mutex, NULL);
@ -84,7 +84,7 @@ DefaultMutex::DefaultMutex()
DefaultMutex::~DefaultMutex()
{
#if defined HAVE_PTHREAD
#if defined HAVE_PTHREAD_H
pthread_mutex_destroy(&_mutex);
@ -94,7 +94,7 @@ DefaultMutex::~DefaultMutex()
void DefaultMutex::lock()
{
#if defined HAVE_PTHREAD
#if defined HAVE_PTHREAD_H
pthread_mutex_lock(&_mutex);
@ -104,7 +104,7 @@ void DefaultMutex::lock()
void DefaultMutex::unlock()
{
#if defined HAVE_PTHREAD
#if defined HAVE_PTHREAD_H
pthread_mutex_unlock(&_mutex);

View file

@ -131,7 +131,11 @@ bool InterfaceProxy::dispatch_signal( const SignalMessage& msg )
if( si != _signals.end() )
{
si->second.call( msg );
return true;
// Here we always return false because there might be
// another InterfaceProxy listening for the same signal.
// This way we instruct libdbus-1 to go on dispatching
// the signal.
return false;
}
else
{

View file

@ -61,7 +61,7 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call )
IntrospectedInterface* const intro = iti->second->introspect();
if(intro)
{
xml << "<interface name=\"" << intro->name << "\">";
xml << "\n\t<interface name=\"" << intro->name << "\">";
for(const IntrospectedProperty* p = intro->properties; p->name; ++p)
{
@ -70,18 +70,18 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call )
if(p->read) access += "read";
if(p->write) access += "write";
xml << "<property name=\"" << p->name << "\""
xml << "\n\t\t<property name=\"" << p->name << "\""
<< " type=\"" << p->type << "\""
<< " access=\"" << access << "\"/>";
}
for(const IntrospectedMethod* m = intro->methods; m->args; ++m)
{
xml << "<method name=\"" << m->name << "\">";
xml << "\n\t\t<method name=\"" << m->name << "\">";
for(const IntrospectedArgument* a = m->args; a->type; ++a)
{
xml << "<arg direction=\"" << (a->in ? "in" : "out") << "\""
xml << "\n\t\t\t<arg direction=\"" << (a->in ? "in" : "out") << "\""
<< " type=\"" << a->type << "\"";
if(a->name) xml << " name=\"" << a->name << "\"";
@ -89,12 +89,12 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call )
xml << "/>";
}
xml << "</method>";
xml << "\n\t\t</method>";
}
for(const IntrospectedMethod* m = intro->signals; m->args; ++m)
{
xml << "<signal name=\"" << m->name << "\">";
xml << "\n\t\t<signal name=\"" << m->name << "\">";
for(const IntrospectedArgument* a = m->args; a->type; ++a)
{
@ -104,12 +104,22 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call )
xml << "/>";
}
xml << "</signal>";
xml << "\n\t\t</signal>";
}
xml << "</interface>";
xml << "\n\t</interface>";
}
}
const ObjectPathList nodes = ObjectAdaptor::child_nodes_from_prefix(path + '/');
ObjectPathList::const_iterator oni;
for(oni = nodes.begin(); oni != nodes.end(); ++oni)
{
xml << "\n\t<node name=\"" << (*oni) << "\"/>";
}
/* broken
const ObjectAdaptorPList children = ObjectAdaptor::from_path_prefix(path + '/');
ObjectAdaptorPList::const_iterator oci;
@ -121,8 +131,9 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call )
xml << "<node name=\"" << name << "\"/>";
}
*/
xml << "</node>";
xml << "\n</node>";
ReturnMessage reply(call);
MessageIter wi = reply.writer();

View file

@ -119,6 +119,31 @@ ObjectAdaptorPList ObjectAdaptor::from_path_prefix( const std::string& prefix )
return ali;
}
ObjectPathList ObjectAdaptor::child_nodes_from_prefix( const std::string& prefix )
{
ObjectPathList ali;
ObjectAdaptorTable::iterator ati = _adaptor_table.begin();
size_t plen = prefix.length();
while(ati != _adaptor_table.end())
{
if(!strncmp(ati->second->path().c_str(), prefix.c_str(), plen))
{
std::string p = ati->second->path().substr(plen);
p = p.substr(0,p.find('/'));
ali.push_back(p);
}
++ati;
}
ali.sort();
ali.unique();
return ali;
}
ObjectAdaptor::ObjectAdaptor( Connection& conn, const Path& path )
: Object(conn, path, conn.unique_name())
{
@ -138,16 +163,6 @@ void ObjectAdaptor::register_obj()
{
throw ErrorNoMemory("unable to register object path");
}
else
{
InterfaceAdaptorTable::const_iterator ii = _interfaces.begin();
while( ii != _interfaces.end() )
{
std::string im = "type='method_call',interface='"+ii->first+"',path='"+path()+"'";
conn().add_match(im.c_str());
++ii;
}
}
_adaptor_table[path()] = this;
}
@ -159,14 +174,6 @@ void ObjectAdaptor::unregister_obj()
debug_log("unregistering local object %s", path().c_str());
dbus_connection_unregister_object_path(conn()._pvt->conn, path().c_str());
InterfaceAdaptorTable::const_iterator ii = _interfaces.begin();
while( ii != _interfaces.end() )
{
std::string im = "type='method_call',interface='"+ii->first+"',path='"+path()+"'";
conn().remove_match(im.c_str());
++ii;
}
}
void ObjectAdaptor::_emit_signal( SignalMessage& sig )