From: Bert Vermeulen Date: Mon, 21 Sep 2015 11:41:03 +0000 (+0200) Subject: scpi: Pass SCPI device instance to open and close callbacks. X-Git-Tag: libsigrok-0.4.0~257 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=04229f7bfc750f2b67e8dd54ac82ae6bb7eae1e4;p=libsigrok.git scpi: Pass SCPI device instance to open and close callbacks. Only close() really needs this (for access to a Rigol firmware quirk), but do the same in open() for consistency. --- diff --git a/src/scpi.h b/src/scpi.h index 28b33287..aee1bfba 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -77,7 +77,7 @@ struct sr_scpi_dev_inst { GSList *(*scan)(struct drv_context *drvc); int (*dev_inst_new)(void *priv, struct drv_context *drvc, const char *resource, char **params, const char *serialcomm); - int (*open)(void *priv); + int (*open)(struct sr_scpi_dev_inst *scpi); int (*source_add)(struct sr_session *session, void *priv, int events, int timeout, sr_receive_data_callback cb, void *cb_data); int (*source_remove)(struct sr_session *session, void *priv); @@ -85,7 +85,7 @@ struct sr_scpi_dev_inst { int (*read_begin)(void *priv); int (*read_data)(void *priv, char *buf, int maxlen); int (*read_complete)(void *priv); - int (*close)(void *priv); + int (*close)(struct sr_scpi_dev_inst *scpi); void (*free)(void *priv); unsigned int read_timeout_ms; void *priv; diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index 9b5b1ea9..576aa76e 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -210,7 +210,7 @@ SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc, */ SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi) { - return scpi->open(scpi->priv); + return scpi->open(scpi); } /** @@ -352,7 +352,7 @@ SR_PRIV int sr_scpi_read_complete(struct sr_scpi_dev_inst *scpi) */ SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi) { - return scpi->close(scpi->priv); + return scpi->close(scpi); } /** diff --git a/src/scpi/scpi_libgpib.c b/src/scpi/scpi_libgpib.c index 31522eb1..7632f74c 100644 --- a/src/scpi/scpi_libgpib.c +++ b/src/scpi/scpi_libgpib.c @@ -49,9 +49,9 @@ static int scpi_gpib_dev_inst_new(void *priv, struct drv_context *drvc, return SR_OK; } -static int scpi_gpib_open(void *priv) +static int scpi_gpib_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_gpib *gscpi = priv; + struct scpi_gpib *gscpi = scpi->priv; if ((gscpi->descriptor = ibfind(gscpi->name)) < 0) return SR_ERR; @@ -134,9 +134,9 @@ static int scpi_gpib_read_complete(void *priv) return gscpi->read_started && (ibsta & END); } -static int scpi_gpib_close(void *priv) +static int scpi_gpib_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_gpib *gscpi = priv; + struct scpi_gpib *gscpi = scpi->priv; ibonl(gscpi->descriptor, 0); diff --git a/src/scpi/scpi_serial.c b/src/scpi/scpi_serial.c index 257ff883..ef507bb4 100644 --- a/src/scpi/scpi_serial.c +++ b/src/scpi/scpi_serial.c @@ -85,9 +85,9 @@ static int scpi_serial_dev_inst_new(void *priv, struct drv_context *drvc, return SR_OK; } -static int scpi_serial_open(void *priv) +static int scpi_serial_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_serial *sscpi = priv; + struct scpi_serial *sscpi = scpi->priv; struct sr_serial_dev_inst *serial = sscpi->serial; if (serial_open(serial, SERIAL_RDWR) != SR_OK) @@ -209,9 +209,9 @@ static int scpi_serial_read_complete(void *priv) } } -static int scpi_serial_close(void *priv) +static int scpi_serial_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_serial *sscpi = priv; + struct scpi_serial *sscpi = scpi->priv; return serial_close(sscpi->serial); } diff --git a/src/scpi/scpi_tcp.c b/src/scpi/scpi_tcp.c index 43b7a78a..62974680 100644 --- a/src/scpi/scpi_tcp.c +++ b/src/scpi/scpi_tcp.c @@ -72,9 +72,9 @@ static int scpi_tcp_dev_inst_new(void *priv, struct drv_context *drvc, return SR_OK; } -static int scpi_tcp_open(void *priv) +static int scpi_tcp_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_tcp *tcp = priv; + struct scpi_tcp *tcp = scpi->priv; struct addrinfo hints; struct addrinfo *results, *res; int err; @@ -230,9 +230,9 @@ static int scpi_tcp_read_complete(void *priv) tcp->response_bytes_read >= tcp->response_length); } -static int scpi_tcp_close(void *priv) +static int scpi_tcp_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_tcp *tcp = priv; + struct scpi_tcp *tcp = scpi->priv; if (close(tcp->socket) < 0) return SR_ERR; diff --git a/src/scpi/scpi_usbtmc_libusb.c b/src/scpi/scpi_usbtmc_libusb.c index 95a28370..61d1b70d 100644 --- a/src/scpi/scpi_usbtmc_libusb.c +++ b/src/scpi/scpi_usbtmc_libusb.c @@ -289,9 +289,9 @@ static void scpi_usbtmc_local(struct scpi_usbtmc_libusb *uscpi) return; } -static int scpi_usbtmc_libusb_open(void *priv) +static int scpi_usbtmc_libusb_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_usbtmc_libusb *uscpi = priv; + struct scpi_usbtmc_libusb *uscpi = scpi->priv; struct sr_usb_dev_inst *usb = uscpi->usb; struct libusb_device *dev; struct libusb_device_descriptor des; @@ -634,11 +634,11 @@ static int scpi_usbtmc_libusb_read_complete(void *priv) uscpi->bulkin_attributes & EOM; } -static int scpi_usbtmc_libusb_close(void *priv) +static int scpi_usbtmc_libusb_close(struct sr_scpi_dev_inst *scpi) { - int ret; - struct scpi_usbtmc_libusb *uscpi = priv; + struct scpi_usbtmc_libusb *uscpi = scpi->priv; struct sr_usb_dev_inst *usb = uscpi->usb; + int ret; if (!usb->devhdl) return SR_ERR; diff --git a/src/scpi/scpi_visa.c b/src/scpi/scpi_visa.c index fee25ba1..220ead4f 100644 --- a/src/scpi/scpi_visa.c +++ b/src/scpi/scpi_visa.c @@ -51,9 +51,9 @@ static int scpi_visa_dev_inst_new(void *priv, struct drv_context *drvc, return SR_OK; } -static int scpi_visa_open(void *priv) +static int scpi_visa_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_visa *vscpi = priv; + struct scpi_visa *vscpi = scpi->priv; if (viOpenDefaultRM(&vscpi->rmgr) != VI_SUCCESS) { sr_err("Cannot open default resource manager."); @@ -140,9 +140,9 @@ static int scpi_visa_read_complete(void *priv) return !(status & 16); } -static int scpi_visa_close(void *priv) +static int scpi_visa_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_visa *vscpi = priv; + struct scpi_visa *vscpi = scpi->priv; viClose(vscpi->vi); viClose(vscpi->rmgr); diff --git a/src/scpi/scpi_vxi.c b/src/scpi/scpi_vxi.c index c1329088..26cd832d 100644 --- a/src/scpi/scpi_vxi.c +++ b/src/scpi/scpi_vxi.c @@ -60,9 +60,9 @@ static int scpi_vxi_dev_inst_new(void *priv, struct drv_context *drvc, return SR_OK; } -static int scpi_vxi_open(void *priv) +static int scpi_vxi_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_vxi *vxi = priv; + struct scpi_vxi *vxi = scpi->priv; Create_LinkParms link_parms; Create_LinkResp *link_resp; @@ -195,9 +195,9 @@ static int scpi_vxi_read_complete(void *priv) return vxi->read_complete; } -static int scpi_vxi_close(void *priv) +static int scpi_vxi_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_vxi *vxi = priv; + struct scpi_vxi *vxi = scpi->priv; Device_Error *dev_error; if (!vxi->client)