#include <inttypes.h>
#include <stdlib.h>
-
/* List of decoder instances. */
static GSList *di_list = NULL;
/* List of frontend callbacks to receive PD output. */
static GSList *callbacks = NULL;
-/* lives in decoder.c */
+/* decoder.c */
extern GSList *pd_list;
-/* lives in module_sigrokdecode.c */
+/* module_sigrokdecode.c */
extern PyMODINIT_FUNC PyInit_sigrokdecode(void);
-/* lives in type_logic.c */
+/* type_logic.c */
extern PyTypeObject srd_logic_type;
-
/**
* Initialize libsigrokdecode.
*
return SRD_OK;
}
-
/**
* Shutdown libsigrokdecode.
*
*/
int srd_exit(void)
{
-
srd_dbg("Exiting libsigrokdecode.");
srd_unload_all_decoders();
return SRD_OK;
}
-
/**
* Add an additional search directory for the protocol decoders.
*
return ret;
}
-
/**
* Set options in a decoder instance.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
int srd_instance_set_options(struct srd_decoder_instance *di,
- GHashTable *options)
+ GHashTable * options)
{
PyObject *py_dec_options, *py_dec_optkeys, *py_di_options, *py_optval;
PyObject *py_optlist, *py_classval;
int num_optkeys, ret, size, i;
char *key, *value;
- if(!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
+ if (!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
/* Decoder has no options. */
if (g_hash_table_size(options) == 0) {
/* No options provided. */
if (!(py_classval = PyList_GetItem(py_optlist, 1)))
goto err_out;
if (!PyUnicode_Check(py_classval) && !PyLong_Check(py_classval)) {
- srd_err("Options of type %s are not yet supported.", Py_TYPE(py_classval)->tp_name);
+ srd_err("Options of type %s are not yet supported.",
+ Py_TYPE(py_classval)->tp_name);
goto err_out;
}
if (!(py_optval = PyLong_FromString(value, NULL, 0))) {
/* ValueError Exception */
PyErr_Clear();
- srd_err("Option %s has invalid value %s: expected integer.",
- key, value);
+ srd_err("Option %s has invalid value "
+ "%s: expected integer.",
+ key, value);
goto err_out;
}
}
if (val_ull == (unsigned long long)-1) {
/* OverFlowError exception */
PyErr_Clear();
- srd_err("Invalid integer value for %s: expected integer.", key);
+ srd_err("Invalid integer value for %s: "
+ "expected integer.", key);
goto err_out;
}
if (!(py_optval = PyLong_FromUnsignedLongLong(val_ull)))
/* Helper GComparefunc for g_slist_find_custom() in srd_instance_set_probes() */
static gint compare_probe_id(struct srd_probe *a, char *probe_id)
{
-
return strcmp(a->id, probe_id);
}
*
* @param di Decoder instance.
* @param probes A GHashTable of probes to set. Key is probe name, value is
- * the probe number. Samples passed to this instance will be arranged in this
- * order.
- *
+ * the probe number. Samples passed to this instance will be
+ * arranged in this order.
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
int srd_instance_set_probes(struct srd_decoder_instance *di,
- GHashTable *new_probes)
+ GHashTable * new_probes)
{
GList *l;
GSList *sl;
char *probe_id, *probenum_str;
srd_dbg("set probes called for instance %s with list of %d probes",
- di->instance_id, g_hash_table_size(new_probes));
+ di->instance_id, g_hash_table_size(new_probes));
if (g_hash_table_size(new_probes) == 0)
/* No probes provided. */
return SRD_OK;
- if(di->dec_num_probes == 0) {
+ if (di->dec_num_probes == 0) {
/* Decoder has no probes. */
srd_err("Protocol decoder %s has no probes to define.",
- di->decoder->name);
+ di->decoder->name);
return SRD_ERR_ARG;
}
probenum_str = g_hash_table_lookup(new_probes, probe_id);
if (!probenum_str) {
/* Probe name was specified without a value. */
- srd_err("No probe number was specified for %s.", probe_id);
+ srd_err("No probe number was specified for %s.",
+ probe_id);
g_free(new_probemap);
return SRD_ERR_ARG;
}
(GCompareFunc)compare_probe_id))) {
/* Fall back on optional probes. */
if (!(sl = g_slist_find_custom(di->decoder->opt_probes,
- probe_id, (GCompareFunc)compare_probe_id))) {
- srd_err("Protocol decoder %s has no probe '%s'.",
- di->decoder->name, probe_id);
+ probe_id, (GCompareFunc) compare_probe_id))) {
+ srd_err("Protocol decoder %s has no probe "
+ "'%s'.", di->decoder->name, probe_id);
g_free(new_probemap);
return SRD_ERR_ARG;
}
}
p = sl->data;
new_probemap[p->order] = new_probenum;
- srd_dbg("setting probe mapping for %d = probe %d", p->order, new_probenum);
+ srd_dbg("setting probe mapping for %d = probe %d", p->order,
+ new_probenum);
}
g_free(di->dec_probemap);
di->dec_probemap = new_probemap;
*
* @param id Decoder 'id' field.
* @param options GHashtable of options which override the defaults set in
- * the decoder class.
+ * the decoder class.
* @return Pointer to a newly allocated struct srd_decoder_instance, or
- * NULL in case of failure.
+ * NULL in case of failure.
*/
struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
- GHashTable *options)
+ GHashTable *options)
{
+ int i;
struct srd_decoder *dec;
struct srd_decoder_instance *di;
- int i;
char *instance_id;
srd_dbg("Creating new %s instance.", decoder_id);
* order in which the decoder class defined them.
*/
di->dec_num_probes = g_slist_length(di->decoder->probes) +
- g_slist_length(di->decoder->opt_probes);
+ g_slist_length(di->decoder->opt_probes);
if (di->dec_num_probes) {
- if (!(di->dec_probemap = g_try_malloc(sizeof(int) * di->dec_num_probes))) {
+ if (!(di->dec_probemap =
+ g_try_malloc(sizeof(int) * di->dec_num_probes))) {
srd_err("Failed to malloc probe map.");
g_free(di);
return NULL;
/* Create a new instance of this decoder class. */
if (!(di->py_instance = PyObject_CallObject(dec->py_dec, NULL))) {
if (PyErr_Occurred())
- catch_exception("failed to create %s instance: ", decoder_id);
+ catch_exception("failed to create %s instance: ",
+ decoder_id);
g_free(di->dec_probemap);
g_free(di);
return NULL;
}
int srd_instance_stack(struct srd_decoder_instance *di_from,
- struct srd_decoder_instance *di_to)
+ struct srd_decoder_instance *di_to)
{
-
if (!di_from || !di_to) {
srd_err("Invalid from/to instance pair.");
return SRD_ERR_ARG;
* @return Pointer to struct srd_decoder_instance, or NULL if not found.
*/
struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
- PyObject *obj)
+ PyObject *obj)
{
GSList *l;
struct srd_decoder_instance *tmp, *di;
if (!(py_name = PyUnicode_FromString("start"))) {
srd_err("Unable to build python object for 'start'.");
- catch_exception("Protocol decoder instance %s: ", di->instance_id);
+ catch_exception("Protocol decoder instance %s: ",
+ di->instance_id);
return SRD_ERR_PYTHON;
}
if (!(py_res = PyObject_CallMethodObjArgs(di->py_instance,
- py_name, args, NULL))) {
- catch_exception("Protocol decoder instance %s: ", di->instance_id);
+ py_name, args, NULL))) {
+ catch_exception("Protocol decoder instance %s: ",
+ di->instance_id);
return SRD_ERR_PYTHON;
}
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
int srd_instance_decode(uint64_t start_samplenum,
- struct srd_decoder_instance *di, uint8_t *inbuf, uint64_t inbuflen)
+ struct srd_decoder_instance *di, uint8_t *inbuf,
+ uint64_t inbuflen)
{
PyObject *py_res;
srd_logic *logic;
Py_IncRef(di->py_instance);
end_samplenum = start_samplenum + inbuflen / di->data_unitsize;
if (!(py_res = PyObject_CallMethod(di->py_instance, "decode",
- "KKO", logic->start_samplenum, end_samplenum, logic))) {
- catch_exception("Protocol decoder instance %s: ", di->instance_id);
+ "KKO", logic->start_samplenum,
+ end_samplenum, logic))) {
+ catch_exception("Protocol decoder instance %s: ",
+ di->instance_id);
return SRD_ERR_PYTHON; /* TODO: More specific error? */
}
Py_DecRef(py_res);
g_free(pdo);
}
g_slist_free(di->pd_output);
-
}
void srd_instance_free_all(GSList *stack)
g_slist_free(di_list);
di_list = NULL;
}
-
}
int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
}
/* Feed logic samples to decoder session. */
-int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen)
+int srd_session_feed(uint64_t start_samplenum, uint8_t * inbuf,
+ uint64_t inbuflen)
{
GSList *d;
int ret;
srd_dbg("Calling decode() on all instances with starting sample "
- "number %"PRIu64", %"PRIu64" bytes at 0x%p", start_samplenum,
- inbuflen, inbuf);
+ "number %" PRIu64 ", %" PRIu64 " bytes at 0x%p",
+ start_samplenum, inbuflen, inbuf);
for (d = di_list; d; d = d->next) {
if ((ret = srd_instance_decode(start_samplenum, d->data, inbuf,
- inbuflen)) != SRD_OK)
+ inbuflen)) != SRD_OK)
return ret;
}
return cb;
}
-
/* This is the backend function to python sigrokdecode.add() call. */
int pd_add(struct srd_decoder_instance *di, int output_type, char *proto_id)
{
return pdo->pdo_id;
}
-
/* The list of protocol decoders. */
GSList *pd_list = NULL;
-/* lives in module_sigrokdecode.c */
+/* module_sigrokdecode.c */
extern PyObject *mod_sigrokdecode;
-
/**
* Returns the list of supported/loaded protocol decoders.
*
*/
GSList *srd_list_decoders(void)
{
-
return pd_list;
}
-
/**
* Get the decoder with the specified ID.
*
return NULL;
}
-
static int get_probes(struct srd_decoder *d, char *attr, GSList **pl)
{
PyObject *py_probelist, *py_entry;
py_probelist = PyObject_GetAttrString(d->py_dec, attr);
if (!PyList_Check(py_probelist)) {
srd_err("Protocol decoder %s %s attribute is not "
- "a list.", d->name, attr);
+ "a list.", d->name, attr);
goto err_out;
}
py_entry = PyList_GetItem(py_probelist, i);
if (!PyDict_Check(py_entry)) {
srd_err("Protocol decoder %s %s attribute is not "
- "a list with dict elements.", d->name, attr);
+ "a list with dict elements.", d->name, attr);
goto err_out;
}
if (!PyObject_IsSubclass(d->py_dec, py_basedec)) {
srd_err("Decoder class in protocol decoder module %s is not "
- "a subclass of sigrokdecode.Decoder.", name);
+ "a subclass of sigrokdecode.Decoder.", name);
goto err_out;
}
Py_CLEAR(py_basedec);
/* Check for a proper start() method. */
if (!PyObject_HasAttrString(d->py_dec, "start")) {
srd_err("Protocol decoder %s has no start() method Decoder "
- "class.", name);
+ "class.", name);
goto err_out;
}
py_method = PyObject_GetAttrString(d->py_dec, "start");
if (!PyFunction_Check(py_method)) {
srd_err("Protocol decoder %s Decoder class attribute 'start' "
- "is not a method.", name);
+ "is not a method.", name);
goto err_out;
}
Py_CLEAR(py_method);
/* Check for a proper decode() method. */
if (!PyObject_HasAttrString(d->py_dec, "decode")) {
srd_err("Protocol decoder %s has no decode() method Decoder "
- "class.", name);
+ "class.", name);
goto err_out;
}
py_method = PyObject_GetAttrString(d->py_dec, "decode");
if (!PyFunction_Check(py_method)) {
srd_err("Protocol decoder %s Decoder class attribute 'decode' "
- "is not a method.", name);
+ "is not a method.", name);
goto err_out;
}
Py_CLEAR(py_method);
py_attr = PyObject_GetAttrString(d->py_dec, "options");
if (!PyDict_Check(py_attr)) {
srd_err("Protocol decoder %s options attribute is not "
- "a dictionary.", d->name);
+ "a dictionary.", d->name);
Py_DecRef(py_attr);
goto err_out;
}
if (PyObject_HasAttrString(d->py_dec, "annotations")) {
py_annlist = PyObject_GetAttrString(d->py_dec, "annotations");
if (!PyList_Check(py_annlist)) {
- srd_err("Protocol decoder module %s annotations should be a list.", name);
+ srd_err("Protocol decoder module %s annotations "
+ "should be a list.", name);
goto err_out;
}
alen = PyList_Size(py_annlist);
for (i = 0; i < alen; i++) {
py_ann = PyList_GetItem(py_annlist, i);
if (!PyList_Check(py_ann) || PyList_Size(py_ann) != 2) {
- srd_err("Protocol decoder module %s annotation %d should "
- "be a list with two elements.", name, i+1);
+ srd_err("Protocol decoder module %s "
+ "annotation %d should be a list with "
+ "two elements.", name, i + 1);
goto err_out;
}
return doc;
}
-
static void free_probes(GSList *probelist)
{
GSList *l;
return SRD_OK;
}
-
-
-
#include <glib.h>
#include <frameobject.h> /* Python header not pulled in by default. */
-
void catch_exception(const char *format, ...)
{
PyObject *etype, *evalue, *etb, *py_str;
tracestr = NULL;
py_tb = (PyTracebackObject *) etb;
py_str = PyUnicode_FromFormat("%U:%d in %U",
- py_tb->tb_frame->f_code->co_filename, py_tb->tb_frame->f_lineno,
- py_tb->tb_frame->f_code->co_name);
+ py_tb->tb_frame->f_code->co_filename,
+ py_tb->tb_frame->f_lineno,
+ py_tb->tb_frame->f_code->co_name);
py_str_as_str(py_str, &tracestr);
Py_DecRef(py_str);
g_string_printf(msg, "%s in %s: %s", ename, tracestr, str);
/* Just in case. */
PyErr_Clear();
-
- return;
}
-
-
#include "sigrokdecode-internal.h"
#include "config.h"
-
-/* lives in type_decoder.c */
+/* type_decoder.c */
extern PyTypeObject srd_Decoder_type;
-/* lives in type_logic.c */
+/* type_logic.c */
extern PyTypeObject srd_logic_type;
-
-/* When initialized, a reference to this module inside the python interpreter
+/*
+ * When initialized, a reference to this module inside the python interpreter
* lives here.
*/
PyObject *mod_sigrokdecode = NULL;
.m_size = -1,
};
-
PyMODINIT_FUNC PyInit_sigrokdecode(void)
{
PyObject *mod;
mod = PyModule_Create(&sigrokdecode_module);
Py_INCREF(&srd_Decoder_type);
- if (PyModule_AddObject(mod, "Decoder", (PyObject *)&srd_Decoder_type) == -1)
+ if (PyModule_AddObject(mod, "Decoder",
+ (PyObject *)&srd_Decoder_type) == -1)
return NULL;
Py_INCREF(&srd_logic_type);
- if (PyModule_AddObject(mod, "srd_logic", (PyObject *)&srd_logic_type) == -1)
+ if (PyModule_AddObject(mod, "srd_logic",
+ (PyObject *)&srd_logic_type) == -1)
return NULL;
/* expose output types as symbols in the sigrokdecode module */
- if(PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
+ if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
return NULL;
- if(PyModule_AddIntConstant(mod, "OUTPUT_PROTO", SRD_OUTPUT_PROTO) == -1)
+ if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO",
+ SRD_OUTPUT_PROTO) == -1)
return NULL;
- if(PyModule_AddIntConstant(mod, "OUTPUT_BINARY", SRD_OUTPUT_BINARY) == -1)
+ if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY",
+ SRD_OUTPUT_BINARY) == -1)
return NULL;
mod_sigrokdecode = mod;
return mod;
}
-
#define SRD_LOG_DBG 4 /**< Output debug messages. */
#define SRD_LOG_SPEW 5 /**< Output very noisy debug messages. */
+/*
+ * When adding an output type, don't forget to...
+ * - expose it to PDs in controller.c:PyInit_sigrokdecode()
+ * - add a check in module_sigrokdecode.c:Decoder_put()
+ * - add a debug string in type_decoder.c:OUTPUT_TYPES
+ */
enum {
SRD_OUTPUT_ANN,
SRD_OUTPUT_PROTO,
SRD_OUTPUT_BINARY,
- /* When adding an output type, don't forget to...
- * - expose it to PDs in controller.c:PyInit_sigrokdecode()
- * - add a check in module_sigrokdecode.c:Decoder_put()
- * - add a debug string in type_decoder.c:OUTPUT_TYPES
- */
};
#define SRD_MAX_NUM_PROBES 64
/** Optional probes */
GSList *opt_probes;
- /* List of NULL-terminated char[], containing descriptions of the
+ /*
+ * List of NULL-terminated char[], containing descriptions of the
* supported annotation output.
*/
GSList *annotations;
void (*callback)(struct srd_proto_data *);
};
-
/* custom python types */
typedef struct {
PyObject_HEAD
PyObject *sample;
} srd_logic;
-
/*--- controller.c ----------------------------------------------------------*/
+
int srd_init(void);
int srd_exit(void);
int set_modulepath(void);
int srd_instance_set_options(struct srd_decoder_instance *di,
- GHashTable *options);
+ GHashTable *options);
int srd_instance_set_probes(struct srd_decoder_instance *di,
- GHashTable *probes);
+ GHashTable *probes);
struct srd_decoder_instance *srd_instance_new(const char *id,
- GHashTable *options);
+ GHashTable *options);
int srd_instance_stack(struct srd_decoder_instance *di_from,
- struct srd_decoder_instance *di_to);
+ struct srd_decoder_instance *di_to);
struct srd_decoder_instance *srd_instance_find_by_id(char *instance_id);
struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
- PyObject *obj);
+ PyObject *obj);
int srd_instance_start(struct srd_decoder_instance *di, PyObject *args);
int srd_instance_decode(uint64_t start_samplenum,
- struct srd_decoder_instance *dec, uint8_t *inbuf, uint64_t inbuflen);
+ struct srd_decoder_instance *dec,
+ uint8_t *inbuf, uint64_t inbuflen);
void srd_instance_free(struct srd_decoder_instance *di);
void srd_instance_free_all(GSList *stack);
int srd_session_start(int num_probes, int unitsize, uint64_t samplerate);
-int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen);
+int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf,
+ uint64_t inbuflen);
int pd_add(struct srd_decoder_instance *di, int output_type, char *output_id);
struct srd_decoder_instance *get_di_by_decobject(void *decobject);
typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata);
void *srd_find_callback(int output_type);
/*--- decoder.c -------------------------------------------------------------*/
+
GSList *srd_list_decoders(void);
struct srd_decoder *srd_get_decoder_by_id(const char *id);
int srd_load_decoder(const char *name, struct srd_decoder **dec);
char *srd_decoder_doc(struct srd_decoder *dec);
/*--- exception.c -----------------------------------------------------------*/
+
void catch_exception(const char *format, ...);
/*--- util.c ----------------------------------------------------------------*/
+
int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr);
int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr);
int py_str_as_str(PyObject *py_str, char **outstr);
int py_strlist_to_char(PyObject *py_strlist, char ***outstr);
/*--- log.c -----------------------------------------------------------------*/
+
typedef int (*srd_log_handler_t)(void *data, int loglevel, const char *format,
va_list args);
+
int srd_log_loglevel_set(int loglevel);
int srd_log_loglevel_get(void);
int srd_log_handler_set(srd_log_handler_t handler, void *data);
#include "config.h"
#include <inttypes.h>
-
/* This is only used for nicer srd_dbg() output. */
char *OUTPUT_TYPES[] = {
"OUTPUT_ANN",
"OUTPUT_BINARY",
};
-
static int convert_pyobj(struct srd_decoder_instance *di, PyObject *obj,
- int *ann_format, char ***ann)
+ int *ann_format, char ***ann)
{
PyObject *py_tmp;
struct srd_pd_output *pdo;
/* Should be a list of [annotation format, [string, ...]] */
if (!PyList_Check(obj) && !PyTuple_Check(obj)) {
srd_err("Protocol decoder %s submitted %s instead of list.",
- di->decoder->name, obj->ob_type->tp_name);
+ di->decoder->name, obj->ob_type->tp_name);
return SRD_ERR_PYTHON;
}
/* Should have 2 elements... */
if (PyList_Size(obj) != 2) {
- srd_err("Protocol decoder %s submitted annotation list with %d elements "
- "instead of 2", di->decoder->name, PyList_Size(obj));
+ srd_err("Protocol decoder %s submitted annotation list with "
+ "%d elements instead of 2", di->decoder->name,
+ PyList_Size(obj));
return SRD_ERR_PYTHON;
}
- /* First element should be an integer matching a previously
- * registered annotation format. */
+ /*
+ * The first element should be an integer matching a previously
+ * registered annotation format.
+ */
py_tmp = PyList_GetItem(obj, 0);
if (!PyLong_Check(py_tmp)) {
- srd_err("Protocol decoder %s submitted annotation list, but first "
- "element was not an integer.", di->decoder->name);
+ srd_err("Protocol decoder %s submitted annotation list, but "
+ "first element was not an integer.", di->decoder->name);
return SRD_ERR_PYTHON;
}
ann_id = PyLong_AsLong(py_tmp);
if (!(pdo = g_slist_nth_data(di->decoder->annotations, ann_id))) {
srd_err("Protocol decoder %s submitted data to unregistered "
- "annotation format %d.", di->decoder->name, ann_id);
+ "annotation format %d.", di->decoder->name, ann_id);
return SRD_ERR_PYTHON;
}
*ann_format = ann_id;
py_tmp = PyList_GetItem(obj, 1);
if (!PyList_Check(py_tmp)) {
srd_err("Protocol decoder %s submitted annotation list, but "
- "second element was not a list.", di->decoder->name);
+ "second element was not a list.", di->decoder->name);
return SRD_ERR_PYTHON;
}
if (py_strlist_to_char(py_tmp, ann) != SRD_OK) {
srd_err("Protocol decoder %s submitted annotation list, but "
- "second element was malformed.", di->decoder->name);
+ "second element was malformed.", di->decoder->name);
return SRD_ERR_PYTHON;
}
return NULL;
}
- if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample, &output_id, &data))
- /* This throws an exception, but by returning NULL here we let python
- * raise it. This results in a much better trace in controller.c
- * on the decode() method call. */
+ if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample,
+ &output_id, &data)) {
+ /*
+ * This throws an exception, but by returning NULL here we let
+ * Python raise it. This results in a much better trace in
+ * controller.c on the decode() method call.
+ */
return NULL;
+ }
if (!(l = g_slist_nth(di->pd_output, output_id))) {
srd_err("Protocol decoder %s submitted invalid output ID %d.",
- di->decoder->name, output_id);
+ di->decoder->name, output_id);
return NULL;
}
pdo = l->data;
if ((cb = srd_find_callback(pdo->output_type))) {
/* Annotations need converting from PyObject. */
if (convert_pyobj(di, data, &pdata->ann_format,
- (char ***)&pdata->data) != SRD_OK) {
+ (char ***)&pdata->data) != SRD_OK) {
/* An error was already logged. */
break;
}
/* TODO: is this needed? */
Py_XINCREF(next_di->py_instance);
srd_spew("Sending %d-%d to instance %s",
- start_sample, end_sample, next_di->instance_id);
- if (!(py_res = PyObject_CallMethod(next_di->py_instance, "decode",
- "KKO", start_sample, end_sample, data))) {
- catch_exception("calling %s decode(): ", next_di->instance_id);
+ start_sample, end_sample,
+ next_di->instance_id);
+ if (!(py_res = PyObject_CallMethod(
+ next_di->py_instance, "decode", "KKO", start_sample,
+ end_sample, data))) {
+ catch_exception("calling %s decode(): ",
+ next_di->instance_id);
}
Py_XDECREF(py_res);
}
break;
default:
srd_err("Protocol decoder %s submitted invalid output type %d.",
- di->decoder->name, pdo->output_type);
+ di->decoder->name, pdo->output_type);
break;
}
Py_RETURN_NONE;
}
-
static PyObject *Decoder_add(PyObject *self, PyObject *args)
{
PyObject *ret;
{NULL, NULL, 0, NULL}
};
-
PyTypeObject srd_Decoder_type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "sigrokdecode.Decoder",
.tp_doc = "Sigrok Decoder base class",
.tp_methods = Decoder_methods,
};
-
#include <inttypes.h>
#include <string.h>
-
PyObject *srd_logic_iter(PyObject *self)
{
-
return self;
}
PyObject *srd_logic_iternext(PyObject *self)
{
+ int i;
PyObject *py_samplenum, *py_samples;
srd_logic *logic;
uint64_t sample;
- int i;
unsigned char probe_samples[SRD_MAX_NUM_PROBES];
- logic = (srd_logic *) self;
+ logic = (srd_logic *)self;
if (logic->itercnt >= logic->inbuflen / logic->di->data_unitsize) {
/* End iteration loop. */
return NULL;
}
- /* Convert the bit-packed sample to an array of bytes, with only 0x01
+ /*
+ * Convert the bit-packed sample to an array of bytes, with only 0x01
* and 0x00 values, so the PD doesn't need to do any bitshifting.
*/
- memcpy(&sample, logic->inbuf + logic->itercnt * logic->di->data_unitsize,
- logic->di->data_unitsize);
+ memcpy(&sample,
+ logic->inbuf + logic->itercnt * logic->di->data_unitsize,
+ logic->di->data_unitsize);
for (i = 0; i < logic->di->dec_num_probes; i++)
- probe_samples[i] = sample & (1 << logic->di->dec_probemap[i]) ? 1 : 0;
+ probe_samples[i] =
+ sample & (1 << logic->di->dec_probemap[i]) ? 1 : 0;
/* Prepare the next samplenum/sample list in this iteration. */
- py_samplenum = PyLong_FromUnsignedLongLong(logic->start_samplenum + logic->itercnt);
+ py_samplenum =
+ PyLong_FromUnsignedLongLong(logic->start_samplenum +
+ logic->itercnt);
PyList_SetItem(logic->sample, 0, py_samplenum);
py_samples = PyBytes_FromStringAndSize((const char *)probe_samples,
- logic->di->dec_num_probes);
+ logic->di->dec_num_probes);
PyList_SetItem(logic->sample, 1, py_samples);
Py_INCREF(logic->sample);
logic->itercnt++;
.tp_iter = srd_logic_iter,
.tp_iternext = srd_logic_iternext,
};
-
#include "sigrokdecode-internal.h"
#include "config.h"
-
/**
* Get the value of a python object's attribute, returned as a newly
* allocated char *.
return ret;
}
-
/**
* Get the value of a python dictionary item, returned as a newly
* allocated char *.
int ret;
if (!PyDict_Check(py_obj)) {
- srd_dbg("Object is a %s, not a dictionary.", Py_TYPE(py_obj)->tp_name);
+ srd_dbg("Object is a %s, not a dictionary.",
+ Py_TYPE(py_obj)->tp_name);
return SRD_ERR_PYTHON;
}
}
if (!PyUnicode_Check(py_value)) {
- srd_dbg("Dictionary value for %s should be a string, but is a %s.",
- key, Py_TYPE(py_value)->tp_name);
+ srd_dbg("Dictionary value for %s should be a string, but is "
+ "a %s.", key, Py_TYPE(py_value)->tp_name);
return SRD_ERR_PYTHON;
}
return SRD_OK;
}
-
/**
* Get the value of a python unicode string object, returned as a newly
* allocated char *.
ret = SRD_OK;
if (!PyUnicode_Check(py_str)) {
- srd_dbg("Object is a %s, not a string object.", Py_TYPE(py_str)->tp_name);
+ srd_dbg("Object is a %s, not a string object.",
+ Py_TYPE(py_str)->tp_name);
ret = SRD_ERR_PYTHON;
goto err_out;
}
return ret;
}
-
/**
* Convert a python list of unicode strings to a NULL-terminated UTF8-encoded
* char * array. The caller must free each string when finished.
return SRD_ERR_MALLOC;
for (i = 0; i < list_len; i++) {
if (!(py_str = PyUnicode_AsEncodedString(
- PyList_GetItem(py_strlist, i), "utf-8", NULL)))
+ PyList_GetItem(py_strlist, i), "utf-8", NULL)))
return SRD_ERR_PYTHON;
if (!(str = PyBytes_AS_STRING(py_str)))
return SRD_ERR_PYTHON;
return SRD_OK;
}
-