Code

main: move LIRC GIOChannel setup to lirc.c
authorMax Kellermann <max.kellermann@gmail.com>
Sun, 19 Mar 2017 09:50:09 +0000 (10:50 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Sun, 19 Mar 2017 09:50:09 +0000 (10:50 +0100)
src/lirc.c
src/lirc.h
src/main.c

index 86447408276a9f68be6f3145d3f6dfc3912a3ad3..58b2cd7b0138afaf0f7d606d06730b3504394a33 100644 (file)
 
 #include <lirc/lirc_client.h>
 
-static struct lirc_config *lc = NULL;
-
-int ncmpc_lirc_open()
-{
-       char prog[] = "ncmpc";
-       int lirc_socket = 0;
-
-       if ((lirc_socket = lirc_init(prog, 0)) == -1)
-               return -1;
-
-       if (lirc_readconfig(NULL, &lc, NULL)) {
-               lirc_deinit();
-               return -1;
-       }
-
-       return lirc_socket;
-}
+#include <glib.h>
 
-void ncmpc_lirc_close()
-{
-       if (lc)
-               lirc_freeconfig(lc);
-       lirc_deinit();
-}
+static struct lirc_config *lc = NULL;
 
-gboolean
+static gboolean
 lirc_event(gcc_unused GIOChannel *source,
           gcc_unused GIOCondition condition, gcc_unused gpointer data)
 {
@@ -68,3 +47,29 @@ lirc_event(gcc_unused GIOChannel *source,
        end_input_event();
        return TRUE;
 }
+
+void
+ncmpc_lirc_open()
+{
+       char prog[] = "ncmpc";
+       int lirc_socket = 0;
+
+       if ((lirc_socket = lirc_init(prog, 0)) == -1)
+               return;
+
+       if (lirc_readconfig(NULL, &lc, NULL)) {
+               lirc_deinit();
+               return;
+       }
+
+       GIOChannel *channel = g_io_channel_unix_new(lirc_socket);
+       g_io_add_watch(channel, G_IO_IN, lirc_event, NULL);
+       g_io_channel_unref(channel);
+}
+
+void ncmpc_lirc_close()
+{
+       if (lc)
+               lirc_freeconfig(lc);
+       lirc_deinit();
+}
index 0c7955c0d8078eae5de516b137b75c422e7a152f..1d7650b559c4cd0518d717926f531d01125607e9 100644 (file)
 #ifndef LIRC_H
 #define LIRC_H
 
-#include "command.h"
-#include <glib.h>
-
-int ncmpc_lirc_open(void);
+void
+ncmpc_lirc_open(void);
 void ncmpc_lirc_close(void);
 
-gboolean
-lirc_event(GIOChannel *source, GIOCondition condition, gpointer data);
-
 #endif
index c20dd6d2a127134908764096ff42028f5cdcf725..fd6cd7be5ae9363f443beb0a031a24c1761029d5 100644 (file)
@@ -555,12 +555,7 @@ main(int argc, const char *argv[])
 
 #ifdef ENABLE_LIRC
        /* watch out for lirc input */
-       int lirc_socket = ncmpc_lirc_open();
-       if (lirc_socket >= 0) {
-               GIOChannel *lirc_channel = g_io_channel_unix_new(lirc_socket);
-               g_io_add_watch(lirc_channel, G_IO_IN, lirc_event, NULL);
-               g_io_channel_unref(lirc_channel);
-       }
+       ncmpc_lirc_open();
 #endif
 
 #ifndef WIN32