X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=sigrokdecode.h;h=ae4ec81650b6c89c87d977f8ea19e7e87ea66152;hp=a7ea910bb5aa7c28ae972bbdc8d137496d4ada25;hb=65e1c7d091956e42aa4d97d7b639e10076e6f8ff;hpb=41106a07486f46de5dac2fd55233691172d4fe59 diff --git a/sigrokdecode.h b/sigrokdecode.h index a7ea910..ae4ec81 100644 --- a/sigrokdecode.h +++ b/sigrokdecode.h @@ -63,18 +63,38 @@ extern "C" { #define SRD_LOG_DBG 4 /**< Output debug messages. */ #define SRD_LOG_SPEW 5 /**< Output very noisy debug messages. */ +/* + * Use SRD_API to mark public API symbols, and SRD_PRIV for private symbols. + * + * Variables and functions marked 'static' are private already and don't + * need SR_PRIV. However, functions which are not static (because they need + * to be used in other libsigrokdecode-internal files) but are also not + * meant to be part of the public libsigrokdecode API, must use SRD_PRIV. + * + * This uses the 'visibility' feature of gcc (requires gcc >= 4.0). + * + * Details: http://gcc.gnu.org/wiki/Visibility + */ + +/* Marks public libsigrokdecode API symbols. */ +#define SRD_API __attribute__((visibility("default"))) + +/* Marks private, non-public libsigrokdecode symbols (not part of the API). */ +#define SRD_PRIV __attribute__((visibility("hidden"))) + +/* + * 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 +#define SRD_MAX_NUM_PROBES 64 /* TODO: Documentation. */ struct srd_decoder { @@ -105,7 +125,8 @@ struct srd_decoder { /** 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; @@ -124,10 +145,10 @@ struct srd_probe { 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; @@ -140,7 +161,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; }; @@ -152,12 +173,15 @@ struct srd_proto_data { void *data; }; +typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata, + void *user_data); + struct srd_pd_callback { int output_type; - void (*callback)(struct srd_proto_data *); + srd_pd_output_callback_t callback; + void *user_data; }; - /* custom python types */ typedef struct { PyObject_HEAD @@ -165,7 +189,7 @@ typedef struct { typedef struct { PyObject_HEAD - struct srd_decoder_instance *di; + struct srd_decoder_inst *di; uint64_t start_samplenum; unsigned int itercnt; uint8_t *inbuf; @@ -173,62 +197,58 @@ typedef struct { 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); -int srd_instance_set_probes(struct srd_decoder_instance *di, - GHashTable *probes); -struct srd_decoder_instance *srd_instance_new(const char *id, - GHashTable *options); -int srd_instance_stack(struct srd_decoder_instance *di_from, - 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); -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); -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 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); -int srd_register_callback(int output_type, srd_pd_output_callback_t cb); -void *srd_find_callback(int output_type); + +SRD_API int srd_init(char *path); +SRD_API int srd_exit(void); +SRD_PRIV int add_modulepath(const char *path); +SRD_API int srd_inst_set_options(struct srd_decoder_inst *di, + GHashTable *options); +SRD_API int srd_inst_set_probes(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(char *inst_id); +SRD_API struct srd_decoder_inst *srd_inst_find_by_obj(GSList *stack, + PyObject *obj); +SRD_API int srd_inst_start(struct srd_decoder_inst *di, PyObject *args); +SRD_API int srd_inst_decode(uint64_t start_samplenum, + struct srd_decoder_inst *dec, + uint8_t *inbuf, uint64_t inbuflen); +SRD_API void srd_inst_free(struct srd_decoder_inst *di); +SRD_API void srd_inst_free_all(GSList *stack); +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, + uint64_t inbuflen); +SRD_API struct srd_decoder_inst *get_di_by_decobject(void *decobject); +SRD_API int srd_register_callback(int output_type, + srd_pd_output_callback_t cb, void *user_data); +SRD_API 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); -int srd_unload_decoder(struct srd_decoder *dec); -int srd_load_all_decoders(void); -int srd_unload_all_decoders(void); -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); + +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); /*--- 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); -int srd_log_handler_set_default(void); -int srd_log_logdomain_set(const char *logdomain); -char *srd_log_logdomain_get(void); + +typedef int (*srd_log_handler_t)(void *user_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 *user_data); +SRD_API int srd_log_handler_set_default(void); +SRD_API int srd_log_logdomain_set(const char *logdomain); +SRD_API char *srd_log_logdomain_get(void); #ifdef __cplusplus }