From: Martin Ling Date: Sat, 21 Mar 2015 00:47:31 +0000 (+0000) Subject: Pass driver struct pointer to driver callbacks. X-Git-Tag: libsigrok-0.4.0~585 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4f840ce965b1c30c5ab75afecc56193cbaf5c1b3;p=libsigrok.git Pass driver struct pointer to driver callbacks. This lays the groundwork for subdrivers to share callbacks without needing a separate wrapper function for each subdriver. --- diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index 7f37d4de..16412a7f 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -998,24 +998,24 @@ struct sr_dev_driver { /** API version (currently 1). */ int api_version; /** Called when driver is loaded, e.g. program startup. */ - int (*init) (struct sr_context *sr_ctx); + int (*init) (struct sr_dev_driver *driver, struct sr_context *sr_ctx); /** Called before driver is unloaded. * Driver must free all resources held by it. */ - int (*cleanup) (void); + int (*cleanup) (const struct sr_dev_driver *driver); /** Scan for devices. Driver should do all initialisation required. * Can be called several times, e.g. with different port options. * \retval NULL Error or no devices found. * \retval other GSList of a struct sr_dev_inst for each device. * Must be freed by caller! */ - GSList *(*scan) (GSList *options); + GSList *(*scan) (struct sr_dev_driver *driver, GSList *options); /** Get list of device instances the driver knows about. * \returns NULL or GSList of a struct sr_dev_inst for each device. * Must not be freed by caller! */ - GSList *(*dev_list) (void); + GSList *(*dev_list) (const struct sr_dev_driver *driver); /** Clear list of devices the driver knows about. */ - int (*dev_clear) (void); + int (*dev_clear) (const struct sr_dev_driver *driver); /** Query value of a configuration key in driver or given device instance. * @see sr_config_get(). */ diff --git a/src/device.c b/src/device.c index d0b9e482..b1c7eae1 100644 --- a/src/device.c +++ b/src/device.c @@ -360,7 +360,7 @@ SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc) SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver) { if (driver && driver->dev_list) - return driver->dev_list(); + return driver->dev_list(driver); else return NULL; } @@ -386,7 +386,7 @@ SR_API int sr_dev_clear(const struct sr_dev_driver *driver) } if (driver->dev_clear) - ret = driver->dev_clear(); + ret = driver->dev_clear(driver); else ret = std_dev_clear(driver, NULL); diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 7cfb69d8..6c41023d 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -71,14 +71,13 @@ static const struct agdmm_profile supported_agdmm[] = { }; SR_PRIV struct sr_dev_driver agdmm_driver_info; -static struct sr_dev_driver *di = &agdmm_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -165,12 +164,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index b9f767d2..27c29e92 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -42,14 +42,13 @@ static const char *data_sources[] = { }; SR_PRIV struct sr_dev_driver appa_55ii_driver_info; -static struct sr_dev_driver *di = &appa_55ii_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -121,12 +120,12 @@ scan_cleanup: return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index e1355e9f..dac6e011 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -39,7 +39,6 @@ #define USB_MODEL_NAME "SIGMA" SR_PRIV struct sr_dev_driver asix_sigma_driver_info; -static struct sr_dev_driver *di = &asix_sigma_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); /* @@ -312,17 +311,17 @@ static void clear_helper(void *priv) ftdi_deinit(&devc->ftdic); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -401,7 +400,7 @@ free: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -803,9 +802,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 1eafaaff..359121f0 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -77,14 +77,13 @@ static struct pps_model models[] = { SR_PRIV struct sr_dev_driver atten_pps3203_driver_info; -static struct sr_dev_driver *di = &atten_pps3203_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options, int modelid) +static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -196,17 +195,17 @@ static GSList *scan(GSList *options, int modelid) return devices; } -static GSList *scan_3203(GSList *options) +static GSList *scan_3203(struct sr_dev_driver *di, GSList *options) { - return scan(options, PPS_3203T_3S); + return scan(di, options, PPS_3203T_3S); } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index b4ef69dd..f1da9b50 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -20,7 +20,6 @@ #include "protocol.h" SR_PRIV struct sr_dev_driver baylibre_acme_driver_info; -static struct sr_dev_driver *di = &baylibre_acme_driver_info; static const uint32_t devopts[] = { SR_CONF_CONTINUOUS | SR_CONF_SET, @@ -42,12 +41,12 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -131,12 +130,12 @@ err_out: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } @@ -161,9 +160,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - dev_clear(); + dev_clear(di); return SR_OK; } diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index e6668ae6..d10d071b 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -21,7 +21,6 @@ #include "beaglelogic.h" SR_PRIV struct sr_dev_driver beaglelogic_driver_info; -static struct sr_dev_driver *di = &beaglelogic_driver_info; /* Scan options */ static const uint32_t scanopts[] = { @@ -61,7 +60,7 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -79,7 +78,7 @@ static struct dev_context *beaglelogic_devc_alloc(void) return devc; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; GSList *devices, *l; @@ -146,12 +145,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } @@ -200,7 +199,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { struct drv_context *drvc; struct sr_dev_inst *sdi; @@ -220,8 +219,6 @@ static int cleanup(void) g_slist_free(drvc->instances); drvc->instances = NULL; - di->priv = NULL; - return SR_OK; } diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index 87d2e5af..79e658f5 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -33,14 +33,13 @@ static const uint32_t devopts[] = { }; SR_PRIV struct sr_dev_driver brymen_bm86x_driver_info; -static struct sr_dev_driver *di = &brymen_bm86x_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { GSList *usb_devices, *devices, *l; struct drv_context *drvc; @@ -92,13 +91,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->priv; struct sr_usb_dev_inst *usb; struct dev_context *devc; @@ -166,7 +166,7 @@ static int dev_close(struct sr_dev_inst *sdi) return ret; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 058835ee..38a5ab8f 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -34,7 +34,7 @@ static const uint32_t devopts[] = { SR_PRIV struct sr_dev_driver brymen_bm857_driver_info; static struct sr_dev_driver *di = &brymen_bm857_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -93,7 +93,7 @@ scan_cleanup: return devices; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct sr_config *src; @@ -130,12 +130,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 5c259542..1e499802 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -67,15 +67,14 @@ static const char *data_sources[] = { "Memory", }; SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info; -static struct sr_dev_driver *di = &cem_dt_885x_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -135,7 +134,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -153,7 +152,7 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index cc9e3d7a..3827c639 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -239,15 +239,21 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) /* Driver-specific API function wrappers */ #define HW_INIT(X) \ -static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } +static int init_##X(struct sr_dev_driver *d, \ + struct sr_context *sr_ctx) { \ + (void) d; return init(sr_ctx, X); } #define HW_CLEANUP(X) \ -static int cleanup_##X(void) { return cleanup(X); } +static int cleanup_##X(const struct sr_dev_driver *d) { \ + (void) d; return cleanup(X); } #define HW_SCAN(X) \ -static GSList *scan_##X(GSList *options) { return scan(options, X); } +static GSList *scan_##X(struct sr_dev_driver *d, GSList *options) { \ + (void) d; return scan(options, X); } #define HW_DEV_LIST(X) \ -static GSList *dev_list_##X(void) { return dev_list(X); } +static GSList *dev_list_##X(const struct sr_dev_driver *d) { \ + (void) d; return dev_list(X); } #define HW_DEV_CLEAR(X) \ -static int dev_clear_##X(void) { return dev_clear(X); } +static int dev_clear_##X(const struct sr_dev_driver *d) { \ + (void) d; return dev_clear(X); } #define HW_DEV_ACQUISITION_START(X) \ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 14f1066e..7d4aae04 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -63,12 +63,12 @@ static void clear_helper(void *priv) g_free(devc->final_buf); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -142,13 +142,14 @@ err_free_devc: return ret; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { int ret; unsigned int i; GSList *devices; struct ftdi_context *ftdic; + (void)di; (void)options; devices = NULL; @@ -188,7 +189,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -267,9 +268,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index 6e907cec..eedffbfb 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -43,14 +43,13 @@ static const uint32_t devopts[] = { }; SR_PRIV struct sr_dev_driver colead_slm_driver_info; -static struct sr_dev_driver *di = &colead_slm_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -97,7 +96,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -115,7 +114,7 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index dc524264..a9ea575e 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -39,14 +39,13 @@ static const uint32_t devopts[] = { }; SR_PRIV struct sr_dev_driver conrad_digi_35_cpu_driver_info; -static struct sr_dev_driver *di = &conrad_digi_35_cpu_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -106,12 +105,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index fb1bb05f..0704cde2 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -180,12 +180,11 @@ static uint8_t pattern_sigrok[] = { }; SR_PRIV struct sr_dev_driver demo_driver_info; -static struct sr_dev_driver *di = &demo_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -266,7 +265,7 @@ static void generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate) } } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -369,7 +368,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -404,7 +403,7 @@ static void clear_helper(void *priv) g_free(devc); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } diff --git a/src/hardware/deree-de5000/api.c b/src/hardware/deree-de5000/api.c index 40ace4ee..88aa8828 100644 --- a/src/hardware/deree-de5000/api.c +++ b/src/hardware/deree-de5000/api.c @@ -34,7 +34,7 @@ static void std_dev_attach(struct sr_dev_driver *di, struct sr_dev_inst *sdi) drvc->instances = g_slist_append(drvc->instances, sdi); } -static GSList *std_dev_list(struct sr_dev_driver *di) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)di->priv)->instances; } @@ -43,33 +43,28 @@ static GSList *std_dev_list(struct sr_dev_driver *di) SR_PRIV struct sr_dev_driver deree_de5000_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, &deree_de5000_driver_info, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return std_dev_clear(&deree_de5000_driver_info, es51919_serial_clean); + return std_dev_clear(di, es51919_serial_clean); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; if (!(sdi = es51919_serial_scan(options, "DER EE", "DE-5000"))) return NULL; - std_dev_attach(&deree_de5000_driver_info, sdi); + std_dev_attach(di, sdi); return g_slist_append(NULL, sdi); } -static GSList *dev_list(void) -{ - return std_dev_list(&deree_de5000_driver_info); -} - SR_PRIV struct sr_dev_driver deree_de5000_driver_info = { .name = "deree-de5000", .longname = "DER EE DE-5000", diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index bb903d2f..52bb084a 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -40,7 +40,6 @@ static const uint32_t devopts[] = { }; SR_PRIV struct sr_dev_driver flukedmm_driver_info; -static struct sr_dev_driver *di = &flukedmm_driver_info; static char *scan_conn[] = { /* 287/289 */ @@ -59,12 +58,13 @@ static const struct flukedmm_profile supported_flukedmm[] = { { FLUKE_190, "199B", 1000, 3500 }, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *fluke_scan(const char *conn, const char *serialcomm) +static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn, + const char *serialcomm) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -149,7 +149,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) return devices; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_config *src; GSList *l, *devices; @@ -174,10 +174,10 @@ static GSList *scan(GSList *options) devices = NULL; if (serialcomm) { /* Use the provided comm specs. */ - devices = fluke_scan(conn, serialcomm); + devices = fluke_scan(di, conn, serialcomm); } else { for (i = 0; scan_conn[i]; i++) { - if ((devices = fluke_scan(conn, scan_conn[i]))) + if ((devices = fluke_scan(di, conn, scan_conn[i]))) break; /* The Scopemeter 199B, at least, requires this * after all the 115k/9.6k confusion. */ @@ -188,12 +188,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 8e9b5be4..1fb2235f 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -158,14 +158,13 @@ static const uint64_t dslogic_samplerates[] = { }; SR_PRIV struct sr_dev_driver fx2lafw_driver_info; -static struct sr_dev_driver *di = &fx2lafw_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -340,13 +339,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; struct dev_context *devc; int ret; @@ -440,7 +440,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -451,7 +451,6 @@ static int cleanup(void) ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -601,7 +600,7 @@ static int receive_data(int fd, int revents, void *cb_data) (void)revents; (void)cb_data; - drvc = di->priv; + drvc = (struct drv_context *) cb_data; tv.tv_sec = tv.tv_usec = 0; libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); @@ -735,6 +734,7 @@ static int dslogic_trigger_request(const struct sr_dev_inst *sdi) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di; struct drv_context *drvc; struct dev_context *devc; int timeout, ret; @@ -742,6 +742,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; + di = sdi->driver; drvc = di->priv; devc = sdi->priv; @@ -752,7 +753,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->acq_aborted = FALSE; timeout = fx2lafw_get_timeout(devc); - usb_source_add(sdi->session, devc->ctx, timeout, receive_data, NULL); + usb_source_add(sdi->session, devc->ctx, timeout, receive_data, drvc); if (devc->dslogic) { dslogic_trigger_request(sdi); diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 96d7656c..13918c63 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -66,16 +66,10 @@ static const uint32_t devopts_bd[] = { * Need to implement device-specific lists. */ -/** Init driver gmc_mh_1x_2x_rs232. */ -static int init_1x_2x_rs232(struct sr_context *sr_ctx) +/** Init driver. */ +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, &gmc_mh_1x_2x_rs232_driver_info, LOG_PREFIX); -} - -/** Init driver gmc_mh_2x_bd232. */ -static int init_2x_bd232(struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, &gmc_mh_2x_bd232_driver_info, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } /** @@ -156,7 +150,7 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) * on configuration and measurement mode the intervals can be much larger and * then the detection might not work. */ -static GSList *scan_1x_2x_rs232(GSList *options) +static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -169,7 +163,7 @@ static GSList *scan_1x_2x_rs232(GSList *options) gboolean serialcomm_given; devices = NULL; - drvc = (&gmc_mh_1x_2x_rs232_driver_info)->priv; + drvc = di->priv; drvc->instances = NULL; conn = serialcomm = NULL; model = METRAHIT_NONE; @@ -234,7 +228,7 @@ static GSList *scan_1x_2x_rs232(GSList *options) devc->settings_ok = FALSE; sdi->conn = serial; sdi->priv = devc; - sdi->driver = &gmc_mh_1x_2x_rs232_driver_info; + sdi->driver = di; sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); @@ -246,7 +240,7 @@ static GSList *scan_1x_2x_rs232(GSList *options) /** Scan for Metrahit 2x in a bidirectional mode using Gossen Metrawatt 'BD 232' interface. * */ -static GSList *scan_2x_bd232(GSList *options) +static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -263,7 +257,7 @@ static GSList *scan_2x_bd232(GSList *options) conn = serialcomm = NULL; devices = NULL; - drvc = (&gmc_mh_2x_bd232_driver_info)->priv; + drvc = di->priv; drvc->instances = NULL; sr_spew("scan_2x_bd232() called!"); @@ -328,7 +322,7 @@ static GSList *scan_2x_bd232(GSList *options) sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min); sdi->conn = serial; sdi->priv = devc; - sdi->driver = &gmc_mh_2x_bd232_driver_info; + sdi->driver = di; sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); @@ -361,16 +355,9 @@ exit_err: } /** Driver device list function */ -static GSList *dev_list_1x_2x_rs232(void) -{ - return ((struct drv_context *)(gmc_mh_1x_2x_rs232_driver_info.priv))->instances; -} - -/** Driver device list function */ -static GSList *dev_list_2x_bd232(void) +static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(gmc_mh_2x_bd232_driver_info.priv)) - ->instances; + return ((struct drv_context *)(di->priv))->instances; } static int dev_close(struct sr_dev_inst *sdi) @@ -391,14 +378,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup_sm_rs232(void) -{ - return std_dev_clear(&gmc_mh_1x_2x_rs232_driver_info, NULL); -} - -static int cleanup_2x_bd232(void) +static int cleanup(const struct sr_dev_driver *di) { - return std_dev_clear(&gmc_mh_2x_bd232_driver_info, NULL); + return std_dev_clear(di, NULL); } /** Get value of configuration item */ @@ -563,10 +545,10 @@ SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = { .name = "gmc-mh-1x-2x-rs232", .longname = "Gossen Metrawatt Metrahit 1x/2x, RS232 interface", .api_version = 1, - .init = init_1x_2x_rs232, - .cleanup = cleanup_sm_rs232, + .init = init, + .cleanup = cleanup, .scan = scan_1x_2x_rs232, - .dev_list = dev_list_1x_2x_rs232, + .dev_list = dev_list, .dev_clear = NULL, .config_get = config_get, .config_set = config_set, @@ -582,10 +564,10 @@ SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info = { .name = "gmc-mh-2x-bd232", .longname = "Gossen Metrawatt Metrahit 2x, BD232/SI232-II interface", .api_version = 1, - .init = init_2x_bd232, - .cleanup = cleanup_2x_bd232, + .init = init, + .cleanup = cleanup, .scan = scan_2x_bd232, - .dev_list = dev_list_2x_bd232, + .dev_list = dev_list, .dev_clear = NULL, .config_get = config_get, .config_set = config_set, diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 77feac86..46db733e 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -23,7 +23,6 @@ #define SERIALCOMM "115200/8n1/flow=1" SR_PRIV struct sr_dev_driver hameg_hmo_driver_info; -static struct sr_dev_driver *di = &hameg_hmo_driver_info; static const char *manufacturers[] = { "HAMEG", @@ -45,7 +44,7 @@ enum { CG_DIGITAL, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -85,7 +84,7 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi sdi->model = g_strdup(hw_info->model); sdi->version = g_strdup(hw_info->firmware_version); sdi->serial_num = g_strdup(hw_info->serial_number); - sdi->driver = di; + sdi->driver = &hameg_hmo_driver_info; sdi->inst_type = SR_INST_SCPI; sdi->conn = scpi; @@ -116,12 +115,12 @@ fail: return NULL; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { return sr_scpi_scan(di->priv, options, hmo_probe_serial_device); } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -140,7 +139,7 @@ static void clear_helper(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } @@ -170,9 +169,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - dev_clear(); + dev_clear(di); return SR_OK; } diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index e2d09142..253d37cd 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -159,7 +159,6 @@ static const char *coupling[] = { }; SR_PRIV struct sr_dev_driver hantek_dso_driver_info; -static struct sr_dev_driver *di = &hantek_dso_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); @@ -176,7 +175,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) sdi->status = SR_ST_INITIALIZING; sdi->vendor = g_strdup(prof->vendor); sdi->model = g_strdup(prof->model); - sdi->driver = di; + sdi->driver = &hantek_dso_driver_info; /* * Add only the real channels -- EXT isn't a source of data, only @@ -208,7 +207,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) devc->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE); devc->triggerposition = DEFAULT_HORIZ_TRIGGERPOS; sdi->priv = devc; - drvc = di->priv; + drvc = hantek_dso_driver_info.priv; drvc->instances = g_slist_append(drvc->instances, sdi); return sdi; @@ -248,17 +247,17 @@ static void clear_dev_context(void *priv) } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_dev_context); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -361,7 +360,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -421,9 +420,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -867,8 +866,9 @@ static int handle_event(int fd, int revents, void *cb_data) const struct sr_dev_inst *sdi; struct sr_datafeed_packet packet; struct timeval tv; + struct sr_dev_driver *di; struct dev_context *devc; - struct drv_context *drvc = di->priv; + struct drv_context *drvc; int num_channels; uint32_t trigger_offset; uint8_t capturestate; @@ -877,6 +877,8 @@ static int handle_event(int fd, int revents, void *cb_data) (void)revents; sdi = cb_data; + di = sdi->driver; + drvc = di->priv; devc = sdi->priv; if (devc->dev_state == STOPPING) { /* We've been told to wind up the acquisition. */ @@ -976,6 +978,7 @@ static int handle_event(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->priv; if (sdi->status != SR_ST_ACTIVE) diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index b9418db2..97a733a1 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -53,14 +53,13 @@ static const char *channel_names[NUM_CHANNELS + 1] = { }; SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info; -static struct sr_dev_driver *di = &ikalogic_scanalogic2_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { GSList *usb_devices, *devices, *l; struct drv_context *drvc; @@ -162,7 +161,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -180,13 +179,14 @@ static void clear_dev_context(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, &clear_dev_context); } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; struct sr_usb_dev_inst *usb; @@ -258,6 +258,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; if (!di->priv) { @@ -279,9 +280,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -386,6 +387,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; uint16_t trigger_bytes, tmp; diff --git a/src/hardware/ikalogic-scanalogic2/protocol.c b/src/hardware/ikalogic-scanalogic2/protocol.c index 663ff527..c26b32a6 100644 --- a/src/hardware/ikalogic-scanalogic2/protocol.c +++ b/src/hardware/ikalogic-scanalogic2/protocol.c @@ -20,7 +20,6 @@ #include "protocol.h" extern struct sr_dev_driver ikalogic_scanalogic2_driver_info; -static struct sr_dev_driver *di = &ikalogic_scanalogic2_driver_info; extern uint64_t sl2_samplerates[NUM_SAMPLERATES]; @@ -199,6 +198,7 @@ static void process_sample_data(const struct sr_dev_inst *sdi) SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; + struct sr_dev_driver *di; struct dev_context *devc; struct drv_context *drvc; struct timeval tv; @@ -214,6 +214,7 @@ SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, void *cb_data if (!(devc = sdi->priv)) return TRUE; + di = sdi->driver; drvc = di->priv; current_time = g_get_monotonic_time(); @@ -642,7 +643,7 @@ SR_PRIV int sl2_get_device_info(struct sr_usb_dev_inst usb, uint8_t buffer[PACKET_LENGTH]; int ret; - drvc = di->priv; + drvc = ikalogic_scanalogic2_driver_info.priv; if (!dev_info) return SR_ERR_ARG; diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 3bd1b273..6e311cbd 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -45,7 +45,6 @@ static const char *channel_names[] = { static uint64_t samplerates[1] = { SR_MHZ(100) }; SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info; -static struct sr_dev_driver *di = &ikalogic_scanaplus_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); @@ -61,17 +60,17 @@ static void clear_helper(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -151,7 +150,7 @@ err_free_devc: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -263,9 +262,9 @@ static int dev_close(struct sr_dev_inst *sdi) return ret; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 7f49364a..37d681cb 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -61,15 +61,15 @@ static const char *data_sources[] = { }; SR_PRIV struct sr_dev_driver kecheng_kc_330b_driver_info; -static struct sr_dev_driver *di = &kecheng_kc_330b_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static int scan_kecheng(struct sr_usb_dev_inst *usb, char **model) +static int scan_kecheng(struct sr_dev_driver *di, + struct sr_usb_dev_inst *usb, char **model) { struct drv_context *drvc; int len, ret; @@ -108,7 +108,7 @@ static int scan_kecheng(struct sr_usb_dev_inst *usb, char **model) return SR_OK; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -126,7 +126,7 @@ static GSList *scan(GSList *options) /* We have a list of sr_usb_dev_inst matching the connection * string. Wrap them in sr_dev_inst and we're done. */ for (l = usb_devices; l; l = l->next) { - if (scan_kecheng(l->data, &model) != SR_OK) + if (scan_kecheng(di, l->data, &model) != SR_OK) continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; @@ -160,13 +160,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct sr_usb_dev_inst *usb; int ret; @@ -197,6 +198,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct sr_usb_dev_inst *usb; @@ -225,7 +227,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -237,7 +239,6 @@ static int cleanup(void) ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -294,6 +295,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; uint64_t p, q; unsigned int i; @@ -415,6 +417,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; struct sr_datafeed_packet packet; diff --git a/src/hardware/kecheng-kc-330b/protocol.c b/src/hardware/kecheng-kc-330b/protocol.c index caf896ac..f5638668 100644 --- a/src/hardware/kecheng-kc-330b/protocol.c +++ b/src/hardware/kecheng-kc-330b/protocol.c @@ -21,11 +21,11 @@ #include "protocol.h" extern struct sr_dev_driver kecheng_kc_330b_driver_info; -static struct sr_dev_driver *di = &kecheng_kc_330b_driver_info; extern const uint64_t kecheng_kc_330b_sample_intervals[][2]; SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data) { + struct sr_dev_driver *di; struct drv_context *drvc; struct dev_context *devc; struct sr_datafeed_packet packet; @@ -40,10 +40,11 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data) (void)fd; (void)revents; - drvc = di->priv; sdi = cb_data; devc = sdi->priv; usb = sdi->conn; + di = sdi->driver; + drvc = di->priv; memset(&tv, 0, sizeof(struct timeval)); libusb_handle_events_timeout_completed(drvc->sr_ctx->libusb_ctx, &tv, diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 73141561..fc65b228 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -24,7 +24,6 @@ #include "protocol.h" SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info; -static struct sr_dev_driver *di = &lascar_el_usb_driver_info; static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -38,12 +37,12 @@ static const uint32_t devopts[] = { SR_CONF_DATALOG | SR_CONF_GET | SR_CONF_SET, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct sr_dev_inst *sdi; @@ -89,13 +88,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct sr_usb_dev_inst *usb; int ret; @@ -121,6 +121,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; if (!di->priv) { @@ -142,7 +143,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -154,7 +155,6 @@ static int cleanup(void) ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -198,6 +198,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; int ret; @@ -329,6 +330,7 @@ static int lascar_proc_config(const struct sr_dev_inst *sdi) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct sr_datafeed_packet packet; struct sr_datafeed_meta meta; struct sr_config *src; @@ -453,6 +455,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) SR_PRIV int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; (void)cb_data; if (!di->priv) { diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index 576d9749..eac2b18a 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -27,7 +27,7 @@ #include "protocol.h" extern struct sr_dev_driver lascar_el_usb_driver_info; -static struct sr_dev_driver *di = &lascar_el_usb_driver_info; +struct sr_dev_driver *di = &lascar_el_usb_driver_info; static const struct elusb_profile profiles[] = { { 1, "EL-USB-1", LOG_UNSUPPORTED }, diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index aa8cb778..6ee01c86 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -50,10 +50,9 @@ static const uint64_t samplerates[] = { }; SR_PRIV struct sr_dev_driver link_mso19_driver_info; -static struct sr_dev_driver *di = &link_mso19_driver_info; /* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */ -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { GSList *l; struct sr_dev_inst *sdi; @@ -88,12 +87,12 @@ static int dev_clear(void) return ret; } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { int i; GSList *devices = NULL; @@ -229,7 +228,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -265,7 +264,7 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return dev_clear(); } diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 5f7aa719..fafd83c3 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -30,7 +30,6 @@ static const char mso_head[] = { 0x40, 0x4c, 0x44, 0x53, 0x7e }; static const char mso_foot[] = { 0x7e }; extern SR_PRIV struct sr_dev_driver link_mso19_driver_info; -static struct sr_dev_driver *di = &link_mso19_driver_info; SR_PRIV int mso_send_control_message(struct sr_serial_dev_inst *serial, uint16_t payload[], int n) diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index d3bd5e1f..b9e6524b 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -73,19 +73,18 @@ static struct hcs_model models[] = { }; SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info; -static struct sr_dev_driver *di = &manson_hcs_3xxx_driver_info; -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { int i, model_id; struct drv_context *drvc; @@ -203,14 +202,14 @@ exit_err: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index 737febaf..5a70df00 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -248,15 +248,20 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) /* Driver-specific API function wrappers */ #define HW_INIT(X) \ -static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } +static int init_##X(struct sr_dev_driver *di, struct sr_context *sr_ctx) { \ + (void) di; return init(sr_ctx, X); } #define HW_CLEANUP(X) \ -static int cleanup_##X(void) { return cleanup(X); } +static int cleanup_##X(const struct sr_dev_driver *di) { \ + (void) di; return cleanup(X); } #define HW_SCAN(X) \ -static GSList *scan_##X(GSList *options) { return scan(options, X); } +static GSList *scan_##X(struct sr_dev_driver *di, GSList *options) { \ + (void) di; return scan(options, X); } #define HW_DEV_LIST(X) \ -static GSList *dev_list_##X(void) { return dev_list(X); } +static GSList *dev_list_##X(const struct sr_dev_driver *di) { \ + (void) di; return dev_list(X); } #define HW_DEV_CLEAR(X) \ -static int dev_clear_##X(void) { return dev_clear(X); } +static int dev_clear_##X(const struct sr_dev_driver *di) { \ + (void) di; return dev_clear(X); } #define HW_CONFIG_LIST(X) \ static int config_list_##X(uint32_t key, GVariant **data, \ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { \ diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index d54b267c..d040fe6e 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -134,9 +134,9 @@ static struct lps_modelspec models[] = { }, }; -static int init_lps301(struct sr_context *sr_ctx) +static int init_lps301(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, &motech_lps_301_driver_info, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } /** Send command to device with va_list. @@ -512,19 +512,14 @@ exit_err: } /** Scan for LPS-301 device. */ -static GSList *scan_lps301(GSList *options) +static GSList *scan_lps301(struct sr_dev_driver *di, GSList *options) { - return do_scan(LPS_301, &motech_lps_301_driver_info, options); + return do_scan(LPS_301, di, options); } -static GSList *doDevList(struct sr_dev_driver *drv) +static GSList *dev_list_lps301(const struct sr_dev_driver *di) { - return ((struct drv_context *)(drv->priv))->instances; -} - -static GSList *dev_list_lps301(void) -{ - return doDevList(&motech_lps_301_driver_info); + return ((struct drv_context *)(di->priv))->instances; } static void dev_clear_private(struct dev_context* devc) @@ -538,14 +533,14 @@ static void dev_clear_private(struct dev_context* devc) g_timer_destroy(devc->elapsed_msec); } -static int dev_clear_lps301(void) +static int dev_clear_lps301(const struct sr_dev_driver *di) { - return std_dev_clear(&motech_lps_301_driver_info, (std_dev_clear_callback)dev_clear_private); + return std_dev_clear(di, (std_dev_clear_callback)dev_clear_private); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear_lps301(); + return dev_clear_lps301(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index 174425b7..6fe8e39d 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -66,17 +66,12 @@ static const char* get_typestr(int type, struct sr_dev_driver* drv) return nameref[type-1][(drv == &siemens_b102x_driver_info)]; } -static int init_norma_dmm(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { - return std_init(sr_ctx, &norma_dmm_driver_info, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } -static int init_siemens_b102x(struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, &siemens_b102x_driver_info, LOG_PREFIX); -} - -static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) +static GSList *scan(struct sr_dev_driver* drv, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -181,24 +176,9 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) return devices; } -static GSList *scan_norma_dmm(GSList *options) -{ - return do_scan(&norma_dmm_driver_info, options); -} - -static GSList *scan_siemens_b102x(GSList *options) +static GSList *dev_list(const struct sr_dev_driver *di) { - return do_scan(&siemens_b102x_driver_info, options); -} - -static GSList *dev_list_norma_dmm(void) -{ - return ((struct drv_context *)(norma_dmm_driver_info.priv))->instances; -} - -static GSList *dev_list_siemens_b102x(void) -{ - return ((struct drv_context *)(siemens_b102x_driver_info.priv))->instances; + return ((struct drv_context *)(di->priv))->instances; } static int dev_close(struct sr_dev_inst *sdi) @@ -217,14 +197,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup_norma_dmm(void) -{ - return std_dev_clear(&norma_dmm_driver_info, NULL); -} - -static int cleanup_siemens_b102x(void) +static int cleanup(const struct sr_dev_driver *di) { - return std_dev_clear(&siemens_b102x_driver_info, NULL); + return std_dev_clear(di, NULL); } static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, @@ -331,10 +306,10 @@ SR_PRIV struct sr_dev_driver norma_dmm_driver_info = { .name = "norma-dmm", .longname = "Norma DM9x0 DMMs", .api_version = 1, - .init = init_norma_dmm, - .cleanup = cleanup_norma_dmm, - .scan = scan_norma_dmm, - .dev_list = dev_list_norma_dmm, + .init = init, + .cleanup = cleanup, + .scan = scan, + .dev_list = dev_list, .dev_clear = NULL, .config_get = NULL, .config_set = config_set, @@ -351,10 +326,10 @@ SR_PRIV struct sr_dev_driver siemens_b102x_driver_info = { .name = "siemens-b102x", .longname = "Siemens B102x DMMs", .api_version = 1, - .init = init_siemens_b102x, - .cleanup = cleanup_siemens_b102x, - .scan = scan_siemens_b102x, - .dev_list = dev_list_siemens_b102x, + .init = init, + .cleanup = cleanup, + .scan = scan, + .dev_list = dev_list, .dev_clear = NULL, .config_get = NULL, .config_set = config_set, diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 487f5b2e..9d1e0607 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -85,14 +85,13 @@ static const uint64_t samplerates[] = { }; SR_PRIV struct sr_dev_driver ols_driver_info; -static struct sr_dev_driver *di = &ols_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_config *src; struct sr_dev_inst *sdi; @@ -214,12 +213,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index d9c2c2bb..9037d19f 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -21,7 +21,6 @@ #include extern SR_PRIV struct sr_dev_driver ols_driver_info; -static struct sr_dev_driver *di = &ols_driver_info; SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, uint8_t command) @@ -150,7 +149,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; - sdi->driver = di; + sdi->driver = &ols_driver_info; devc = ols_dev_new(); sdi->priv = devc; diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index acbfcda0..b23ccf70 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -76,14 +76,13 @@ static const uint64_t samplerates[] = { }; SR_PRIV struct sr_dev_driver p_ols_driver_info; -static struct sr_dev_driver *di = &p_ols_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -205,7 +204,7 @@ err_free_devc: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -220,14 +219,14 @@ static void clear_helper(void *priv) g_free(devc->ftdi_buf); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index 1d0c9f20..f3bd15b0 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -20,7 +20,6 @@ #include "protocol.h" extern SR_PRIV struct sr_dev_driver p_ols_driver_info; -static struct sr_dev_driver *di = &p_ols_driver_info; SR_PRIV int write_shortcommand(struct dev_context *devc, uint8_t command) { @@ -227,7 +226,7 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; - sdi->driver = di; + sdi->driver = &p_ols_driver_info; sdi->priv = devc; devname = g_string_new(""); diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 60d63d59..5aa0b415 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -247,7 +247,6 @@ static const struct rigol_ds_model supported_models[] = { }; SR_PRIV struct sr_dev_driver rigol_ds_driver_info; -static struct sr_dev_driver *di = &rigol_ds_driver_info; static void clear_helper(void *priv) { @@ -265,12 +264,12 @@ static void clear_helper(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -316,7 +315,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) sdi->model = g_strdup(model->name); sdi->version = g_strdup(hw_info->firmware_version); sdi->conn = scpi; - sdi->driver = di; + sdi->driver = &rigol_ds_driver_info; sdi->inst_type = SR_INST_SCPI; sdi->serial_num = g_strdup(hw_info->serial_number); devc = g_malloc0(sizeof(struct dev_context)); @@ -407,12 +406,12 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) return sdi; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { return sr_scpi_scan(di->priv, options, probe_device); } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -460,9 +459,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int analog_frame_size(const struct sr_dev_inst *sdi) diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index cf6063af..7a4a331f 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -39,7 +39,6 @@ #define NUM_SIMUL_TRANSFERS 32 SR_PRIV struct sr_dev_driver saleae_logic16_driver_info; -static struct sr_dev_driver *di = &saleae_logic16_driver_info; static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -96,7 +95,7 @@ static const uint64_t samplerates[] = { SR_MHZ(100), }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -139,7 +138,7 @@ static gboolean check_conf_profile(libusb_device *dev) return ret; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -241,13 +240,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int logic16_dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di; libusb_device **devlist; struct sr_usb_dev_inst *usb; struct libusb_device_descriptor des; @@ -255,6 +255,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) int ret, i, device_count; char connection_id[64]; + di = sdi->driver; drvc = di->priv; usb = sdi->conn; @@ -410,7 +411,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -421,7 +422,6 @@ static int cleanup(void) ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -680,11 +680,13 @@ static int receive_data(int fd, int revents, void *cb_data) struct dev_context *devc; struct drv_context *drvc; const struct sr_dev_inst *sdi; + struct sr_dev_driver *di; (void)fd; (void)revents; sdi = cb_data; + di = sdi->driver; drvc = di->priv; devc = sdi->priv; @@ -701,6 +703,7 @@ static int receive_data(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 0539e81a..33d94286 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -21,7 +21,6 @@ #include "protocol.h" SR_PRIV struct sr_dev_driver scpi_pps_driver_info; -static struct sr_dev_driver *di = &scpi_pps_driver_info; extern unsigned int num_pps_profiles; extern const struct scpi_pps pps_profiles[]; @@ -40,7 +39,7 @@ static struct pps_channel_instance pci[] = { { SR_MQ_POWER, SCPI_CMD_GET_MEAS_POWER, "P" }, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -95,7 +94,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) sdi->model = g_strdup(hw_info->model); sdi->version = g_strdup(hw_info->firmware_version); sdi->conn = scpi; - sdi->driver = di; + sdi->driver = &scpi_pps_driver_info; sdi->inst_type = SR_INST_SCPI; sdi->serial_num = g_strdup(hw_info->serial_number); @@ -172,17 +171,17 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) return sdi; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { return sr_scpi_scan(di->priv, options, probe_device); } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } @@ -247,7 +246,7 @@ static void clear_helper(void *priv) g_free(devc); } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 64b818af..5ab8eb9f 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -629,15 +629,20 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) /* Driver-specific API function wrappers */ #define HW_INIT(X) \ -static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } +static int init_##X(struct sr_dev_driver *di, struct sr_context *sr_ctx) { \ + (void) di; return init(sr_ctx, X); } #define HW_CLEANUP(X) \ -static int cleanup_##X(void) { return cleanup(X); } +static int cleanup_##X(const struct sr_dev_driver *di) { \ + (void) di; return cleanup(X); } #define HW_SCAN(X) \ -static GSList *scan_##X(GSList *options) { return scan(options, X); } +static GSList *scan_##X(struct sr_dev_driver *di, GSList *options) { \ + (void) di; return scan(options, X); } #define HW_DEV_LIST(X) \ -static GSList *dev_list_##X(void) { return dev_list(X); } +static GSList *dev_list_##X(const struct sr_dev_driver *di) { \ + (void) di; return dev_list(X); } #define HW_DEV_CLEAR(X) \ -static int dev_clear_##X(void) { return dev_clear(X); } +static int dev_clear_##X(const struct sr_dev_driver *di) { \ + (void) di; return dev_clear(X); } #define HW_DEV_ACQUISITION_START(X) \ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 959b566d..3fe9b2bd 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -74,7 +74,7 @@ static const char *const signal_edge_names[] = { "r", "f" }; SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info; static struct sr_dev_driver *const di = &sysclk_lwla_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -109,7 +109,7 @@ static struct sr_dev_inst *dev_inst_new(void) return sdi; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { GSList *usb_devices, *devices, *node; struct drv_context *drvc; @@ -154,7 +154,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { struct drv_context *drvc; @@ -175,7 +175,7 @@ static void clear_dev_context(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, &clear_dev_context); } @@ -243,9 +243,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index c1d9b040..a23ff68f 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -36,14 +36,13 @@ static const uint32_t devopts[] = { }; SR_PRIV struct sr_dev_driver teleinfo_driver_info; -static struct sr_dev_driver *di = &teleinfo_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -133,12 +132,12 @@ scan_cleanup: return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 58a5159f..da6d171a 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -23,7 +23,6 @@ #define SERIALCOMM "115200/8n1" SR_PRIV struct sr_dev_driver testo_driver_info; -static struct sr_dev_driver *di = &testo_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static const uint32_t scanopts[] = { @@ -42,12 +41,12 @@ struct testo_model models[] = { { "435", 9, TESTO_x35_REQUEST }, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -149,18 +148,19 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->priv; struct sr_usb_dev_inst *usb; libusb_device **devlist; @@ -211,6 +211,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; if (!di->priv) { @@ -231,7 +232,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -239,9 +240,8 @@ static int cleanup(void) if (!(drvc = di->priv)) return SR_OK; - ret = dev_clear(); + ret = dev_clear(di); g_free(drvc); - di->priv = NULL; return ret; } @@ -272,6 +272,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; gint64 now; int ret; @@ -415,8 +416,9 @@ SR_PRIV void receive_transfer(struct libusb_transfer *transfer) static int handle_events(int fd, int revents, void *cb_data) { + struct sr_dev_driver *di; struct dev_context *devc; - struct drv_context *drvc = di->priv; + struct drv_context *drvc; struct sr_datafeed_packet packet; struct sr_dev_inst *sdi; struct timeval tv; @@ -427,6 +429,8 @@ static int handle_events(int fd, int revents, void *cb_data) sdi = cb_data; devc = sdi->priv; + di = sdi->driver; + drvc = di->priv; if (devc->limit_msec) { now = g_get_monotonic_time() / 1000; @@ -452,6 +456,7 @@ static int handle_events(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; struct sr_usb_dev_inst *usb; @@ -505,6 +510,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; (void)cb_data; if (!di->priv) { diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index cccaeb1d..b41ef9a8 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -38,14 +38,13 @@ static const uint32_t devopts[] = { }; SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info; -static struct sr_dev_driver *di = &tondaj_sl_814_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -106,12 +105,12 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index fea68a76..6f08e735 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -414,15 +414,20 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) /* Driver-specific API function wrappers */ #define HW_INIT(X) \ -static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } +static int init_##X(struct sr_dev_driver *di, struct sr_context *sr_ctx) { \ + (void) di; return init(sr_ctx, X); } #define HW_CLEANUP(X) \ -static int cleanup_##X(void) { return cleanup(X); } +static int cleanup_##X(const struct sr_dev_driver *di) { \ + (void) di; return cleanup(X); } #define HW_SCAN(X) \ -static GSList *scan_##X(GSList *options) { return scan(options, X); } +static GSList *scan_##X(struct sr_dev_driver *di, GSList *options) { \ + (void) di; return scan(options, X); } #define HW_DEV_LIST(X) \ -static GSList *dev_list_##X(void) { return dev_list(X); } +static GSList *dev_list_##X(const struct sr_dev_driver *di) { \ + (void) di; return dev_list(X); } #define HW_DEV_CLEAR(X) \ -static int dev_clear_##X(void) { return dev_clear(X); } +static int dev_clear_##X(const struct sr_dev_driver *di) { \ + (void) di; return dev_clear(X); } #define HW_DEV_ACQUISITION_START(X) \ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index e67a99e3..a8c380d9 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -40,15 +40,14 @@ static const char *data_sources[] = { }; SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info; -static struct sr_dev_driver *di = &uni_t_ut32x_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -101,13 +100,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct sr_usb_dev_inst *usb; int ret; @@ -152,6 +152,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; if (!di->priv) { @@ -172,7 +173,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -184,7 +185,6 @@ static int cleanup(void) ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -217,6 +217,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; int ret; const char *tmp_str; @@ -280,6 +281,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct dev_context *devc; struct sr_usb_dev_inst *usb; diff --git a/src/hardware/uni-t-ut32x/protocol.c b/src/hardware/uni-t-ut32x/protocol.c index 65cb756b..590d3fd5 100644 --- a/src/hardware/uni-t-ut32x/protocol.c +++ b/src/hardware/uni-t-ut32x/protocol.c @@ -23,7 +23,6 @@ #include extern struct sr_dev_driver uni_t_ut32x_driver_info; -static struct sr_dev_driver *di = &uni_t_ut32x_driver_info; static float parse_temperature(unsigned char *buf) { @@ -194,6 +193,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) { struct drv_context *drvc; struct dev_context *devc; + struct sr_dev_driver *di; struct sr_dev_inst *sdi; struct sr_datafeed_packet packet; struct sr_usb_dev_inst *usb; @@ -204,11 +204,12 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) (void)fd; (void)revents; - drvc = di->priv; - if (!(sdi = cb_data)) return TRUE; + di = sdi->driver; + drvc = di->priv; + if (!(devc = sdi->priv)) return TRUE; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 2552027c..85874b12 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -32,7 +32,6 @@ #define VICTOR_ENDPOINT LIBUSB_ENDPOINT_IN | 1 SR_PRIV struct sr_dev_driver victor_dmm_driver_info; -static struct sr_dev_driver *di = &victor_dmm_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static const uint32_t drvopts[] = { @@ -49,12 +48,12 @@ static const uint32_t devopts[] = { SR_CONF_CONN | SR_CONF_GET, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -105,13 +104,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->priv; struct sr_usb_dev_inst *usb; libusb_device **devlist; @@ -164,6 +164,7 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct sr_usb_dev_inst *usb; if (!di->priv) { @@ -185,7 +186,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; @@ -197,7 +198,6 @@ static int cleanup(void) ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -228,6 +228,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; gint64 now; int ret; @@ -334,9 +335,10 @@ static void receive_transfer(struct libusb_transfer *transfer) static int handle_events(int fd, int revents, void *cb_data) { struct dev_context *devc; - struct drv_context *drvc = di->priv; + struct drv_context *drvc; struct sr_datafeed_packet packet; struct sr_dev_inst *sdi; + struct sr_dev_driver *di; struct timeval tv; gint64 now; @@ -345,6 +347,8 @@ static int handle_events(int fd, int revents, void *cb_data) sdi = cb_data; devc = sdi->priv; + di = sdi->driver; + drvc = di->priv; if (devc->limit_msec) { now = g_get_monotonic_time() / 1000; @@ -370,6 +374,7 @@ static int handle_events(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct drv_context *drvc = di->priv; struct sr_usb_dev_inst *usb; @@ -416,6 +421,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; (void)cb_data; if (!di->priv) { diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 27957406..054d431d 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -22,7 +22,6 @@ #include "protocol.h" SR_PRIV struct sr_dev_driver yokogawa_dlm_driver_info; -static struct sr_dev_driver *di = &yokogawa_dlm_driver_info; static char *MANUFACTURER_ID = "YOKOGAWA"; static char *MANUFACTURER_NAME = "Yokogawa"; @@ -39,7 +38,7 @@ enum { CG_DIGITAL, }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -80,7 +79,7 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi) devc = g_malloc0(sizeof(struct dev_context)); - sdi->driver = di; + sdi->driver = &yokogawa_dlm_driver_info; sdi->priv = devc; sdi->inst_type = SR_INST_SCPI; sdi->conn = scpi; @@ -104,12 +103,12 @@ fail: return NULL; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { return sr_scpi_scan(di->priv, options, probe_usbtmc_device); } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -127,7 +126,7 @@ static void clear_helper(void *priv) g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } @@ -157,9 +156,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - dev_clear(); + dev_clear(di); return SR_OK; } diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index fd3ef08b..5d8c534f 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -80,7 +80,6 @@ static const char *channel_names[] = { }; SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info; -static struct sr_dev_driver *di = &zeroplus_logic_cube_driver_info; /* * The hardware supports more samplerates than these, but these are the @@ -156,12 +155,12 @@ SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate) return SR_OK; } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; @@ -262,13 +261,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; @@ -382,7 +382,7 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } diff --git a/src/hwdriver.c b/src/hwdriver.c index 21a80224..a9561d3e 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -315,7 +315,7 @@ SR_API int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver) } sr_spew("Initializing driver '%s'.", driver->name); - if ((ret = driver->init(ctx)) < 0) + if ((ret = driver->init(driver, ctx)) < 0) sr_err("Failed to initialize the driver: %d.", ret); return ret; @@ -409,7 +409,7 @@ SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options) return NULL; } - l = driver->scan(options); + l = driver->scan(driver, options); sr_spew("Scan of '%s' found %d devices.", driver->name, g_slist_length(l)); @@ -427,7 +427,8 @@ SR_PRIV void sr_hw_cleanup_all(void) drivers = sr_driver_list(); for (i = 0; drivers[i]; i++) { if (drivers[i]->cleanup) - drivers[i]->cleanup(); + drivers[i]->cleanup(drivers[i]); + drivers[i]->priv = NULL; } } diff --git a/src/session_driver.c b/src/session_driver.c index 62b16986..8bf7fc6f 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -34,7 +34,6 @@ /** @endcond */ SR_PRIV struct sr_dev_driver session_driver_info; -static struct sr_dev_driver *di = &session_driver_info; struct session_vdev { char *sessionfile; @@ -165,12 +164,12 @@ static int receive_data(int fd, int revents, void *cb_data) /* driver callbacks */ -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { struct drv_context *drvc; GSList *l; @@ -186,9 +185,11 @@ static int dev_clear(void) static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di; struct drv_context *drvc; struct session_vdev *vdev; + di = sdi->driver; drvc = di->priv; vdev = g_malloc0(sizeof(struct session_vdev)); sdi->priv = vdev; diff --git a/src/session_file.c b/src/session_file.c index 29f26ee2..abe002d3 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -175,7 +175,7 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) if (!session_driver_initialized) { /* first device, init the driver */ session_driver_initialized = 1; - sdi->driver->init(NULL); + sdi->driver->init(sdi->driver, NULL); } sr_dev_open(sdi); sr_session_dev_add(*session, sdi);