Use SR_API to mark public API symbols, and SR_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 libsigrok-internal files) but are also not meant to
be part of the public libsigrok API, must use SR_PRIV.
This uses the 'visibility' feature of gcc (requires gcc >= 4.0).
Details: http://gcc.gnu.org/wiki/Visibility
------------
- git
- - gcc
+ - gcc (>= 4.0)
- make
- autoconf >= 2.63
- automake >= 1.11
*
* @return SR_OK upon success, a (negative) error code otherwise.
*/
-int sr_init(void)
+SR_API int sr_init(void)
{
return load_hwplugins();
}
*
* @return SR_OK upon success, a (negative) error code otherwise.
*/
-int sr_exit(void)
+SR_API int sr_exit(void)
{
sr_cleanup_hwplugins();
#define LIBSIGROK_CONFIG_H /* To stop multiple inclusions. */])
AH_BOTTOM([#endif /* LIBSIGROK_CONFIG_H */])
-CFLAGS="-g -Wall -Wextra"
+# Enable more compiler warnings via -Wall and -Wextra. Add -fvisibility=hidden
+# and enforce use of SR_API to explicitly mark all public API functions.
+CFLAGS="-g -Wall -Wextra -fvisibility=hidden"
# Checks for programs.
AC_PROG_CXX
* or SR_ERR_ARG upon invalid arguments. If something other than SR_OK
* is returned, the value of 'ds' is undefined.
*/
-int sr_datastore_new(int unitsize, struct sr_datastore **ds)
+SR_API int sr_datastore_new(int unitsize, struct sr_datastore **ds)
{
if (!ds) {
sr_err("ds: %s: ds was NULL", __func__);
*
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
*/
-int sr_datastore_destroy(struct sr_datastore *ds)
+SR_API int sr_datastore_destroy(struct sr_datastore *ds)
{
GSList *chunk;
* or SR_ERR_ARG upon invalid arguments. If something other than SR_OK
* is returned, the value/state of 'ds' is undefined.
*/
-int sr_datastore_put(struct sr_datastore *ds, void *data, unsigned int length,
- int in_unitsize, int *probelist)
+SR_API int sr_datastore_put(struct sr_datastore *ds, void *data,
+ unsigned int length, int in_unitsize, int *probelist)
{
unsigned int stored;
int capacity, size, num_chunks, chunk_bytes_free, chunk_offset;
*
* @return SR_OK upon success, SR_ERR upon errors.
*/
-int sr_device_scan(void)
+SR_API int sr_device_scan(void)
{
GSList *plugins, *l;
struct sr_device_plugin *plugin;
*
* @return The list (GSList) of detected devices, or NULL if none were found.
*/
-GSList *sr_device_list(void)
+SR_API GSList *sr_device_list(void)
{
if (!devices)
sr_device_scan();
*
* @return Pointer to the newly allocated device, or NULL upon errors.
*/
-struct sr_device *sr_device_new(const struct sr_device_plugin *plugin,
- int plugin_index)
+SR_API struct sr_device *sr_device_new(const struct sr_device_plugin *plugin,
+ int plugin_index)
{
struct sr_device *device;
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
* If something other than SR_OK is returned, 'device' is unchanged.
*/
-int sr_device_clear(struct sr_device *device)
+SR_API int sr_device_clear(struct sr_device *device)
{
unsigned int pnum;
* upon other errors.
* If something other than SR_OK is returned, 'device' is unchanged.
*/
-int sr_device_probe_clear(struct sr_device *device, int probenum)
+SR_API int sr_device_probe_clear(struct sr_device *device, int probenum)
{
struct sr_probe *p;
* or SR_ERR_ARG upon invalid arguments.
* If something other than SR_OK is returned, 'device' is unchanged.
*/
-int sr_device_probe_add(struct sr_device *device, const char *name)
+SR_API int sr_device_probe_add(struct sr_device *device, const char *name)
{
struct sr_probe *p;
int probenum;
* @return A pointer to the requested probe's 'struct sr_probe', or NULL
* if the probe could not be found.
*/
-struct sr_probe *sr_device_probe_find(const struct sr_device *device,
- int probenum)
+SR_API struct sr_probe *sr_device_probe_find(const struct sr_device *device,
+ int probenum)
{
GSList *l;
struct sr_probe *p, *found_probe;
* upon other errors.
* If something other than SR_OK is returned, 'device' is unchanged.
*/
-int sr_device_probe_name(struct sr_device *device, int probenum,
- const char *name)
+SR_API int sr_device_probe_name(struct sr_device *device, int probenum,
+ const char *name)
{
struct sr_probe *p;
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
* If something other than SR_OK is returned, 'device' is unchanged.
*/
-int sr_device_trigger_clear(struct sr_device *device)
+SR_API int sr_device_trigger_clear(struct sr_device *device)
{
struct sr_probe *p;
unsigned int pnum; /* TODO: uint16_t? */
* upon other errors.
* If something other than SR_OK is returned, 'device' is unchanged.
*/
-int sr_device_trigger_set(struct sr_device *device, int probenum,
- const char *trigger)
+SR_API int sr_device_trigger_set(struct sr_device *device, int probenum,
+ const char *trigger)
{
struct sr_probe *p;
* FALSE is also returned upon invalid input parameters or other
* error conditions.
*/
-gboolean sr_device_has_hwcap(const struct sr_device *device, int hwcap)
+SR_API gboolean sr_device_has_hwcap(const struct sr_device *device, int hwcap)
{
int *capabilities, i;
* If something other than SR_OK is returned, the values of
* out_unitsize, data_out, and length_out are undefined.
*/
-int sr_filter_probes(int in_unitsize, int out_unitsize, const int *probelist,
- const unsigned char *data_in, uint64_t length_in,
- char **data_out, uint64_t *length_out)
+SR_API int sr_filter_probes(int in_unitsize, int out_unitsize,
+ const int *probelist, const unsigned char *data_in,
+ uint64_t length_in, char **data_out,
+ uint64_t *length_out)
{
unsigned int in_offset, out_offset;
int num_enabled_probes, out_bit, i;
/* Note: This driver doesn't compile, analog support in sigrok is WIP. */
-#include "config.h" /* Must come before sigrok.h */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
* ASIX SIGMA Logic Analyzer Driver
*/
-#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <ftdi.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
-#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
-int ezusb_reset(struct libusb_device_handle *hdl, int set_clear)
+SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear)
{
int err;
unsigned char buf[1];
return err;
}
-int ezusb_install_firmware(libusb_device_handle *hdl, const char *filename)
+SR_PRIV int ezusb_install_firmware(libusb_device_handle *hdl,
+ const char *filename)
{
FILE *fw;
int offset, chunksize, err, result;
return result;
}
-int ezusb_upload_firmware(libusb_device *dev, int configuration,
- const char *filename)
+SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
+ const char *filename)
{
struct libusb_device_handle *hdl;
int err;
static HANDLE hdl;
#endif
-const char *serial_port_glob[] = {
+static const char *serial_port_glob[] = {
/* Linux */
"/dev/ttyS*",
"/dev/ttyUSB*",
NULL,
};
-GSList *list_serial_ports(void)
+SR_PRIV GSList *list_serial_ports(void)
{
GSList *ports;
return ports;
}
-int serial_open(const char *pathname, int flags)
+SR_PRIV int serial_open(const char *pathname, int flags)
{
#ifdef _WIN32
/* FIXME: Don't hardcode COM1. */
* Close the serial port.
* Returns 0 upon success, -1 upon failure.
*/
-int serial_close(int fd)
+SR_PRIV int serial_close(int fd)
{
#ifdef _WIN32
/* Returns non-zero upon success, 0 upon failure. */
* Flush serial port buffers (if any).
* Returns 0 upon success, -1 upon failure.
*/
-int serial_flush(int fd)
+SR_PRIV int serial_flush(int fd)
{
#ifdef _WIN32
/* Returns non-zero upon success, 0 upon failure. */
* Write a number of bytes to the specified serial port.
* Returns the number of bytes written, or -1 upon failure.
*/
-int serial_write(int fd, const void *buf, size_t count)
+SR_PRIV int serial_write(int fd, const void *buf, size_t count)
{
#ifdef _WIN32
DWORD tmp = 0;
* Read a number of bytes from the specified serial port.
* Returns the number of bytes read, or -1 upon failure.
*/
-int serial_read(int fd, void *buf, size_t count)
+SR_PRIV int serial_read(int fd, void *buf, size_t count)
{
#ifdef _WIN32
DWORD tmp = 0;
#endif
}
-void *serial_backup_params(int fd)
+SR_PRIV void *serial_backup_params(int fd)
{
#ifdef _WIN32
/* TODO */
#endif
}
-void serial_restore_params(int fd, void *backup)
+SR_PRIV void serial_restore_params(int fd, void *backup)
{
#ifdef _WIN32
/* TODO */
* flowcontrol: 1 = rts/cts, 2 = xon/xoff
* parity: 0 = none, 1 = even, 2 = odd
*/
-int serial_set_params(int fd, int speed, int bits, int parity, int stopbits,
- int flowcontrol)
+SR_PRIV int serial_set_params(int fd, int speed, int bits, int parity,
+ int stopbits, int flowcontrol)
{
#ifdef _WIN32
DCB dcb;
#include <fcntl.h>
#define pipe(fds) _pipe(fds, 4096, _O_BINARY)
#endif
-#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
#include <arpa/inet.h>
#include "sigrok.h"
#include "sigrok-internal.h"
-#include "config.h"
#include "link-mso19.h"
#define USB_VENDOR "3195"
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <inttypes.h>
#include <glib.h>
#include <libusb.h>
+#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
#include "saleae-logic.h"
#include <libusb.h>
#include <stdio.h>
+#include "sigrok.h"
#include "sigrok-internal.h"
#include "gl_usb.h"
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
* options.
*/
/* TODO: This shouldn't be a global. */
-struct sr_hwcap_option sr_hwcap_options[] = {
+SR_API struct sr_hwcap_option sr_hwcap_options[] = {
{SR_HWCAP_SAMPLERATE, SR_T_UINT64, "Sample rate", "samplerate"},
{SR_HWCAP_CAPTURE_RATIO, SR_T_UINT64, "Pre-trigger capture ratio", "captureratio"},
{SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "patternmode"},
#endif
/* TODO: No linked list needed, this can be a simple array. */
-int load_hwplugins(void)
+SR_PRIV int load_hwplugins(void)
{
#ifdef HAVE_LA_DEMO
plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info);
return SR_OK;
}
-GSList *sr_list_hwplugins(void)
+SR_API GSList *sr_list_hwplugins(void)
{
return plugins;
}
-int sr_init_hwplugins(struct sr_device_plugin *plugin)
+SR_API int sr_init_hwplugins(struct sr_device_plugin *plugin)
{
int num_devices, num_probes, i, j;
int num_initialized_devices = 0;
return num_initialized_devices;
}
-void sr_cleanup_hwplugins(void)
+SR_API void sr_cleanup_hwplugins(void)
{
struct sr_device_plugin *plugin;
GSList *l;
}
}
-struct sr_device_instance *sr_device_instance_new(int index, int status,
+SR_API struct sr_device_instance *sr_device_instance_new(int index, int status,
const char *vendor, const char *model, const char *version)
{
struct sr_device_instance *sdi;
return sdi;
}
-struct sr_device_instance *sr_get_device_instance(GSList *device_instances,
- int device_index)
+SR_API struct sr_device_instance *sr_get_device_instance(
+ GSList *device_instances, int device_index)
{
struct sr_device_instance *sdi;
GSList *l;
return NULL;
}
-void sr_device_instance_free(struct sr_device_instance *sdi)
+SR_API void sr_device_instance_free(struct sr_device_instance *sdi)
{
g_free(sdi->priv);
g_free(sdi->vendor);
#ifdef HAVE_LIBUSB_1_0
-struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
+SR_PRIV struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
uint8_t address, struct libusb_device_handle *hdl)
{
struct sr_usb_device_instance *udi;
return udi;
}
-void sr_usb_device_instance_free(struct sr_usb_device_instance *usb)
+SR_PRIV void sr_usb_device_instance_free(struct sr_usb_device_instance *usb)
{
/* Avoid compiler warnings. */
(void)usb;
#endif
-struct sr_serial_device_instance *sr_serial_device_instance_new(
+SR_PRIV struct sr_serial_device_instance *sr_serial_device_instance_new(
const char *port, int fd)
{
struct sr_serial_device_instance *serial;
return serial;
}
-void sr_serial_device_instance_free(struct sr_serial_device_instance *serial)
+SR_PRIV void sr_serial_device_instance_free(
+ struct sr_serial_device_instance *serial)
{
free(serial->port);
}
-int sr_find_hwcap(int *capabilities, int hwcap)
+SR_API int sr_find_hwcap(int *capabilities, int hwcap)
{
int i;
return FALSE;
}
-struct sr_hwcap_option *sr_find_hwcap_option(int hwcap)
+SR_API struct sr_hwcap_option *sr_find_hwcap_option(int hwcap)
{
int i;
*/
#include "sigrok.h"
+#include "sigrok-internal.h"
extern struct sr_input_format input_chronovu_la8;
extern struct sr_input_format input_binary;
NULL,
};
-struct sr_input_format **sr_input_list(void)
+SR_API struct sr_input_format **sr_input_list(void)
{
return input_module_list;
}
* SR_LOG_INFO, SR_LOG_DBG, or SR_LOG_SPEW).
* @return SR_OK upon success, SR_ERR_ARG upon invalid loglevel.
*/
-int sr_set_loglevel(int loglevel)
+SR_API int sr_set_loglevel(int loglevel)
{
if (loglevel < SR_LOG_NONE || loglevel > SR_LOG_SPEW) {
sr_err("log: %s: invalid loglevel %d", __func__, loglevel);
*
* @return The currently configured libsigrok loglevel.
*/
-int sr_get_loglevel(void)
+SR_API int sr_get_loglevel(void)
{
return sr_loglevel;
}
return ret;
}
-int sr_log(int loglevel, const char *format, ...)
+SR_PRIV int sr_log(int loglevel, const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int sr_spew(const char *format, ...)
+SR_PRIV int sr_spew(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int sr_dbg(const char *format, ...)
+SR_PRIV int sr_dbg(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int sr_info(const char *format, ...)
+SR_PRIV int sr_info(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int sr_warn(const char *format, ...)
+SR_PRIV int sr_warn(const char *format, ...)
{
int ret;
va_list args;
return ret;
}
-int sr_err(const char *format, ...)
+SR_PRIV int sr_err(const char *format, ...)
{
int ret;
va_list args;
#include <string.h>
#include <glib.h>
#include "sigrok.h"
-#include "config.h"
#define DEFAULT_BPL_BITS 64
#define DEFAULT_BPL_HEX 192
#include <glib.h>
#include "sigrok.h"
#include "sigrok-internal.h"
-#include "config.h"
static int data(struct sr_output *o, const char *data_in, uint64_t length_in,
char **data_out, uint64_t *length_out)
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
-#include "config.h"
struct context {
unsigned int num_enabled_probes;
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
-#include "config.h"
struct context {
unsigned int num_enabled_probes;
#include <glib.h>
#include "sigrok.h"
#include "sigrok-internal.h"
-#include "config.h"
struct context {
GString *header;
*/
#include "sigrok.h"
+#include "sigrok-internal.h"
extern struct sr_output_format output_text_bits;
extern struct sr_output_format output_text_hex;
NULL,
};
-struct sr_output_format **sr_output_list(void)
+SR_API struct sr_output_format **sr_output_list(void)
{
return output_module_list;
}
#include <stdio.h>
#include <string.h>
#include <glib.h>
-#include "sigrok.h"
#include "config.h"
+#include "sigrok.h"
#include "text.h"
void flush_linebufs(struct context *ctx, char *outbuf)
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
-#include "config.h"
struct context {
int num_enabled_probes;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
*
* @return A pointer to the newly allocated session, or NULL upon errors.
*/
-struct sr_session *sr_session_new(void)
+SR_API struct sr_session *sr_session_new(void)
{
if (!(session = calloc(1, sizeof(struct sr_session)))) {
sr_err("session: %s: session malloc failed", __func__);
*
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
*/
-int sr_session_destroy(void)
+SR_API int sr_session_destroy(void)
{
if (!session) {
sr_warn("session: %s: session was NULL", __func__);
*
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
*/
-int sr_session_device_clear(void)
+SR_API int sr_session_device_clear(void)
{
if (!session) {
sr_warn("session: %s: session was NULL", __func__);
*
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
*/
-int sr_session_device_add(struct sr_device *device)
+SR_API int sr_session_device_add(struct sr_device *device)
{
int ret;
*
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
*/
-int sr_session_datafeed_callback_clear(void)
+SR_API int sr_session_datafeed_callback_clear(void)
{
if (!session) {
sr_err("session: %s: session was NULL", __func__);
* @param callback TODO.
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
*/
-int sr_session_datafeed_callback_add(sr_datafeed_callback callback)
+SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback callback)
{
if (!session) {
sr_err("session: %s: session was NULL", __func__);
*
* @return SR_OK upon success, SR_ERR upon errors.
*/
-int sr_session_start(void)
+SR_API int sr_session_start(void)
{
struct sr_device *device;
GSList *l;
*
* @return SR_OK upon success, SR_ERR_BUG upon errors.
*/
-int sr_session_run(void)
+SR_API int sr_session_run(void)
{
if (!session) {
sr_err("session: %s: session was NULL; a session must be "
*
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
*/
-int sr_session_halt(void)
+SR_API int sr_session_halt(void)
{
if (!session) {
sr_err("session: %s: session was NULL", __func__);
*
* @return SR_OK upon success, SR_ERR_BUG if no session exists.
*/
-int sr_session_stop(void)
+SR_API int sr_session_stop(void)
{
struct sr_device *device;
GSList *l;
* @param packet TODO.
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
*/
-int sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet)
+SR_API int sr_session_bus(struct sr_device *device,
+ struct sr_datafeed_packet *packet)
{
GSList *l;
sr_datafeed_callback cb;
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors.
*/
-int sr_session_source_add(int fd, int events, int timeout,
- sr_receive_data_callback callback, void *user_data)
+SR_API int sr_session_source_add(int fd, int events, int timeout,
+ sr_receive_data_callback callback, void *user_data)
{
struct source *new_sources, *s;
* SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
* internal errors.
*/
-int sr_session_source_remove(int fd)
+SR_API int sr_session_source_remove(int fd)
{
struct source *new_sources;
int old, new;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <zip.h>
#include <glib.h>
#include <glib/gstdio.h>
+#include "config.h"
#include "sigrok.h"
#include "sigrok-internal.h"
* SR_ERR_MALLOC upon memory allocation errors, or SR_ERR upon
* other errors.
*/
-int sr_session_load(const char *filename)
+SR_API int sr_session_load(const char *filename)
{
GKeyFile *kf;
GPtrArray *capturefiles;
#include <stdarg.h>
#include <glib.h>
+#include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
#ifdef HAVE_LIBUSB_1_0
#include <libusb.h>
#endif
/*--- hwplugin.c ------------------------------------------------------------*/
-int load_hwplugins(void);
+SR_PRIV int load_hwplugins(void);
#ifdef HAVE_LIBUSB_1_0
struct sr_usb_device_instance {
#ifdef HAVE_LIBUSB_1_0
/* USB-specific instances */
-struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
+SR_PRIV struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
uint8_t address, struct libusb_device_handle *hdl);
-void sr_usb_device_instance_free(struct sr_usb_device_instance *usb);
+SR_PRIV void sr_usb_device_instance_free(struct sr_usb_device_instance *usb);
#endif
/* Serial-specific instances */
-struct sr_serial_device_instance *sr_serial_device_instance_new(
+SR_PRIV struct sr_serial_device_instance *sr_serial_device_instance_new(
const char *port, int fd);
-void sr_serial_device_instance_free(struct sr_serial_device_instance *serial);
+SR_PRIV void sr_serial_device_instance_free(
+ struct sr_serial_device_instance *serial);
/*--- log.c -----------------------------------------------------------------*/
-int sr_log(int loglevel, const char *format, ...);
-int sr_spew(const char *format, ...);
-int sr_dbg(const char *format, ...);
-int sr_info(const char *format, ...);
-int sr_warn(const char *format, ...);
-int sr_err(const char *format, ...);
+SR_PRIV int sr_log(int loglevel, const char *format, ...);
+SR_PRIV int sr_spew(const char *format, ...);
+SR_PRIV int sr_dbg(const char *format, ...);
+SR_PRIV int sr_info(const char *format, ...);
+SR_PRIV int sr_warn(const char *format, ...);
+SR_PRIV int sr_err(const char *format, ...);
/*--- hardware/common/serial.c ----------------------------------------------*/
-GSList *list_serial_ports(void);
-int serial_open(const char *pathname, int flags);
-int serial_close(int fd);
-int serial_flush(int fd);
-int serial_write(int fd, const void *buf, size_t count);
-int serial_read(int fd, void *buf, size_t count);
-void *serial_backup_params(int fd);
-void serial_restore_params(int fd, void *backup);
-int serial_set_params(int fd, int speed, int bits, int parity, int stopbits,
- int flowcontrol);
+SR_PRIV GSList *list_serial_ports(void);
+SR_PRIV int serial_open(const char *pathname, int flags);
+SR_PRIV int serial_close(int fd);
+SR_PRIV int serial_flush(int fd);
+SR_PRIV int serial_write(int fd, const void *buf, size_t count);
+SR_PRIV int serial_read(int fd, void *buf, size_t count);
+SR_PRIV void *serial_backup_params(int fd);
+SR_PRIV void serial_restore_params(int fd, void *backup);
+SR_PRIV int serial_set_params(int fd, int speed, int bits, int parity,
+ int stopbits, int flowcontrol);
/*--- hardware/common/ezusb.c -----------------------------------------------*/
#ifdef HAVE_LIBUSB_1_0
-int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
-int ezusb_install_firmware(libusb_device_handle *hdl, const char *filename);
-int ezusb_upload_firmware(libusb_device *dev, int configuration,
- const char *filename);
+SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
+SR_PRIV int ezusb_install_firmware(libusb_device_handle *hdl,
+ const char *filename);
+SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
+ const char *filename);
#endif
/*--- hardware/common/misc.c ------------------------------------------------*/
#ifdef HAVE_LIBUSB_1_0
-int opendev2(int device_index, struct sr_device_instance **sdi,
- libusb_device *dev, struct libusb_device_descriptor *des,
- int *skip, uint16_t vid, uint16_t pid, int interface);
-int opendev3(struct sr_device_instance **sdi, libusb_device *dev,
- struct libusb_device_descriptor *des,
- uint16_t vid, uint16_t pid, int interface);
+SR_PRIV int opendev2(int device_index, struct sr_device_instance **sdi,
+ libusb_device *dev, struct libusb_device_descriptor *des,
+ int *skip, uint16_t vid, uint16_t pid, int interface);
+SR_PRIV int opendev3(struct sr_device_instance **sdi, libusb_device *dev,
+ struct libusb_device_descriptor *des,
+ uint16_t vid, uint16_t pid, int interface);
#endif
#endif
/*--- backend.c -------------------------------------------------------------*/
-int sr_init(void);
-int sr_exit(void);
+SR_API int sr_init(void);
+SR_API int sr_exit(void);
/*--- log.c -----------------------------------------------------------------*/
-int sr_set_loglevel(int loglevel);
-int sr_get_loglevel(void);
+SR_API int sr_set_loglevel(int loglevel);
+SR_API int sr_get_loglevel(void);
/*--- datastore.c -----------------------------------------------------------*/
-int sr_datastore_new(int unitsize, struct sr_datastore **ds);
-int sr_datastore_destroy(struct sr_datastore *ds);
-int sr_datastore_put(struct sr_datastore *ds, void *data, unsigned int length,
- int in_unitsize, int *probelist);
+SR_API int sr_datastore_new(int unitsize, struct sr_datastore **ds);
+SR_API int sr_datastore_destroy(struct sr_datastore *ds);
+SR_API int sr_datastore_put(struct sr_datastore *ds, void *data,
+ unsigned int length, int in_unitsize,
+ int *probelist);
/*--- device.c --------------------------------------------------------------*/
-int sr_device_scan(void);
-GSList *sr_device_list(void);
-struct sr_device *sr_device_new(const struct sr_device_plugin *plugin,
- int plugin_index);
-int sr_device_clear(struct sr_device *device);
-int sr_device_probe_clear(struct sr_device *device, int probenum);
-int sr_device_probe_add(struct sr_device *device, const char *name);
-struct sr_probe *sr_device_probe_find(const struct sr_device *device,
- int probenum);
-int sr_device_probe_name(struct sr_device *device, int probenum,
- const char *name);
-int sr_device_trigger_clear(struct sr_device *device);
-int sr_device_trigger_set(struct sr_device *device, int probenum,
- const char *trigger);
-gboolean sr_device_has_hwcap(const struct sr_device *device, int hwcap);
-int sr_device_get_info(const struct sr_device *device, int id,
- const void **data);
+SR_API int sr_device_scan(void);
+SR_API GSList *sr_device_list(void);
+SR_API struct sr_device *sr_device_new(const struct sr_device_plugin *plugin,
+ int plugin_index);
+SR_API int sr_device_clear(struct sr_device *device);
+SR_API int sr_device_probe_clear(struct sr_device *device, int probenum);
+SR_API int sr_device_probe_add(struct sr_device *device, const char *name);
+SR_API struct sr_probe *sr_device_probe_find(const struct sr_device *device,
+ int probenum);
+SR_API int sr_device_probe_name(struct sr_device *device, int probenum,
+ const char *name);
+SR_API int sr_device_trigger_clear(struct sr_device *device);
+SR_API int sr_device_trigger_set(struct sr_device *device, int probenum,
+ const char *trigger);
+SR_API gboolean sr_device_has_hwcap(const struct sr_device *device, int hwcap);
+SR_API int sr_device_get_info(const struct sr_device *device, int id,
+ const void **data);
/*--- filter.c --------------------------------------------------------------*/
-int sr_filter_probes(int in_unitsize, int out_unitsize, const int *probelist,
- const unsigned char *data_in, uint64_t length_in,
- char **data_out, uint64_t *length_out);
+SR_API int sr_filter_probes(int in_unitsize, int out_unitsize,
+ const int *probelist, const unsigned char *data_in,
+ uint64_t length_in, char **data_out,
+ uint64_t *length_out);
/*--- hwplugin.c ------------------------------------------------------------*/
-GSList *sr_list_hwplugins(void);
-int sr_init_hwplugins(struct sr_device_plugin *plugin);
-void sr_cleanup_hwplugins(void);
+SR_API GSList *sr_list_hwplugins(void);
+SR_API int sr_init_hwplugins(struct sr_device_plugin *plugin);
+SR_API void sr_cleanup_hwplugins(void);
/* Generic device instances */
-struct sr_device_instance *sr_device_instance_new(int index,
+SR_API struct sr_device_instance *sr_device_instance_new(int index,
int status, const char *vendor, const char *model, const char *version);
-struct sr_device_instance *sr_get_device_instance(GSList *device_instances,
- int device_index);
-void sr_device_instance_free(struct sr_device_instance *sdi);
+SR_API struct sr_device_instance *sr_get_device_instance(
+ GSList *device_instances, int device_index);
+SR_API void sr_device_instance_free(struct sr_device_instance *sdi);
-int sr_find_hwcap(int *capabilities, int hwcap);
-struct sr_hwcap_option *sr_find_hwcap_option(int hwcap);
-void sr_source_remove(int fd);
-void sr_source_add(int fd, int events, int timeout,
- sr_receive_data_callback rcv_cb, void *user_data);
+SR_API int sr_find_hwcap(int *capabilities, int hwcap);
+SR_API struct sr_hwcap_option *sr_find_hwcap_option(int hwcap);
+SR_API void sr_source_remove(int fd);
+SR_API void sr_source_add(int fd, int events, int timeout,
+ sr_receive_data_callback rcv_cb, void *user_data);
/*--- session.c -------------------------------------------------------------*/
struct sr_datafeed_packet *packet);
/* Session setup */
-int sr_session_load(const char *filename);
-struct sr_session *sr_session_new(void);
-int sr_session_destroy(void);
-int sr_session_device_clear(void);
-int sr_session_device_add(struct sr_device *device);
+SR_API int sr_session_load(const char *filename);
+SR_API struct sr_session *sr_session_new(void);
+SR_API int sr_session_destroy(void);
+SR_API int sr_session_device_clear(void);
+SR_API int sr_session_device_add(struct sr_device *device);
/* Datafeed setup */
-int sr_session_datafeed_callback_clear(void);
-int sr_session_datafeed_callback_add(sr_datafeed_callback callback);
+SR_API int sr_session_datafeed_callback_clear(void);
+SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback callback);
/* Session control */
-int sr_session_start(void);
-int sr_session_run(void);
-int sr_session_halt(void);
-int sr_session_stop(void);
-int sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet);
-int sr_session_save(const char *filename);
-int sr_session_source_add(int fd, int events, int timeout,
- sr_receive_data_callback callback, void *user_data);
-int sr_session_source_remove(int fd);
+SR_API int sr_session_start(void);
+SR_API int sr_session_run(void);
+SR_API int sr_session_halt(void);
+SR_API int sr_session_stop(void);
+SR_API int sr_session_bus(struct sr_device *device,
+ struct sr_datafeed_packet *packet);
+SR_API int sr_session_save(const char *filename);
+SR_API int sr_session_source_add(int fd, int events, int timeout,
+ sr_receive_data_callback callback, void *user_data);
+SR_API int sr_session_source_remove(int fd);
/*--- input/input.c ---------------------------------------------------------*/
-struct sr_input_format **sr_input_list(void);
+SR_API struct sr_input_format **sr_input_list(void);
/*--- output/output.c -------------------------------------------------------*/
-struct sr_output_format **sr_output_list(void);
+SR_API struct sr_output_format **sr_output_list(void);
/*--- output/common.c -------------------------------------------------------*/
-char *sr_samplerate_string(uint64_t samplerate);
-char *sr_period_string(uint64_t frequency);
-char **sr_parse_triggerstring(struct sr_device *device,
- const char *triggerstring);
-int sr_parse_sizestring(const char *sizestring, uint64_t *size);
-uint64_t sr_parse_timestring(const char *timestring);
-gboolean sr_parse_boolstring(const char *boolstring);
+SR_API char *sr_samplerate_string(uint64_t samplerate);
+SR_API char *sr_period_string(uint64_t frequency);
+SR_API char **sr_parse_triggerstring(struct sr_device *device,
+ const char *triggerstring);
+SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size);
+SR_API uint64_t sr_parse_timestring(const char *timestring);
+SR_API gboolean sr_parse_boolstring(const char *boolstring);
#endif
#define SR_LOG_DBG 4
#define SR_LOG_SPEW 5
+/*
+ * Use SR_API to mark public API symbols, and SR_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 libsigrok-internal files) but are also not meant to
+ * be part of the public libsigrok API, must use SR_PRIV.
+ *
+ * This uses the 'visibility' feature of gcc (requires gcc >= 4.0).
+ *
+ * Details: http://gcc.gnu.org/wiki/Visibility
+ */
+
+/* Marks public libsigrok API symbols. */
+#define SR_API __attribute__((visibility("default")))
+
+/* Marks private, non-public libsigrok symbols (not part of the API). */
+#define SR_PRIV __attribute__((visibility("hidden")))
+
typedef int (*sr_receive_data_callback) (int fd, int revents, void *user_data);
/* Data types used by hardware plugins for set_configuration() */
* @return A malloc()ed string representation of the samplerate value,
* or NULL upon errors. The caller is responsible to free() the memory.
*/
-char *sr_samplerate_string(uint64_t samplerate)
+SR_API char *sr_samplerate_string(uint64_t samplerate)
{
char *o;
int r;
* @return A malloc()ed string representation of the frequency value,
* or NULL upon errors. The caller is responsible to free() the memory.
*/
-char *sr_period_string(uint64_t frequency)
+SR_API char *sr_period_string(uint64_t frequency)
{
char *o;
int r;
* @param triggerstring TODO
* @return TODO
*/
-char **sr_parse_triggerstring(struct sr_device *device,
- const char *triggerstring)
+SR_API char **sr_parse_triggerstring(struct sr_device *device,
+ const char *triggerstring)
{
GSList *l;
struct sr_probe *probe;
* @return SR_OK or error code
*
*/
-int sr_parse_sizestring(const char *sizestring, uint64_t *size)
+SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size)
{
int multiplier, done;
char *s;
* TODO: picoseconds?
* TODO: Allow both lower-case and upper-case.
*/
-uint64_t sr_parse_timestring(const char *timestring)
+SR_API uint64_t sr_parse_timestring(const char *timestring)
{
uint64_t time_msec;
char *s;
return time_msec;
}
-gboolean sr_parse_boolstring(const char *boolstr)
+SR_API gboolean sr_parse_boolstring(const char *boolstr)
{
if (!boolstr)
return FALSE;
- if (!g_strcasecmp(boolstr, "true") ||
+ if (!g_strcasecmp(boolstr, "true") ||
!g_strcasecmp(boolstr, "yes") ||
!g_strcasecmp(boolstr, "on") ||
- !g_strcasecmp(boolstr, "1"))
+ !g_strcasecmp(boolstr, "1"))
return TRUE;
return FALSE;