[rygel/wip/basic-management: 57/68] core: Handle default parameter values in BasicManagement NSLookup



commit d7c830aad1873e5e0ff7b7247f260f26b4ee6d10
Author: Jussi Kukkonen <jussi kukkonen intel com>
Date:   Thu Jun 6 16:15:18 2013 +0300

    core: Handle default parameter values in BasicManagement NSLookup
    
    Add property setters for repetition and timeout, so the default values
    can be used for value '0'. repetitions still uses base class 'iterations'
    variable internally.
    
    Rename variables in BasicaManagement to be clearer.

 .../rygel-basic-management-test-nslookup.vala      |   34 +++++++++++++++++--
 src/librygel-core/rygel-basic-management-test.vala |   10 +++---
 2 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/src/librygel-core/rygel-basic-management-test-nslookup.vala 
b/src/librygel-core/rygel-basic-management-test-nslookup.vala
index a440f3f..53e07fc 100644
--- a/src/librygel-core/rygel-basic-management-test-nslookup.vala
+++ b/src/librygel-core/rygel-basic-management-test-nslookup.vala
@@ -107,9 +107,11 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
         }
     }
 
-    private static const uint MAX_REPEAT_COUNT = 100;
+    private static const uint MAX_REPETITIONS = 100;
+    private static const uint DEFAULT_REPETITIONS = 1;
     private static const uint MIN_INTERVAL_TIMEOUT = 1000;
     private static const uint MAX_INTERVAL_TIMEOUT = 30000;
+    private static const uint DEFAULT_INTERVAL_TIMEOUT = 1000;
 
     private struct Result {
         private ProcessState state;
@@ -151,7 +153,31 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
 
     public string host_name { construct; private get; default = ""; }
     public string? name_server { construct; private get; default = null; }
-    public uint interval_time_out { construct; private get; default = MIN_INTERVAL_TIMEOUT; }
+
+    private uint _interval_time_out;
+    public uint interval_time_out {
+        construct {
+            this._interval_time_out = value;
+            if (this._interval_time_out == 0)
+                this._interval_time_out = DEFAULT_INTERVAL_TIMEOUT;
+        }
+        private get {
+            return this._interval_time_out;
+        }
+        default = DEFAULT_INTERVAL_TIMEOUT;
+    }
+
+    public uint repetitions {
+        construct {
+            this.iterations = value;
+            if (this.iterations == 0)
+                this.iterations = DEFAULT_REPETITIONS;
+        }
+        private get {
+            return this.iterations;
+        }
+        default = DEFAULT_REPETITIONS;
+    }
 
     private Result[] results;
     private GenericStatus generic_status;
@@ -185,11 +211,11 @@ internal class Rygel.BasicManagementTestNSLookup : BasicManagementTest {
             this.command += name_server;
 
         /* Fail early if internal parameter limits are violated */
-        if (this.repetitions > MAX_REPEAT_COUNT) {
+        if (this.repetitions > MAX_REPETITIONS) {
             init_state = InitState.INVALID_PARAMETER;
             var msg = "NumberOfRepetitions %u is not in allowed range [0, %u]";
             this.additional_info = msg.printf (this.repetitions,
-                                               MAX_REPEAT_COUNT);
+                                               MAX_REPETITIONS);
         } else if (this.interval_time_out < MIN_INTERVAL_TIMEOUT ||
                    this.interval_time_out > MAX_INTERVAL_TIMEOUT) {
             init_state = InitState.INVALID_PARAMETER;
diff --git a/src/librygel-core/rygel-basic-management-test.vala 
b/src/librygel-core/rygel-basic-management-test.vala
index eca44d3..0d7b79c 100644
--- a/src/librygel-core/rygel-basic-management-test.vala
+++ b/src/librygel-core/rygel-basic-management-test.vala
@@ -71,7 +71,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
     public abstract string results_type { get; }
 
     /* properties for implementations to access */
-    public uint repetitions { construct; protected get; default = 1; }
+    protected uint iterations;
     protected SpawnFlags flags = SpawnFlags.SEARCH_PATH |
                                  SpawnFlags.LEAVE_DESCRIPTORS_OPEN;
     protected string[] command;
@@ -81,7 +81,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
     private int std_err;
     private Pid child_pid;
     private SourceFunc async_callback;
-    private uint iteration;
+    private uint current_iteration;
 
     /* These virtual/abstract functions will be called from execute():
      * - For every iteration:
@@ -95,11 +95,11 @@ internal abstract class Rygel.BasicManagementTest : Object {
         warning ("%s stderr: %s", command[0], line);
     }
     protected virtual void finish_iteration () {
-        this.iteration++;
+        this.current_iteration++;
 
         if (this.init_state != InitState.OK ||
             this.execution_state == ExecutionState.COMPLETED ||
-            this.iteration >= this.repetitions) {
+            this.current_iteration >= this.iterations) {
             /* No more iterations if 
              *  - init failed, recovery is impossible or
              *  - execution has ended (remaining iterations should be skipped)
@@ -215,7 +215,7 @@ internal abstract class Rygel.BasicManagementTest : Object {
                                                 ("Already executing or executed");
 
         this.execution_state = ExecutionState.IN_PROGRESS;
-        this.iteration = 0;
+        this.current_iteration = 0;
         this.async_callback = execute.callback;
 
         this.run_iteration ();


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