Remove obsolete output API.

This commit is contained in:
Bert Vermeulen 2014-04-19 13:28:17 +02:00
parent 6f64ebb223
commit 44559b2c3b
12 changed files with 5 additions and 391 deletions

View File

@ -59,8 +59,6 @@ libsigrok_la_SOURCES += \
output/csv.c \
output/analog.c \
output/output.c \
output/text/text.c \
output/text/text.h \
output/hex.c \
output/ascii.c

View File

@ -280,26 +280,14 @@ static int sanity_check_all_output_modules(void)
errors++;
}
if (!outputs[i]->description) {
sr_err("No description in module %d ('%s').", i, d);
sr_err("No description in module '%s'.", d);
errors++;
}
if (outputs[i]->df_type < 10000 || outputs[i]->df_type > 10007) {
sr_err("Invalid df_type %d in module %d ('%s').",
outputs[i]->df_type, i, d);
if (!outputs[i]->receive) {
sr_err("No receive in module '%s'.", d);
errors++;
}
/* All modules must provide a data or recv API callback. */
if (!outputs[i]->data && !outputs[i]->receive) {
sr_err("No data/receive in module %d ('%s').", i, d);
errors++;
}
/*
* Currently most API calls are optional (their function
* pointers can thus be NULL) in theory: init, event, cleanup.
*/
if (errors == 0)
continue;

View File

@ -479,9 +479,6 @@ struct sr_output_format {
*/
char *description;
/** Datafeed type, SR_DF_HEADER, etc. */
int df_type;
/**
* This function is called once, at the beginning of an output stream.
*
@ -499,72 +496,6 @@ struct sr_output_format {
*/
int (*init) (struct sr_output *o);
/**
* Whenever a chunk of data comes in, it will be passed to the
* output module via this function. The <code>data_in</code> and
* <code>length_in</code> values refers to this data; the module
* must not alter or g_free() this buffer.
*
* The function must allocate a buffer for storing its output, and
* pass along a pointer to this buffer in the <code>data_out</code>
* parameter, as well as storing the length of the buffer in
* <code>length_out</code>. The calling frontend will g_free()
* this buffer when it's done with it.
*
* IMPORTANT: The memory allocation much happen using a glib memory
* allocation call (not a "normal" malloc) since g_free() will be
* used to free the memory!
*
* If there is no output, this function MUST store NULL in the
* <code>data_out</code> parameter, so the caller knows not to try
* and g_free() it.
*
* Note: This API call is obsolete, use receive() instead.
*
* @param o Pointer to the respective 'struct sr_output'.
* @param data_in Pointer to the input data buffer.
* @param length_in Length of the input.
* @param data_out Pointer to the allocated output buffer.
* @param length_out Length (in bytes) of the output.
*
* @retval SR_OK Success
* @retval other Negative error code.
*/
int (*data) (struct sr_output *o, const uint8_t *data_in,
uint64_t length_in, uint8_t **data_out,
uint64_t *length_out);
/**
* This function is called when an event occurs in the datafeed
* which the output module may need to be aware of. No data is
* passed in, only the fact that the event occurs. The following
* events can currently be passed in:
*
* - SR_DF_TRIGGER: At this point in the datafeed, the trigger
* matched. The output module may mark this in some way, e.g. by
* plotting a red line on a graph.
*
* - SR_DF_END: This marks the end of the datafeed. No more calls
* into the output module will be done, so this is a good time to
* free up any memory used to keep state, for example.
*
* Any output generated by this function must have a reference to
* it stored in the <code>data_out</code> and <code>length_out</code>
* parameters, or NULL if no output was generated.
*
* Note: This API call is obsolete, use receive() instead.
*
* @param o Pointer to the respective 'struct sr_output'.
* @param event_type Type of event that occured.
* @param data_out Pointer to the allocated output buffer.
* @param length_out Length (in bytes) of the output.
*
* @retval SR_OK Success
* @retval other Negative error code.
*/
int (*event) (struct sr_output *o, int event_type, uint8_t **data_out,
uint64_t *length_out);
/**
* This function is passed a copy of every packed in the data feed.
* Any output generated by the output module in response to the

View File

@ -264,7 +264,6 @@ static int cleanup(struct sr_output *o)
SR_PRIV struct sr_output_format output_analog = {
.id = "analog",
.description = "Analog data",
.df_type = SR_DF_ANALOG,
.init = init,
.receive = receive,
.cleanup = cleanup

View File

@ -46,7 +46,6 @@ static int receive(struct sr_output *o, const struct sr_dev_inst *sdi,
SR_PRIV struct sr_output_format output_binary = {
.id = "binary",
.description = "Raw binary",
.df_type = SR_DF_LOGIC,
.init = NULL,
.receive = receive,
};

View File

@ -2,6 +2,7 @@
* This file is part of the libsigrok project.
*
* Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2014 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
@ -14,8 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
@ -186,7 +186,6 @@ static int cleanup(struct sr_output *o)
SR_PRIV struct sr_output_format output_chronovu_la8 = {
.id = "chronovu-la8",
.description = "ChronoVu LA8",
.df_type = SR_DF_LOGIC,
.init = init,
.receive = receive,
.cleanup = cleanup,

View File

@ -190,7 +190,6 @@ static int cleanup(struct sr_output *o)
SR_PRIV struct sr_output_format output_csv = {
.id = "csv",
.description = "Comma-separated values (CSV)",
.df_type = SR_DF_LOGIC,
.init = init,
.receive = receive,
.cleanup = cleanup,

View File

@ -218,7 +218,6 @@ static int cleanup(struct sr_output *o)
SR_PRIV struct sr_output_format output_gnuplot = {
.id = "gnuplot",
.description = "Gnuplot",
.df_type = SR_DF_LOGIC,
.init = init,
.receive = receive,
.cleanup = cleanup,

View File

@ -151,7 +151,6 @@ static int cleanup(struct sr_output *o)
SR_PRIV struct sr_output_format output_ols = {
.id = "ols",
.description = "OpenBench Logic Sniffer",
.df_type = SR_DF_LOGIC,
.init = init,
.receive = receive,
.cleanup = cleanup

View File

@ -1,226 +0,0 @@
/*
* This file is part of the libsigrok project.
*
* Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
* Copyright (C) 2011 Håvard Espeland <gus@ping.uio.no>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "config.h" /* Needed for PACKAGE_STRING and others. */
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "text.h"
#define LOG_PREFIX "output/text"
SR_PRIV void flush_linebufs(struct context *ctx, uint8_t *outbuf)
{
static int max_channelname_len = 0;
int len, i;
GSList *l;
char *channel_name;
if (ctx->linebuf[0] == 0)
return;
if (max_channelname_len == 0) {
/* First time through... */
for (l = ctx->channelnames; l; l = l->next) {
channel_name = l->data;
len = strlen(channel_name);
if (len > max_channelname_len)
max_channelname_len = len;
}
}
for (i = 0, l = ctx->channelnames; l; l = l->next, i++) {
channel_name = l->data;
sprintf((char *)outbuf + strlen((const char *)outbuf),
"%*s:%s\n", max_channelname_len,
channel_name, ctx->linebuf + i * ctx->linebuf_len);
}
/* Mark trigger with a ^ character. */
if (ctx->mark_trigger != -1)
{
int space_offset = ctx->mark_trigger / 8;
if (ctx->mode == MODE_ASCII)
space_offset = 0;
sprintf((char *)outbuf + strlen((const char *)outbuf),
"T:%*s^\n", ctx->mark_trigger + space_offset, "");
}
memset(ctx->linebuf, 0, i * ctx->linebuf_len);
}
SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
{
struct context *ctx;
struct sr_channel *ch;
GSList *l;
GVariant *gvar;
uint64_t samplerate;
int num_channels, ret;
char *samplerate_s;
if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
sr_err("%s: ctx malloc failed", __func__);
return SR_ERR_MALLOC;
}
o->internal = ctx;
ctx->num_enabled_channels = 0;
ctx->channelnames = NULL;
for (l = o->sdi->channels; l; l = l->next) {
ch = l->data;
if (ch->type != SR_CHANNEL_LOGIC)
continue;
if (!ch->enabled)
continue;
ctx->channelnames = g_slist_append(ctx->channelnames, ch->name);
ctx->num_enabled_channels++;
}
ctx->unitsize = (ctx->num_enabled_channels + 7) / 8;
ctx->line_offset = 0;
ctx->spl_cnt = 0;
ctx->mark_trigger = -1;
ctx->mode = mode;
ret = SR_OK;
if (o->param && o->param[0]) {
ctx->samples_per_line = strtoul(o->param, NULL, 10);
if (ctx->samples_per_line < 1) {
ret = SR_ERR;
goto err;
}
} else
ctx->samples_per_line = default_spl;
if (!(ctx->header = g_try_malloc0(512))) {
sr_err("%s: ctx->header malloc failed", __func__);
ret = SR_ERR_MALLOC;
goto err;
}
snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING);
num_channels = g_slist_length(o->sdi->channels);
if (sr_config_get(o->sdi->driver, o->sdi, NULL, SR_CONF_SAMPLERATE,
&gvar) == SR_OK) {
samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
if (!(samplerate_s = sr_samplerate_string(samplerate))) {
ret = SR_ERR;
goto err;
}
snprintf(ctx->header + strlen(ctx->header),
511 - strlen(ctx->header),
"Acquisition with %d/%d channels at %s\n",
ctx->num_enabled_channels, num_channels, samplerate_s);
g_free(samplerate_s);
}
ctx->linebuf_len = ctx->samples_per_line * 2 + 4;
if (!(ctx->linebuf = g_try_malloc0(num_channels * ctx->linebuf_len))) {
sr_err("%s: ctx->linebuf malloc failed", __func__);
ret = SR_ERR_MALLOC;
goto err;
}
if (!(ctx->linevalues = g_try_malloc0(num_channels))) {
sr_err("%s: ctx->linevalues malloc failed", __func__);
ret = SR_ERR_MALLOC;
}
if (mode == MODE_ASCII &&
!(ctx->prevsample = g_try_malloc0(num_channels / 8))) {
sr_err("%s: ctx->prevsample malloc failed", __func__);
ret = SR_ERR_MALLOC;
}
err:
if (ret != SR_OK) {
g_free(ctx->header);
g_free(ctx);
}
return ret;
}
SR_PRIV int text_cleanup(struct sr_output *o)
{
struct context *ctx;
if (!o)
return SR_ERR_ARG;
ctx = o->internal;
g_free(ctx->header);
g_free(ctx->linebuf);
g_free(ctx->linevalues);
if (ctx->prevsample)
g_free(ctx->prevsample);
g_slist_free(ctx->channelnames);
g_free(ctx);
o->internal = NULL;
return SR_OK;
}
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
uint64_t *length_out)
{
struct context *ctx;
int outsize;
uint8_t *outbuf;
ctx = o->internal;
switch (event_type) {
case SR_DF_TRIGGER:
ctx->mark_trigger = ctx->spl_cnt;
*data_out = NULL;
*length_out = 0;
break;
case SR_DF_END:
outsize = ctx->num_enabled_channels
* (ctx->samples_per_line + 20) + 512;
if (!(outbuf = g_try_malloc0(outsize))) {
sr_err("%s: outbuf malloc failed", __func__);
return SR_ERR_MALLOC;
}
flush_linebufs(ctx, outbuf);
*data_out = outbuf;
*length_out = strlen((const char *)outbuf);
break;
default:
*data_out = NULL;
*length_out = 0;
break;
}
return SR_OK;
}

