Change sr_dev_inst_new() to take no parameters.

Change all callers to set the fields manually as needed.
This commit is contained in:
Uwe Hermann 2014-11-12 02:06:15 +01:00
parent c7e4556258
commit 0af636bed9
51 changed files with 209 additions and 204 deletions

View File

@ -203,32 +203,22 @@ SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key)
/** @private /** @private
* Allocate and init a new device instance struct. * Allocate and init a new device instance struct.
* @param[in] index @copydoc sr_dev_inst::index
* @param[in] status @copydoc sr_dev_inst::status
* @param[in] vendor @copydoc sr_dev_inst::vendor
* @param[in] model @copydoc sr_dev_inst::model
* @param[in] version @copydoc sr_dev_inst::version
* *
* @retval NULL Error
* @retval struct sr_dev_inst *. Dynamically allocated, free using * @retval struct sr_dev_inst *. Dynamically allocated, free using
* sr_dev_inst_free(). * sr_dev_inst_free().
*/ */
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status, SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void)
const char *vendor, const char *model, const char *version)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
if (!(sdi = g_try_malloc(sizeof(struct sr_dev_inst)))) { sdi = g_malloc0(sizeof(struct sr_dev_inst));
sr_err("Device instance malloc failed.");
return NULL;
}
sdi->driver = NULL; sdi->driver = NULL;
sdi->status = status; sdi->status = -1;
sdi->inst_type = -1; sdi->inst_type = -1;
sdi->vendor = vendor ? g_strdup(vendor) : NULL; sdi->vendor = NULL;
sdi->model = model ? g_strdup(model) : NULL; sdi->model = NULL;
sdi->version = version ? g_strdup(version) : NULL; sdi->version = NULL;
sdi->serial_num = NULL; sdi->serial_num = NULL;
sdi->connection_id = NULL; sdi->connection_id = NULL;
sdi->channels = NULL; sdi->channels = NULL;
@ -248,10 +238,10 @@ SR_API struct sr_dev_inst *sr_dev_inst_user_new(const char *vendor,
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
sdi = sr_dev_inst_new(0, vendor, model, version); sdi = sr_dev_inst_new();
if (!sdi) sdi->vendor = g_strdup(vendor);
return NULL; sdi->model = g_strdup(model);
sdi->version = g_strdup(version);
sdi->inst_type = SR_INST_USER; sdi->inst_type = SR_INST_USER;
return sdi; return sdi;

View File

@ -136,9 +136,11 @@ static GSList *scan(GSList *options)
for (i = 0; supported_agdmm[i].model; i++) { for (i = 0; supported_agdmm[i].model; i++) {
if (strcmp(supported_agdmm[i].modelname, tokens[1])) if (strcmp(supported_agdmm[i].modelname, tokens[1]))
continue; continue;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Agilent", sdi = sr_dev_inst_new();
tokens[1], tokens[3]))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup("Agilent");
sdi->model = g_strdup(tokens[1]);
sdi->version = g_strdup(tokens[3]);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");
return NULL; return NULL;

View File

@ -96,8 +96,10 @@ static GSList *scan(GSList *options)
sr_info("Found device on port %s.", conn); sr_info("Found device on port %s.", conn);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "APPA", "55II", NULL))) sdi = sr_dev_inst_new();
goto scan_cleanup; sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("APPA");
sdi->model = g_strdup("55II");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -380,11 +380,10 @@ static GSList *scan(GSList *options)
devc->use_triggers = 0; devc->use_triggers = 0;
/* Register SIGMA device. */ /* Register SIGMA device. */
if (!(sdi = sr_dev_inst_new(SR_ST_INITIALIZING, USB_VENDOR_NAME, sdi = sr_dev_inst_new();
USB_MODEL_NAME, NULL))) { sdi->status = SR_ST_INITIALIZING;
sr_err("%s: sdi was NULL", __func__); sdi->vendor = g_strdup(USB_VENDOR_NAME);
goto free; sdi->model = g_strdup(USB_MODEL_NAME);
}
sdi->driver = di; sdi->driver = di;
for (i = 0; i < ARRAY_SIZE(channel_names); i++) { for (i = 0; i < ARRAY_SIZE(channel_names); i++) {

View File

@ -164,7 +164,10 @@ static GSList *scan(GSList *options, int modelid)
return NULL; return NULL;
} }
sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Atten", model->name, NULL); sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Atten");
sdi->model = g_strdup(model->name);
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_SERIAL; sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial; sdi->conn = serial;

