aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-04-24 22:43:15 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-04-24 22:43:15 -0500
commit27b500307fe8035defb510a0d694fa1fa7fa3950 (patch)
treeb5108a91beabf803c4ea4d71a99129718c5a7026 /include
parent4008e0a91ebdc1cf5c5715a122fed318124c8802 (diff)
parenta396e6af3cd16530202f6cbecbd45c7a3f6ac893 (diff)
downloadayatana-indicator-datetime-27b500307fe8035defb510a0d694fa1fa7fa3950.tar.gz
ayatana-indicator-datetime-27b500307fe8035defb510a0d694fa1fa7fa3950.tar.bz2
ayatana-indicator-datetime-27b500307fe8035defb510a0d694fa1fa7fa3950.zip
prefer to use ubuntu-platform-hardware-api for wakeups when possible s.t. user-defined alarms/appointments can wake up the phone from sleep to give a snap decision.
Diffstat (limited to 'include')
-rw-r--r--include/datetime/alarm-queue-simple.h63
-rw-r--r--include/datetime/alarm-queue.h (renamed from include/datetime/clock-watcher.h)40
-rw-r--r--include/datetime/date-time.h3
-rw-r--r--include/datetime/planner-range.h2
-rw-r--r--include/datetime/wakeup-timer-mainloop.h62
-rw-r--r--include/datetime/wakeup-timer-uha.h64
-rw-r--r--include/datetime/wakeup-timer.h55
7 files changed, 260 insertions, 29 deletions
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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_ALARM_QUEUE_SIMPLE_H
+#define INDICATOR_DATETIME_ALARM_QUEUE_SIMPLE_H
+
+#include <datetime/alarm-queue.h>
+#include <datetime/clock.h>
+#include <datetime/planner.h>
+#include <datetime/wakeup-timer.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief A #AlarmQueue implementation
+ */
+class SimpleAlarmQueue: public AlarmQueue
+{
+public:
+ SimpleAlarmQueue(const std::shared_ptr<Clock>& clock,
+ const std::shared_ptr<Planner>& upcoming_planner,
+ const std::shared_ptr<WakeupTimer>& timer);
+ ~SimpleAlarmQueue();
+ core::Signal<const Appointment&>& alarm_reached();
+
+private:
+ void requeue();
+ bool find_next_alarm(Appointment& setme) const;
+ std::vector<Appointment> find_current_alarms() const;
+ void check_alarms();
+
+ std::set<std::string> m_triggered;
+ const std::shared_ptr<Clock> m_clock;
+ const std::shared_ptr<Planner> m_planner;
+ const std::shared_ptr<WakeupTimer> m_timer;
+ core::Signal<const Appointment&> m_alarm_reached;
+ DateTime m_time;
+};
+
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_ALARM_QUEUE_H
diff --git a/include/datetime/clock-watcher.h b/include/datetime/alarm-queue.h
index 90bbb63..ea51957 100644
--- a/include/datetime/clock-watcher.h
+++ b/include/datetime/alarm-queue.h
@@ -17,12 +17,10 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#ifndef INDICATOR_DATETIME_CLOCK_WATCHER_H
-#define INDICATOR_DATETIME_CLOCK_WATCHER_H
+#ifndef INDICATOR_DATETIME_ALARM_QUEUE_H
+#define INDICATOR_DATETIME_ALARM_QUEUE_H
#include <datetime/appointment.h>
-#include <datetime/clock.h>
-#include <datetime/planner-upcoming.h>
#include <core/signal.h>
@@ -34,42 +32,28 @@ namespace unity {
namespace indicator {
namespace datetime {
+/***
+****
+***/
/**
* \brief Watches the clock and appointments to notify when an
* appointment's time is reached.
*/
-class ClockWatcher
+class AlarmQueue
{
public:
- ClockWatcher() =default;
- virtual ~ClockWatcher() =default;
+ AlarmQueue() =default;
+ virtual ~AlarmQueue() =default;
virtual core::Signal<const Appointment&>& alarm_reached() = 0;
};
-
-/**
- * \brief A #ClockWatcher implementation
- */
-class ClockWatcherImpl: public ClockWatcher
-{
-public:
- ClockWatcherImpl(const std::shared_ptr<Clock>& clock,
- const std::shared_ptr<UpcomingPlanner>& upcoming_planner);
- ~ClockWatcherImpl() =default;
- core::Signal<const Appointment&>& alarm_reached();
-
-private:
- void pulse();
- std::set<std::string> m_triggered;
- const std::shared_ptr<Clock> m_clock;
- const std::shared_ptr<UpcomingPlanner> m_upcoming_planner;
- core::Signal<const Appointment&> m_alarm_reached;
-};
-
+/***
+****
+***/
} // namespace datetime
} // namespace indicator
} // namespace unity
-#endif // INDICATOR_DATETIME_CLOCK_WATCHER_H
+#endif // INDICATOR_DATETIME_ALARM_QUEUE_H
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<GDateTime> 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>& engine,
- const std::shared_ptr<Timezone>& timezone);
+ const std::shared_ptr<Timezone>& timezone);
virtual ~SimpleRangePlanner();
core::Property<std::vector<Appointment>>& 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_MAINLOOP_H
+#define INDICATOR_DATETIME_WAKEUP_TIMER_MAINLOOP_H
+
+#include <datetime/clock.h>
+#include <datetime/wakeup-timer.h>
+
+#include <memory> // 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<Clock>&);
+ ~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<Impl> 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_UHA_H
+#define INDICATOR_DATETIME_WAKEUP_TIMER_UHA_H
+
+#include <datetime/clock.h>
+#include <datetime/wakeup-timer.h>
+
+#include <memory> // 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<Clock>&);
+ ~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<Impl> 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..0a9923c
--- /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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_H
+#define INDICATOR_DATETIME_WAKEUP_TIMER_H
+
+#include <datetime/date-time.h>
+
+#include <core/signal.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/***
+****
+***/
+
+/**
+ * \brief A one-shot timer that emits a signal when its 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