core: Use enum to represent transfer status
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 18 Feb 2010 17:38:24 +0000 (19:38 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 18 Feb 2010 17:52:36 +0000 (19:52 +0200)
src/rygel/rygel-content-directory.vala
src/rygel/rygel-import-resource.vala

index 3acd955..2b439da 100644 (file)
@@ -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 += ",";
                 }
index 445fd22..7e9970b 100644 (file)
 
 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,