[Lunar-commits] <lconnman> connmanmanager.vala: add get_properties for manager

Samuel samuel.verstraete at gmail.com
Thu Aug 18 10:01:38 CEST 2011


commit 50c01fe90baea7e67524607725fd55f36f769277
Author: Samuel <samuel.verstraete at gmail.com>
Date:   Thu Aug 18 10:01:38 2011 +0200

    connmanmanager.vala: add get_properties for manager
---
 src/connmanmanager.vala |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/connmanmanager.vala b/src/connmanmanager.vala
index 63c3597..ddde309 100644
--- a/src/connmanmanager.vala
+++ b/src/connmanmanager.vala
@@ -2,6 +2,7 @@
 interface ConnmanManager : Object {
   public abstract string get_state() throws IOError;
   public abstract Service[] get_services() throws IOError;
+  public abstract GLib.HashTable<string, Variant> get_properties() throws IOError;
 }
 
 public struct Service {
@@ -15,22 +16,26 @@ void main () {
 
   try {
     connmanManager = Bus.get_proxy_sync (BusType.SYSTEM, "net.connman", "/");
+    stdout.printf( "System state:\n" );
     string state = get_state();
     stdout.printf(state +"\n");
   } catch (IOError e) {
     stderr.printf (e.message +"\n");
   }
-
+  stdout.printf( "Available Services:\n");
   foreach (Service service in get_services()) {
     stdout.printf(print_service(service));
   }
+  stdout.printf( "System Properties:\n");
+  GLib.HashTable<string,Variant> SystemProperties = get_properties();
+  stdout.printf( print_system_properties(SystemProperties) );
 }
 
 public static string get_state() {
   try {
     return connmanManager.get_state();
   } catch (IOError e) {
-    stderr.printf (e.message +"\n");
+    stderr.printf (e.message + "\n");
     return e.message;
   }
 }
@@ -39,11 +44,20 @@ public static Service[] get_services() {
   try {
     return connmanManager.get_services();
   } catch (IOError e) {
-    stderr.printf (e.message +"\n");
+    stderr.printf (e.message + "\n");
     return new Service[0];
   }
 }
 
+public static GLib.HashTable<string, Variant> get_properties() {
+  try {
+    return connmanManager.get_properties();
+  } catch ( IOError e ) {
+    stderr.printf ( e.message + "\n" );
+    return new GLib.HashTable<string, Variant>( GLib.str_hash, GLib.str_equal );
+  }
+}
+
 public string print_service(Service service) {
   StringBuilder result = new StringBuilder();
   result.append("ServicePath: " + service.ServicePath.to_string() + "\n");
@@ -56,3 +70,14 @@ public string print_service(Service service) {
   }
   return result.str;
 }
+
+public string print_system_properties (GLib.HashTable<string,Variant> systemProperties) {
+  StringBuilder result = new StringBuilder();
+  HashTableIter<string, Variant> systemPropertiesIter = HashTableIter<string, Variant> (systemProperties);
+  string hash_key;
+  GLib.Variant hash_value;
+  while (systemPropertiesIter.next(out hash_key, out hash_value)) {
+    result.append(hash_key.to_string() + " : " + hash_value.print(false) + "\n" );
+  }
+  return result.str;
+}


More information about the Lunar-commits mailing list