aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-02-12 14:38:49 -0600
committerCharles Kerr <charles.kerr@canonical.com>2015-02-12 14:38:49 -0600
commitde6bc91f29122242fab6da7f5120f5bc8c64a1d6 (patch)
treeaf6ed585a0cd3466702742fd0d61edda2130e901 /src
parent5df082224c0f4664b8798261abce1d0b1b5ab2d9 (diff)
downloadayatana-indicator-datetime-de6bc91f29122242fab6da7f5120f5bc8c64a1d6.tar.gz
ayatana-indicator-datetime-de6bc91f29122242fab6da7f5120f5bc8c64a1d6.tar.bz2
ayatana-indicator-datetime-de6bc91f29122242fab6da7f5120f5bc8c64a1d6.zip
extract the timerfd_settime() code into its own method. Add a new call to it when we might have triggered via TFD_TIMER_CANCEL_ON_SET
Diffstat (limited to 'src')
-rw-r--r--src/clock-live.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/clock-live.cpp b/src/clock-live.cpp
index 7827444..b91fc62 100644
--- a/src/clock-live.cpp
+++ b/src/clock-live.cpp
@@ -59,26 +59,7 @@ public:
}
else
{
- struct itimerspec timerval;
- // set args to fire at the beginning of the next minute...
- int flags = TFD_TIMER_ABSTIME;
- auto now = g_date_time_new_now(m_gtimezone);
- auto next = g_date_time_add_minutes(now, 1);
- auto start_of_next = g_date_time_add_seconds(next, -g_date_time_get_seconds(next));
- timerval.it_value.tv_sec = g_date_time_to_unix(start_of_next);
- timerval.it_value.tv_nsec = 0;
- g_date_time_unref(start_of_next);
- g_date_time_unref(next);
- g_date_time_unref(now);
- // ...and also to fire at the beginning of every subsequent minute...
- timerval.it_interval.tv_sec = 60;
- timerval.it_interval.tv_nsec = 0;
- // ...and also to fire if someone changes the time
- // manually (eg toggling from manual<->ntp)
- flags |= TFD_TIMER_CANCEL_ON_SET;
-
- if (timerfd_settime(m_timerfd, flags, &timerval, NULL) == -1)
- g_error("timerfd_settime failed: %s", g_strerror(errno));
+ reset_timer();
m_timerfd_tag = g_unix_fd_add(m_timerfd,
(GIOCondition)(G_IO_IN|G_IO_HUP|G_IO_ERR),
@@ -112,6 +93,30 @@ public:
private:
+ void reset_timer()
+ {
+ struct itimerspec timerval;
+ // set args to fire at the beginning of the next minute...
+ int flags = TFD_TIMER_ABSTIME;
+ auto now = g_date_time_new_now(m_gtimezone);
+ auto next = g_date_time_add_minutes(now, 1);
+ auto start_of_next = g_date_time_add_seconds(next, -g_date_time_get_seconds(next));
+ timerval.it_value.tv_sec = g_date_time_to_unix(start_of_next);
+ timerval.it_value.tv_nsec = 0;
+ g_date_time_unref(start_of_next);
+ g_date_time_unref(next);
+ g_date_time_unref(now);
+ // ...and also to fire at the beginning of every subsequent minute...
+ timerval.it_interval.tv_sec = 60;
+ timerval.it_interval.tv_nsec = 0;
+ // ...and also to fire if someone changes the time
+ // manually (eg toggling from manual<->ntp)
+ flags |= TFD_TIMER_CANCEL_ON_SET;
+
+ if (timerfd_settime(m_timerfd, flags, &timerval, NULL) == -1)
+ g_error("timerfd_settime failed: %s", g_strerror(errno));
+ }
+
static gboolean on_timerfd_cond (gint fd, GIOCondition cond G_GNUC_UNUSED, gpointer gself)
{
// let's see what triggered this event
@@ -127,6 +132,10 @@ private:
s, n_interrupts);
g_free(now_str);
g_date_time_unref(now);
+
+ // if we weren't triggered because of a timeout, then it may have
+ // happened due to time being set, so reset the timer
+ self->reset_timer();
self->refresh();
return G_SOURCE_CONTINUE;