This is not yet finished, more things should be made private.
static GSList *callbacks = NULL;
/* decoder.c */
-extern GSList *pd_list;
+extern SRD_PRIV GSList *pd_list;
/* module_sigrokdecode.c */
-extern PyMODINIT_FUNC PyInit_sigrokdecode(void);
+extern SRD_PRIV PyMODINIT_FUNC PyInit_sigrokdecode(void);
/* type_logic.c */
-extern PyTypeObject srd_logic_type;
+extern SRD_PRIV PyTypeObject srd_logic_type;
/**
* Initialize libsigrokdecode.
* directory cannot be accessed, return SRD_ERR_DECODERS_DIR.
* If not enough memory could be allocated, return SRD_ERR_MALLOC.
*/
-int srd_init(void)
+SRD_API int srd_init(void)
{
int ret;
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-int srd_exit(void)
+SRD_API int srd_exit(void)
{
srd_dbg("Exiting libsigrokdecode.");
*
* @return TODO.
*/
-int set_modulepath(void)
+SRD_API int set_modulepath(void)
{
int ret;
gchar *path, *s;
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-int srd_instance_set_options(struct srd_decoder_instance *di,
- GHashTable * options)
+SRD_API int srd_instance_set_options(struct srd_decoder_instance *di,
+ GHashTable *options)
{
PyObject *py_dec_options, *py_dec_optkeys, *py_di_options, *py_optval;
PyObject *py_optlist, *py_classval;
* 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)
+SRD_API int srd_instance_set_probes(struct srd_decoder_instance *di,
+ GHashTable *new_probes)
{
GList *l;
GSList *sl;
* @return Pointer to a newly allocated struct srd_decoder_instance, or
* NULL in case of failure.
*/
-struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
- GHashTable *options)
+SRD_API struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
+ GHashTable *options)
{
int i;
struct srd_decoder *dec;
return di;
}
-int srd_instance_stack(struct srd_decoder_instance *di_from,
- struct srd_decoder_instance *di_to)
+SRD_API int srd_instance_stack(struct srd_decoder_instance *di_from,
+ struct srd_decoder_instance *di_to)
{
if (!di_from || !di_to) {
srd_err("Invalid from/to instance pair.");
*
* @return Pointer to struct srd_decoder_instance, or NULL if not found.
*/
-struct srd_decoder_instance *srd_instance_find_by_id(char *instance_id)
+SRD_API struct srd_decoder_instance *srd_instance_find_by_id(char *instance_id)
{
GSList *l;
struct srd_decoder_instance *tmp, *di;
*
* @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)
+SRD_API struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
+ PyObject *obj)
{
GSList *l;
struct srd_decoder_instance *tmp, *di;
return di;
}
-int srd_instance_start(struct srd_decoder_instance *di, PyObject *args)
+SRD_API int srd_instance_start(struct srd_decoder_instance *di, PyObject *args)
{
PyObject *py_name, *py_res;
GSList *l;
*
* @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)
+SRD_API int srd_instance_decode(uint64_t start_samplenum,
+ struct srd_decoder_instance *di,
+ uint8_t *inbuf, uint64_t inbuflen)
{
PyObject *py_res;
srd_logic *logic;
return SRD_OK;
}
-void srd_instance_free(struct srd_decoder_instance *di)
+SRD_API void srd_instance_free(struct srd_decoder_instance *di)
{
GSList *l;
struct srd_pd_output *pdo;
g_slist_free(di->pd_output);
}
-void srd_instance_free_all(GSList *stack)
+SRD_API void srd_instance_free_all(GSList *stack)
{
GSList *l;
struct srd_decoder_instance *di;
}
}
-int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
+SRD_API int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
{
PyObject *args;
GSList *d;
}
/* Feed logic samples to decoder session. */
-int srd_session_feed(uint64_t start_samplenum, uint8_t * inbuf,
- uint64_t inbuflen)
+SRD_API int srd_session_feed(uint64_t start_samplenum, uint8_t * inbuf,
+ uint64_t inbuflen)
{
GSList *d;
int ret;
return SRD_OK;
}
-int srd_register_callback(int output_type, srd_pd_output_callback_t cb)
+SRD_API int srd_register_callback(int output_type, srd_pd_output_callback_t cb)
{
struct srd_pd_callback *pd_cb;
return SRD_OK;
}
-void *srd_find_callback(int output_type)
+SRD_API void *srd_find_callback(int output_type)
{
GSList *l;
struct srd_pd_callback *pd_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)
+SRD_PRIV int pd_add(struct srd_decoder_instance *di, int output_type,
+ char *proto_id)
{
struct srd_pd_output *pdo;
#include <glib.h>
/* The list of protocol decoders. */
-GSList *pd_list = NULL;
+SRD_PRIV GSList *pd_list = NULL;
/* module_sigrokdecode.c */
-extern PyObject *mod_sigrokdecode;
+extern SRD_PRIV PyObject *mod_sigrokdecode;
/**
* Returns the list of supported/loaded protocol decoders.
*
* @return List of decoders, NULL if none are supported or loaded.
*/
-GSList *srd_list_decoders(void)
+SRD_API GSList *srd_list_decoders(void)
{
return pd_list;
}
* @param id The ID string of the decoder to return.
* @return The decoder with the specified ID, or NULL if not found.
*/
-struct srd_decoder *srd_get_decoder_by_id(const char *id)
+SRD_API struct srd_decoder *srd_get_decoder_by_id(const char *id)
{
GSList *l;
struct srd_decoder *dec;
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-int srd_load_decoder(const char *name, struct srd_decoder **dec)
+SRD_API int srd_load_decoder(const char *name, struct srd_decoder **dec)
{
PyObject *py_basedec, *py_method, *py_attr, *py_annlist, *py_ann;
struct srd_decoder *d;
return ret;
}
-char *srd_decoder_doc(struct srd_decoder *dec)
+SRD_API char *srd_decoder_doc(struct srd_decoder *dec)
{
PyObject *py_str;
char *doc;
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-int srd_unload_decoder(struct srd_decoder *dec)
+SRD_API int srd_unload_decoder(struct srd_decoder *dec)
{
-
srd_dbg("unloading decoder %s", dec->name);
/* Since any instances of this decoder need to be released as well,
return SRD_OK;
}
-int srd_load_all_decoders(void)
+SRD_API int srd_load_all_decoders(void)
{
GDir *dir;
GError *error;
/**
* TODO
*/
-int srd_unload_all_decoders(void)
+SRD_API int srd_unload_all_decoders(void)
{
GSList *l;
struct srd_decoder *dec;
#include <glib.h>
#include <frameobject.h> /* Python header not pulled in by default. */
-void catch_exception(const char *format, ...)
+SRD_PRIV void catch_exception(const char *format, ...)
{
PyObject *etype, *evalue, *etb, *py_str;
PyTracebackObject *py_tb;
* SRD_LOG_WARN, SRD_LOG_INFO, SRD_LOG_DBG, or SRD_LOG_SPEW).
* @return SRD_OK upon success, SRD_ERR_ARG upon invalid loglevel.
*/
-int srd_log_loglevel_set(int loglevel)
+SRD_API int srd_log_loglevel_set(int loglevel)
{
if (loglevel < SRD_LOG_NONE || loglevel > SRD_LOG_SPEW) {
srd_err("Invalid loglevel %d.", loglevel);
*
* @return The currently configured libsigrokdecode loglevel.
*/
-int srd_log_loglevel_get(void)
+SRD_API int srd_log_loglevel_get(void)
{
return srd_loglevel;
}
* the caller does not need to keep it around.
* @return SRD_OK upon success, SRD_ERR_ARG upon invalid logdomain.
*/
-int srd_log_logdomain_set(const char *logdomain)
+SRD_API int srd_log_logdomain_set(const char *logdomain)
{
if (!logdomain) {
srd_err("log: %s: logdomain was NULL", __func__);
* string. The caller is responsible for g_free()ing the string when
* it is no longer needed.
*/
-char *srd_log_logdomain_get(void)
+SRD_API char *srd_log_logdomain_get(void)
{
return g_strdup((const char *)&srd_log_domain);
}
* to be NULL if the caller doesn't need/want to pass any data.
* @return SRD_OK upon success, SRD_ERR_ARG upon invalid arguments.
*/
-int srd_log_handler_set(srd_log_handler_t handler, void *data)
+SRD_API int srd_log_handler_set(srd_log_handler_t handler, void *data)
{
if (!handler) {
srd_err("log: %s: handler was NULL", __func__);
*
* @return SRD_OK upon success, a negative error code otherwise.
*/
-int srd_log_handler_set_default(void)
+SRD_API int srd_log_handler_set_default(void)
{
/*
* Note: No log output in this function, as it should safely work
return ret;
}
-int srd_log(int loglevel, const char *format, ...)
+SRD_PRIV int srd_log(int loglevel, const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int srd_spew(const char *format, ...)
+SRD_PRIV int srd_spew(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int srd_dbg(const char *format, ...)
+SRD_PRIV int srd_dbg(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int srd_info(const char *format, ...)
+SRD_PRIV int srd_info(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int srd_warn(const char *format, ...)
+SRD_PRIV int srd_warn(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int srd_err(const char *format, ...)
+SRD_PRIV int srd_err(const char *format, ...)
{
int ret;
va_list args;
#include "config.h"
/* type_decoder.c */
-extern PyTypeObject srd_Decoder_type;
+extern SRD_PRIV PyTypeObject srd_Decoder_type;
/* type_logic.c */
-extern PyTypeObject srd_logic_type;
+extern SRD_PRIV PyTypeObject srd_logic_type;
/*
* When initialized, a reference to this module inside the python interpreter
* lives here.
*/
-PyObject *mod_sigrokdecode = NULL;
+SRD_PRIV PyObject *mod_sigrokdecode = NULL;
static struct PyModuleDef sigrokdecode_module = {
PyModuleDef_HEAD_INIT,
.m_size = -1,
};
-PyMODINIT_FUNC PyInit_sigrokdecode(void)
+SRD_PRIV PyMODINIT_FUNC PyInit_sigrokdecode(void)
{
PyObject *mod;
#ifndef LIBSIGROKDECODE_SIGROKDECODE_INTERNAL_H
#define LIBSIGROKDECODE_SIGROKDECODE_INTERNAL_H
+#include "sigrokdecode.h"
// #include <stdarg.h>
// #include <glib.h>
/*--- log.c -----------------------------------------------------------------*/
-int srd_log(int loglevel, const char *format, ...);
-int srd_spew(const char *format, ...);
-int srd_dbg(const char *format, ...);
-int srd_info(const char *format, ...);
-int srd_warn(const char *format, ...);
-int srd_err(const char *format, ...);
+SRD_PRIV int srd_log(int loglevel, const char *format, ...);
+SRD_PRIV int srd_spew(const char *format, ...);
+SRD_PRIV int srd_dbg(const char *format, ...);
+SRD_PRIV int srd_info(const char *format, ...);
+SRD_PRIV int srd_warn(const char *format, ...);
+SRD_PRIV int srd_err(const char *format, ...);
#endif
#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()
/*--- 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);
+SRD_API int srd_init(void);
+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_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_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);
-int srd_register_callback(int output_type, srd_pd_output_callback_t cb);
-void *srd_find_callback(int output_type);
+SRD_API int srd_register_callback(int output_type, srd_pd_output_callback_t cb);
+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);
+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 -----------------------------------------------------------*/
-void catch_exception(const char *format, ...);
+SRD_PRIV 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_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);
/*--- 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);
+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_logdomain_set(const char *logdomain);
+SRD_API char *srd_log_logdomain_get(void);
#ifdef __cplusplus
}
{NULL, NULL, 0, NULL}
};
-PyTypeObject srd_Decoder_type = {
+SRD_PRIV PyTypeObject srd_Decoder_type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "sigrokdecode.Decoder",
.tp_basicsize = sizeof(srd_Decoder),
#include <inttypes.h>
#include <string.h>
-PyObject *srd_logic_iter(PyObject *self)
+static PyObject *srd_logic_iter(PyObject *self)
{
return self;
}
-PyObject *srd_logic_iternext(PyObject *self)
+static PyObject *srd_logic_iternext(PyObject *self)
{
int i;
PyObject *py_samplenum, *py_samples;
return logic->sample;
}
-PyTypeObject srd_logic_type = {
+SRD_PRIV PyTypeObject srd_logic_type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "srd_logic",
.tp_basicsize = sizeof(srd_logic),
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed string upon success.
*/
-int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr)
+SRD_PRIV int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr)
{
PyObject *py_str;
int ret;
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed string upon success.
*/
-int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr)
+SRD_PRIV int py_dictitem_as_str(PyObject *py_obj, const char *key,
+ char **outstr)
{
PyObject *py_value;
int ret;
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed string upon success.
*/
-int py_str_as_str(PyObject *py_str, char **outstr)
+SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr)
{
PyObject *py_encstr;
int ret;
* @return SRD_OK upon success, a (negative) error code otherwise.
* The 'outstr' argument points to a malloc()ed char ** upon success.
*/
-int py_strlist_to_char(PyObject *py_strlist, char ***outstr)
+SRD_PRIV int py_strlist_to_char(PyObject *py_strlist, char ***outstr)
{
PyObject *py_str;
int list_len, i;