View File

@ -97,7 +97,10 @@ static GSList *scan(GSList *options)
if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
return NULL; return NULL;
sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, "BeagleLogic", "1.0"); sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->model = g_strdup("BeagleLogic");
sdi->version = g_strdup("1.0");
sdi->driver = di; sdi->driver = di;
/* Unless explicitly specified, keep max channels to 8 only */ /* Unless explicitly specified, keep max channels to 8 only */

View File

@ -73,11 +73,10 @@ static GSList *scan(GSList *options)
for (l = usb_devices; l; l = l->next) { for (l = usb_devices; l; l = l->next) {
usb = l->data; usb = l->data;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
"Brymen", "BM869", NULL))) { sdi->status = SR_ST_INACTIVE;
sr_err("sr_dev_inst_new returned NULL."); sdi->vendor = g_strdup("Brymen");
return NULL; sdi->model = g_strdup("BM869");
}
if (!(devc = g_try_malloc0(sizeof(*devc)))) { if (!(devc = g_try_malloc0(sizeof(*devc)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -75,8 +75,10 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm)
sr_info("Found device on port %s.", conn); sr_info("Found device on port %s.", conn);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Brymen", "BM85x", NULL))) sdi = sr_dev_inst_new();
goto scan_cleanup; sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Brymen");
sdi->model = g_strdup("BM85x");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -109,9 +109,10 @@ static GSList *scan(GSList *options)
while (g_get_monotonic_time() - start < MAX_SCAN_TIME) { while (g_get_monotonic_time() - start < MAX_SCAN_TIME) {
if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) { if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) {
/* Found one. */ /* Found one. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "CEM", sdi = sr_dev_inst_new();
"DT-885x", NULL))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup("CEM");
sdi->model = g_strdup("DT-885x");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_dbg("Device context malloc failed."); sr_dbg("Device context malloc failed.");

View File

@ -85,9 +85,10 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
sr_info("Found device on port %s.", conn); sr_info("Found device on port %s.", conn);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, center_devs[idx].vendor, sdi = sr_dev_inst_new();
center_devs[idx].device, NULL))) sdi->status = SR_ST_INACTIVE;
goto scan_cleanup; sdi->vendor = g_strdup(center_devs[idx].vendor);
sdi->model = g_strdup(center_devs[idx].device);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -120,13 +120,10 @@ static int add_device(int idx, int model, GSList **devices)
devc->cur_samplerate = devc->prof->max_samplerate; devc->cur_samplerate = devc->prof->max_samplerate;
/* Register the device with libsigrok. */ /* Register the device with libsigrok. */
sdi = sr_dev_inst_new(SR_ST_INITIALIZING, sdi = sr_dev_inst_new();
"ChronoVu", devc->prof->modelname, NULL); sdi->status = SR_ST_INITIALIZING;
if (!sdi) { sdi->vendor = g_strdup("ChronoVu");
sr_err("Failed to create device instance."); sdi->model = g_strdup(devc->prof->modelname);
ret = SR_ERR;
goto err_free_final_buf;
}
sdi->driver = di; sdi->driver = di;
sdi->priv = devc; sdi->priv = devc;
@ -147,7 +144,6 @@ static int add_device(int idx, int model, GSList **devices)
err_free_dev_inst: err_free_dev_inst:
sr_dev_inst_free(sdi); sr_dev_inst_free(sdi);
err_free_final_buf:
g_free(devc->final_buf); g_free(devc->final_buf);
err_free_devc: err_free_devc:
g_free(devc); g_free(devc);

View File

@ -82,9 +82,10 @@ static GSList *scan(GSList *options)
if (!serialcomm) if (!serialcomm)
serialcomm = SERIALCOMM; serialcomm = SERIALCOMM;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Colead", sdi = sr_dev_inst_new();
"SL-5868P", NULL))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup("Colead");
sdi->model = g_strdup("SL-5868P");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_dbg("Device context malloc failed."); sr_dbg("Device context malloc failed.");

View File

@ -94,9 +94,10 @@ static GSList *scan(GSList *options)
sr_spew("Conrad DIGI 35 CPU assumed at %s.", conn); sr_spew("Conrad DIGI 35 CPU assumed at %s.", conn);
if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, "Conrad", "DIGI 35 CPU", NULL))) sdi = sr_dev_inst_new();
return NULL; sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup("Conrad");
sdi->model = g_strdup("DIGI 35 CPU");
sdi->conn = serial; sdi->conn = serial;
sdi->priv = NULL; sdi->priv = NULL;
sdi->driver = di; sdi->driver = di;

