From a396e6af3cd16530202f6cbecbd45c7a3f6ac893 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 24 Apr 2014 22:34:42 -0500 Subject: hw alarms --- include/datetime/alarm-queue-simple.h | 63 +++++++++++++++++++++++++++++++ include/datetime/alarm-queue.h | 28 +++----------- include/datetime/date-time.h | 3 ++ include/datetime/planner-range.h | 2 +- include/datetime/wakeup-timer-mainloop.h | 62 +++++++++++++++++++++++++++++++ include/datetime/wakeup-timer-uha.h | 64 ++++++++++++++++++++++++++++++++ include/datetime/wakeup-timer.h | 55 +++++++++++++++++++++++++++ 7 files changed, 254 insertions(+), 23 deletions(-) create mode 100644 include/datetime/alarm-queue-simple.h create mode 100644 include/datetime/wakeup-timer-mainloop.h create mode 100644 include/datetime/wakeup-timer-uha.h create mode 100644 include/datetime/wakeup-timer.h (limited to 'include/datetime') diff --git a/include/datetime/alarm-queue-simple.h b/include/datetime/alarm-queue-simple.h new file mode 100644 index 0000000..8461227 --- /dev/null +++ b/include/datetime/alarm-queue-simple.h @@ -0,0 +1,63 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_ALARM_QUEUE_SIMPLE_H +#define INDICATOR_DATETIME_ALARM_QUEUE_SIMPLE_H + +#include +#include +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A #AlarmQueue implementation + */ +class SimpleAlarmQueue: public AlarmQueue +{ +public: + SimpleAlarmQueue(const std::shared_ptr& clock, + const std::shared_ptr& upcoming_planner, + const std::shared_ptr& timer); + ~SimpleAlarmQueue(); + core::Signal& alarm_reached(); + +private: + void requeue(); + bool find_next_alarm(Appointment& setme) const; + std::vector find_current_alarms() const; + void check_alarms(); + + std::set m_triggered; + const std::shared_ptr m_clock; + const std::shared_ptr m_planner; + const std::shared_ptr m_timer; + core::Signal m_alarm_reached; + DateTime m_time; +}; + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_ALARM_QUEUE_H diff --git a/include/datetime/alarm-queue.h b/include/datetime/alarm-queue.h index 5db4ad8..ea51957 100644 --- a/include/datetime/alarm-queue.h +++ b/include/datetime/alarm-queue.h @@ -21,8 +21,6 @@ #define INDICATOR_DATETIME_ALARM_QUEUE_H #include -#include -#include #include @@ -34,6 +32,9 @@ namespace unity { namespace indicator { namespace datetime { +/*** +**** +***/ /** * \brief Watches the clock and appointments to notify when an @@ -47,26 +48,9 @@ public: virtual core::Signal& alarm_reached() = 0; }; - -/** - * \brief A #AlarmQueue implementation - */ -class AlarmQueueImpl: public AlarmQueue -{ -public: - AlarmQueueImpl(const std::shared_ptr& clock, - const std::shared_ptr& upcoming_planner); - ~AlarmQueueImpl() =default; - core::Signal& alarm_reached(); - -private: - void pulse(); - std::set m_triggered; - const std::shared_ptr m_clock; - const std::shared_ptr m_upcoming_planner; - core::Signal m_alarm_reached; -}; - +/*** +**** +***/ } // namespace datetime } // namespace indicator diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index f861c2e..490ed40 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -61,10 +61,13 @@ public: bool operator<=(const DateTime& that) const; bool operator!=(const DateTime& that) const; bool operator==(const DateTime& that) const; + int64_t operator- (const DateTime& that) const; static bool is_same_day(const DateTime& a, const DateTime& b); static bool is_same_minute(const DateTime& a, const DateTime& b); + bool is_set() const { return m_dt.get() != nullptr; } + private: std::shared_ptr m_dt; }; diff --git a/include/datetime/planner-range.h b/include/datetime/planner-range.h index 25334a6..2ee2fa0 100644 --- a/include/datetime/planner-range.h +++ b/include/datetime/planner-range.h @@ -53,7 +53,7 @@ class SimpleRangePlanner: public RangePlanner { public: SimpleRangePlanner(const std::shared_ptr& engine, - const std::shared_ptr& timezone); + const std::shared_ptr& timezone); virtual ~SimpleRangePlanner(); core::Property>& appointments(); diff --git a/include/datetime/wakeup-timer-mainloop.h b/include/datetime/wakeup-timer-mainloop.h new file mode 100644 index 0000000..480d728 --- /dev/null +++ b/include/datetime/wakeup-timer-mainloop.h @@ -0,0 +1,62 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_MAINLOOP_H +#define INDICATOR_DATETIME_WAKEUP_TIMER_MAINLOOP_H + +#include +#include + +#include // std::unique_ptr, std::shared_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +/** + * \brief a WakeupTimer implemented with g_timeout_add() + */ +class MainloopWakeupTimer: public WakeupTimer +{ +public: + MainloopWakeupTimer(const std::shared_ptr&); + ~MainloopWakeupTimer(); + void set_wakeup_time (const DateTime&); + core::Signal<>& timeout(); + +private: + MainloopWakeupTimer(const MainloopWakeupTimer&) =delete; + MainloopWakeupTimer& operator= (const MainloopWakeupTimer&) =delete; + class Impl; + std::unique_ptr p; +}; + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_WAKEUP_TIMER_MAINLOOP_H diff --git a/include/datetime/wakeup-timer-uha.h b/include/datetime/wakeup-timer-uha.h new file mode 100644 index 0000000..093548b --- /dev/null +++ b/include/datetime/wakeup-timer-uha.h @@ -0,0 +1,64 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_UHA_H +#define INDICATOR_DATETIME_WAKEUP_TIMER_UHA_H + +#include +#include + +#include // std::unique_ptr, std::shared_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +/** + * \brief a WakeupTimer implemented the UbuntuHardwareAlarm API + */ +class UhaWakeupTimer: public WakeupTimer +{ +public: + UhaWakeupTimer(const std::shared_ptr&); + ~UhaWakeupTimer(); + void set_wakeup_time (const DateTime&); + core::Signal<>& timeout(); + + static bool is_supported(); + +private: + UhaWakeupTimer(const UhaWakeupTimer&) =delete; + UhaWakeupTimer& operator= (const UhaWakeupTimer&) =delete; + class Impl; + std::unique_ptr p; +}; + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_WAKEUP_TIMER_UHA_H diff --git a/include/datetime/wakeup-timer.h b/include/datetime/wakeup-timer.h new file mode 100644 index 0000000..b84d347 --- /dev/null +++ b/include/datetime/wakeup-timer.h @@ -0,0 +1,55 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_H +#define INDICATOR_DATETIME_WAKEUP_TIMER_H + +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +/** + * \brief A one-shot timer that emits a signal when the timeout is reached + */ +class WakeupTimer +{ +public: + WakeupTimer() =default; + virtual ~WakeupTimer() =default; + virtual void set_wakeup_time (const DateTime&) =0; + virtual core::Signal<>& timeout() = 0; +}; + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_WAKEUP_TIMER_H -- cgit v1.2.3