aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-04-24 22:34:42 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-04-24 22:34:42 -0500
commita396e6af3cd16530202f6cbecbd45c7a3f6ac893 (patch)
tree8c97c9827b21e19cf95df0ae6125a4bd01f169e9 /include
parentcff541acfef717aae4c9b696627b4817e7eac851 (diff)
downloadayatana-indicator-datetime-a396e6af3cd16530202f6cbecbd45c7a3f6ac893.tar.gz
ayatana-indicator-datetime-a396e6af3cd16530202f6cbecbd45c7a3f6ac893.tar.bz2
ayatana-indicator-datetime-a396e6af3cd16530202f6cbecbd45c7a3f6ac893.zip
hw alarms
Diffstat (limited to 'include')
-rw-r--r--include/datetime/alarm-queue-simple.h63
-rw-r--r--include/datetime/alarm-queue.h28
-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, 254 insertions, 23 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/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 <datetime/appointment.h>
-#include <datetime/clock.h>
-#include <datetime/planner-upcoming.h>
#include <core/signal.h>
@@ -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<const Appointment&>& alarm_reached() = 0;
};
-
-/**
- * \brief A #AlarmQueue implementation
- */
-class AlarmQueueImpl: public AlarmQueue
-{
-public:
- AlarmQueueImpl(const std::shared_ptr<Clock>& clock,
- const std::shared_ptr<UpcomingPlanner>& upcoming_planner);
- ~AlarmQueueImpl() =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
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..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 <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 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