View File

@ -289,11 +289,10 @@ static GSList *scan(GSList *options)
} }
devices = NULL; devices = NULL;
sdi = sr_dev_inst_new(SR_ST_ACTIVE, "Demo device", NULL, NULL);
if (!sdi) { sdi = sr_dev_inst_new();
sr_err("Device instance creation failed."); sdi->status = SR_ST_ACTIVE;
return NULL; sdi->model = "Demo device";
}
sdi->driver = di; sdi->driver = di;
devc = g_malloc(sizeof(struct dev_context)); devc = g_malloc(sizeof(struct dev_context));

View File

@ -122,9 +122,11 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
continue; continue;
/* Skip leading spaces in version number. */ /* Skip leading spaces in version number. */
for (s = 0; tokens[1][s] == ' '; s++); for (s = 0; tokens[1][s] == ' '; s++);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Fluke", sdi = sr_dev_inst_new();
tokens[0] + 6, tokens[1] + s))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup("Fluke");
sdi->model = g_strdup(tokens[0] + 6);
sdi->version = g_strdup(tokens[1] + s);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");
return NULL; return NULL;

View File

@ -238,10 +238,11 @@ static GSList *scan(GSList *options)
if (!prof) if (!prof)
continue; continue;
sdi = sr_dev_inst_new(SR_ST_INITIALIZING, sdi = sr_dev_inst_new();
prof->vendor, prof->model, prof->model_version); sdi->status = SR_ST_INITIALIZING;
if (!sdi) sdi->vendor = g_strdup(prof->vendor);
return NULL; sdi->model = g_strdup(prof->model);
sdi->version = g_strdup(prof->model_version);
sdi->driver = di; sdi->driver = di;
sdi->serial_num = g_strdup(serial_num); sdi->serial_num = g_strdup(serial_num);
sdi->connection_id = g_strdup(connection_id); sdi->connection_id = g_strdup(connection_id);

View File

@ -223,9 +223,10 @@ static GSList *scan_1x_2x_rs232(GSList *options)
if (model != METRAHIT_NONE) { if (model != METRAHIT_NONE) {
sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model)); sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model));
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, sdi = sr_dev_inst_new();
gmc_model_str(model), NULL))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup(VENDOR_GMC);
sdi->model = g_strdup(gmc_model_str(model));
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");
return NULL; return NULL;
@ -303,9 +304,9 @@ static GSList *scan_2x_bd232(GSList *options)
goto exit_err; goto exit_err;
} }
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL))) sdi = sr_dev_inst_new();
goto exit_err; sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
sdi->priv = devc; sdi->priv = devc;
/* Send message 03 "Query multimeter version and status" */ /* Send message 03 "Query multimeter version and status" */
@ -354,8 +355,9 @@ static GSList *scan_2x_bd232(GSList *options)
goto exit_err; goto exit_err;
} }
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL))) sdi = sr_dev_inst_new();
goto exit_err; sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
} }
}; };