View File

@ -1,70 +0,0 @@
/*
* This file is part of the libsigrok project.
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBSIGROK_OUTPUT_TEXT_TEXT_H
#define LIBSIGROK_OUTPUT_TEXT_TEXT_H
#define DEFAULT_BPL_BITS 64
#define DEFAULT_BPL_HEX 192
#define DEFAULT_BPL_ASCII 74
enum outputmode {
MODE_BITS = 1,
MODE_HEX,
MODE_ASCII,
};
struct context {
unsigned int num_enabled_channels;
int samples_per_line;
unsigned int unitsize;
int line_offset;
int linebuf_len;
GSList *channelnames;
uint8_t *linebuf;
int spl_cnt;
uint8_t *linevalues;
char *header;
int mark_trigger;
uint8_t *prevsample;
enum outputmode mode;
};
SR_PRIV void flush_linebufs(struct context *ctx, uint8_t *outbuf);
SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode);
SR_PRIV int text_cleanup(struct sr_output *o);
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
uint64_t *length_out);
SR_PRIV int init_bits(struct sr_output *o);
SR_PRIV int data_bits(struct sr_output *o, const uint8_t *data_in,
uint64_t length_in, uint8_t **data_out,
uint64_t *length_out);
SR_PRIV int init_hex(struct sr_output *o);
SR_PRIV int data_hex(struct sr_output *o, const uint8_t *data_in,
uint64_t length_in, uint8_t **data_out,
uint64_t *length_out);
SR_PRIV int init_ascii(struct sr_output *o);
SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in,
uint64_t length_in, uint8_t **data_out,
uint64_t *length_out);
#endif

View File

@ -243,7 +243,6 @@ static int cleanup(struct sr_output *o)
struct sr_output_format output_vcd = {
.id = "vcd",
.description = "Value Change Dump (VCD)",
.df_type = SR_DF_LOGIC,
.init = init,
.receive = receive,
.cleanup = cleanup,