]> sigrok.org Git - libsigrok.git/blobdiff - sigrok.h
Gnuplot output format support.
[libsigrok.git] / sigrok.h
index 3729a43c36ae042c6bd94f6db00ce6dee6100a27..50fd0716ba17229988db7ebcba047e78a9a4d452 100644 (file)
--- a/sigrok.h
+++ b/sigrok.h
 #include <glib.h>
 #include <libusb.h>
 
-/* Returned status/error codes */
-#define SIGROK_STATUS_DISABLED         0
-#define SIGROK_OK                      1
-#define SIGROK_NOK                     2
-#define SIGROK_ERR_BADVALUE            20
+/*
+ * Status/error codes returned by libsigrok functions.
+ *
+ * All possible return codes of libsigrok 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.
+ *
+ * The error codes are globally unique in libsigrok, i.e. if one of the
+ * libsigrok functions returns a "malloc error" it must be exactly the same
+ * return value as used by all other functions to indicate "malloc error".
+ * There must be no functions which indicate two different errors via the
+ * 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
+ * return codes, but never remove or redefine existing ones.
+ */
+#define SIGROK_OK                       0 /* No error */
+#define SIGROK_ERR                     -1 /* Generic/unspecified error */
+#define SIGROK_ERR_MALLOC              -2 /* Malloc/calloc/realloc error */
+#define SIGROK_ERR_SAMPLERATE          -3 /* Incorrect samplerate */
 
 /* Handy little macros */
 #define KHZ(n) (n * 1000)
@@ -81,7 +97,7 @@ struct datafeed_packet {
 struct datafeed_header {
        int feed_version;
        struct timeval starttime;
-       uint64_t rate;
+       uint64_t samplerate;
        int protocol_id;
        int num_probes;
 };
@@ -99,7 +115,7 @@ struct output {
 struct output_format {
        char *extension;
        char *description;
-       void (*init) (struct output *o);
+       int (*init) (struct output *o);
        int (*data) (struct output *o, char *data_in, uint64_t length_in,
                     char **data_out, uint64_t *length_out);
        int (*event) (struct output *o, int event_type, char **data_out,
@@ -197,7 +213,7 @@ void device_trigger_set(struct device *device, int probenum, char *trigger);
 enum {
        HWCAP_DUMMY,            // used to terminate lists
        HWCAP_LOGIC_ANALYZER,
-       HWCAP_SAMPLERATE,       // change sample rate
+       HWCAP_SAMPLERATE,       // change samplerate
        HWCAP_PROBECONFIG,      // configure probe mask
        HWCAP_CAPTURE_RATIO,    // set pre-trigger / post-trigger ratio
        HWCAP_LIMIT_MSEC,       // set a time limit for sample acquisition
@@ -263,12 +279,12 @@ enum {
        DI_INSTANCE,
        /* The number of probes connected to this device */
        DI_NUM_PROBES,
-       /* Sample rates supported by this device, (struct samplerates) */
+       /* Samplerates supported by this device, (struct samplerates) */
        DI_SAMPLERATES,
        /* Types of trigger supported, out of "01crf" (char *) */
        DI_TRIGGER_TYPES,
-       /* The currently set sample rate in Hz (uint64_t) */
-       DI_CUR_SAMPLE_RATE,
+       /* The currently set samplerate in Hz (uint64_t) */
+       DI_CUR_SAMPLERATE,
 };
 
 /* a device supports either a range of samplerates with steps of a given