[rygel] core: Use enum to represent transfer status



commit 23b5b3f053b6ce5108a5b6e6ed9cae1b9bfdedbd
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Feb 18 19:38:24 2010 +0200

    core: Use enum to represent transfer status

 src/rygel/rygel-content-directory.vala |    2 +-
 src/rygel/rygel-import-resource.vala   |   31 +++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala
index 3acd955..2b439da 100644
--- a/src/rygel/rygel-content-directory.vala
+++ b/src/rygel/rygel-content-directory.vala
@@ -326,7 +326,7 @@ public class Rygel.ContentDirectory: Service {
         var ids = "";
 
         foreach (var import in this.active_imports) {
-            if (!import.complete) {
+            if (import.status != TransferStatus.COMPLETED) {
                 if (ids != "") {
                     ids += ",";
                 }
diff --git a/src/rygel/rygel-import-resource.vala b/src/rygel/rygel-import-resource.vala
index 445fd22..7e9970b 100644
--- a/src/rygel/rygel-import-resource.vala
+++ b/src/rygel/rygel-import-resource.vala
@@ -23,6 +23,13 @@
 
 using GUPnP;
 
+internal enum Rygel.TransferStatus {
+    COMPLETED,
+    ERROR,
+    IN_PROGRESS,
+    STOPPED
+}
+
 /**
  * Responsible for handling ImportResource action.
  */
@@ -36,7 +43,23 @@ internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
     // Out arguments
     public uint32 transfer_id;
 
-    public bool complete;
+    public TransferStatus status;
+
+    public string status_as_string {
+        get {
+            switch (this.status) {
+                case TransferStatus.COMPLETED:
+                    return "COMPLETED";
+                case TransferStatus.ERROR:
+                    return "ERROR";
+                case TransferStatus.IN_PROGRESS:
+                    return "IN_PROGRESS";
+                case TransferStatus.STOPPED:
+                default:
+                    return "STOPPED";
+            }
+        }
+    }
 
     public Cancellable cancellable { get; set; }
 
@@ -58,6 +81,8 @@ internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
 
         this.bytes_copied = 0;
         this.bytes_total = 0;
+
+        this.status = TransferStatus.IN_PROGRESS;
     }
 
     public async void run () {
@@ -81,6 +106,7 @@ internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
                      error.message);
 
             this.action.return_error (719, error.message);
+            this.status = TransferStatus.ERROR;
 
             return;
         }
@@ -99,9 +125,10 @@ internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
                                           this.copy_progress_cb);
         } catch (Error err) {
             warning ("%s", err.message);
+            this.status = TransferStatus.ERROR;
         }
 
-        this.complete = true;
+        this.status = TransferStatus.COMPLETED;
 
         debug ("Import of '%s' to '%s' completed",
                source_uri,



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