]> sigrok.org Git - sigrok-cli.git/blobdiff - input.c
Fix output module enumeration + code cleanup.
[sigrok-cli.git] / input.c
diff --git a/input.c b/input.c
index 7ef694d4bad2e9a3a429d4debc68fe593d698cdc..c62c96406917a74e424a4de7e054625bee5894c3 100644 (file)
--- a/input.c
+++ b/input.c
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "sigrok-cli.h"
 #include "config.h"
 #include "config.h"
+#include <sys/stat.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
 #include <glib.h>
 #include <glib.h>
-#include <libsigrok/libsigrok.h>
-#include "sigrok-cli.h"
-
-extern gchar *opt_input_file;
-extern gchar *opt_input_format;
-extern gchar *opt_probes;
-
 
 /**
  * Return the input file format which the CLI tool should use.
 
 /**
  * Return the input file format which the CLI tool should use.
@@ -90,6 +88,7 @@ static void load_input_file_format(void)
 {
        GHashTable *fmtargs = NULL;
        struct stat st;
 {
        GHashTable *fmtargs = NULL;
        struct stat st;
+       struct sr_session *session;
        struct sr_input *in;
        struct sr_input_format *input_format;
        char *fmtspec = NULL;
        struct sr_input *in;
        struct sr_input_format *input_format;
        char *fmtspec = NULL;
@@ -128,20 +127,20 @@ static void load_input_file_format(void)
                }
        }
 
                }
        }
 
-       if (select_probes(in->sdi) > 0)
+       if (select_channels(in->sdi) != SR_OK)
                return;
 
                return;
 
-       sr_session_new();
-       sr_session_datafeed_callback_add(datafeed_in, NULL);
-       if (sr_session_dev_add(in->sdi) != SR_OK) {
+       sr_session_new(&session);
+       sr_session_datafeed_callback_add(session, &datafeed_in, NULL);
+       if (sr_session_dev_add(session, in->sdi) != SR_OK) {
                g_critical("Failed to use device.");
                g_critical("Failed to use device.");
-               sr_session_destroy();
+               sr_session_destroy(session);
                return;
        }
 
        input_format->loadfile(in, opt_input_file);
 
                return;
        }
 
        input_format->loadfile(in, opt_input_file);
 
-       sr_session_destroy();
+       sr_session_destroy(session);
 
        if (fmtargs)
                g_hash_table_destroy(fmtargs);
 
        if (fmtargs)
                g_hash_table_destroy(fmtargs);
@@ -149,17 +148,31 @@ static void load_input_file_format(void)
 
 void load_input_file(void)
 {
 
 void load_input_file(void)
 {
+       GSList *devices;
+       struct sr_session *session;
+       struct sr_dev_inst *sdi;
+       int ret;
 
 
-       if (sr_session_load(opt_input_file) == SR_OK) {
+       if (sr_session_load(opt_input_file, &session) == SR_OK) {
                /* sigrok session file */
                /* sigrok session file */
-               sr_session_datafeed_callback_add(datafeed_in, NULL);
-               sr_session_start();
-               sr_session_run();
-               sr_session_stop();
+               ret = sr_session_dev_list(session, &devices);
+               if (ret != SR_OK || !devices->data) {
+                       g_critical("Failed to access session device.");
+                       sr_session_destroy(session);
+                       return;
+               }
+               sdi = devices->data;
+               if (select_channels(sdi) != SR_OK) {
+                       sr_session_destroy(session);
+                       return;
+               }
+               sr_session_datafeed_callback_add(session, datafeed_in, NULL);
+               sr_session_start(session);
+               sr_session_run(session);
+               sr_session_stop(session);
        }
        else {
                /* fall back on input modules */
                load_input_file_format();
        }
 }
        }
        else {
                /* fall back on input modules */
                load_input_file_format();
        }
 }
-