summaryrefslogtreecommitdiff
path: root/fmrx-ctl.c
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-12-31 17:50:06 +0100
committerJavier S. Pedro <maemo@javispedro.com>2011-12-31 17:50:06 +0100
commit352dad23c7847d234e11c1034e1354fbd9a8349a (patch)
tree6caab2315dcb20882a05453412788578acc119e5 /fmrx-ctl.c
downloadfmrxd-352dad23c7847d234e11c1034e1354fbd9a8349a.tar.gz
fmrxd-352dad23c7847d234e11c1034e1354fbd9a8349a.zip
initial import
Diffstat (limited to 'fmrx-ctl.c')
-rw-r--r--fmrx-ctl.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/fmrx-ctl.c b/fmrx-ctl.c
new file mode 100644
index 0000000..408dadd
--- /dev/null
+++ b/fmrx-ctl.c
@@ -0,0 +1,115 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+static GMainLoop *main_loop;
+static DBusConnection *bus;
+
+static gdouble cmd_tune = 0.0;
+static gboolean cmd_next = FALSE;
+static gboolean cmd_prev = FALSE;
+
+static GOptionEntry entries[] = {
+ { "tune", 't', 0, G_OPTION_ARG_DOUBLE, &cmd_tune, "Tune to a specific frequency", "MHz" },
+ { "next", 'n', 0, G_OPTION_ARG_NONE, &cmd_next, "Forward scan for a signal", NULL },
+ { "prev", 'p', 0, G_OPTION_ARG_NONE, &cmd_prev, "Backward scan for a signal", NULL },
+ { NULL }
+};
+
+#define BUS_NAME "com.javispedro.fmrxd"
+#define BUS_PATH "/com/javispedro/fmrxd"
+#define BUS_INTERFACE BUS_NAME
+
+static void tune(double f)
+{
+ DBusError err;
+ DBusMessage *reply;
+ DBusMessage *msg = dbus_message_new_method_call(BUS_NAME, BUS_PATH,
+ BUS_INTERFACE, "Tune");
+ g_assert(msg != NULL);
+
+ dbus_error_init(&err);
+
+ dbus_message_append_args(msg, DBUS_TYPE_DOUBLE, &f, DBUS_TYPE_INVALID);
+
+ reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &err);
+ g_assert(reply != NULL);
+ g_assert(!dbus_error_is_set(&err));
+ dbus_message_unref(msg);
+
+ dbus_message_unref(reply);
+}
+
+static void next()
+{
+ DBusError err;
+ DBusMessage *reply;
+ DBusMessage *msg = dbus_message_new_method_call(BUS_NAME, BUS_PATH,
+ BUS_INTERFACE, "SearchForward");
+ g_assert(msg != NULL);
+
+ dbus_error_init(&err);
+
+ reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &err);
+ g_assert(reply != NULL);
+ g_assert(!dbus_error_is_set(&err));
+ dbus_message_unref(msg);
+
+ dbus_message_unref(reply);
+}
+
+static void prev()
+{
+ DBusError err;
+ DBusMessage *reply;
+ DBusMessage *msg = dbus_message_new_method_call(BUS_NAME, BUS_PATH,
+ BUS_INTERFACE, "SearchBackward");
+ g_assert(msg != NULL);
+
+ dbus_error_init(&err);
+
+ reply = dbus_connection_send_with_reply_and_block(bus, msg, -1, &err);
+ g_assert(reply != NULL);
+ g_assert(!dbus_error_is_set(&err));
+ dbus_message_unref(msg);
+
+ dbus_message_unref(reply);
+}
+
+static void dbus_init()
+{
+ DBusError err; dbus_error_init(&err);
+ bus = dbus_bus_get(DBUS_BUS_SESSION, &err);
+ g_assert(bus != NULL);
+ g_assert(!dbus_error_is_set(&err));
+ dbus_connection_setup_with_g_main(bus, g_main_loop_get_context(main_loop));
+}
+
+int main(int argc, char **argv)
+{
+ GError *error = NULL;
+ GOptionContext *context = g_option_context_new("- control the fmrxd daemon");
+ main_loop = g_main_loop_new(NULL, FALSE);
+
+ g_option_context_add_main_entries(context, entries, NULL);
+ if (!g_option_context_parse(context, &argc, &argv, &error)) {
+ g_printerr("Option parsing failed: %s\n", error->message);
+ return 1;
+ }
+
+ dbus_init();
+
+ if (cmd_tune > 0.0) {
+ tune(cmd_tune);
+ }
+ if (cmd_prev) {
+ prev();
+ }
+ if (cmd_next) {
+ next();
+ }
+
+ return 0;
+}