From fd81f5e0ee50651dd97f91ea3adc574601a97087 Mon Sep 17 00:00:00 2001 From: Michael 'Mickey' Lauer Date: Fri, 2 Jan 2009 13:16:02 +0100 Subject: [PATCH] ListObjectsByInterface now works --- src/obj.vala | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/src/obj.vala b/src/obj.vala index b7d3454..1bc6e45 100644 --- a/src/obj.vala +++ b/src/obj.vala @@ -25,7 +25,7 @@ using CONST; //=========================================================================== -string[]? stringListToArray( List theList ) +string[] stringListToArray( List? theList ) { var res = new string[theList.length()]; int counter = 0; @@ -105,12 +105,12 @@ public class Server : Object return names; } - public string[]? ListObjectPaths( string? busname ) throws DBus.Error + public string[] ListObjectPaths( string? busname ) throws DBus.Error { // // Check whether the given busname is present on the bus // - string[] names = null; + var paths = new List(); var existing_busnames = this.ListBusNames(); bool found = false; foreach ( string name in existing_busnames ) @@ -124,17 +124,14 @@ public class Server : Object if ( !found ) { message( "requested busname '%s' not found.", busname ); - // FIXME return a dbus error - return names; + // FIXME return a dbus error? + return stringListToArray( paths ); } - - var paths = new List(); listObjectPaths( ref paths, busname, "/" ); - return stringListToArray( paths ); } - private void listObjectPaths( ref List paths, string? busname, string? objname ) throws DBus.Error + private void listObjectPaths( ref List paths, string busname, string objname ) throws DBus.Error { debug( "listObjectPaths: %s, %s", busname, objname ); dynamic DBus.Object obj = conn.get_object( busname, objname, DBUS_INTERFACE_INTROSPECTABLE ); @@ -150,4 +147,51 @@ public class Server : Object listObjectPaths( ref paths, busname, objname+"/"+node ); } } + + public string[] ListObjectsByInterface( string busname, string iface ) throws DBus.Error + { + // + // Check whether the given busname is present on the bus + // + var paths = new List(); + var existing_busnames = this.ListBusNames(); + bool found = false; + foreach ( string name in existing_busnames ) + { + if ( busname == name ) + { + found = true; + break; + } + } + if ( !found ) + { + message( "requested busname '%s' not found.", busname ); + // FIXME return a dbus error + return stringListToArray( paths ); + } + listObjectsByInterface( ref paths, busname, "/", iface ); + return stringListToArray( paths ); + } + + private void listObjectsByInterface( ref List paths, string busname, string objname, string iface ) throws DBus.Error + { + debug( "listObjectsByInterface: %s, %s, %s", busname, objname, iface ); + dynamic DBus.Object obj = conn.get_object( busname, objname, DBUS_INTERFACE_INTROSPECTABLE ); + Introspection data = new Introspection( obj.Introspect() ); + if ( data.interfaces.length() > 1 ) // we don't count the introspection interface that is always present + foreach ( string ifacename in data.interfaces ) + { + if ( ifacename == iface ) + paths.append( objname ); + } + if ( data.nodes.length() > 0 ) + foreach ( string node in data.nodes ) + { + if ( objname == "/" ) + listObjectsByInterface( ref paths, busname, objname+node, iface ); + else + listObjectsByInterface( ref paths, busname, objname+"/"+node, iface ); + } + } } -- 2.11.4.GIT