]> sigrok.org Git - libsigrokdecode.git/blobdiff - sigrokdecode.h
sr/srd: Small fixes, constifications, doc updates.
[libsigrokdecode.git] / sigrokdecode.h
index 69fc2ce72304675d69a8c19f443694c16418a800..3f2d3c987e36511e5db8de71c19233a90867b667 100644 (file)
@@ -94,23 +94,26 @@ enum {
        SRD_OUTPUT_BINARY,
 };
 
-#define SRD_MAX_NUM_PROBES   64
+#define SRD_MAX_NUM_PROBES 64
 
 /* TODO: Documentation. */
 struct srd_decoder {
        /** The decoder ID. Must be non-NULL and unique for all decoders. */
        char *id;
 
-       /** The (short) decoder name. */
+       /** The (short) decoder name. Must be non-NULL. */
        char *name;
 
        /** The (long) decoder name. May be NULL. */
        char *longname;
 
-       /** A (short, one-line) description of the decoder. */
+       /** A (short, one-line) description of the decoder. Must be non-NULL. */
        char *desc;
 
-       /** The license of the decoder. Valid values: "gplv2+", "gplv3+". */
+       /**
+        * The license of the decoder. Valid values: "gplv2+", "gplv3+".
+        * Other values are currently not allowed. Must be non-NULL.
+        */
        char *license;
 
        /** TODO */
@@ -119,36 +122,44 @@ struct srd_decoder {
        /** TODO */
        GSList *outputformats;
 
-       /** Probes */
+       /** List of probes required by this decoder. */
        GSList *probes;
 
-       /** Optional probes */
+       /** List of optional probes for this decoder. */
        GSList *opt_probes;
 
-       /*
+       /**
         * List of NULL-terminated char[], containing descriptions of the
         * supported annotation output.
         */
        GSList *annotations;
 
-       /** Python module */
+       /** Python module. */
        PyObject *py_mod;
 
-       /** sigrokdecode.Decoder class */
+       /** sigrokdecode.Decoder class. */
        PyObject *py_dec;
 };
 
+/**
+ * Structure which contains information about one protocol decoder probe.
+ * For example, I2C has two probes, SDA and SCL.
+ */
 struct srd_probe {
+       /** The ID of the probe. Must be non-NULL. */
        char *id;
+       /** The name of the probe. Must not be NULL. */
        char *name;
+       /** The description of the probe. Must not be NULL. */
        char *desc;
+       /** The index of the probe, i.e. its order in the list of probes. */
        int order;
 };
 
-struct srd_decoder_instance {
+struct srd_decoder_inst {
        struct srd_decoder *decoder;
-       PyObject *py_instance;
-       char *instance_id;
+       PyObject *py_inst;
+       char *inst_id;
        GSList *pd_output;
        int dec_num_probes;
        int *dec_probemap;
@@ -161,7 +172,7 @@ struct srd_decoder_instance {
 struct srd_pd_output {
        int pdo_id;
        int output_type;
-       struct srd_decoder_instance *di;
+       struct srd_decoder_inst *di;
        char *proto_id;
 };
 
@@ -173,19 +184,24 @@ struct srd_proto_data {
        void *data;
 };
 
+typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata,
+                                        void *cb_data);
+
 struct srd_pd_callback {
        int output_type;
-       void (*callback)(struct srd_proto_data *);
+       srd_pd_output_callback_t cb;
+       void *cb_data;
 };
 
-/* custom python types */
+/* Custom Python types: */
+
 typedef struct {
        PyObject_HEAD
 } srd_Decoder;
 
 typedef struct {
        PyObject_HEAD
-       struct srd_decoder_instance *di;
+       struct srd_decoder_inst *di;
        uint64_t start_samplenum;
        unsigned int itercnt;
        uint8_t *inbuf;
@@ -195,67 +211,43 @@ typedef struct {
 
 /*--- controller.c ----------------------------------------------------------*/
 
-SRD_API int srd_init(void);
+SRD_API int srd_init(const char *path);
 SRD_API int srd_exit(void);
-SRD_API int set_modulepath(void);
-SRD_API int srd_instance_set_options(struct srd_decoder_instance *di,
-                                    GHashTable *options);
-SRD_API int srd_instance_set_probes(struct srd_decoder_instance *di,
-                                   GHashTable *probes);
-SRD_API struct srd_decoder_instance *srd_instance_new(const char *id,
-                                                     GHashTable *options);
-SRD_API int srd_instance_stack(struct srd_decoder_instance *di_from,
-                              struct srd_decoder_instance *di_to);
-SRD_API struct srd_decoder_instance *srd_instance_find_by_id(char *instance_id);
-SRD_API struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
-                                                             PyObject *obj);
-SRD_API int srd_instance_start(struct srd_decoder_instance *di, PyObject *args);
-SRD_API int srd_instance_decode(uint64_t start_samplenum,
-                               struct srd_decoder_instance *dec,
-                               uint8_t *inbuf, uint64_t inbuflen);
-SRD_API void srd_instance_free(struct srd_decoder_instance *di);
-SRD_API void srd_instance_free_all(GSList *stack);
+SRD_API int srd_inst_options_set(struct srd_decoder_inst *di,
+                                GHashTable *options);
+SRD_API int srd_inst_probes_set(struct srd_decoder_inst *di,
+                               GHashTable *probes);
+SRD_API struct srd_decoder_inst *srd_inst_new(const char *id,
+                                             GHashTable *options);
+SRD_API int srd_inst_stack(struct srd_decoder_inst *di_from,
+                          struct srd_decoder_inst *di_to);
+SRD_API struct srd_decoder_inst *srd_inst_find_by_id(const char *inst_id);
 SRD_API int srd_session_start(int num_probes, int unitsize,
                              uint64_t samplerate);
-SRD_API int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf,
+SRD_API int srd_session_send(uint64_t start_samplenum, const uint8_t *inbuf,
                             uint64_t inbuflen);
-SRD_PRIV int pd_add(struct srd_decoder_instance *di, int output_type,
-                   char *output_id);
-SRD_API struct srd_decoder_instance *get_di_by_decobject(void *decobject);
-typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata);
-SRD_API int srd_register_callback(int output_type, srd_pd_output_callback_t cb);
-SRD_API void *srd_find_callback(int output_type);
+SRD_API int srd_register_callback(int output_type,
+                                 srd_pd_output_callback_t cb, void *cb_data);
 
 /*--- decoder.c -------------------------------------------------------------*/
 
-SRD_API GSList *srd_list_decoders(void);
-SRD_API struct srd_decoder *srd_get_decoder_by_id(const char *id);
-SRD_API int srd_load_decoder(const char *name, struct srd_decoder **dec);
-SRD_API int srd_unload_decoder(struct srd_decoder *dec);
-SRD_API int srd_load_all_decoders(void);
-SRD_API int srd_unload_all_decoders(void);
-SRD_API char *srd_decoder_doc(struct srd_decoder *dec);
-
-/*--- exception.c -----------------------------------------------------------*/
-
-SRD_PRIV void catch_exception(const char *format, ...);
-
-/*--- util.c ----------------------------------------------------------------*/
-
-SRD_PRIV int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr);
-SRD_PRIV int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr);
-SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr);
-SRD_PRIV int py_strlist_to_char(PyObject *py_strlist, char ***outstr);
+SRD_API GSList *srd_decoder_list(void);
+SRD_API struct srd_decoder *srd_decoder_get_by_id(const char *id);
+SRD_API int srd_decoder_load(const char *name);
+SRD_API int srd_decoder_unload(struct srd_decoder *dec);
+SRD_API int srd_decoder_load_all(void);
+SRD_API int srd_decoder_unload_all(void);
+SRD_API char *srd_decoder_doc(const struct srd_decoder *dec);
 
 /*--- log.c -----------------------------------------------------------------*/
 
-typedef int (*srd_log_handler_t)(void *data, int loglevel, const char *format,
-                                va_list args);
+typedef int (*srd_log_callback_t)(void *cb_data, int loglevel,
+                                 const char *format, va_list args);
 
 SRD_API int srd_log_loglevel_set(int loglevel);
 SRD_API int srd_log_loglevel_get(void);
-SRD_API int srd_log_handler_set(srd_log_handler_t handler, void *data);
-SRD_API int srd_log_handler_set_default(void);
+SRD_API int srd_log_callback_set(srd_log_callback_t cb, void *cb_data);
+SRD_API int srd_log_callback_set_default(void);
 SRD_API int srd_log_logdomain_set(const char *logdomain);
 SRD_API char *srd_log_logdomain_get(void);