[gnome-dvb-daemon] Use async methods instead of calling the methods with Idle.add



commit 2b54f6d20c0aa068c31c88851ef87686099d5f43
Author: Sebastian Pölsterl <sebp k-d-w org>
Date:   Fri May 6 20:44:10 2011 +0200

    Use async methods instead of calling the methods with Idle.add
    
    https://bugs.launchpad.net/bugs/769531

 src/Channel.vala         |    4 +++-
 src/Main.vala            |    4 ++--
 src/Schedule.vala        |   22 ++++++++++------------
 src/rtsp/Server.vala     |    3 +--
 src/rygel/Services2.vala |    3 +--
 5 files changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/src/Channel.vala b/src/Channel.vala
index 0fabcd3..09cb06f 100644
--- a/src/Channel.vala
+++ b/src/Channel.vala
@@ -27,8 +27,10 @@ namespace DVB {
             get { return this.sid; }
             set {
                 this.sid = value;
-                if (this.has_schedule)
+                if (this.has_schedule) {
                     this.schedule = new DVB.Schedule (this);
+                    this.schedule.restore.begin ();
+                }
             }
         }
         public uint GroupId {get; set;}
diff --git a/src/Main.vala b/src/Main.vala
index 034c075..2583b07 100644
--- a/src/Main.vala
+++ b/src/Main.vala
@@ -204,10 +204,10 @@ namespace Main {
 
         start_manager ();
 
-        Idle.add (DVB.RTSPServer.start);
+        DVB.RTSPServer.start.begin ();
 
         if (!disable_mediaserver) {
-            Idle.add (DVB.MediaServer2.start_rygel_services);
+            DVB.MediaServer2.start_rygel_services.begin ();
         }
 
         // Start GLib mainloop
diff --git a/src/Schedule.vala b/src/Schedule.vala
index 1c6950c..b76fdf6 100644
--- a/src/Schedule.vala
+++ b/src/Schedule.vala
@@ -45,23 +45,22 @@ namespace DVB {
         construct {
             this.events = new EventStorage ();
             this.epgstore = Factory.get_epg_store ();
-
-            Idle.add (this.restore);
         }
 
-        private bool restore () {
+        public async void restore () {
             Gee.List<Event> levents;
             try {                        
                 levents = this.epgstore.get_events (
                     this.channel.Sid, this.channel.GroupId);
-            } catch (SqlError e) {
-                log.error ("%s", e.message);
-                return false;
+            } catch (SqlError e1) {
+                log.error ("%s", e1.message);
+                return;
             }
 
             int newest_expired = -1;
+            Event event;
             for (int i=0; i<levents.size; i++) {
-                Event event = levents.get (i);
+                event = levents.get (i);
                 if (event.has_expired ()) {
                     /* events are sorted by starttime */
                     newest_expired = i;
@@ -71,19 +70,18 @@ namespace DVB {
             }
 
             if (newest_expired != -1) {
-                Event event = levents.get (newest_expired);
+                event = levents.get (newest_expired);
                 try {
                     this.epgstore.remove_events_older_than (event,
                         this.channel.Sid, this.channel.GroupId);
-                } catch (SqlError e) {
-                    log.error ("%s", e.message);
-                    return false;
+                } catch (SqlError e2) {
+                    log.error ("%s", e2.message);
+                    return;
                 }
             }
 
             log.debug ("Finished restoring EPG events for channel %u",
                 this.channel.Sid);
-            return false;
         }
         
         public Schedule (Channel channel) {
diff --git a/src/rtsp/Server.vala b/src/rtsp/Server.vala
index 7cfc783..9dc3cf1 100644
--- a/src/rtsp/Server.vala
+++ b/src/rtsp/Server.vala
@@ -47,7 +47,7 @@ namespace DVB.RTSPServer {
         return address;
     }
 
-    public static bool start () {
+    public async static void start () {
         log = LogManager.getLogManager().getDefaultLogger();
         log.info ("Starting RTSP server");
         server = new Gst.RTSPServer ();
@@ -55,7 +55,6 @@ namespace DVB.RTSPServer {
         server.set_address (get_address ());
         server.attach (null);
         timeout_id = GLib.Timeout.add_seconds (2, (GLib.SourceFunc)timeout);
-        return false;
     }
     
     public static void shutdown () {
diff --git a/src/rygel/Services2.vala b/src/rygel/Services2.vala
index afb79ae..42cd9c8 100644
--- a/src/rygel/Services2.vala
+++ b/src/rygel/Services2.vala
@@ -382,10 +382,9 @@ namespace DVB.MediaServer2 {
         root_container.create_container_services ();
     }
 
-    public static bool start_rygel_services () {
+    public static async void start_rygel_services () {
         log = LogManager.getLogManager().getDefaultLogger();
         Utils.dbus_own_name (SERVICE_NAME, on_bus_acquired);
-        return false;
     }
 
 }



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