X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Foutput.c;h=941678ec8d2185887b10cd429fcbb7582c8996c2;hb=768579456c7800e462a404c2c28af1e306989fd8;hp=d726ad934819f09829444b3f4036de781a5d75bb;hpb=393fb9cb18c5746d8567c9cf74b872804043345a;p=libsigrok.git diff --git a/output/output.c b/output/output.c index d726ad93..941678ec 100644 --- a/output/output.c +++ b/output/output.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2010-2012 Bert Vermeulen * @@ -31,37 +31,45 @@ * * Output file/data format handling. * + * libsigrok supports several output (file) formats, e.g. binary, VCD, + * gnuplot, and so on. It provides an output API that frontends can use. + * New output formats can be added/implemented in libsigrok without having + * to change the frontends at all. + * + * All output modules are fed data in a stream. Devices that can stream data + * into libsigrok, instead of storing and then transferring the whole buffer, + * can thus generate output live. + * + * Output modules generate a newly allocated GString. The caller is then + * expected to free this with g_string_free() when finished with it. + * * @{ */ /** @cond PRIVATE */ -extern SR_PRIV struct sr_output_format output_text_bits; -extern SR_PRIV struct sr_output_format output_text_hex; -extern SR_PRIV struct sr_output_format output_text_ascii; +extern SR_PRIV struct sr_output_format output_bits; +extern SR_PRIV struct sr_output_format output_hex; +extern SR_PRIV struct sr_output_format output_ascii; extern SR_PRIV struct sr_output_format output_binary; extern SR_PRIV struct sr_output_format output_vcd; extern SR_PRIV struct sr_output_format output_ols; extern SR_PRIV struct sr_output_format output_gnuplot; extern SR_PRIV struct sr_output_format output_chronovu_la8; extern SR_PRIV struct sr_output_format output_csv; -extern SR_PRIV struct sr_output_format output_float; extern SR_PRIV struct sr_output_format output_analog; -/* extern SR_PRIV struct sr_output_format output_analog_gnuplot; */ /* @endcond */ static struct sr_output_format *output_module_list[] = { - &output_text_bits, - &output_text_hex, - &output_text_ascii, + &output_ascii, &output_binary, - &output_vcd, - &output_ols, + &output_bits, + &output_csv, &output_gnuplot, + &output_hex, + &output_ols, + &output_vcd, &output_chronovu_la8, - &output_csv, - &output_float, &output_analog, - /* &output_analog_gnuplot, */ NULL, }; @@ -70,4 +78,40 @@ SR_API struct sr_output_format **sr_output_list(void) return output_module_list; } +SR_API struct sr_output *sr_output_new(struct sr_output_format *of, + GHashTable *params, const struct sr_dev_inst *sdi) +{ + struct sr_output *o; + + o = g_malloc(sizeof(struct sr_output)); + o->format = of; + o->sdi = sdi; + o->params = params; + if (o->format->init && o->format->init(o) != SR_OK) { + g_free(o); + o = NULL; + } + + return o; +} + +SR_API int sr_output_send(struct sr_output *o, + const struct sr_datafeed_packet *packet, GString **out) +{ + return o->format->receive(o, packet, out); +} + +SR_API int sr_output_free(struct sr_output *o) +{ + int ret; + + ret = SR_OK; + if (o->format->cleanup) + ret = o->format->cleanup(o); + g_free(o); + + return ret; +} + + /** @} */