diff options
Diffstat (limited to 'src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java')
-rwxr-xr-x | src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java new file mode 100755 index 0000000..93d4ad5 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java @@ -0,0 +1,74 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +/** + * This class lists all the names currently connected on the bus + */ +public class ListDBus +{ + public static void syntax() + { + System.out.println("Syntax: ListDBus [--version] [-v] [--help] [-h] [--owners] [-o] [--uids] [-u] [--session] [-s] [--system] [-y]"); + System.exit(1); + } + public static void version() + { + System.out.println("Java D-Bus Version "+System.getProperty("Version")); + System.exit(1); + } + public static void main(String args[]) throws Exception + { + boolean owners = false; + boolean users = false; + int connection = DBusConnection.SESSION; + + for (String a: args) + if ("--help".equals(a)) syntax(); + else if ("-h".equals(a)) syntax(); + else if ("--version".equals(a)) version(); + else if ("-v".equals(a)) version(); + else if ("-u".equals(a)) users = true; + else if ("--uids".equals(a)) users = true; + else if ("-o".equals(a)) owners = true; + else if ("--owners".equals(a)) owners = true; + else if ("--session".equals(a)) connection = DBusConnection.SESSION; + else if ("-s".equals(a)) connection = DBusConnection.SESSION; + else if ("--system".equals(a)) connection = DBusConnection.SYSTEM; + else if ("-y".equals(a)) connection = DBusConnection.SYSTEM; + else syntax(); + + DBusConnection conn = DBusConnection.getConnection(connection); + DBus dbus = conn.getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class); + String[] names = dbus.ListNames(); + for (String s: names) { + if (users) + try { + System.out.print(dbus.GetConnectionUnixUser(s)+"\t"); + } catch (DBusExecutionException DBEe) { + System.out.print("\t"); + } + System.out.print(s); + if (!s.startsWith(":") && owners) { + try { + System.out.print("\t"+dbus.GetNameOwner(s)); + } catch (DBusExecutionException DBEe) { + } + } + System.out.println(); + } + conn.disconnect(); + } +} |