View File

@ -75,16 +75,15 @@ static struct sr_dev_inst *hmo_probe_serial_device(struct sr_scpi_dev_inst *scpi
if (check_manufacturer(hw_info->manufacturer) != SR_OK) if (check_manufacturer(hw_info->manufacturer) != SR_OK)
goto fail; goto fail;
if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, sdi = sr_dev_inst_new();
hw_info->manufacturer, hw_info->model, sdi->status = SR_ST_ACTIVE;
hw_info->firmware_version))) { sdi->vendor = g_strdup(hw_info->manufacturer);
goto fail; 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 = di;
sdi->inst_type = SR_INST_SCPI; sdi->inst_type = SR_INST_SCPI;
sdi->conn = scpi; sdi->conn = scpi;
sdi->serial_num = g_strdup(hw_info->serial_number);
sr_scpi_hw_info_free(hw_info); sr_scpi_hw_info_free(hw_info);
hw_info = NULL; hw_info = NULL;

View File

@ -172,7 +172,10 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
struct dev_context *devc; struct dev_context *devc;
int i; int i;
sdi = sr_dev_inst_new(SR_ST_INITIALIZING, prof->vendor, prof->model, NULL); sdi = sr_dev_inst_new();
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
sdi->driver = di; sdi->driver = di;
/* /*

View File

@ -70,7 +70,6 @@ static GSList *scan(GSList *options)
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
struct device_info dev_info; struct device_info dev_info;
int ret, i; int ret, i;
char *fw_ver_str;
(void)options; (void)options;
@ -113,34 +112,16 @@ static GSList *scan(GSList *options)
continue; continue;
} }
fw_ver_str = g_strdup_printf("%u.%u", dev_info.fw_ver_major, sdi = sr_dev_inst_new();
dev_info.fw_ver_minor); sdi->status = SR_ST_INACTIVE;
if (!fw_ver_str) { sdi->vendor = g_strdup(VENDOR_NAME);
sr_err("Firmware string malloc failed."); sdi->model = g_strdup(MODEL_NAME);
sr_usb_dev_inst_free(usb); sdi->version = g_strdup_printf("%u.%u", dev_info.fw_ver_major, dev_info.fw_ver_minor);
libusb_free_transfer(devc->xfer_in); sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
libusb_free_transfer(devc->xfer_out);
g_free(devc);
continue;
}
sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_NAME,
MODEL_NAME, fw_ver_str);
g_free(fw_ver_str);
if (!sdi) {
sr_err("sr_dev_inst_new failed.");
sr_usb_dev_inst_free(usb);
libusb_free_transfer(devc->xfer_in);
libusb_free_transfer(devc->xfer_out);
g_free(devc);
continue;
}
sdi->priv = devc; sdi->priv = devc;
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_USB; sdi->inst_type = SR_INST_USB;
sdi->conn = usb; sdi->conn = usb;
sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
for (i = 0; channel_names[i]; i++) { for (i = 0; channel_names[i]; i++) {
ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE,

View File

@ -123,12 +123,10 @@ static GSList *scan(GSList *options)
} }
/* Register the device with libsigrok. */ /* Register the device with libsigrok. */
sdi = sr_dev_inst_new(SR_ST_INITIALIZING, sdi = sr_dev_inst_new();
USB_VENDOR_NAME, USB_MODEL_NAME, NULL); sdi->status = SR_ST_INITIALIZING;
if (!sdi) { sdi->vendor = g_strdup(USB_VENDOR_NAME);
sr_err("Failed to create device instance."); sdi->model = g_strdup(USB_MODEL_NAME);
goto err_close_ftdic;
}
sdi->driver = di; sdi->driver = di;
sdi->priv = devc; sdi->priv = devc;
@ -147,7 +145,6 @@ static GSList *scan(GSList *options)
return devices; return devices;
err_close_ftdic:
scanaplus_close(devc); scanaplus_close(devc);
err_free_ftdic: err_free_ftdic:
ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ ftdi_free(devc->ftdic); /* NOT free() or g_free()! */

View File

@ -129,10 +129,10 @@ static GSList *scan(GSList *options)
for (l = usb_devices; l; l = l->next) { for (l = usb_devices; l; l = l->next) {
if (scan_kecheng(l->data, &model) != SR_OK) if (scan_kecheng(l->data, &model) != SR_OK)
continue; continue;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR, sdi = sr_dev_inst_new();
model, NULL))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup(VENDOR);
g_free(model); sdi->model = model; /* Already g_strndup()'d. */
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_USB; sdi->inst_type = SR_INST_USB;
sdi->conn = l->data; sdi->conn = l->data;

View File

@ -323,9 +323,11 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
return NULL; return NULL;
} }
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, LASCAR_VENDOR, sdi = sr_dev_inst_new();
profile->modelname, firmware))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup(LASCAR_VENDOR);
sdi->model = g_strdup(profile->modelname);
sdi->version = g_strdup(firmware);
sdi->driver = di; sdi->driver = di;
if (profile->logformat == LOG_TEMP_RH) { if (profile->logformat == LOG_TEMP_RH) {

View File

@ -150,12 +150,10 @@ static GSList *scan(GSList *options)
} }
/* Init device instance, etc. */ /* Init device instance, etc. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Manson", sdi = sr_dev_inst_new();
models[model_id].name, NULL))) { sdi->status = SR_ST_INACTIVE;
sr_err("Failed to create device instance."); sdi->vendor = g_strdup("Manson");
return NULL; sdi->model = g_strdup(models[model_id].name);
}
sdi->inst_type = SR_INST_SERIAL; sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial; sdi->conn = serial;
sdi->driver = di; sdi->driver = di;

View File

@ -84,9 +84,10 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
sr_info("Found device on port %s.", conn); sr_info("Found device on port %s.", conn);
/* TODO: Fill in version from protocol response. */ /* TODO: Fill in version from protocol response. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, mic_devs[idx].vendor, sdi = sr_dev_inst_new();
mic_devs[idx].device, NULL))) sdi->status = SR_ST_INACTIVE;
goto scan_cleanup; sdi->vendor = g_strdup(mic_devs[idx].vendor);
sdi->model = g_strdup(mic_devs[idx].device);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -377,7 +377,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
int cnt; int cnt;
gchar buf[LINELEN_MAX]; gchar buf[LINELEN_MAX];
gchar channel[10]; gchar channel[10];
char* verstr; char *verstr;
sdi = NULL; sdi = NULL;
devc = NULL; devc = NULL;
@ -444,7 +444,11 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
Therefore just print an error message, but do not exit with error. */ Therefore just print an error message, but do not exit with error. */
sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno)); sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno));
sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_MOTECH, models[modelid].modelstr, verstr); sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_MOTECH);
sdi->model = g_strdup(models[modelid].modelstr);
sdi->version = g_strdup(verstr);
sdi->driver = drv; sdi->driver = drv;
sdi->inst_type = SR_INST_SERIAL; sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial; sdi->conn = serial;

