]> sigrok.org Git - sigrok-cli.git/blobdiff - anykey.c
Fix output module enumeration + code cleanup.
[sigrok-cli.git] / anykey.c
index f0ab52efe6548a9654822781670acd4ab80d046d..4126518e8a0801dc3700bdc3c0e86582668b47fd 100644 (file)
--- a/anykey.c
+++ b/anykey.c
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the sigrok-cli project.
  *
  * Copyright (C) 2011 Bert Vermeulen <bert@biot.com>
  *
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "sigrok-cli.h"
 #include <stdio.h>
 #ifdef _WIN32
 #include <windows.h>
@@ -26,8 +27,6 @@
 #include <unistd.h>
 #include <string.h>
 #include <glib.h>
-#include <sigrok.h>
-#include "sigrok-cli.h"
 
 #ifdef _WIN32
 static HANDLE stdin_handle;
@@ -36,20 +35,21 @@ static DWORD stdin_mode;
 static struct termios term_orig;
 #endif
 
-static int received_anykey(int fd, int revents, void *user_data)
+static int received_anykey(int fd, int revents, void *cb_data)
 {
-       /* Avoid compiler warnings. */
+       struct sr_session *session;
        (void)fd;
        (void)revents;
-       (void)user_data;
 
-       sr_session_stop();
+       session = cb_data;
+       sr_session_source_remove(session, STDIN_FILENO);
+       sr_session_stop(session);
 
        return TRUE;
 }
 
 /* Turn off buffering on stdin. */
-void add_anykey(void)
+void add_anykey(struct sr_session *session)
 {
 #ifdef _WIN32
        stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
@@ -68,9 +68,10 @@ void add_anykey(void)
        tcsetattr(STDIN_FILENO, TCSADRAIN, &term);
 #endif
 
-       sr_session_source_add(STDIN_FILENO, G_IO_IN, -1, received_anykey, NULL);
+       sr_session_source_add(session, STDIN_FILENO, G_IO_IN, -1,
+                       received_anykey, session);
 
-       printf("Press any key to stop acquisition.\n");
+       g_message("Press any key to stop acquisition.");
 }
 
 /* Restore stdin attributes. */