[Lunar-commits] <lconnman> connmanmanager.vala: add get_services

Samuel Verstraete samuel.verstraete at gmail.com
Sat Aug 13 13:17:38 CEST 2011


commit 99eff85a9e0846bf88662f45096cf4eaca681cca
Author: Samuel Verstraete <samuel.verstraete at gmail.com>
Date:   Sat Aug 13 13:17:38 2011 +0200

    connmanmanager.vala: add get_services
---
 src/connmanmanager.vala |   52 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/src/connmanmanager.vala b/src/connmanmanager.vala
index dc3c351..af6c069 100644
--- a/src/connmanmanager.vala
+++ b/src/connmanmanager.vala
@@ -1,16 +1,64 @@
 [DBus (name = "net.connman.Manager")]
 interface ConnmanManager : Object {
   public abstract string get_state() throws IOError;
+  public abstract Service[] get_services() throws IOError;
 }
 
+public struct Service {
+  public GLib.ObjectPath first;
+  public GLib.HashTable<string, Variant> second;
+}
+
+ConnmanManager connmanManager;
+
 void main () {
-  ConnmanManager connmanManager;
 
   try {
     connmanManager = Bus.get_proxy_sync (BusType.SYSTEM, "net.connman", "/");
-    string state = connmanManager.get_state();
+    string state = get_state();
     stdout.printf(state +"\n");
   } catch (IOError e) {
     stderr.printf (e.message +"\n");
   }
 
+  foreach (Service service in get_services()) {
+    stdout.printf(print_service(service));
+  }
+}
+
+public static string get_state() {
+  try {
+    return connmanManager.get_state();
+  } catch (IOError e) {
+    stderr.printf (e.message +"\n");
+    return null;
+  }
+}
+
+public static Service[] get_services() {
+  try {
+    return connmanManager.get_services();
+  } catch (IOError e) {
+    stderr.printf (e.message +"\n");
+    return null;
+  }
+}
+
+public string print_service(Service service) {
+  StringBuilder result = new StringBuilder();
+  result.append("Name: " + service.first.to_string() + "\n");
+//  List<string> keys = service.second.get_keys();
+//  List<Variant> values = service.second.get_values();
+
+  foreach (var key in service.second.get_keys()) {
+    GLib.Variant service_value;
+    string orig_key="";
+    service.second.lookup_extended(key, out orig_key, out service_value);
+    result.append("\t" + key.to_string() + " : " + service_value.print(false) +"\n");
+  }
+
+// for (int i = 0; i <= keys.length; i++) {
+//   result+="\t" + keys.nth(i).to_string() + " : " + values.nth(i).to_string() + "\n";
+// }
+  return result.str;
+}


More information about the Lunar-commits mailing list