View File

@ -144,9 +144,11 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options)
auxtype = xgittoint(buf[7]); auxtype = xgittoint(buf[7]);
sr_spew("%s %s DMM %s detected!", get_brandstr(drv), get_typestr(auxtype, drv), buf + 9); sr_spew("%s %s DMM %s detected!", get_brandstr(drv), get_typestr(auxtype, drv), buf + 9);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
get_brandstr(drv), get_typestr(auxtype, drv), buf + 9))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup(get_brandstr(drv));
sdi->model = g_strdup(get_typestr(auxtype, drv));
sdi->version = g_strdup(buf + 9);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");
return NULL; return NULL;

View File

@ -177,8 +177,11 @@ static GSList *scan(GSList *options)
} else { } else {
/* Not an OLS -- some other board that uses the sump protocol. */ /* Not an OLS -- some other board that uses the sump protocol. */
sr_info("Device does not support metadata."); sr_info("Device does not support metadata.");
sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
"Sump", "Logic Analyzer", "v1.0"); sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Sump");
sdi->model = g_strdup("Logic Analyzer");
sdi->version = g_strdup("v1.0");
sdi->driver = di; sdi->driver = di;
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE,

View File

@ -152,7 +152,8 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
GString *tmp_str, *devname, *version; GString *tmp_str, *devname, *version;
guchar tmp_c; guchar tmp_c;
sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL); sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->driver = di; sdi->driver = di;
devc = ols_dev_new(); devc = ols_dev_new();
sdi->priv = devc; sdi->priv = devc;

