]> sigrok.org Git - libsigrok.git/blobdiff - src/libsigrok-internal.h
ensure the only entry point of libdrivers doesn't have visibility=hidden
[libsigrok.git] / src / libsigrok-internal.h
index 328e17078f32b77faa91a6643e8166e6b2749dc3..3537c132c4d4d80807ead329b5bbf126255034bf 100644 (file)
@@ -267,6 +267,73 @@ struct zip_stat;
 #define ALL_ZERO { 0 }
 #endif
 
+#ifdef __APPLE__
+#define SR_DRIVER_LIST_SECTION "__DATA,__sr_driver_list"
+#else
+#define SR_DRIVER_LIST_SECTION "sr_driver_list"
+#endif
+
+/**
+ * Register a list of hardware drivers.
+ *
+ * This macro can be used to register multiple hardware drivers to the library.
+ * This is useful when a driver supports multiple similar but slightly
+ * different devices that require different sr_dev_driver struct definitions.
+ *
+ * For registering only a single driver see SR_REGISTER_DEV_DRIVER().
+ *
+ * Example:
+ * @code{c}
+ * #define MY_DRIVER(_name) \
+ *     &(struct sr_dev_driver){ \
+ *         .name = _name, \
+ *         ...
+ *     };
+ *
+ * SR_REGISTER_DEV_DRIVER_LIST(my_driver_infos,
+ *     MY_DRIVER("driver 1"),
+ *     MY_DRIVER("driver 2"),
+ *     ...
+ * );
+ * @endcode
+ *
+ * @param name Name to use for the driver list identifier.
+ * @param ... Comma separated list of pointers to sr_dev_driver structs.
+ */
+#define SR_REGISTER_DEV_DRIVER_LIST(name, ...) \
+       static const struct sr_dev_driver *name[] \
+               __attribute__((section (SR_DRIVER_LIST_SECTION), used, \
+                       aligned(sizeof(struct sr_dev_driver *)))) \
+               = { \
+                       __VA_ARGS__ \
+               };
+
+/**
+ * Register a hardware driver.
+ *
+ * This macro is used to register a hardware driver with the library. It has
+ * to be used in order to make the driver accessible to applications using the
+ * library.
+ *
+ * The macro invocation should be placed directly under the struct
+ * sr_dev_driver definition.
+ *
+ * Example:
+ * @code{c}
+ * static struct sr_dev_driver driver_info = {
+ *     .name = "driver",
+ *     ....
+ * };
+ * SR_REGISTER_DEV_DRIVER(driver_info);
+ * @endcode
+ *
+ * @param name Identifier name of sr_dev_driver struct to register.
+ */
+#define SR_REGISTER_DEV_DRIVER(name) \
+       SR_REGISTER_DEV_DRIVER_LIST(name##_list, &name);
+
+SR_API void sr_drivers_init(struct sr_context *context);
+
 struct sr_context {
        struct sr_dev_driver **driver_list;
 #ifdef HAVE_LIBUSB_1_0
@@ -760,8 +827,6 @@ SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc);
 
 /*--- hwdriver.c ------------------------------------------------------------*/
 
-extern SR_PRIV struct sr_dev_driver **drivers_lists[];
-
 SR_PRIV const GVariantType *sr_variant_type_get(int datatype);
 SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *data);
 SR_PRIV void sr_hw_cleanup_all(const struct sr_context *ctx);
@@ -859,23 +924,19 @@ SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
 typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);
 typedef void (*std_dev_clear_callback)(void *priv);
 
-SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx,
-               const char *prefix);
+SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx);
 SR_PRIV int std_cleanup(const struct sr_dev_driver *di);
 #ifdef HAVE_LIBSERIALPORT
 SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi);
-SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
-               dev_close_callback dev_close_fn,
-               struct sr_serial_dev_inst *serial, const char *prefix);
+SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi);
 #endif
-SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
-               const char *prefix);
-SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi,
-               const char *prefix);
+SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
+SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
 SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
                std_dev_clear_callback clear_private);
 SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
 SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
+SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
 
 /*--- resource.c ------------------------------------------------------------*/
 
