From b96ba1beb969e7116881137d326967b48044845b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 5 Feb 2014 08:36:31 -0600 Subject: bugfix: when closing the snap decision, ensure there's not a timeout waiting to loop the ringtone --- src/snap.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/snap.cpp') diff --git a/src/snap.cpp b/src/snap.cpp index a64f358..0d548b8 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -48,6 +48,7 @@ namespace const int32_t alarm_ca_id = 1; ca_context *c_context = nullptr; +guint timeout_tag = 0; ca_context* get_ca_context() { @@ -80,6 +81,7 @@ void play_alarm_sound(); gboolean play_alarm_sound_idle (gpointer) { + timeout_tag = 0; play_alarm_sound(); return G_SOURCE_REMOVE; } @@ -87,8 +89,8 @@ gboolean play_alarm_sound_idle (gpointer) void on_alarm_play_done (ca_context* /*context*/, uint32_t /*id*/, int rv, void* /*user_data*/) { // wait one second, then play it again - if (rv == CA_SUCCESS) - g_timeout_add_seconds (1, play_alarm_sound_idle, nullptr); + if ((rv == CA_SUCCESS) && (timeout_tag == 0)) + timeout_tag = g_timeout_add_seconds (1, play_alarm_sound_idle, nullptr); } void play_alarm_sound() @@ -118,6 +120,12 @@ void stop_alarm_sound() if (rv != CA_SUCCESS) g_warning("Failed to cancel alarm sound: %s", ca_strerror(rv)); } + + if (timeout_tag != 0) + { + g_source_remove(timeout_tag); + timeout_tag = 0; + } } /** -- cgit v1.2.3