From: Bert Vermeulen Date: Tue, 3 Jul 2012 10:55:46 +0000 (+0200) Subject: sr: remove unused argument from hardware driver function init() X-Git-Tag: dsupstream~852 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=40dda2c3a509e9e031078427e32249e2ebc33ec5 sr: remove unused argument from hardware driver function init() It was actually used in one way: the session file loaded abused it for passing in the filename -- something it definitely wasn't intended for. This now uses the proper way to pass arguments to a driver: the new SR_HWCAP_SESSIONFILE. The OLS driver could also use it as an indication of the serial port to use instead of actively probing all serial ports on the system, but there wasn't any frontend code that passed in such a parameter, making it entirely useless. That will soon be handled differently with the new scan() API call, regardless. --- diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index b5d2b97f..4884afde 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -405,7 +405,7 @@ static int bin2bitbang(const char *filename, return SR_OK; } -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; struct context *ctx; @@ -413,9 +413,6 @@ static int hw_init(const char *devinfo) char serial_txt[10]; uint32_t serial; - /* Avoid compiler warnings. */ - (void)devinfo; - if (!(ctx = g_try_malloc(sizeof(struct context)))) { sr_err("sigma: %s: ctx malloc failed", __func__); return SR_ERR_MALLOC; diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 5b82c3ab..5a4ddbbe 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -39,16 +39,13 @@ static const uint16_t usb_pids[] = { /* Function prototypes. */ static int hw_dev_acquisition_stop(int dev_index, void *cb_data); -static int hw_init(const char *devinfo) +static int hw_init(void) { int ret; struct sr_dev_inst *sdi; struct context *ctx; unsigned int i; - /* Avoid compiler errors. */ - (void)devinfo; - /* Allocate memory for our private driver context. */ if (!(ctx = g_try_malloc(sizeof(struct context)))) { sr_err("la8: %s: struct context malloc failed", __func__); diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 91f105f3..ed8c6f4b 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -140,13 +140,10 @@ static int thread_running; static int hw_dev_acquisition_stop(int dev_index, void *cb_data); -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; - /* Avoid compiler warnings. */ - (void)devinfo; - sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, DEMONAME, NULL, NULL); if (!sdi) { sr_err("demo: %s: sr_dev_inst_new failed", __func__); diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 951c9196..736490fe 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -382,7 +382,7 @@ static struct context *fx2lafw_dev_new(void) * API callbacks */ -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; struct libusb_device_descriptor des; @@ -393,9 +393,6 @@ static int hw_init(const char *devinfo) int devcnt = 0; int i, j; - /* Avoid compiler warnings. */ - (void)devinfo; - if (libusb_init(&usb_context) != 0) { sr_warn("fx2lafw: Failed to initialize libusb."); return 0; diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index 8f332263..ca50a728 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -56,15 +56,12 @@ SR_PRIV GSList *genericdmm_dev_insts = NULL; SR_PRIV libusb_context *genericdmm_usb_context = NULL; -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; struct context *ctx; int devcnt = 0; - /* Avoid compiler warnings. */ - (void)devinfo; - if (libusb_init(&genericdmm_usb_context) != 0) { sr_err("genericdmm: Failed to initialize USB."); return 0; diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 8a7e9f74..dc8dbef8 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -200,7 +200,7 @@ static int configure_probes(struct context *ctx, const GSList *probes) return SR_OK; } -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; struct libusb_device_descriptor des; @@ -209,9 +209,6 @@ static int hw_init(const char *devinfo) libusb_device **devlist; int err, devcnt, i, j; - /* Avoid compiler warnings. */ - (void)devinfo; - if (libusb_init(&usb_context) != 0) { sr_err("hantek-dso: Failed to initialize USB."); return 0; diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 7c25817b..4b3d9218 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -401,7 +401,7 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct, return SR_OK; } -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; int devcnt = 0; @@ -410,8 +410,6 @@ static int hw_init(const char *devinfo) struct udev_list_entry *devs, *dev_list_entry; struct context *ctx; - devinfo = devinfo; - /* It's easier to map usb<->serial using udev */ /* * FIXME: On windows we can get the same information from the diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index f2706d11..02afff33 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -348,7 +348,7 @@ static struct sr_dev_inst *get_metadata(int fd) return sdi; } -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; struct context *ctx; @@ -359,12 +359,8 @@ static int hw_init(const char *devinfo) final_devcnt = 0; - if (devinfo) - ports = g_slist_append(NULL, g_strdup(devinfo)); - else - /* No specific device given, so scan all serial ports. */ - ports = list_serial_ports(); - + /* Scan all serial ports. */ + ports = list_serial_ports(); num_ports = g_slist_length(ports); if (!(fds = g_try_malloc0(num_ports * sizeof(GPollFD)))) { diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 627b937e..25660af0 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -327,7 +327,7 @@ static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes) * API callbacks */ -static int hw_init(const char *devinfo) +static int hw_init(void) { struct sr_dev_inst *sdi; struct libusb_device_descriptor des; @@ -335,9 +335,6 @@ static int hw_init(const char *devinfo) int ret, devcnt, i; struct context *ctx; - /* Avoid compiler warnings. */ - (void)devinfo; - /* Allocate memory for our private driver context. */ if (!(ctx = g_try_malloc(sizeof(struct context)))) { sr_err("zp: %s: ctx malloc failed", __func__); diff --git a/hwdriver.c b/hwdriver.c index bd3bf8a1..7a9e7e66 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -144,7 +144,7 @@ SR_API int sr_driver_init(struct sr_dev_driver *driver) char **probe_names; sr_dbg("initializing %s driver", driver->name); - num_devs = driver->init(NULL); + num_devs = driver->init(); for (i = 0; i < num_devs; i++) { num_probes = GPOINTER_TO_INT( driver->dev_info_get(i, SR_DI_NUM_PROBES)); diff --git a/libsigrok.h b/libsigrok.h index 369b2a17..695b360b 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -337,6 +337,9 @@ enum { /*--- Special stuff -------------------------------------------------*/ + /** Session filename */ + SR_HWCAP_SESSIONFILE, + /* TODO: Better description. */ /** The device supports specifying a capturefile to inject. */ SR_HWCAP_CAPTUREFILE, @@ -467,7 +470,7 @@ struct sr_dev_driver { char *name; char *longname; int api_version; - int (*init) (const char *devinfo); + int (*init) (void); int (*cleanup) (void); /* Device-specific */ diff --git a/session_driver.c b/session_driver.c index ddcf0add..ed397a96 100644 --- a/session_driver.c +++ b/session_driver.c @@ -30,6 +30,7 @@ #define CHUNKSIZE (512 * 1024) struct session_vdev { + char *sessionfile; char *capturefile; struct zip *archive; struct zip_file *capfile; @@ -39,7 +40,6 @@ struct session_vdev { int num_probes; }; -static char *sessionfile = NULL; static GSList *dev_insts = NULL; static const int hwcaps[] = { SR_HWCAP_CAPTUREFILE, @@ -148,9 +148,8 @@ static int hw_cleanup(void); * * @return TODO. */ -static int hw_init(const char *devinfo) +static int hw_init(void) { - sessionfile = g_strdup(devinfo); return 0; } @@ -169,8 +168,6 @@ static int hw_cleanup(void) sr_session_source_remove(-1); - g_free(sessionfile); - return SR_OK; } @@ -246,6 +243,11 @@ static int hw_dev_config_set(int dev_index, int hwcap, const void *value) sr_info("session driver: setting samplerate to %" PRIu64, vdev->samplerate); break; + case SR_HWCAP_SESSIONFILE: + vdev->sessionfile = g_strdup(value); + sr_info("session driver: setting sessionfile to %s", + vdev->sessionfile); + break; case SR_HWCAP_CAPTUREFILE: vdev->capturefile = g_strdup(value); sr_info("session driver: setting capturefile to %s", @@ -280,24 +282,24 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) if (!(vdev = get_vdev_by_index(dev_index))) return SR_ERR; - sr_info("session_driver: opening archive %s file %s", sessionfile, + sr_info("session_driver: opening archive %s file %s", vdev->sessionfile, vdev->capturefile); - if (!(vdev->archive = zip_open(sessionfile, 0, &ret))) { + if (!(vdev->archive = zip_open(vdev->sessionfile, 0, &ret))) { sr_err("session driver: Failed to open session file '%s': " - "zip error %d\n", sessionfile, ret); + "zip error %d\n", vdev->sessionfile, ret); return SR_ERR; } if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) == -1) { sr_err("session driver: Failed to check capture file '%s' in " - "session file '%s'.", vdev->capturefile, sessionfile); + "session file '%s'.", vdev->capturefile, vdev->sessionfile); return SR_ERR; } if (!(vdev->capfile = zip_fopen(vdev->archive, vdev->capturefile, 0))) { sr_err("session driver: Failed to open capture file '%s' in " - "session file '%s'.", vdev->capturefile, sessionfile); + "session file '%s'.", vdev->capturefile, vdev->sessionfile); return SR_ERR; } diff --git a/session_file.c b/session_file.c index 6b778162..c4830673 100644 --- a/session_file.c +++ b/session_file.c @@ -117,8 +117,9 @@ SR_API int sr_session_load(const char *filename) dev = sr_dev_new(&session_driver, devcnt); if (devcnt == 0) /* first device, init the driver */ - dev->driver->init((char *)filename); + dev->driver->init(); sr_session_dev_add(dev); + dev->driver->dev_config_set(devcnt, SR_HWCAP_SESSIONFILE, filename); dev->driver->dev_config_set(devcnt, SR_HWCAP_CAPTUREFILE, val); g_ptr_array_add(capturefiles, val); } else if (!strcmp(keys[j], "samplerate")) {