@@ -1068,25 +1129,25 @@ struct es519xx_info {
 
 SR_PRIV gboolean sr_es519xx_2400_11b_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_2400_11b_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 SR_PRIV gboolean sr_es519xx_2400_11b_altfn_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_2400_11b_altfn_parse(const uint8_t *buf,
-               float *floatval, struct sr_datafeed_analog_old *analog, void *info);
+               float *floatval, struct sr_datafeed_analog *analog, void *info);
 SR_PRIV gboolean sr_es519xx_19200_11b_5digits_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_19200_11b_5digits_parse(const uint8_t *buf,
-               float *floatval, struct sr_datafeed_analog_old *analog, void *info);
+               float *floatval, struct sr_datafeed_analog *analog, void *info);
 SR_PRIV gboolean sr_es519xx_19200_11b_clamp_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_19200_11b_clamp_parse(const uint8_t *buf,
-               float *floatval, struct sr_datafeed_analog_old *analog, void *info);
+               float *floatval, struct sr_datafeed_analog *analog, void *info);
 SR_PRIV gboolean sr_es519xx_19200_11b_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_19200_11b_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 SR_PRIV gboolean sr_es519xx_19200_14b_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_19200_14b_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 SR_PRIV gboolean sr_es519xx_19200_14b_sel_lpf_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_es519xx_19200_14b_sel_lpf_parse(const uint8_t *buf,
-               float *floatval, struct sr_datafeed_analog_old *analog, void *info);
+               float *floatval, struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/fs9922.c -------------------------------------------------*/
 
@@ -1103,8 +1164,8 @@ struct fs9922_info {
 
 SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval,
-                           struct sr_datafeed_analog_old *analog, void *info);
-SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog_old *analog, void *info);
+                           struct sr_datafeed_analog *analog, void *info);
+SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/fs9721.c -------------------------------------------------*/
 
@@ -1119,12 +1180,12 @@ struct fs9721_info {
 
 SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval,
-                           struct sr_datafeed_analog_old *analog, void *info);
-SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog_old *analog, void *info);
-SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog_old *analog, void *info);
-SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog_old *analog, void *info);
-SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog_old *analog, void *info);
-SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog_old *analog, void *info);
+                           struct sr_datafeed_analog *analog, void *info);
+SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info);
+SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info);
+SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info);
+SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info);
+SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/dtm0660.c ------------------------------------------------*/
 
@@ -1140,7 +1201,7 @@ struct dtm0660_info {
 
 SR_PRIV gboolean sr_dtm0660_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_dtm0660_parse(const uint8_t *buf, float *floatval,
-                       struct sr_datafeed_analog_old *analog, void *info);
+                       struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/m2110.c --------------------------------------------------*/
 
@@ -1148,7 +1209,7 @@ SR_PRIV int sr_dtm0660_parse(const uint8_t *buf, float *floatval,
 
 SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
-                            struct sr_datafeed_analog_old *analog, void *info);
+                            struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/metex14.c ------------------------------------------------*/
 
@@ -1167,7 +1228,7 @@ SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial);
 #endif
 SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
-                            struct sr_datafeed_analog_old *analog, void *info);
+                            struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/rs9lcd.c -------------------------------------------------*/
 
@@ -1178,7 +1239,7 @@ struct rs9lcd_info { int dummy; };
 
 SR_PRIV gboolean sr_rs9lcd_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
-                           struct sr_datafeed_analog_old *analog, void *info);
+                           struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/bm25x.c --------------------------------------------------*/
 
@@ -1189,7 +1250,7 @@ struct bm25x_info { int dummy; };
 
 SR_PRIV gboolean sr_brymen_bm25x_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_brymen_bm25x_parse(const uint8_t *buf, float *floatval,
-                            struct sr_datafeed_analog_old *analog, void *info);
+                            struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/ut71x.c --------------------------------------------------*/
 
@@ -1204,7 +1265,7 @@ struct ut71x_info {
 
 SR_PRIV gboolean sr_ut71x_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_ut71x_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/dmm/vc870.c --------------------------------------------------*/
 
@@ -1225,7 +1286,7 @@ struct vc870_info {
 
 SR_PRIV gboolean sr_vc870_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/lcr/es51919.c ------------------------------------------------*/
 
@@ -1255,7 +1316,7 @@ struct ut372_info {
 
 SR_PRIV gboolean sr_ut372_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 
 /*--- hardware/scale/kern.c -------------------------------------------------*/
 
@@ -1268,7 +1329,7 @@ struct kern_info {
 
 SR_PRIV gboolean sr_kern_packet_valid(const uint8_t *buf);
 SR_PRIV int sr_kern_parse(const uint8_t *buf, float *floatval,
-               struct sr_datafeed_analog_old *analog, void *info);
+               struct sr_datafeed_analog *analog, void *info);
 
 /*--- sw_limits.c -----------------------------------------------------------*/