X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=output%2Foutput.c;h=4cf78f60a8b201d2ba6c60a9d6e50702d750ba5e;hp=76ff758bfea7e0a09d60694267c793fd052c26bc;hb=43cd4637285833706f8a404ca027bcf0ee75b9ae;hpb=8d3af2e868c4fcfb0119ec74c541fb5d04a10fce diff --git a/output/output.c b/output/output.c index 76ff758b..4cf78f60 100644 --- a/output/output.c +++ b/output/output.c @@ -37,13 +37,11 @@ * to change the frontends at all. * * All output modules are fed data in a stream. Devices that can stream data - * into libsigrok live, instead of storing and then transferring the whole - * buffer, can thus generate output live. + * into libsigrok, instead of storing and then transferring the whole buffer, + * can thus generate output live. * - * Output modules are responsible for allocating enough memory to store - * their own output, and passing a pointer to that memory (and length) of - * the allocated memory back to the caller. The caller is then expected to - * free this memory when finished with it. + * Output modules generate a newly allocated GString. The caller is then + * expected to free this with g_string_free() when finished with it. * * @{ */ @@ -51,7 +49,7 @@ /** @cond PRIVATE */ 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_text_ascii; +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; @@ -59,27 +57,64 @@ 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_analog; -/* extern SR_PRIV struct sr_output_format output_analog_gnuplot; */ /* @endcond */ static struct sr_output_format *output_module_list[] = { + &output_ascii, + &output_binary, &output_bits, + &output_csv, + &output_gnuplot, &output_hex, - &output_text_ascii, - &output_binary, - &output_vcd, &output_ols, - &output_gnuplot, + &output_vcd, &output_chronovu_la8, - &output_csv, &output_analog, - /* &output_analog_gnuplot, */ NULL, }; +/** @since 0.1.0 */ SR_API struct sr_output_format **sr_output_list(void) { return output_module_list; } +/** @since 0.3.0 */ +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; +} + +/** @since 0.3.0 */ +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); +} + +/** @since 0.3.0 */ +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; +} + /** @} */