View File

@ -226,7 +226,8 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
guchar tmp_c; guchar tmp_c;
int index, i; int index, i;
sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL); sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->driver = di; sdi->driver = di;
sdi->priv = devc; sdi->priv = devc;

View File

@ -291,14 +291,16 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
} }
} }
if (!model || !(sdi = sr_dev_inst_new(SR_ST_ACTIVE, if (!model) {
model->series->vendor->name,
model->name,
hw_info->firmware_version))) {
sr_scpi_hw_info_free(hw_info); sr_scpi_hw_info_free(hw_info);
return NULL; return NULL;
} }
sdi = sr_dev_inst_new();
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(model->series->vendor->name);
sdi->model = g_strdup(model->name);
sdi->version = g_strdup(hw_info->firmware_version);
sdi->conn = scpi; sdi->conn = scpi;
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_SCPI; sdi->inst_type = SR_INST_SCPI;

View File

@ -198,10 +198,10 @@ static GSList *scan(GSList *options)
if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID) if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
continue; continue;
sdi = sr_dev_inst_new(SR_ST_INITIALIZING, sdi = sr_dev_inst_new();
"Saleae", "Logic16", NULL); sdi->status = SR_ST_INITIALIZING;
if (!sdi) sdi->vendor = g_strdup("Saleae");
return NULL; sdi->model = g_strdup("Logic16");
sdi->driver = di; sdi->driver = di;
sdi->connection_id = g_strdup(connection_id); sdi->connection_id = g_strdup(connection_id);

View File

@ -90,8 +90,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
return NULL; return NULL;
} }
sdi = sr_dev_inst_new(SR_ST_ACTIVE, vendor, hw_info->model, sdi = sr_dev_inst_new();
hw_info->firmware_version); sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(hw_info->model);
sdi->version = g_strdup(hw_info->firmware_version);
sdi->conn = scpi; sdi->conn = scpi;
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_SCPI; sdi->inst_type = SR_INST_SCPI;

View File

@ -456,9 +456,10 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm)
sr_info("Found device on port %s.", conn); sr_info("Found device on port %s.", conn);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, dmms[dmm].vendor, sdi = sr_dev_inst_new();
dmms[dmm].device, NULL))) sdi->status = SR_ST_INACTIVE;
goto scan_cleanup; sdi->vendor = g_strdup(dmms[dmm].vendor);
sdi->model = g_strdup(dmms[dmm].device);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -99,7 +99,7 @@ static GSList *gen_channel_list(int num_channels)
return list; return list;
} }
static struct sr_dev_inst *dev_inst_new() static struct sr_dev_inst *dev_inst_new(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct dev_context *devc; struct dev_context *devc;
@ -112,13 +112,10 @@ static struct sr_dev_inst *dev_inst_new()
} }
/* Register the device with libsigrok. */ /* Register the device with libsigrok. */
sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
VENDOR_NAME, MODEL_NAME, NULL); sdi->status = SR_ST_INACTIVE;
if (!sdi) { sdi->vendor = g_strdup(VENDOR_NAME);
sr_err("Failed to instantiate device."); sdi->model = g_strdup(MODEL_NAME);
g_free(devc);
return NULL;
}
/* Enable all channels to match the default channel configuration. */ /* Enable all channels to match the default channel configuration. */
devc->channel_mask = ALL_CHANNELS_MASK; devc->channel_mask = ALL_CHANNELS_MASK;

