[rygel/wip/basic-management: 120/138] core: Use rygel coding style in BasicManagement



commit f34ab5da11c517a80020858af822e4b779815a39
Author: Jussi Kukkonen <jussi kukkonen intel com>
Date:   Mon Jun 3 10:16:48 2013 +0300

    core: Use rygel coding style in BasicManagement
    
    * Use 'this' to refer to object variables
    * line length
    * empty lines before break/return/etc.

 .../rygel-basic-management-test-nslookup.vala      |   63 ++++++++++---------
 src/librygel-core/rygel-basic-management-test.vala |   64 ++++++++++---------
 2 files changed, 68 insertions(+), 59 deletions(-)
---
diff --git a/src/librygel-core/rygel-basic-management-test-nslookup.vala 
b/src/librygel-core/rygel-basic-management-test-nslookup.vala
index c09fa61..b92650b 100644
--- a/src/librygel-core/rygel-basic-management-test-nslookup.vala
+++ b/src/librygel-core/rygel-basic-management-test-nslookup.vala
@@ -124,17 +124,17 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
 
         private string get_addresses_csv () {
             var builder = new StringBuilder ("");
-            foreach (var address in addresses) {
+            foreach (var address in this.addresses) {
                 if (builder.len != 0)
                     builder.append (",");
                 builder.append (address);
             }
+
             return builder.str;
         }
 
         public string to_xml_fragment() {
             /* TODO limit the returned values */
-
             return ("<Result>\n" +
                     "<Status>%s</Status>\n" +
                     "<AnswerType>%s</AnswerType>\n" +
@@ -161,9 +161,9 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
 
     public void init(string host_name, string? name_server, uint repetitions,
                      uint32 interval_time_out) throws BasicManagementTestError {
-        command = { "nslookup" };
-        generic_status = GenericStatus.ERROR_INTERNAL;
-        results = {};
+        this.command = { "nslookup" };
+        this.generic_status = GenericStatus.ERROR_INTERNAL;
+        this.results = {};
 
         /* TODO should invalid values fail now instead of just limit ? */
         repetitions = uint.max (1, repetitions);
@@ -171,15 +171,15 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
 
         interval_time_out = uint.max (MIN_INTERVAL_TIMEOUT, interval_time_out);
         interval_time_out = uint.min (interval_time_out, MAX_INTERVAL_TIMEOUT);
-        command += ("-timeout=%u").printf (interval_time_out/1000);
+        this.command += ("-timeout=%u").printf (interval_time_out/1000);
 
         if (host_name == null || host_name.length < 1)
             throw new BasicManagementTestError.INIT_FAILED
                                                 ("Host name is required");
-        command += host_name;
+        this.command += host_name;
 
         if (name_server != null && name_server.length > 0)
-            command += name_server;
+            this.command += name_server;
 
     }
 
@@ -194,21 +194,25 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
             answer_type = AnswerType.NONE,
             execution_time = 0
         };
-        results += result;
+        this.results += result;
 
-        timer.start ();
+        this.timer.start ();
     }
 
     protected override void finish_iteration () {
         switch (this.execution_state) {
             case ExecutionState.SPAWN_FAILED:
-                generic_status = GenericStatus.ERROR_INTERNAL;
-                additional_info = "Failed spawn nslookup";
-                results[results.length - 1].status = ResultStatus.ERROR_OTHER;
+                this.generic_status = GenericStatus.ERROR_INTERNAL;
+                this.additional_info = "Failed spawn nslookup";
+                this.results[results.length - 1].status = 
+                                        ResultStatus.ERROR_OTHER;
+
                 break;
             default:
-                var execution_time = (uint)Math.round(timer.elapsed (null) * 1000);
-                results[results.length - 1].execution_time = execution_time;
+                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;
+
                 break;
         }
 
@@ -216,21 +220,21 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
     }
 
     protected override void handle_error (string line) {
-        var result = results[results.length - 1];
+        var result = this.results[results.length - 1];
 
         if (line.contains ("couldn't get address for")) {
-            generic_status = GenericStatus.ERROR_DNS_SERVER_NOT_RESOLVED;
-            result.status = ResultStatus.ERROR_DNS_SERVER_NOT_AVAILABLE;
+            this.generic_status = GenericStatus.ERROR_DNS_SERVER_NOT_RESOLVED;
             this.execution_state = ExecutionState.COMPLETED;
+            result.status = ResultStatus.ERROR_DNS_SERVER_NOT_AVAILABLE;
         }
 
         /* there has to be a nicer way to do this... */
-        results[results.length - 1] = result;
+        this.results[results.length - 1] = result;
     }
 
     protected override void handle_output (string line) {
-        var result = results[results.length - 1];
-        line.strip();
+        var result = this.results[results.length - 1];
+        line.strip ();
         if (line.has_prefix ("Server:")) {
             if (result.state != ProcessState.INIT)
                 warning ("nslookup parser: Unexpected 'Server:' line.\n");
@@ -239,15 +243,16 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
             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(); 
+                result.returned_host_name =
+                                        line.substring ("Name:".length).strip ();
             result.state = ProcessState.NAME;
         } else if (line.has_prefix ("Address:")) {
             if (result.state == ProcessState.SERVER) {
-                var address = line.substring ("Address:".length).strip();
+                var address = line.substring ("Address:".length).strip ();
                 result.name_server_address = address.split ("#", 2)[0];
-                generic_status = GenericStatus.SUCCESS;
+                this.generic_status = GenericStatus.SUCCESS;
             } else if (result.state == ProcessState.NAME) {
-                result.addresses += line.substring ("Address:".length).strip();
+                result.addresses += line.substring ("Address:".length).strip ();
                 result.status = ResultStatus.SUCCESS;
                 if (result.answer_type == AnswerType.NONE)
                     result.answer_type = AnswerType.AUTHORITATIVE;
@@ -258,7 +263,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         } else if (line.contains ("server can't find")) {
             result.status = ResultStatus.ERROR_HOSTNAME_NOT_RESOLVED;
         } else if (line.contains ("couldn't get address for")) {
-            generic_status = GenericStatus.ERROR_DNS_SERVER_NOT_RESOLVED;
+            this.generic_status = GenericStatus.ERROR_DNS_SERVER_NOT_RESOLVED;
             result.status = ResultStatus.ERROR_DNS_SERVER_NOT_AVAILABLE;
             this.execution_state = ExecutionState.COMPLETED;
         } else if (line.contains ("no servers could be reached")) {
@@ -266,7 +271,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         }
 
         /* there has to be a nicer way to do this... */
-        results[results.length - 1] = result;
+        this.results[results.length - 1] = result;
     }
 
 
@@ -275,7 +280,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         success_count = 0;
         StringBuilder builder = new StringBuilder (HEADER);
 
-        foreach (var result in results) {
+        foreach (var result in this.results) {
             builder.append (result.to_xml_fragment ());
             if (result.status == ResultStatus.SUCCESS)
                 success_count++;
@@ -283,7 +288,7 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         builder.append (FOOTER);
         result_string = builder.str;
 
-        status = generic_status.to_string();
+        status = this.generic_status.to_string();
         additional_info = "";
     }
 /*
diff --git a/src/librygel-core/rygel-basic-management-test.vala 
b/src/librygel-core/rygel-basic-management-test.vala
index 6d7287b..bcde4d5 100644
--- a/src/librygel-core/rygel-basic-management-test.vala
+++ b/src/librygel-core/rygel-basic-management-test.vala
@@ -89,14 +89,14 @@ internal abstract class Rygel.BasicManagementTest : Object {
         warning ("%s stderr: %s", command[0], line);
     }
     protected virtual void finish_iteration () {
-        iteration++;
+        this.iteration++;
         if (this.execution_state != ExecutionState.IN_PROGRESS) {
-            async_callback ();
-        } else if (iteration >= repetitions) {
+            this.async_callback ();
+        } else if (this.iteration >= this.repetitions) {
             this.execution_state = ExecutionState.COMPLETED;
-            async_callback ();
+            this.async_callback ();
         } else {
-            run_iteration ();
+            this.run_iteration ();
         }
     }
         
@@ -112,29 +112,29 @@ internal abstract class Rygel.BasicManagementTest : Object {
 
     private void run_iteration () {
         try {
-            init_iteration ();
-            eof_count = 0;
+            this.init_iteration ();
+            this.eof_count = 0;
             Process.spawn_async_with_pipes (null,
-                                            command,
+                                            this.command,
                                             null,
-                                            flags,
-                                            child_setup,
-                                            out child_pid,
+                                            this.flags,
+                                            this.child_setup,
+                                            out this.child_pid,
                                             null,
-                                            out std_out,
-                                            out std_err);
+                                            out this.std_out,
+                                            out this.std_err);
 
             var out_channel = new IOChannel.unix_new (std_out);
             out_channel.add_watch (IOCondition.OUT | IOCondition.HUP,
-                                   out_watch);
+                                   this.out_watch);
 
             var err_channel = new IOChannel.unix_new (std_err);
             err_channel.add_watch (IOCondition.OUT | IOCondition.HUP,
-                                   err_watch);
+                                   this.err_watch);
         } catch (SpawnError e) {
             /* Let the async function yeild, then error out */
             this.execution_state = ExecutionState.SPAWN_FAILED;
-            Idle.add ((SourceFunc)finish_iteration);
+            Idle.add ((SourceFunc)this.finish_iteration);
         }
     }
 
@@ -143,18 +143,20 @@ internal abstract class Rygel.BasicManagementTest : Object {
             string line;
             IOStatus status = channel.read_line (out line, null, null);
             if (line != null)
-                handle_output (line);
+                this.handle_output (line);
 
             if (status == IOStatus.EOF) {
-                eof_count++;
-                if (eof_count > 1)
-                    finish_iteration ();
+                this.eof_count++;
+                if (this.eof_count > 1)
+                    this.finish_iteration ();
+
                 return false;
             }
         } catch (Error e) {
             warning ("Failed readline() from nslookup stdout: %s", e.message);
             /* TODO set execution_state ? */
-            finish_iteration();
+            this.finish_iteration();
+
             return false;
         }
 
@@ -166,18 +168,20 @@ internal abstract class Rygel.BasicManagementTest : Object {
             string line;
             IOStatus status = channel.read_line (out line, null, null);
             if (line != null)
-                handle_error (line);
+                this.handle_error (line);
 
             if (status == IOStatus.EOF) {
-                eof_count++;
-                if (eof_count > 1)
-                    finish_iteration ();
+                this.eof_count++;
+                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 ? */
-            finish_iteration();
+            this.finish_iteration();
+
             return false;
         }
 
@@ -196,10 +200,10 @@ internal abstract class Rygel.BasicManagementTest : Object {
                                                 ("Already executing or executed");
 
         this.execution_state = ExecutionState.IN_PROGRESS;
-        iteration = 0;
-        async_callback = execute.callback;
+        this.iteration = 0;
+        this.async_callback = execute.callback;
 
-        run_iteration ();
+        this.run_iteration ();
         yield;
 
         return;
@@ -209,7 +213,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
         if (this.execution_state != ExecutionState.IN_PROGRESS)
             throw new BasicManagementTestError.NOT_POSSIBLE ("Not executing");
 
-        Posix.killpg (child_pid, Posix.SIGTERM);
+        Posix.killpg (this.child_pid, Posix.SIGTERM);
 
         this.execution_state = ExecutionState.CANCELED;
     }


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