+ break;
+ }
+
+ if (o && o->format->recv) {
+ out = o->format->recv(o, sdi, packet);
+ if (out && out->len) {
+ fwrite(out->str, 1, out->len, outfile);
+ fflush(outfile);
+ }
+ }
+
+ /* SR_DF_END needs to be handled after the output module's recv()
+ * is called, so it can properly clean up that module etc. */
+ if (packet->type == SR_DF_END) {
+ g_debug("cli: Received SR_DF_END");
+
+ if (o->format->event) {
+ o->format->event(o, SR_DF_END, &output_buf, &output_len);
+ if (output_buf) {
+ if (outfile)
+ fwrite(output_buf, 1, output_len, outfile);
+ g_free(output_buf);
+ output_len = 0;
+ }
+ }
+
+ if (limit_samples && received_samples < limit_samples)
+ g_warning("Device only sent %" PRIu64 " samples.",
+ received_samples);
+
+ if (opt_continuous)
+ g_warning("Device stopped after %" PRIu64 " samples.",
+ received_samples);
+
+ g_array_free(logic_probelist, TRUE);
+
+ if (o->format->cleanup)
+ o->format->cleanup(o);
+ g_free(o);
+ o = NULL;
+
+ if (outfile && outfile != stdout)
+ fclose(outfile);
+
+ if (opt_output_file && default_output_format) {
+ if (sr_session_save(opt_output_file, sdi, savebuf->data,
+ unitsize, savebuf->len / unitsize) != SR_OK)
+ g_critical("Failed to save session.");
+ g_byte_array_free(savebuf, FALSE);
+ }
+ }
+
+}
+
+#ifdef HAVE_SRD
+static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash,
+ GHashTable **options)
+{
+ struct srd_decoder_option *o;
+ GSList *optl;
+ GVariant *gvar;
+ gint64 val_int;
+ int ret;
+ char *val_str, *conv;
+
+ ret = TRUE;
+ *options = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify)g_variant_unref);
+
+ for (optl = dec->options; optl; optl = optl->next) {
+ o = optl->data;
+ if (!(val_str = g_hash_table_lookup(hash, o->id)))
+ /* Not specified. */
+ continue;
+ if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_STRING)) {
+ gvar = g_variant_new_string(val_str);
+ } else if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_INT64)) {
+ val_int = strtoll(val_str, &conv, 10);
+ if (!conv || conv == val_str) {
+ g_critical("Protocol decoder '%s' option '%s' "
+ "requires a number.", dec->name, o->id);
+ ret = FALSE;
+ break;
+ }
+ gvar = g_variant_new_int64(val_int);
+ } else {
+ g_critical("Unsupported type for option '%s' (%s)",
+ o->id, g_variant_get_type_string(o->def));
+ ret = FALSE;
+ break;
+ }
+ g_variant_ref_sink(gvar);
+ g_hash_table_insert(*options, g_strdup(o->id), gvar);
+ g_hash_table_remove(hash, o->id);