summaryrefslogtreecommitdiff
path: root/radio.c
diff options
context:
space:
mode:
Diffstat (limited to 'radio.c')
-rw-r--r--radio.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/radio.c b/radio.c
new file mode 100644
index 0000000..bc0d5ea
--- /dev/null
+++ b/radio.c
@@ -0,0 +1,97 @@
+/*
+ * fmrxd - a daemon to enable and multiplex access to the N950/N9 radio tuner
+ * Copyright (C) 2011 Javier S. Pedro <maemo@javispedro.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <glib.h>
+#include "fmrxd.h"
+
+static guint start_source_id = 0;
+static guint stop_source_id = 0;
+static bool active = false;
+
+bool radio_active()
+{
+ return active;
+}
+
+void radio_start()
+{
+ g_return_if_fail(!active);
+ g_debug("Starting radio");
+
+ configure_bt_muxer(true);
+ configure_mixer(true);
+ configure_tuner(true);
+ configure_capture(true);
+ configure_rds(true);
+
+ active = true;
+}
+
+void radio_stop()
+{
+ g_return_if_fail(active);
+ g_debug("Stopping radio");
+
+ configure_rds(false);
+ configure_capture(false);
+ configure_tuner(false);
+ configure_mixer(false);
+ configure_bt_muxer(false);
+
+ server_notify_stopped();
+
+ active = false;
+}
+
+static gboolean radio_start_func(gpointer data)
+{
+ radio_start();
+ start_source_id = 0;
+ return FALSE;
+}
+
+static gboolean radio_stop_func(gpointer data)
+{
+ radio_stop();
+ stop_source_id = 0;
+ return FALSE;
+}
+
+void radio_queue_start()
+{
+ if (stop_source_id) {
+ /* If there was a queued stop pending, remove it. */
+ g_source_remove(stop_source_id);
+ }
+ if (!start_source_id) {
+ start_source_id = g_idle_add(radio_start_func, NULL);
+ }
+}
+
+void radio_queue_stop()
+{
+ if (start_source_id) {
+ /* If there is a queued start, remove it. */
+ g_source_remove(start_source_id);
+ }
+ if (!stop_source_id) {
+ stop_source_id = g_timeout_add_seconds(RADIO_LINGER_TIME,
+ radio_stop_func, NULL);
+ }
+}