*
* Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
*
* Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
-#include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
-#include "sigrokdecode-internal.h"
+#include "libsigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include "libsigrokdecode-internal.h"
/**
* Initialize libsigrokdecode.
*
* This initializes the Python interpreter, and creates and initializes
* a "sigrokdecode" Python module.
*
/**
* Initialize libsigrokdecode.
*
* This initializes the Python interpreter, and creates and initializes
* a "sigrokdecode" Python module.
*
- * Then, it searches for sigrok protocol decoder files (*.py) in the
- * "decoders" subdirectory of the the sigrok installation directory.
+ * Then, it searches for sigrok protocol decoders in the "decoders"
+ * subdirectory of the the libsigrokdecode installation directory.
*
* The caller is responsible for calling the clean-up function srd_exit(),
* which will properly shut down libsigrokdecode and free its allocated memory.
*
* The caller is responsible for calling the clean-up function srd_exit(),
* which will properly shut down libsigrokdecode and free its allocated memory.
- * Upon Python errors, return SRD_ERR_PYTHON. If the sigrok decoders
- * directory cannot be accessed, return SRD_ERR_DECODERS_DIR.
- * If not enough memory could be allocated, return SRD_ERR_MALLOC.
+ * Upon Python errors, SRD_ERR_PYTHON is returned. If the decoders
+ * directory cannot be accessed, SRD_ERR_DECODERS_DIR is returned.
+ * If not enough memory could be allocated, SRD_ERR_MALLOC is returned.
+ *
+ * @since 0.1.0
* any successful srd_init() calls in between, is not allowed.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* any successful srd_init() calls in between, is not allowed.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* be added to the Python sys.path, or NULL.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* be added to the Python sys.path, or NULL.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
srd_dbg("Adding '%s' to module path.", path);
new_path = g_string_sized_new(256);
srd_dbg("Adding '%s' to module path.", path);
new_path = g_string_sized_new(256);
py_item = PyList_GetItem(py_cur_path, i);
if (!PyUnicode_Check(py_item))
/* Shouldn't happen. */
py_item = PyList_GetItem(py_cur_path, i);
if (!PyUnicode_Check(py_item))
/* Shouldn't happen. */
if (py_str_as_str(py_item, &item) != SRD_OK)
continue;
g_string_append(new_path, item);
if (py_str_as_str(py_item, &item) != SRD_OK)
continue;
g_string_append(new_path, item);
* @param options A GHashTable of options to set.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param options A GHashTable of options to set.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
{
PyObject *py_dec_options, *py_dec_optkeys, *py_di_options, *py_optval;
PyObject *py_optlist, *py_classval;
Py_UNICODE *py_ustr;
{
PyObject *py_dec_options, *py_dec_optkeys, *py_di_options, *py_optval;
PyObject *py_optlist, *py_classval;
Py_UNICODE *py_ustr;
int num_optkeys, ret, size, i;
int num_optkeys, ret, size, i;
if (!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
/* Decoder has no options. */
if (!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
/* Decoder has no options. */
- if (!(py_optval = PyUnicode_FromString(value))) {
+ if (!g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ srd_err("Option '%s' requires a string value.", key);
+ goto err_out;
+ }
+ val_str = g_variant_get_string(value, NULL);
+ if (!(py_optval = PyUnicode_FromString(val_str))) {
- if (!(py_optval = PyLong_FromString(value, NULL, 0))) {
+ if (!g_variant_is_of_type(value, G_VARIANT_TYPE_INT64)) {
+ srd_err("Option '%s' requires an integer value.", key);
+ goto err_out;
+ }
+ val_int = g_variant_get_int64(value);
+ if (!(py_optval = PyLong_FromLong(val_int))) {
* arranged in this order.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* arranged in this order.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
int i, num_required_probes;
srd_dbg("set probes called for instance %s with list of %d probes",
int i, num_required_probes;
srd_dbg("set probes called for instance %s with list of %d probes",
- probenum_str = g_hash_table_lookup(new_probes, probe_id);
- if (!probenum_str) {
+ probe_val= g_hash_table_lookup(new_probes, probe_id);
+ if (!g_variant_is_of_type(probe_val, G_VARIANT_TYPE_INT32)) {
/* Probe name was specified without a value. */
srd_err("No probe number was specified for %s.",
/* Probe name was specified without a value. */
srd_err("No probe number was specified for %s.",
if (!(sl = g_slist_find_custom(di->decoder->probes, probe_id,
(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 "
if (!(sl = g_slist_find_custom(di->decoder->probes, probe_id,
(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 "
*
* @return Pointer to a newly allocated struct srd_decoder_inst, or
* NULL in case of failure.
*
* @return Pointer to a newly allocated struct srd_decoder_inst, or
* NULL in case of failure.
* @param di_to The instance on top of which di_from will be stacked.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param di_to The instance on top of which di_from will be stacked.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param inst_id The instance ID to be found.
*
* @return Pointer to struct srd_decoder_inst, or NULL if not found.
* @param inst_id The instance ID to be found.
*
* @return Pointer to struct srd_decoder_inst, or NULL if not found.
* @param obj The Python class instantiation.
*
* @return Pointer to struct srd_decoder_inst, or NULL if not found.
* @param obj The Python class instantiation.
*
* @return Pointer to struct srd_decoder_inst, or NULL if not found.
SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di, PyObject *args)
{
PyObject *py_name, *py_res;
SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di, PyObject *args)
{
PyObject *py_name, *py_res;
* @param inbuflen Length of the buffer. Must be > 0.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param inbuflen Length of the buffer. Must be > 0.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
- const struct srd_decoder_inst *di,
- const uint8_t *inbuf, uint64_t inbuflen)
+ const struct srd_decoder_inst *di, const uint8_t *inbuf,
+ uint64_t inbuflen)
end_samplenum, logic))) {
srd_exception_catch("Protocol decoder instance %s: ",
di->inst_id);
end_samplenum, logic))) {
srd_exception_catch("Protocol decoder instance %s: ",
di->inst_id);
* @param samplerate The samplerate of the incoming feed.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param samplerate The samplerate of the incoming feed.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param inbuflen Length in bytes of the buffer.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* @param inbuflen Length in bytes of the buffer.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
* callback per output type can be registered.
* @param cb The function to call. Must not be NULL.
* @param cb_data Private data for the callback function. Can be NULL.
* callback per output type can be registered.
* @param cb The function to call. Must not be NULL.
* @param cb_data Private data for the callback function. Can be NULL.
SRD_PRIV int srd_inst_pd_output_add(struct srd_decoder_inst *di,
int output_type, const char *proto_id)
{
SRD_PRIV int srd_inst_pd_output_add(struct srd_decoder_inst *di,
int output_type, const char *proto_id)
{