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.
This commit is contained in:
parent
0d012ede9d
commit
40dda2c3a5
|
@ -405,7 +405,7 @@ static int bin2bitbang(const char *filename,
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
|
@ -413,9 +413,6 @@ static int hw_init(const char *devinfo)
|
||||||
char serial_txt[10];
|
char serial_txt[10];
|
||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
||||||
sr_err("sigma: %s: ctx malloc failed", __func__);
|
sr_err("sigma: %s: ctx malloc failed", __func__);
|
||||||
return SR_ERR_MALLOC;
|
return SR_ERR_MALLOC;
|
||||||
|
|
|
@ -39,16 +39,13 @@ static const uint16_t usb_pids[] = {
|
||||||
/* Function prototypes. */
|
/* Function prototypes. */
|
||||||
static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
|
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;
|
int ret;
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
/* Avoid compiler errors. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
/* Allocate memory for our private driver context. */
|
/* Allocate memory for our private driver context. */
|
||||||
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
||||||
sr_err("la8: %s: struct context malloc failed", __func__);
|
sr_err("la8: %s: struct context malloc failed", __func__);
|
||||||
|
|
|
@ -140,13 +140,10 @@ static int thread_running;
|
||||||
|
|
||||||
static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
|
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;
|
struct sr_dev_inst *sdi;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, DEMONAME, NULL, NULL);
|
sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, DEMONAME, NULL, NULL);
|
||||||
if (!sdi) {
|
if (!sdi) {
|
||||||
sr_err("demo: %s: sr_dev_inst_new failed", __func__);
|
sr_err("demo: %s: sr_dev_inst_new failed", __func__);
|
||||||
|
|
|
@ -382,7 +382,7 @@ static struct context *fx2lafw_dev_new(void)
|
||||||
* API callbacks
|
* API callbacks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct libusb_device_descriptor des;
|
struct libusb_device_descriptor des;
|
||||||
|
@ -393,9 +393,6 @@ static int hw_init(const char *devinfo)
|
||||||
int devcnt = 0;
|
int devcnt = 0;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
if (libusb_init(&usb_context) != 0) {
|
if (libusb_init(&usb_context) != 0) {
|
||||||
sr_warn("fx2lafw: Failed to initialize libusb.");
|
sr_warn("fx2lafw: Failed to initialize libusb.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -56,15 +56,12 @@ SR_PRIV GSList *genericdmm_dev_insts = NULL;
|
||||||
SR_PRIV libusb_context *genericdmm_usb_context = 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 sr_dev_inst *sdi;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
int devcnt = 0;
|
int devcnt = 0;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
if (libusb_init(&genericdmm_usb_context) != 0) {
|
if (libusb_init(&genericdmm_usb_context) != 0) {
|
||||||
sr_err("genericdmm: Failed to initialize USB.");
|
sr_err("genericdmm: Failed to initialize USB.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -200,7 +200,7 @@ static int configure_probes(struct context *ctx, const GSList *probes)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct libusb_device_descriptor des;
|
struct libusb_device_descriptor des;
|
||||||
|
@ -209,9 +209,6 @@ static int hw_init(const char *devinfo)
|
||||||
libusb_device **devlist;
|
libusb_device **devlist;
|
||||||
int err, devcnt, i, j;
|
int err, devcnt, i, j;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
if (libusb_init(&usb_context) != 0) {
|
if (libusb_init(&usb_context) != 0) {
|
||||||
sr_err("hantek-dso: Failed to initialize USB.");
|
sr_err("hantek-dso: Failed to initialize USB.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -401,7 +401,7 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct,
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
int devcnt = 0;
|
int devcnt = 0;
|
||||||
|
@ -410,8 +410,6 @@ static int hw_init(const char *devinfo)
|
||||||
struct udev_list_entry *devs, *dev_list_entry;
|
struct udev_list_entry *devs, *dev_list_entry;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
|
|
||||||
devinfo = devinfo;
|
|
||||||
|
|
||||||
/* It's easier to map usb<->serial using udev */
|
/* It's easier to map usb<->serial using udev */
|
||||||
/*
|
/*
|
||||||
* FIXME: On windows we can get the same information from the
|
* FIXME: On windows we can get the same information from the
|
||||||
|
|
|
@ -348,7 +348,7 @@ static struct sr_dev_inst *get_metadata(int fd)
|
||||||
return sdi;
|
return sdi;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
|
@ -359,12 +359,8 @@ static int hw_init(const char *devinfo)
|
||||||
|
|
||||||
final_devcnt = 0;
|
final_devcnt = 0;
|
||||||
|
|
||||||
if (devinfo)
|
/* Scan all serial ports. */
|
||||||
ports = g_slist_append(NULL, g_strdup(devinfo));
|
ports = list_serial_ports();
|
||||||
else
|
|
||||||
/* No specific device given, so scan all serial ports. */
|
|
||||||
ports = list_serial_ports();
|
|
||||||
|
|
||||||
num_ports = g_slist_length(ports);
|
num_ports = g_slist_length(ports);
|
||||||
|
|
||||||
if (!(fds = g_try_malloc0(num_ports * sizeof(GPollFD)))) {
|
if (!(fds = g_try_malloc0(num_ports * sizeof(GPollFD)))) {
|
||||||
|
|
|
@ -327,7 +327,7 @@ static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
* API callbacks
|
* API callbacks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct libusb_device_descriptor des;
|
struct libusb_device_descriptor des;
|
||||||
|
@ -335,9 +335,6 @@ static int hw_init(const char *devinfo)
|
||||||
int ret, devcnt, i;
|
int ret, devcnt, i;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
|
||||||
(void)devinfo;
|
|
||||||
|
|
||||||
/* Allocate memory for our private driver context. */
|
/* Allocate memory for our private driver context. */
|
||||||
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
||||||
sr_err("zp: %s: ctx malloc failed", __func__);
|
sr_err("zp: %s: ctx malloc failed", __func__);
|
||||||
|
|
|
@ -144,7 +144,7 @@ SR_API int sr_driver_init(struct sr_dev_driver *driver)
|
||||||
char **probe_names;
|
char **probe_names;
|
||||||
|
|
||||||
sr_dbg("initializing %s driver", driver->name);
|
sr_dbg("initializing %s driver", driver->name);
|
||||||
num_devs = driver->init(NULL);
|
num_devs = driver->init();
|
||||||
for (i = 0; i < num_devs; i++) {
|
for (i = 0; i < num_devs; i++) {
|
||||||
num_probes = GPOINTER_TO_INT(
|
num_probes = GPOINTER_TO_INT(
|
||||||
driver->dev_info_get(i, SR_DI_NUM_PROBES));
|
driver->dev_info_get(i, SR_DI_NUM_PROBES));
|
||||||
|
|
|
@ -337,6 +337,9 @@ enum {
|
||||||
|
|
||||||
/*--- Special stuff -------------------------------------------------*/
|
/*--- Special stuff -------------------------------------------------*/
|
||||||
|
|
||||||
|
/** Session filename */
|
||||||
|
SR_HWCAP_SESSIONFILE,
|
||||||
|
|
||||||
/* TODO: Better description. */
|
/* TODO: Better description. */
|
||||||
/** The device supports specifying a capturefile to inject. */
|
/** The device supports specifying a capturefile to inject. */
|
||||||
SR_HWCAP_CAPTUREFILE,
|
SR_HWCAP_CAPTUREFILE,
|
||||||
|
@ -467,7 +470,7 @@ struct sr_dev_driver {
|
||||||
char *name;
|
char *name;
|
||||||
char *longname;
|
char *longname;
|
||||||
int api_version;
|
int api_version;
|
||||||
int (*init) (const char *devinfo);
|
int (*init) (void);
|
||||||
int (*cleanup) (void);
|
int (*cleanup) (void);
|
||||||
|
|
||||||
/* Device-specific */
|
/* Device-specific */
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define CHUNKSIZE (512 * 1024)
|
#define CHUNKSIZE (512 * 1024)
|
||||||
|
|
||||||
struct session_vdev {
|
struct session_vdev {
|
||||||
|
char *sessionfile;
|
||||||
char *capturefile;
|
char *capturefile;
|
||||||
struct zip *archive;
|
struct zip *archive;
|
||||||
struct zip_file *capfile;
|
struct zip_file *capfile;
|
||||||
|
@ -39,7 +40,6 @@ struct session_vdev {
|
||||||
int num_probes;
|
int num_probes;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *sessionfile = NULL;
|
|
||||||
static GSList *dev_insts = NULL;
|
static GSList *dev_insts = NULL;
|
||||||
static const int hwcaps[] = {
|
static const int hwcaps[] = {
|
||||||
SR_HWCAP_CAPTUREFILE,
|
SR_HWCAP_CAPTUREFILE,
|
||||||
|
@ -148,9 +148,8 @@ static int hw_cleanup(void);
|
||||||
*
|
*
|
||||||
* @return TODO.
|
* @return TODO.
|
||||||
*/
|
*/
|
||||||
static int hw_init(const char *devinfo)
|
static int hw_init(void)
|
||||||
{
|
{
|
||||||
sessionfile = g_strdup(devinfo);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -169,8 +168,6 @@ static int hw_cleanup(void)
|
||||||
|
|
||||||
sr_session_source_remove(-1);
|
sr_session_source_remove(-1);
|
||||||
|
|
||||||
g_free(sessionfile);
|
|
||||||
|
|
||||||
return SR_OK;
|
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,
|
sr_info("session driver: setting samplerate to %" PRIu64,
|
||||||
vdev->samplerate);
|
vdev->samplerate);
|
||||||
break;
|
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:
|
case SR_HWCAP_CAPTUREFILE:
|
||||||
vdev->capturefile = g_strdup(value);
|
vdev->capturefile = g_strdup(value);
|
||||||
sr_info("session driver: setting capturefile to %s",
|
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)))
|
if (!(vdev = get_vdev_by_index(dev_index)))
|
||||||
return SR_ERR;
|
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);
|
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': "
|
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;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) == -1) {
|
if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) == -1) {
|
||||||
sr_err("session driver: Failed to check capture file '%s' in "
|
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;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vdev->capfile = zip_fopen(vdev->archive, vdev->capturefile, 0))) {
|
if (!(vdev->capfile = zip_fopen(vdev->archive, vdev->capturefile, 0))) {
|
||||||
sr_err("session driver: Failed to open capture file '%s' in "
|
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;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,9 @@ SR_API int sr_session_load(const char *filename)
|
||||||
dev = sr_dev_new(&session_driver, devcnt);
|
dev = sr_dev_new(&session_driver, devcnt);
|
||||||
if (devcnt == 0)
|
if (devcnt == 0)
|
||||||
/* first device, init the driver */
|
/* first device, init the driver */
|
||||||
dev->driver->init((char *)filename);
|
dev->driver->init();
|
||||||
sr_session_dev_add(dev);
|
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);
|
dev->driver->dev_config_set(devcnt, SR_HWCAP_CAPTUREFILE, val);
|
||||||
g_ptr_array_add(capturefiles, val);
|
g_ptr_array_add(capturefiles, val);
|
||||||
} else if (!strcmp(keys[j], "samplerate")) {
|
} else if (!strcmp(keys[j], "samplerate")) {
|
||||||
|
|
Loading…
Reference in New Issue