4 * Authored by Michael 'Mickey' Lauer <mlauer@vanille-media.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //===========================================================================
27 //===========================================================================
28 string[] stringListToArray( List
<string>? theList
)
30 var res
= new
string[theList
.length()];
32 foreach ( string el
in theList
)
41 //===========================================================================
42 public class Introspection
: Object
44 private string[] _xmldata
;
46 public List
<string> interfaces
;
47 public List
<string> nodes
;
49 public Introspection( string xmldata
)
51 debug( "introspection object created" );
52 _xmldata
= xmldata
.split( "\n" );
54 foreach ( string line
in _xmldata
)
56 //debug( "dealing with line '%s'", line );
59 res
= line
.scanf( " <node name=\"%a[a-zA-Z0-9_]\"/>", out name
);
63 message( "object has node '%s'", name
);
65 res
= line
.scanf( " <interface name=\"%a[a-zA-Z0-9_.]\">", out name
);
68 message( "object supports interface '%s'", name
);
69 interfaces
.append( name
);
75 //===========================================================================
76 [DBus (name
= "org.freesmartphone.DBus")]
77 public class Server
: Object
80 dynamic DBus
.Object dbus
;
86 debug( "server object created" );
87 conn
= DBus
.Bus
.get( DBus
.BusType
.SYSTEM
);
88 dbus
= conn
.get_object( DBUS_BUS_NAME
, DBUS_OBJ_PATH
, DBUS_INTERFACE
);
89 } catch (DBus
.Error e
) {
94 public string[]?
ListBusNames()
96 string[] names
= null;
98 names
= dbus
.ListNames();
99 } catch (DBus
.Error e
) {
108 public string[] ListObjectPaths( string? busname
) throws DBus
.Error
111 // Check whether the given busname is present on the bus
113 var paths
= new List
<string>();
114 var existing_busnames
= this
.ListBusNames();
116 foreach ( string name
in existing_busnames
)
118 if ( busname
== name
)
126 message( "requested busname '%s' not found.", busname
);
127 // FIXME return a dbus error?
128 return stringListToArray( paths
);
130 listObjectPaths( ref paths
, busname
, "/" );
131 return stringListToArray( paths
);
134 private void listObjectPaths( ref List
<string> paths
, string busname
, string objname
) throws DBus
.Error
136 debug( "listObjectPaths: %s, %s", busname
, objname
);
137 dynamic DBus
.Object obj
= conn
.get_object( busname
, objname
, DBUS_INTERFACE_INTROSPECTABLE
);
138 Introspection data
= new
Introspection( obj
.Introspect() );
139 if ( data
.interfaces
.length() > 1 ) // we don't count the introspection interface that is always present
140 paths
.append( objname
);
141 if ( data
.nodes
.length() > 0 )
142 foreach ( string node
in data
.nodes
)
144 if ( objname
== "/" )
145 listObjectPaths( ref paths
, busname
, objname
+node
);
147 listObjectPaths( ref paths
, busname
, objname
+"/"+node
);
151 public string[] ListObjectsByInterface( string busname
, string iface
) throws DBus
.Error
154 // Check whether the given busname is present on the bus
156 var paths
= new List
<string>();
157 var existing_busnames
= this
.ListBusNames();
159 foreach ( string name
in existing_busnames
)
161 if ( busname
== name
)
169 message( "requested busname '%s' not found.", busname
);
170 // FIXME return a dbus error
171 return stringListToArray( paths
);
173 listObjectsByInterface( ref paths
, busname
, "/", iface
);
174 return stringListToArray( paths
);
177 private void listObjectsByInterface( ref List
<string> paths
, string busname
, string objname
, string iface
) throws DBus
.Error
179 debug( "listObjectsByInterface: %s, %s, %s", busname
, objname
, iface
);
180 dynamic DBus
.Object obj
= conn
.get_object( busname
, objname
, DBUS_INTERFACE_INTROSPECTABLE
);
181 Introspection data
= new
Introspection( obj
.Introspect() );
182 if ( data
.interfaces
.length() > 1 ) // we don't count the introspection interface that is always present
183 foreach ( string ifacename
in data
.interfaces
)
185 if ( ifacename
== iface
)
186 paths
.append( objname
);
188 if ( data
.nodes
.length() > 0 )
189 foreach ( string node
in data
.nodes
)
191 if ( objname
== "/" )
192 listObjectsByInterface( ref paths
, busname
, objname
+node
, iface
);
194 listObjectsByInterface( ref paths
, busname
, objname
+"/"+node
, iface
);