]> sigrok.org Git - libsigrok.git/blobdiff - output/output.c
build: Portability fixes.
[libsigrok.git] / output / output.c
index 87cb86568ff346cc65481e1a818c59585a5a000e..4cf78f60a8b201d2ba6c60a9d6e50702d750ba5e 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
- * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
+ * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "sigrok.h"
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
 
-extern struct output_format output_text_binary;
-extern struct output_format output_text_hex;
+/**
+ * @file
+ *
+ * Output file/data format handling.
+ */
 
+/**
+ * @defgroup grp_output Output formats
+ *
+ * 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.
+ *
+ * @{
+ */
 
-struct output_format *output_module_list[] = {
-       &output_text_binary,
-       &output_text_hex,
-       NULL
-};
+/** @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_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_analog;
+/* @endcond */
 
+static struct sr_output_format *output_module_list[] = {
+       &output_ascii,
+       &output_binary,
+       &output_bits,
+       &output_csv,
+       &output_gnuplot,
+       &output_hex,
+       &output_ols,
+       &output_vcd,
+       &output_chronovu_la8,
+       &output_analog,
+       NULL,
+};
 
+/** @since 0.1.0 */
+SR_API struct sr_output_format **sr_output_list(void)
+{
+       return output_module_list;
+}
 
-struct output_format **output_list(void)
+/** @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;
 
-       return output_module_list;
+       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;
+}
 
+/** @} */