]> sigrok.org Git - libsigrokdecode.git/blobdiff - libsigrokdecode.h.in
Drop obsolete report() method.
[libsigrokdecode.git] / libsigrokdecode.h.in
index 877aeb15401d45e8f44e12f0098647fa16bb7963..a654373c570048e6a944ac110eb6e73085e27059 100644 (file)
@@ -30,6 +30,8 @@
 extern "C" {
 #endif
 
+struct srd_session;
+
 /**
  * @file
  *
@@ -79,11 +81,9 @@ extern "C" {
 #define SRD_LIB_VERSION_STRING "@SRD_LIB_VERSION@"
 
 /*
- * Status/error codes returned by libsigrokdecode functions.
- *
  * All possible return codes of libsigrokdecode functions must be listed here.
  * Functions should never return hardcoded numbers as status, but rather
- * use these #defines instead. All error codes are negative numbers.
+ * use these enum values. All error codes are negative numbers.
  *
  * The error codes are globally unique in libsigrokdecode, i.e. if one of the
  * libsigrokdecode functions returns a "malloc error" it must be exactly the
@@ -92,24 +92,35 @@ extern "C" {
  * same return code.
  *
  * Also, for compatibility reasons, no defined return codes are ever removed
- * or reused for different #defines later. You can only add new #defines and
+ * or reused for different errors later. You can only add new entries and
  * return codes, but never remove or redefine existing ones.
  */
-#define SRD_OK                 0 /**< No error */
-#define SRD_ERR               -1 /**< Generic/unspecified error */
-#define SRD_ERR_MALLOC        -2 /**< Malloc/calloc/realloc error */
-#define SRD_ERR_ARG           -3 /**< Function argument error */
-#define SRD_ERR_BUG           -4 /**< Errors hinting at internal bugs */
-#define SRD_ERR_PYTHON        -5 /**< Python C API error */
-#define SRD_ERR_DECODERS_DIR  -6 /**< Protocol decoder path invalid */
+
+/** Status/error codes returned by libsigrokdecode functions. */
+enum {
+       SRD_OK               =  0, /**< No error */
+       SRD_ERR              = -1, /**< Generic/unspecified error */
+       SRD_ERR_MALLOC       = -2, /**< Malloc/calloc/realloc error */
+       SRD_ERR_ARG          = -3, /**< Function argument error */
+       SRD_ERR_BUG          = -4, /**< Errors hinting at internal bugs */
+       SRD_ERR_PYTHON       = -5, /**< Python C API error */
+       SRD_ERR_DECODERS_DIR = -6, /**< Protocol decoder path invalid */
+
+       /*
+        * Note: When adding entries here, don't forget to also update the
+        * srd_strerror() and srd_strerror_name() functions in error.c.
+        */
+};
 
 /* libsigrokdecode loglevels. */
-#define SRD_LOG_NONE   0 /**< Output no messages at all. */
-#define SRD_LOG_ERR    1 /**< Output error messages. */
-#define SRD_LOG_WARN   2 /**< Output warnings. */
-#define SRD_LOG_INFO   3 /**< Output informational messages. */
-#define SRD_LOG_DBG    4 /**< Output debug messages. */
-#define SRD_LOG_SPEW   5 /**< Output very noisy debug messages. */
+enum {
+       SRD_LOG_NONE = 0, /**< Output no messages at all. */
+       SRD_LOG_ERR  = 1, /**< Output error messages. */
+       SRD_LOG_WARN = 2, /**< Output warnings. */
+       SRD_LOG_INFO = 3, /**< Output informational messages. */
+       SRD_LOG_DBG  = 4, /**< Output debug messages. */
+       SRD_LOG_SPEW = 5, /**< Output very noisy debug messages. */
+};
 
 /*
  * Use SRD_API to mark public API symbols, and SRD_PRIV for private symbols.
@@ -149,12 +160,17 @@ extern "C" {
  */
 enum {
        SRD_OUTPUT_ANN,
-       SRD_OUTPUT_PROTO,
+       SRD_OUTPUT_PYTHON,
        SRD_OUTPUT_BINARY,
+       SRD_OUTPUT_META,
 };
 
 #define SRD_MAX_NUM_PROBES 64
 
+enum {
+       SRD_CONF_SAMPLERATE = 10000,
+};
+
 struct srd_decoder {
        /** The decoder ID. Must be non-NULL and unique for all decoders. */
        char *id;
@@ -219,14 +235,13 @@ struct srd_decoder_option {
 
 struct srd_decoder_inst {
        struct srd_decoder *decoder;
+       struct srd_session *sess;
        PyObject *py_inst;
        char *inst_id;
        GSList *pd_output;
        int dec_num_probes;
        int *dec_probemap;
-       int data_num_probes;
        int data_unitsize;
-       uint64_t data_samplerate;
        GSList *next_di;
 };
 
@@ -235,15 +250,22 @@ struct srd_pd_output {
        int output_type;
        struct srd_decoder_inst *di;
        char *proto_id;
+       /* Only used for OUTPUT_META. */
+       const GVariantType *meta_type;
+       char *meta_name;
+       char *meta_descr;
 };
 
 struct srd_proto_data {
        uint64_t start_sample;
        uint64_t end_sample;
        struct srd_pd_output *pdo;
-       int ann_format;
        void *data;
 };
+struct srd_proto_data_annotation {
+       int ann_format;
+       char **ann_text;
+};
 
 typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata,
                                         void *cb_data);
@@ -278,16 +300,22 @@ SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
                GHashTable *options);
 SRD_API int srd_inst_probe_set_all(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_send(uint64_t start_samplenum, const uint8_t *inbuf,
-               uint64_t inbuflen);
-SRD_API int srd_pd_output_callback_add(int output_type,
-               srd_pd_output_callback_t cb, void *cb_data);
+SRD_API struct srd_decoder_inst *srd_inst_new(struct srd_session *sess,
+               const char *id, GHashTable *options);
+SRD_API int srd_inst_stack(struct srd_session *sess,
+               struct srd_decoder_inst *di_from, struct srd_decoder_inst *di_to);
+SRD_API struct srd_decoder_inst *srd_inst_find_by_id(struct srd_session *sess,
+               const char *inst_id);
+SRD_API int srd_session_new(struct srd_session **sess);
+SRD_API int srd_session_start(struct srd_session *sess);
+SRD_API int srd_session_metadata_set(struct srd_session *sess, int key,
+               GVariant *data);
+SRD_API int srd_session_send(struct srd_session *sess,
+               uint64_t start_samplenum, uint64_t end_samplenum,
+               const uint8_t *inbuf, uint64_t inbuflen);
+SRD_API int srd_session_destroy(struct srd_session *sess);
+SRD_API int srd_pd_output_callback_add(struct srd_session *sess,
+               int output_type, srd_pd_output_callback_t cb, void *cb_data);
 
 /*--- decoder.c -------------------------------------------------------------*/
 
@@ -323,6 +351,11 @@ SRD_API int srd_lib_version_revision_get(void);
 SRD_API int srd_lib_version_age_get(void);
 SRD_API const char *srd_lib_version_string_get(void);
 
+/*--- error.c ---------------------------------------------------------------*/
+
+SRD_API const char *srd_strerror(int error_code);
+SRD_API const char *srd_strerror_name(int error_code);
+
 #ifdef __cplusplus
 }
 #endif