Try to use fso for scheduling alarms
authorEnrico Zini <enrico@enricozini.org>
Mon, 17 Aug 2009 13:00:51 +0000 (14:00 +0100)
committerEnrico Zini <enrico@enricozini.org>
Mon, 17 Aug 2009 13:00:51 +0000 (14:00 +0100)
src/clock.vala
src/zavai.vala

index 90c8785245de1d52b58b6c481a24e3cfa67b0c41..8dec2e334c7fc242dd909f3627b9fe96a5ea2f16 100644 (file)
@@ -59,6 +59,8 @@ public class Clock: zavai.Service
     protected time_t chosen_time;
     protected SourceType chosen_type;
 
+       protected dynamic DBus.Object otimed_alarm;
+       protected dynamic DBus.Object notification;
     protected SList<Alarm> alarms;
 
     // Ticks once a minute
@@ -78,12 +80,42 @@ public class Clock: zavai.Service
                        "org.freesmartphone.ogpsd",
                        "/org/freedesktop/Gypsy",
                        "org.freedesktop.Gypsy.Time");
+
+        // FSO alarm system
+           otimed_alarm = zavai.registry.sbus.get_object(
+                       "org.freesmartphone.otimed",
+                       "/org/freesmartphone/Time/Alarm",
+                       "org.freesmartphone.Time.Alarm");
+        notification = zavai.registry.sbus.get_object(
+            "org.freesmartphone",
+            "org/freesmartphone/Notification",
+            "org.freesmartphone.Notification");
+        notification.Alarm += on_alarm;
        }
 
     public void schedule(Alarm a)
     {
         alarms.insert_sorted(a, alarm_compare);
         zavai.log.info("Next alarm: " + alarms.data.label + " at " + Time.local(alarms.data.deadline).to_string());
+        otimed_reschedule();
+    }
+
+    private void otimed_reschedule()
+    {
+        if (alarms != null)
+        {
+            try {
+                otimed_alarm.ClearAlarm();
+                otimed_alarm.SetAlarm(alarms.data.deadline);
+            } catch (Error e) {
+                zavai.log.error("Cannot reschedule alarms: " + e.message);
+            }
+        }
+    }
+
+    private void on_alarm()
+    {
+        check_alarms();
     }
 
     public void check_alarms()
@@ -97,6 +129,8 @@ public class Clock: zavai.Service
             zavai.log.info("Triggering " + a.label);
             a.trigger();
         }
+
+        otimed_reschedule();
     }
 
        private void on_gps_time(dynamic DBus.Object pos, int t)
index 7a799533e897b2d6de4c3ea36956a8baf79474e3..a392a0af79b39c4e5f24029feac4bc67f9e64596 100644 (file)
@@ -22,11 +22,6 @@ using GLib;
 
 //string VERSION = "0.1";
 
-void on_alarm()
-{
-       stderr.printf("RETURNED\n");
-}
-
 static int main (string[] args) {
        Gtk.init (ref args);
 
@@ -58,10 +53,12 @@ static int main (string[] args) {
        zavai.gps.init();
        zavai.clock.init();
 
+       /*
        zavai.clock.clock.schedule(new zavai.clock.Alarm(123456, "Second"));
        zavai.clock.clock.schedule(new zavai.clock.Alarm(1234567, "Third"));
        zavai.clock.clock.schedule(new zavai.clock.Alarm(12345, "First"));
        zavai.clock.clock.check_alarms();
+       */
 
        zavai.registry.register_menu("menu.main", new zavai.Menu("Main menu"));
 
@@ -77,6 +74,9 @@ static int main (string[] args) {
        //zavai.app.show_applet("menu.main");
        zavai.app.show_applet("zavai.status");
 
+       zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 3, "Test second"));
+       zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + 2, "Test first"));
+
        //zavai.ui.power.power_menu.toggle();
 
        // # Shutdown the main loop on SIGINT