View File

@ -92,8 +92,10 @@ static GSList *scan(GSList *options)
sr_info("Found device on port %s.", conn); sr_info("Found device on port %s.", conn);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "EDF", "Teleinfo", NULL))) sdi = sr_dev_inst_new();
goto scan_cleanup; sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("EDF");
sdi->model = g_strdup("Teleinfo");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -124,8 +124,10 @@ static GSList *scan(GSList *options)
if (strcmp(product, "testo 435/635/735")) if (strcmp(product, "testo 435/635/735"))
continue; continue;
sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Testo", sdi = sr_dev_inst_new();
"435/635/735", NULL); sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Testo");
sdi->model = g_strdup("435/635/735");
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_USB; sdi->inst_type = SR_INST_USB;
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),

View File

@ -84,11 +84,10 @@ static GSList *scan(GSList *options)
if (!serialcomm) if (!serialcomm)
serialcomm = SERIALCOMM; serialcomm = SERIALCOMM;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Tondaj", sdi = sr_dev_inst_new();
"SL-814", NULL))) { sdi->status = SR_ST_INACTIVE;
sr_err("Failed to create device instance."); sdi->vendor = g_strdup("Tondaj");
return NULL; sdi->model = g_strdup("SL-814");
}
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -260,11 +260,10 @@ static GSList *scan(GSList *options, int dmm)
devc->first_run = TRUE; devc->first_run = TRUE;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
udmms[dmm].vendor, udmms[dmm].device, NULL))) { sdi->status = SR_ST_INACTIVE;
sr_err("sr_dev_inst_new returned NULL."); sdi->vendor = g_strdup(udmms[dmm].vendor);
return NULL; sdi->model = g_strdup(udmms[dmm].device);
}
sdi->priv = devc; sdi->priv = devc;
sdi->driver = udmms[dmm].di; sdi->driver = udmms[dmm].di;
if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1")))

View File

@ -79,9 +79,10 @@ static GSList *scan(GSList *options)
/* We have a list of sr_usb_dev_inst matching the connection /* We have a list of sr_usb_dev_inst matching the connection
* string. Wrap them in sr_dev_inst and we're done. */ * string. Wrap them in sr_dev_inst and we're done. */
for (l = usb_devices; l; l = l->next) { for (l = usb_devices; l; l = l->next) {
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR, sdi = sr_dev_inst_new();
MODEL, NULL))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup(VENDOR);
sdi->model = g_strdup(MODEL);
sdi->driver = di; sdi->driver = di;
sdi->inst_type = SR_INST_USB; sdi->inst_type = SR_INST_USB;
sdi->conn = l->data; sdi->conn = l->data;

View File

@ -82,9 +82,9 @@ static GSList *scan(GSList *options)
usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
VICTOR_VENDOR, NULL, NULL))) sdi->status = SR_ST_INACTIVE;
return NULL; sdi->vendor = g_strdup(VICTOR_VENDOR);
sdi->driver = di; sdi->driver = di;
sdi->connection_id = g_strdup(connection_id); sdi->connection_id = g_strdup(connection_id);

View File

@ -62,9 +62,11 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK) if (dlm_model_get(hw_info->model, &model_name, &model_index) != SR_OK)
goto fail; goto fail;
if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, MANUFACTURER_NAME, sdi = sr_dev_inst_new();
model_name, hw_info->firmware_version))) sdi->status = SR_ST_ACTIVE;
goto fail; sdi->vendor = g_strdup(MANUFACTURER_NAME);
sdi->model = g_strdup(model_name);
sdi->version = g_strdup(hw_info->firmware_version);
sdi->serial_num = g_strdup(hw_info->serial_number); sdi->serial_num = g_strdup(hw_info->serial_number);

View File

