[rygel/wip/basic-management: 138/138] core: Style fixes in BasicManagement files



commit 0b763b2728cbce5b814640f122cca57bb5e5bb81
Author: Jussi Kukkonen <jussi kukkonen intel com>
Date:   Mon Sep 9 16:04:24 2013 +0300

    core: Style fixes in BasicManagement files

 .../rygel-basic-management-test-nslookup.vala      |  128 ++++++---------
 .../rygel-basic-management-test-ping.vala          |   77 ++++++---
 .../rygel-basic-management-test-traceroute.vala    |   91 ++++++++---
 src/librygel-core/rygel-basic-management-test.vala |   33 ++--
 src/librygel-core/rygel-basic-management.vala      |  172 ++++++++++----------
 5 files changed, 276 insertions(+), 225 deletions(-)
---
diff --git a/src/librygel-core/rygel-basic-management-test-nslookup.vala 
b/src/librygel-core/rygel-basic-management-test-nslookup.vala
index 6a73575..855852f 100644
--- a/src/librygel-core/rygel-basic-management-test-nslookup.vala
+++ b/src/librygel-core/rygel-basic-management-test-nslookup.vala
@@ -2,7 +2,7 @@
  * Copyright (C) 2013 Intel Corporation.
  *
  * Author: Christophe Guiraud,
- *         Jussi Kukkonen 
+ *         Jussi Kukkonen
  *
  * This file is part of Rygel.
  *
@@ -46,8 +46,8 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         ERROR_DNS_SERVER_NOT_RESOLVED,
         ERROR_INTERNAL,
         ERROR_OTHER;
-        
-        public string to_string() {
+
+        public string to_string () {
             switch (this) {
                 case SUCCESS:
                     return "Success";
@@ -58,7 +58,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
                 case ERROR_OTHER:
                     return "Error_Other";
                 default:
-                    assert_not_reached();
+                    assert_not_reached ();
             }
         }
     }
@@ -70,7 +70,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         ERROR_TIMEOUT,
         ERROR_OTHER;
 
-        public string to_string() {
+        public string to_string () {
             switch (this) {
                 case SUCCESS:
                     return "Success";
@@ -83,7 +83,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
                 case ERROR_OTHER:
                     return "Error_Other";
                 default:
-                    assert_not_reached();
+                    assert_not_reached ();
             }
         }
     }
@@ -93,7 +93,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         AUTHORITATIVE,
         NON_AUTHORITATIVE;
 
-        public string to_string() {
+        public string to_string () {
             switch (this) {
                 case NONE:
                     return "None";
@@ -102,7 +102,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
                 case NON_AUTHORITATIVE:
                     return "NonAuthoritative";
                 default:
-                    assert_not_reached();
+                    assert_not_reached ();
             }
         }
     }
@@ -133,8 +133,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
             return builder.str;
         }
 
-        public string to_xml_fragment() {
-            /* TODO limit the returned values */
+        public string to_xml_fragment () {
             return ("<Result>\n" +
                     "<Status>%s</Status>\n" +
                     "<AnswerType>%s</AnswerType>\n" +
@@ -142,12 +141,12 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
                     "<IPAddresses>%s</IPAddresses>\n" +
                     "<DNSServerIP>%s</DNSServerIP>\n" +
                     "<ResponseTime>%u</ResponseTime>\n" +
-                    "</Result>\n").printf (this.status.to_string(),
-                                           this.answer_type.to_string(),
+                    "</Result>\n").printf (this.status.to_string (),
+                                           this.answer_type.to_string (),
                                            this.returned_host_name,
                                            this.get_addresses_csv (),
                                            this.name_server_address,
-                                           this.execution_time); 
+                                           this.execution_time);
         }
     }
 
@@ -173,6 +172,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
             if (this.iterations == 0)
                 this.iterations = DEFAULT_REPETITIONS;
         }
+
         private get {
             return this.iterations;
         }
@@ -184,13 +184,22 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
     private string additional_info;
     private Timer timer = new Timer ();
 
-    public override string method_type { get { return "NSLookup"; } }
-    public override string results_type { get { return "GetNSLookupResult"; } }
+    public override string method_type {
+        get {
+            return "NSLookup";
+        }
+    }
+
+    public override string results_type {
+        get {
+            return "GetNSLookupResult";
+        }
+    }
 
