- "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");
- if (otimed_alarm == null)
- zavai.log.error("ALARM IS NULL");
- notification = zavai.registry.sbus.get_object(
- "org.freesmartphone",
- "org/freesmartphone/Notification",
- "org.freesmartphone.Notification");
- notification.Alarm += on_alarm;
+ "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");
+
+ rtc = zavai.registry.sbus.get_object(
+ "org.freesmartphone.odeviced",
+ "/org/freesmartphone/Device/RTC/0",
+ "org.freesmartphone.Device.RealtimeClock");
+
+ zavai.registry.sbus.register_object("/", listener);
+
+ }
+
+ public Alarm? next_alarm()
+ {
+ if (alarms == null)
+ return null;
+ return alarms.data;
+ }
+
+ public void schedule(Alarm a)
+ {
+ alarms.insert_sorted(a, alarm_compare);
+ otimed_reschedule();
+ }
+
+ private void otimed_reschedule()
+ {
+ if (alarms != null)
+ {
+ zavai.log.info("Scheduling next alarm: " + alarms.data.label + " at " + Time.local(alarms.data.deadline).to_string());
+ zavai.log.info("Scheduling at abs " + "%d".printf((int)alarms.data.deadline));
+
+ try {
+ otimed_alarm.ClearAlarm(zavai.registry.bus_name);
+ } catch (Error e) {
+ zavai.log.error("Cannot clear alarms: " + e.message);
+ }
+ try {
+ otimed_alarm.SetAlarm(zavai.registry.bus_name, (int)alarms.data.deadline);
+ } catch (Error e) {
+ zavai.log.error("Cannot reschedule alarms: " + e.message);
+ }
+
+ int t = rtc.GetCurrentTime();
+ stderr.printf("Current time: %d, RTC time: %d\n", (int)time_t(), t);
+ t = rtc.GetWakeupTime();
+ stderr.printf("Scheduled alarm: %d, RTC wakeup time: %d\n", (int)alarms.data.deadline, t);
+ } else
+ zavai.log.info("No alarms left to reschedule");
+ schedule_changed();