@ -222,11 +222,10 @@ static GSList *scan(GSList *options)
sr_info("Found ZEROPLUS %s.", prof->model_name); sr_info("Found ZEROPLUS %s.", prof->model_name);
/* Register the device with libsigrok. */ /* Register the device with libsigrok. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, sdi = sr_dev_inst_new();
VENDOR_NAME, prof->model_name, NULL))) { sdi->status = SR_ST_INACTIVE;
sr_err("%s: sr_dev_inst_new failed", __func__); sdi->vendor = g_strdup(VENDOR_NAME);
return NULL; sdi->model = g_strdup(prof->model_name);
}
sdi->driver = di; sdi->driver = di;
sdi->serial_num = g_strdup(serial_num); sdi->serial_num = g_strdup(serial_num);
sdi->connection_id = g_strdup(connection_id); sdi->connection_id = g_strdup(connection_id);

View File

@ -50,7 +50,7 @@ static int init(struct sr_input *in, GHashTable *options)
return SR_ERR_ARG; return SR_ERR_ARG;
} }
in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); in->sdi = sr_dev_inst_new();
in->priv = inc = g_malloc0(sizeof(struct context)); in->priv = inc = g_malloc0(sizeof(struct context));
inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate")); inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));

View File

@ -62,7 +62,7 @@ static int init(struct sr_input *in, GHashTable *options)
return SR_ERR_ARG; return SR_ERR_ARG;
} }
in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); in->sdi = sr_dev_inst_new();
in->priv = inc = g_malloc0(sizeof(struct context)); in->priv = inc = g_malloc0(sizeof(struct context));
inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate")); inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));

View File

@ -393,7 +393,7 @@ static int init(struct sr_input *in, GHashTable *options)
struct context *inc; struct context *inc;
const char *s; const char *s;
in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); in->sdi = sr_dev_inst_new();
in->priv = inc = g_malloc0(sizeof(struct context)); in->priv = inc = g_malloc0(sizeof(struct context));
inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column")); inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column"));

View File

@ -429,7 +429,7 @@ static int init(struct sr_input *in, GHashTable *options)
inc->skip = g_variant_get_int32(g_hash_table_lookup(options, "skip")); inc->skip = g_variant_get_int32(g_hash_table_lookup(options, "skip"));
inc->skip /= inc->downsample; inc->skip /= inc->downsample;
in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); in->sdi = sr_dev_inst_new();
in->priv = inc; in->priv = inc;
for (i = 0; i < num_channels; i++) { for (i = 0; i < num_channels; i++) {

View File

@ -150,7 +150,7 @@ static int init(struct sr_input *in, GHashTable *options)
{ {
(void)options; (void)options;
in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); in->sdi = sr_dev_inst_new();
in->priv = g_malloc0(sizeof(struct context)); in->priv = g_malloc0(sizeof(struct context));
return SR_OK; return SR_OK;

View File

@ -843,8 +843,10 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
sr_info("Found device on port %s.", serial->port); sr_info("Found device on port %s.", serial->port);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, vendor, model, NULL))) sdi = sr_dev_inst_new();
goto scan_cleanup; sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");

View File

@ -521,8 +521,7 @@ struct sr_dev_inst {
}; };
/* Generic device instances */ /* Generic device instances */
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status, SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void);
const char *vendor, const char *model, const char *version);
SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi); SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
#ifdef HAVE_LIBUSB_1_0 #ifdef HAVE_LIBUSB_1_0

View File

@ -170,8 +170,9 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
for (j = 0; keys[j]; j++) { for (j = 0; keys[j]; j++) {
val = g_key_file_get_string(kf, sections[i], keys[j], NULL); val = g_key_file_get_string(kf, sections[i], keys[j], NULL);
if (!strcmp(keys[j], "capturefile")) { if (!strcmp(keys[j], "capturefile")) {
sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); sdi = sr_dev_inst_new();
sdi->driver = &session_driver; sdi->driver = &session_driver;
sdi->status = SR_ST_ACTIVE;
if (!session_driver_initialized) { if (!session_driver_initialized) {
/* first device, init the driver */ /* first device, init the driver */
session_driver_initialized = 1; session_driver_initialized = 1;