-    public BasicManagementTestNSLookup(string host_name,
-                                       string? name_server,
-                                       uint repetitions,
-                                       uint32 interval_time_out) {
+    public BasicManagementTestNSLookup (string host_name,
+                                        string? name_server,
+                                        uint repetitions,
+                                        uint32 interval_time_out) {
         Object (host_name: host_name,
                 name_server: name_server,
                 repetitions: repetitions,
@@ -207,8 +216,9 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         this.command = { "nslookup",
                          "-timeout=%u".printf (this.interval_time_out/1000),
                          host_name };
-        if (name_server != null && name_server.length > 0)
+        if (name_server != null && name_server.length > 0) {
             this.command += name_server;
+        }
 
         /* Fail early if internal parameter limits are violated */
         if (this.repetitions > MAX_REPETITIONS) {
@@ -248,20 +258,23 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
                 /* quitting early */
                 this.generic_status = GenericStatus.ERROR_INTERNAL;
                 this.additional_info = "Failed to spawn nslookup";
-                this.results[results.length - 1].status = 
+                this.results[results.length - 1].status =
                                         ResultStatus.ERROR_OTHER;
+
                 break;
             case InitState.INVALID_PARAMETER:
                 /* quitting early */
-                /* constructed() has set info already */
+                /* constructed () has set info already */
                 this.generic_status = GenericStatus.ERROR_OTHER;
-                this.results[results.length - 1].status = 
+                this.results[results.length - 1].status =
                                         ResultStatus.ERROR_OTHER;
+
                 break;
             default:
                 var elapsed_msec = this.timer.elapsed (null) * 1000;
-                var execution_time = (uint)Math.round(elapsed_msec);
-                this.results[results.length - 1].execution_time = execution_time;
+                var exec_time = (uint)Math.round (elapsed_msec);
+                this.results[results.length - 1].execution_time = exec_time;
+
                 break;
         }
 
@@ -285,15 +298,17 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         var result = this.results[results.length - 1];
         line.strip ();
         if (line.has_prefix ("Server:")) {
-            if (result.state != ProcessState.INIT)
+            if (result.state != ProcessState.INIT) {
                 warning ("nslookup parser: Unexpected 'Server:' line.\n");
+            }
             result.state = ProcessState.SERVER;
         } else if (line.has_prefix ("Name:")) {
-            if (result.state == ProcessState.INIT)
+            if (result.state == ProcessState.INIT) {
                 warning ("nslookup parser: Unexpected 'Name:' line");
-            else if (result.state == ProcessState.SERVER)
-                result.returned_host_name =
-                                        line.substring ("Name:".length).strip ();
+            } else if (result.state == ProcessState.SERVER) {
+                var name = line.substring ("Name:".length).strip ();
+                result.returned_host_name = name;
+            }
             result.state = ProcessState.NAME;
         } else if (line.has_prefix ("Address:")) {
             if (result.state == ProcessState.SERVER) {
@@ -305,8 +320,9 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
                 result.status = ResultStatus.SUCCESS;
                 if (result.answer_type == AnswerType.NONE)
                     result.answer_type = AnswerType.AUTHORITATIVE;
-            } else
+            } else {
                 warning ("nslookup parser: Unexpected 'Address:' line");
+            }
         } else if (line.has_prefix ("Non-authoritative answer:")) {
             result.answer_type = AnswerType.NON_AUTHORITATIVE;
         } else if (line.contains ("server can't find")) {
@@ -323,9 +339,10 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         this.results[results.length - 1] = result;
     }
 
-
-    public void get_results(out string status, out string additional_info,
-                            out uint success_count, out string result_string) {
+    public void get_results (out string status,
+                             out string additional_info,
+                             out uint success_count,
+                             out string result_string) {
         success_count = 0;
         StringBuilder builder = new StringBuilder (HEADER);
 
@@ -337,48 +354,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         builder.append (FOOTER);
         result_string = builder.str;
 
-        status = this.generic_status.to_string();
+        status = this.generic_status.to_string ();
         additional_info = this.additional_info;
     }
-
-/*
-    //valac --pkg gio-2.0 --pkg posix -X -lm  rygel-bm-test-nslookup.vala rygel-bm-test.vala
-
-    private static int main(string[] args) {
-        MainLoop loop = new MainLoop();
-        BasicManagementTestNSLookup nslookup = new BasicManagementTestNSLookup ();
-
-        if (args.length < 2) {
-            print ("Usage: %s <hostname> [<nameserver> [<repetitions> [<timeout>]]]\n", args[0]);
-            return 0;
-        }
-        
-        try {
-            nslookup.init (args[1],
-                           args.length > 2 ? args[2] : null,
-                           args.length > 3 ? int.parse (args[3]): 0,
-                           args.length > 4 ? int.parse (args[4]) : 0);
-        } catch (BasicManagementTestError e) {
-            warning ("Incorrect parameters");
-        }
-
-        nslookup.execute.begin((obj, res)=> {
-            try {
-                string status;
-                string info;
-                string results;
-                uint count;
-                nslookup.execute.end(res);
-                nslookup.get_results (out status, out info, out count, out results);
-                print ("\nStatus: %s, %u successful iterations.\nResults:\n%s", status, count, results);
-            } catch (Error e) {
-                print ("Oops: %s\n", e.message);
-            }
-            loop.quit();
-        });
-        loop.run();
-
-        return 0;
-    }
-*/
 }
diff --git a/src/librygel-core/rygel-basic-management-test-ping.vala 
b/src/librygel-core/rygel-basic-management-test-ping.vala
index 8bb7a57..9639e76 100644
--- a/src/librygel-core/rygel-basic-management-test-ping.vala
+++ b/src/librygel-core/rygel-basic-management-test-ping.vala
@@ -49,7 +49,7 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
         ERROR_INTERNAL,
         ERROR_OTHER;
 
-        public string to_string() {
+        public string to_string () {
             switch (this) {
                 case SUCCESS:
                     return "Success";
@@ -60,7 +60,7 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
                 case ERROR_OTHER:
                     return "Error_Other";
                 default:
-                    assert_not_reached();
+                    assert_not_reached ();
             }
         }
     }
@@ -71,10 +71,15 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
     public uint repeat_count {
         construct {
             this._repeat_count = value;
-            if (this._repeat_count == 0)
+            if (this._repeat_count == 0) {
                 this._repeat_count = DEFAULT_REPEAT_COUNT;
+            }
+        }
+
+        get {
+            return this._repeat_count;
         }
-        get { return this._repeat_count; }
+
         default = DEFAULT_REPEAT_COUNT;
     }
 
@@ -82,10 +87,15 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
     public uint data_block_size {
         construct {
             this._data_block_size = value;
-            if (this._data_block_size == 0)
+            if (this._data_block_size == 0) {
                 this._data_block_size = DEFAULT_DATA_BLOCK_SIZE;
+            }
         }
-        get { return this._data_block_size; }
+
+        get {
+            return this._data_block_size;
+        }
+
         default = DEFAULT_DATA_BLOCK_SIZE;
     }
 
@@ -93,10 +103,15 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
     public uint dscp {
         construct {
             this._dscp = value;
-            if (this._dscp == 0)
+            if (this._dscp == 0) {
                 this._dscp = DEFAULT_DSCP;
+            }
+        }
+
+        get {
+            return this._dscp;
         }
-        get { return this._dscp; }
+
         default = DEFAULT_DSCP;
     }
 
@@ -104,10 +119,15 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
     public uint32 interval_time_out {
         construct {
             this._interval_time_out = value;
-            if (this._interval_time_out == 0)
+            if (this._interval_time_out == 0) {
                 this._interval_time_out = DEFAULT_REQUEST_INTERVAL_TIMEOUT;
+            }
         }
-        get { return _interval_time_out; }
+
+        get {
+            return _interval_time_out;
+        }
+
         default = DEFAULT_REQUEST_INTERVAL_TIMEOUT;
     }
 
@@ -121,8 +141,17 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
     private uint32 min_response_time;
     private uint32 max_response_time;
 
-    public override string method_type { get { return "Ping"; } }
-    public override string results_type { get { return "GetPingResult"; } }
+    public override string method_type {
+        get {
+            return "Ping";
+        }
+    }
+
+    public override string results_type {
+        get {
+            return "GetPingResult";
+        }
+    }
 
     public BasicManagementTestPing (string host,
                                     uint repeat_count,
@@ -229,23 +258,25 @@ internal class Rygel.BasicManagementTestPing : BasicManagementTest {
                 if (rtt.length >= 2) {
                     var rtt_values = rtt[1].split ("/", 4);
                     if (rtt_values.length >= 3) {
-                        this.min_response_time = (uint) Math.round (
-                                                  double.parse (rtt_values[0]));
-                        this.avg_response_time = (uint) Math.round (
-                                                  double.parse (rtt_values[1]));
-                        this.max_response_time = (uint) Math.round (
-                                                  double.parse (rtt_values[2]));
+                        this.min_response_time = (uint) Math.round
+                                        (double.parse (rtt_values[0]));
+                        this.avg_response_time = (uint) Math.round
+                                        (double.parse (rtt_values[1]));
+                        this.max_response_time = (uint) Math.round
+                                        (double.parse (rtt_values[2]));
                     }
                 }
             }
         }
     }
 
-    public void get_results(out string status, out string additional_info,
-                            out uint success_count, out uint failure_count,
-                            out uint32 avg_response_time,
-                            out uint32 min_response_time,
-                            out uint32 max_response_time) {
+    public void get_results (out string status,
+                             out string additional_info,
+                             out uint success_count,
+                             out uint failure_count,
+                             out uint32 avg_response_time,
+                             out uint32 min_response_time,
+                             out uint32 max_response_time) {
         status = this.status.to_string ();
         additional_info = this.additional_info;
         success_count = this.success_count;
diff --git a/src/librygel-core/rygel-basic-management-test-traceroute.vala 
b/src/librygel-core/rygel-basic-management-test-traceroute.vala
index d2a8b73..6dd1227 100644
--- a/src/librygel-core/rygel-basic-management-test-traceroute.vala
+++ b/src/librygel-core/rygel-basic-management-test-traceroute.vala
@@ -50,7 +50,7 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
         ERROR_INTERNAL,
         ERROR_OTHER;
 
-        public string to_string() {
+        public string to_string () {
             switch (this) {
                 case SUCCESS:
                     return "Success";
@@ -63,7 +63,7 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
                 case ERROR_OTHER:
                     return "Error_Other";
                 default:
-                    assert_not_reached();
+                    assert_not_reached ();
             }
         }
     }
@@ -74,10 +74,15 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
     public uint32 wait_time_out {
         construct {
             this._wait_time_out = value;
-            if (this._wait_time_out == 0)
+            if (this._wait_time_out == 0) {
                 this._wait_time_out = DEFAULT_TIMEOUT;
+            }
+        }
+
+        get {
+            return this._wait_time_out;
         }
-        get { return this._wait_time_out; }
+
         default = DEFAULT_TIMEOUT;
     }
 
@@ -85,10 +90,15 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
     public uint data_block_size {
         construct {
             this._data_block_size = value;
-            if (this._data_block_size == 0)
+            if (this._data_block_size == 0) {
                 this._data_block_size = DEFAULT_DATA_BLOCK_SIZE;
+            }
+        }
+
+        get {
+            return this._data_block_size;
         }
-        get { return this._data_block_size; }
+
         default = DEFAULT_DATA_BLOCK_SIZE;
     }
 
@@ -96,10 +106,15 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
     public uint max_hop_count {
         construct {
             this._max_hop_count = value;
-            if (this._max_hop_count == 0)
+            if (this._max_hop_count == 0) {
                 this._max_hop_count = DEFAULT_HOPS;
+            }
+        }
+
+        get {
+            return this._max_hop_count;
         }
-        get { return this._max_hop_count; }
+
         default = DEFAULT_HOPS;
     }
 
@@ -107,10 +122,15 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
     public uint dscp {
         construct {
             this._dscp = value;
-            if (this._dscp == 0)
+            if (this._dscp == 0) {
                 this._dscp = DEFAULT_DSCP;
+            }
+        }
+
+        get {
+            return this._dscp;
         }
-        get { return this._dscp; }
+
         default = DEFAULT_DSCP;
     }
 
@@ -124,8 +144,17 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
     private uint32 response_time;
     private string hop_ips;
 
-    public override string method_type { get { return "Traceroute"; } }
-    public override string results_type { get { return "GetTracerouteResult"; } }
+    public override string method_type {
+        get {
+            return "Traceroute";
+        }
+    }
+
+    public override string results_type {
+        get {
+            return "GetTracerouteResult";
+        }
+    }
 
     public BasicManagementTestTraceroute (string host,
                                           uint32 wait_time_out,
@@ -160,7 +189,7 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
                          "-t", (this.dscp >> 2).to_string (),
                          "-n",
                          this.host,
-                         this.data_block_size.to_string () };   
+                         this.data_block_size.to_string () };
 
         /* Fail early if internal parameter limits are violated */
         if (this.wait_time_out < MIN_TIMEOUT ||
@@ -219,34 +248,37 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
                 this.state = ProcessState.HOPS;
                 var start = line.index_of_char ('(');
                 var end = line.index_of_char (')', start);
-                if (end > start)
+                if (end > start) {
                     this.host_ip = line.slice (start + 1, end);
+                }
             } else {
                 warning ("traceroute parser: Unexpected line '%s'", line);
             }
             break;
         case ProcessState.HOPS:
-            if (line.contains (" !H "))
+            if (line.contains (" !H ")) {
                 error = "Host is unreachable.";
-            else if (line.contains (" !N "))
+            } else if (line.contains (" !N ")) {
                 error = "Network is unreachable.";
-            else if (line.contains (" !P "))
+            } else if (line.contains (" !P ")) {
                 error = "Protocol is unreachable.";
-            else if (line.contains (" !S "))
+            } else if (line.contains (" !S ")) {
                 error = "Source route failed.";
-            else if (line.contains (" !F "))
+            } else if (line.contains (" !F ")) {
                 error = "Fragmentation needed.";
-            else if (line.contains (" !X "))
+            } else if (line.contains (" !X ")) {
                 error = "Network blocks traceroute.";
+            }
 
             if (error != null) {
-                /* should ERROR_CANNOT_RESOLVE_HOSTNAME be used for some errors ? */
                 this.set_error (Status.ERROR_OTHER, error);
+
                 return;
             }
             MatchInfo info;
             if (!regex.match (line, 0, out info)) {
                 warning ("traceroute parser: Unexpected line '%s'", line);
+
                 return;
             }
 
@@ -256,13 +288,14 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
                     this.status = Status.SUCCESS;
                 } else {
                     /* set this error as placeholder: normally a later
-                     * handle_output() call will set status to SUCCESS */
+                     * handle_output () call will set status to SUCCESS */
                     this.status = Status.ERROR_MAX_HOP_COUNT_EXCEEDED;
                 }
             }
 
