aboutsummaryrefslogtreecommitdiff
path: root/include/datetime
diff options
context:
space:
mode:
Diffstat (limited to 'include/datetime')
-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..d191aec
--- /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::pair<std::string,DateTime>> 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_datetime;
+};
+
+
+} // 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..4be35f7 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 != 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