-            if (ip_address == "*")
+            if (ip_address == "*") {
                 ip_address = "";
+            }
 
             var rtt_string = info.fetch (3);
             rtt_regex.match (rtt_string, 0, out info);
@@ -278,12 +311,14 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
                 warning ("Regex error while parsing rtt values: %s", e.message);
             }
 
-            if (rtt_count > 0)
+            if (rtt_count > 0) {
                 rtt_average = rtt_average / rtt_count;
+            }
 
             this.response_time = (uint) Math.round (rtt_average);
-            if (this.hop_ips.length != 0)
+            if (this.hop_ips.length != 0) {
                 this.hop_ips += ",";
+            }
             this.hop_ips += ip_address;
 
             break;
@@ -291,8 +326,10 @@ internal class Rygel.BasicManagementTestTraceroute : BasicManagementTest {
             assert_not_reached ();
         }
     }
-    public void get_results(out string status, out string additional_info,
-                            out uint32 response_time, out string hop_ips) {
+    public void get_results (out string status,
+                             out string additional_info,
+                             out uint32 response_time,
+                             out string hop_ips) {
         status = this.status.to_string ();
         additional_info = this.additional_info;
         response_time = this.response_time;
diff --git a/src/librygel-core/rygel-basic-management-test.vala 
b/src/librygel-core/rygel-basic-management-test.vala
index 83414b7..316a804 100644
--- a/src/librygel-core/rygel-basic-management-test.vala
+++ b/src/librygel-core/rygel-basic-management-test.vala
@@ -23,7 +23,6 @@
 
 using GLib;
 
-
 internal errordomain Rygel.BasicManagementTestError {
     NOT_POSSIBLE
 }
@@ -43,7 +42,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
         CANCELED;
 
         /* Return values fit for A_ARG_TYPE_TestState */
-        public string to_string () { 
+        public string to_string () {
             switch (this) {
                 case REQUESTED:
                     return "Requested";
@@ -61,7 +60,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
 
     public ExecutionState execution_state {
         get;
-        protected set; 
+        protected set;
         default = ExecutionState.REQUESTED;
     }
     public string id;
@@ -115,7 +114,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
             this.run_iteration ();
         }
     }
-        
+
     private void child_setup () {
         /* try to prevent possible changes in output */
         Environment.set_variable("LC_MESSAGES", "C", true);
@@ -132,6 +131,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
         /*if we failed to initialize, skip spawning */
         if (this.init_state != InitState.OK) {
             Idle.add ((SourceFunc)this.finish_iteration);
+
             return;
         }
 
@@ -156,7 +156,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
             err_channel.add_watch (IOCondition.OUT | IOCondition.HUP,
                                    this.err_watch);
         } catch (SpawnError e) {
-            /* Let the async function yeild, then let the Test 
+            /* Let the async function yeild, then let the Test
              * implementation handle this in finish_iteration */
             this.init_state = InitState.SPAWN_FAILED;
             Idle.add ((SourceFunc)this.finish_iteration);
@@ -167,8 +167,9 @@ internal abstract class Rygel.BasicManagementTest : Object {
         try {
             string line;
             IOStatus status = channel.read_line (out line, null, null);
-            if (line != null)
+            if (line != null) {
                 this.handle_output (line);
+            }
 
             if (status == IOStatus.EOF) {
                 this.eof_count++;
@@ -178,8 +179,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
                 return false;
             }
         } catch (Error e) {
-            warning ("Failed readline() from nslookup stdout: %s", e.message);
-            /* TODO set execution_state ? */
+            warning ("Failed readline() from stdout: %s", e.message);
             this.finish_iteration();
 
             return false;
@@ -192,19 +192,20 @@ internal abstract class Rygel.BasicManagementTest : Object {
         try {
             string line;
             IOStatus status = channel.read_line (out line, null, null);
-            if (line != null)
+            if (line != null) {
                 this.handle_error (line);
+            }
 
             if (status == IOStatus.EOF) {
                 this.eof_count++;
-                if (this.eof_count > 1)
+                if (this.eof_count > 1) {
                     this.finish_iteration ();
+                }
 
                 return false;
             }
         } catch (Error e) {
-            warning ("Failed readline() from nslookup stderr: %s", e.message);
-            /* TODO set execution_state ? */
+            warning ("Failed readline() from stderr: %s", e.message);
             this.finish_iteration();
 
             return false;
@@ -219,9 +220,10 @@ internal abstract class Rygel.BasicManagementTest : Object {
     }
 
     public async virtual void execute () throws BasicManagementTestError {
-        if (this.execution_state != ExecutionState.REQUESTED)
+        if (this.execution_state != ExecutionState.REQUESTED) {
             throw new BasicManagementTestError.NOT_POSSIBLE
-                                                ("Already executing or executed");
+                                        ("Already executing or executed");
+        }
 
         this.execution_state = ExecutionState.IN_PROGRESS;
         this.current_iteration = 0;
@@ -234,8 +236,9 @@ internal abstract class Rygel.BasicManagementTest : Object {
     }
 
     public void cancel () throws BasicManagementTestError {
-        if (this.execution_state != ExecutionState.IN_PROGRESS)
+        if (this.execution_state != ExecutionState.IN_PROGRESS) {
             throw new BasicManagementTestError.NOT_POSSIBLE ("Not executing");
+        }
 
         Posix.killpg (this.child_pid, Posix.SIGTERM);
 
diff --git a/src/librygel-core/rygel-basic-management.vala b/src/librygel-core/rygel-basic-management.vala
index 74e33db..d60d49d 100644
--- a/src/librygel-core/rygel-basic-management.vala
+++ b/src/librygel-core/rygel-basic-management.vala
@@ -30,11 +30,10 @@ using GUPnP;
  */
 public class Rygel.BasicManagement : Service {
     public const string UPNP_ID = "urn:upnp-org:serviceId:BasicManagement";
-    public const string UPNP_TYPE =
-                        "urn:schemas-upnp-org:service:BasicManagement:2";
+    public const string UPNP_TYPE = "urn:schemas-upnp-org:service:BasicManagement:2";
     public const string DESCRIPTION_PATH = "xml/BasicManagement2.xml";
 
-    public uint max_history_size { get; set; default = 10;}
+    public uint max_history_size { get; set; default = 10; }
 
     private HashMap<string, BasicManagementTest> tests_map;
     private HashMap<string, LinkedList<string>> test_ids_by_type;
@@ -55,44 +54,38 @@ public class Rygel.BasicManagement : Service {
 
         this.query_variable["DeviceStatus"].connect
                                         (this.query_device_status_cb);
-        this.query_variable["TestIDs"].connect
-                                        (this.query_test_ids_cb);
+        this.query_variable["TestIDs"].connect (this.query_test_ids_cb);
         this.query_variable["ActiveTestIDs"].connect
                                         (this.query_active_test_ids_cb);
 
         this.action_invoked["GetDeviceStatus"].connect
                                         (this.get_device_status_cb);
-        this.action_invoked["Ping"].connect
-                                        (this.ping_cb);
-        this.action_invoked["GetPingResult"].connect
-                                        (this.ping_result_cb);
-        this.action_invoked["NSLookup"].connect
-                                        (this.nslookup_cb);
+        this.action_invoked["Ping"].connect (this.ping_cb);
+        this.action_invoked["GetPingResult"].connect (this.ping_result_cb);
+        this.action_invoked["NSLookup"].connect (this.nslookup_cb);
         this.action_invoked["GetNSLookupResult"].connect
                                         (this.nslookup_result_cb);
-        this.action_invoked["Traceroute"].connect
-                                        (this.traceroute_cb);
+        this.action_invoked["Traceroute"].connect (this.traceroute_cb);
         this.action_invoked["GetTracerouteResult"].connect
                                         (this.traceroute_result_cb);
-        this.action_invoked["GetTestIDs"].connect
-                                        (this.get_test_ids_cb);
+        this.action_invoked["GetTestIDs"].connect (this.get_test_ids_cb);
         this.action_invoked["GetActiveTestIDs"].connect
                                         (this.get_active_test_ids_cb);
-        this.action_invoked["GetTestInfo"].connect
-                                        (this.get_test_info_cb);
-        this.action_invoked["CancelTest"].connect
-                                        (this.cancel_test_cb);
+        this.action_invoked["GetTestInfo"].connect (this.get_test_info_cb);
+        this.action_invoked["CancelTest"].connect (this.cancel_test_cb);
     }
 
     private string create_test_ids_list (bool active_only) {
         string test_ids_list = "";
 
         foreach (var test in this.tests_map.values) {
-            if (active_only && !test.is_active())
+            if (active_only && !test.is_active ()) {
                 continue;
+            }
 
-            if (test_ids_list.length > 0)
+            if (test_ids_list.length > 0) {
                 test_ids_list += ",";
+            }
 
             test_ids_list += test.id;
         }
@@ -106,8 +99,10 @@ public class Rygel.BasicManagement : Service {
 
         this.tests_map.set (test.id, test);
 
-        /* Add test to a list of ids of that method type (creating the list if needed) */
-        LinkedList<string> type_test_ids = this.test_ids_by_type[test.method_type];
+        /* Add test to a list of ids of that method type
+           (creating the list if needed) */
+        LinkedList<string> type_test_ids;
+        type_test_ids = this.test_ids_by_type[test.method_type];
         if (type_test_ids == null) {
             type_test_ids = new LinkedList<string> ();
             this.test_ids_by_type.set (test.method_type, type_test_ids);
@@ -119,22 +114,23 @@ public class Rygel.BasicManagement : Service {
             var old_id = type_test_ids.poll_head ();
 
             try {
-                this.tests_map[old_id].cancel();
+                this.tests_map[old_id].cancel ();
             } catch (BasicManagementTestError e) {
                 /* test was not running, not a problem */
             }
             this.tests_map.unset (old_id);
         }
 
-        this.notify ("TestIDs", typeof (string),
-                     create_test_ids_list (false));
-        this.notify ("ActiveTestIDs", typeof (string),
+        this.notify ("TestIDs", typeof (string), create_test_ids_list (false));
+        this.notify ("ActiveTestIDs",
+                     typeof (string),
                      create_test_ids_list (true));
+
         return test.id;
     }
 
     private void add_test_and_return_action (BasicManagementTest bm_test,
-                                             ServiceAction action) {
+                                             ServiceAction       action) {
         var id = this.add_test (bm_test);
 
         /* TODO: decide if test should really execute now */
@@ -144,18 +140,18 @@ public class Rygel.BasicManagement : Service {
             } catch (BasicManagementTestError e) {
                 /* already executing */
             }
-            this.notify ("ActiveTestIDs", typeof (string),
+
+            this.notify ("ActiveTestIDs",
+                         typeof (string),
                          create_test_ids_list (true));
         });
 
-        action.set ("TestID",
-                        typeof (string),
-                        id);
+        action.set ("TestID", typeof (string), id);
 
         action.return ();
     }
 
-    private bool ensure_test_exists (ServiceAction action,
+    private bool ensure_test_exists (ServiceAction           action,
                                      out BasicManagementTest bm_test) {
 
         string test_id;
@@ -163,30 +159,31 @@ public class Rygel.BasicManagement : Service {
         action.get ("TestID", typeof (string), out test_id);
 
         bm_test = this.tests_map[test_id];
+        var action_name = action.get_name ();
 
         if (bm_test == null) {
             /// No test with the specified TestID was found
             action.return_error (706, _("No Such Test"));
 
             return false;
-        } else if ((bm_test.results_type != action.get_name()) &&
-                   ((action.get_name() == "GetPingResult") ||
-                    (action.get_name() == "GetNSLookupResult") ||
-                    (action.get_name() == "GetTracerouteResult"))) {
+        } else if ((bm_test.results_type != action_name) &&
+                   ((action_name == "GetPingResult") ||
+                    (action_name == "GetNSLookupResult") ||
+                    (action_name == "GetTracerouteResult"))) {
             /// TestID is valid but refers to the wrong test type
             action.return_error (707, _("Wrong Test Type"));
 
             return false;
         } else if ((bm_test.execution_state != BasicManagementTest.ExecutionState.COMPLETED) &&
-                   ((action.get_name() == "GetPingResult") ||
-                    (action.get_name() == "GetNSLookupResult") ||
-                    (action.get_name() == "GetTracerouteResult"))) {
+                   ((action_name == "GetPingResult") ||
+                    (action_name == "GetNSLookupResult") ||
+                    (action_name == "GetTracerouteResult"))) {
             /// TestID is valid but the test Results are not available
             action.return_error (708, _("Invalid Test State '%s'").printf (
-                                        bm_test.execution_state.to_string()));
+                                        bm_test.execution_state.to_string ()));
 
             return false;
-        } else if ((action.get_name() == "CancelTest") && !bm_test.is_active()) {
+        } else if ((action_name == "CancelTest") && !bm_test.is_active ()) {
             /// TestID is valid but the test can't be canceled
             action.return_error (709, _("State '%s' Precludes Cancel").printf (
                                         bm_test.execution_state.to_string ()));
@@ -197,28 +194,28 @@ public class Rygel.BasicManagement : Service {
         return true;
     }
 
-    private void query_device_status_cb (Service   cm,
+    private void query_device_status_cb (Service   bm,
                                          string    var,
                                          ref Value val) {
         val.init (typeof (string));
         val.set_string (device_status);
     }
 
-    private void query_test_ids_cb (Service   cm,
+    private void query_test_ids_cb (Service   bm,
                                     string    var,
                                     ref Value val) {
         val.init (typeof (string));
         val.set_string (create_test_ids_list (false));
     }
 
-    private void query_active_test_ids_cb (Service   cm,
+    private void query_active_test_ids_cb (Service   bm,
                                            string    var,
                                            ref Value val) {
         val.init (typeof (string));
         val.set_string (create_test_ids_list (true));
     }
 
-    private void get_device_status_cb (Service             cm,
+    private void get_device_status_cb (Service       bm,
                                        ServiceAction action) {
         if (action.get_argument_count () != 0) {
             action.return_error (402, _("Invalid argument"));
@@ -233,7 +230,7 @@ public class Rygel.BasicManagement : Service {
         action.return ();
     }
 
-    private void ping_cb (Service             cm,
+    private void ping_cb (Service       bm,
                           ServiceAction action) {
         if (action.get_argument_count () != 5) {
             action.return_error (402, _("Invalid argument"));
@@ -261,13 +258,15 @@ public class Rygel.BasicManagement : Service {
                         typeof (uint),
                         out dscp);
 
-        var ping = new BasicManagementTestPing(host, repeat_count,
-                                               interval_time_out,
-                                               data_block_size, dscp);
+        var ping = new BasicManagementTestPing (host,
+                                                repeat_count,
+                                                interval_time_out,
+                                                data_block_size,
+                                                dscp);
         this.add_test_and_return_action (ping as BasicManagementTest, action);
     }
 
-    private void ping_result_cb (Service             cm,
+    private void ping_result_cb (Service       bm,
                                  ServiceAction action) {
         if (action.get_argument_count () != 1) {
             action.return_error (402, _("Invalid argument"));
@@ -285,13 +284,14 @@ public class Rygel.BasicManagement : Service {
         uint success_count, failure_count;
         uint32 avg_response_time, min_response_time, max_response_time;
 
-        (bm_test as BasicManagementTestPing).get_results (out status,
-                                             out additional_info,
-                                             out success_count,
-                                             out failure_count,
-                                             out avg_response_time,
-                                             out min_response_time,
-                                             out max_response_time);
+        (bm_test as BasicManagementTestPing).get_results
+                                        (out status,
+                                         out additional_info,
+                                         out success_count,
+                                         out failure_count,
+                                         out avg_response_time,
+                                         out min_response_time,
+                                         out max_response_time);
 
         action.set ("Status",
                         typeof (string),
@@ -318,7 +318,7 @@ public class Rygel.BasicManagement : Service {
         action.return ();
     }
 
-    private void nslookup_cb (Service             cm,
+    private void nslookup_cb (Service       bm,
                               ServiceAction action) {
         if (action.get_argument_count () != 4) {
             action.return_error (402, _("Invalid argument"));
@@ -344,15 +344,15 @@ public class Rygel.BasicManagement : Service {
                         typeof (uint32),
                         out interval_time_out);
 
-        var nslookup = new BasicManagementTestNSLookup(hostname,
-                                                       dns_server,
-                                                       repeat_count,
-                                                       interval_time_out);
+        var nslookup = new BasicManagementTestNSLookup (hostname,
+                                                        dns_server,
+                                                        repeat_count,
+                                                        interval_time_out);
         this.add_test_and_return_action (nslookup as BasicManagementTest,
                                          action);
     }
 
-    private void nslookup_result_cb (Service             cm,
+    private void nslookup_result_cb (Service       bm,
                                      ServiceAction action) {
         if (action.get_argument_count () != 1) {
             action.return_error (402, _("Invalid argument"));
@@ -369,10 +369,11 @@ public class Rygel.BasicManagement : Service {
         string status, additional_info, result;
         uint success_count;
 
-        (bm_test as BasicManagementTestNSLookup).get_results (out status,
-                                                 out additional_info,
-                                                 out success_count,
-                                                 out result);
+        (bm_test as BasicManagementTestNSLookup).get_results
+                                        (out status,
+                                         out additional_info,
+                                         out success_count,
+                                         out result);
 
         action.set ("Status",
                         typeof (string),
@@ -390,7 +391,7 @@ public class Rygel.BasicManagement : Service {
         action.return ();
     }
 
-    private void traceroute_cb (Service             cm,
+    private void traceroute_cb (Service       bm,
                                 ServiceAction action) {
         if (action.get_argument_count () != 5) {
             action.return_error (402, _("Invalid argument"));
@@ -418,14 +419,16 @@ public class Rygel.BasicManagement : Service {
                         typeof (uint),
                         out dscp);
 
-        var traceroute = new BasicManagementTestTraceroute(host, wait_time_out,
-                                                           data_block_size,
-                                                           max_hop_count, dscp);
+        var traceroute = new BasicManagementTestTraceroute (host,
+                                                            wait_time_out,
+                                                            data_block_size,
+                                                            max_hop_count,
+                                                            dscp);
         this.add_test_and_return_action (traceroute as BasicManagementTest,
                                          action);
     }
 
-    private void traceroute_result_cb (Service             cm,
+    private void traceroute_result_cb (Service       bm,
                                        ServiceAction action) {
         if (action.get_argument_count () != 1) {
             action.return_error (402, _("Invalid argument"));
@@ -442,10 +445,11 @@ public class Rygel.BasicManagement : Service {
         string status, additional_info, hop_hosts;
         uint32 response_time;
 
-        (bm_test as BasicManagementTestTraceroute).get_results (out status,
-                                                   out additional_info,
-                                                   out response_time,
-                                                   out hop_hosts);
+        (bm_test as BasicManagementTestTraceroute).get_results
+                                        (out status,
+                                         out additional_info,
+                                         out response_time,
+                                         out hop_hosts);
 
         action.set ("Status",
                         typeof (string),
@@ -463,7 +467,7 @@ public class Rygel.BasicManagement : Service {
         action.return ();
     }
 
-    private void get_test_ids_cb (Service             cm,
+    private void get_test_ids_cb (Service       bm,
                                   ServiceAction action) {
         if (action.get_argument_count () != 0) {
             action.return_error (402, _("Invalid argument"));
@@ -478,7 +482,7 @@ public class Rygel.BasicManagement : Service {
         action.return ();
     }
 
-    private void get_active_test_ids_cb (Service             cm,
+    private void get_active_test_ids_cb (Service       bm,
                                          ServiceAction action) {
         if (action.get_argument_count () != 0) {
             action.return_error (402, _("Invalid argument"));
@@ -493,7 +497,7 @@ public class Rygel.BasicManagement : Service {
         action.return ();
     }
 
-    private void get_test_info_cb (Service             cm,
+    private void get_test_info_cb (Service       bm,
                                    ServiceAction action) {
         if (action.get_argument_count () != 1) {
             action.return_error (402, _("Invalid argument"));
@@ -512,12 +516,12 @@ public class Rygel.BasicManagement : Service {
                         bm_test.method_type,
                     "State",
                         typeof (string),
-                        bm_test.execution_state.to_string());
+                        bm_test.execution_state.to_string ());
 
         action.return ();
     }
 
-    private void cancel_test_cb (Service             cm,
+    private void cancel_test_cb (Service       bm,
                                  ServiceAction action) {
         if (action.get_argument_count () != 1) {
             action.return_error (402, _("Invalid argument"));
@@ -532,11 +536,11 @@ public class Rygel.BasicManagement : Service {
         }
 
         try {
-            bm_test.cancel();
+            bm_test.cancel ();
         } catch (BasicManagementTestError e) {
             warning ("Canceled test was not running\n");
         }
-        /* ActiveTestIDs notification is handled by 
+        /* ActiveTestIDs notification is handled by
          * the tests' execute callback */
 
         action.return ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]