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
* 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
* sr_dev_inst_free().
*/
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status,
const char *vendor, const char *model, const char *version)
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void)
{
struct sr_dev_inst *sdi;
if (!(sdi = g_try_malloc(sizeof(struct sr_dev_inst)))) {
sr_err("Device instance malloc failed.");
return NULL;
}
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->driver = NULL;
sdi->status = status;
sdi->status = -1;
sdi->inst_type = -1;
sdi->vendor = vendor ? g_strdup(vendor) : NULL;
sdi->model = model ? g_strdup(model) : NULL;
sdi->version = version ? g_strdup(version) : NULL;
sdi->vendor = NULL;
sdi->model = NULL;
sdi->version = NULL;
sdi->serial_num = NULL;
sdi->connection_id = 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;
sdi = sr_dev_inst_new(0, vendor, model, version);
if (!sdi)
return NULL;
sdi = sr_dev_inst_new();
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);
sdi->version = g_strdup(version);
sdi->inst_type = SR_INST_USER;
return sdi;

View File

@ -136,9 +136,11 @@ static GSList *scan(GSList *options)
for (i = 0; supported_agdmm[i].model; i++) {
if (strcmp(supported_agdmm[i].modelname, tokens[1]))
continue;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Agilent",
tokens[1], tokens[3])))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
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)))) {
sr_err("Device context malloc failed.");
return NULL;

View File

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

View File

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

View File

@ -164,7 +164,10 @@ static GSList *scan(GSList *options, int modelid)
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->inst_type = SR_INST_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))
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;
/* 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) {
usb = l->data;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE,
"Brymen", "BM869", NULL))) {
sr_err("sr_dev_inst_new returned NULL.");
return NULL;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Brymen");
sdi->model = g_strdup("BM869");
if (!(devc = g_try_malloc0(sizeof(*devc)))) {
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);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Brymen", "BM85x", NULL)))
goto scan_cleanup;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Brymen");
sdi->model = g_strdup("BM85x");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
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) {
if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) {
/* Found one. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "CEM",
"DT-885x", NULL)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("CEM");
sdi->model = g_strdup("DT-885x");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
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);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, center_devs[idx].vendor,
center_devs[idx].device, NULL)))
goto scan_cleanup;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
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)))) {
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;
/* Register the device with libsigrok. */
sdi = sr_dev_inst_new(SR_ST_INITIALIZING,
"ChronoVu", devc->prof->modelname, NULL);
if (!sdi) {
sr_err("Failed to create device instance.");
ret = SR_ERR;
goto err_free_final_buf;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup("ChronoVu");
sdi->model = g_strdup(devc->prof->modelname);
sdi->driver = di;
sdi->priv = devc;
@ -147,7 +144,6 @@ static int add_device(int idx, int model, GSList **devices)
err_free_dev_inst:
sr_dev_inst_free(sdi);
err_free_final_buf:
g_free(devc->final_buf);
err_free_devc:
g_free(devc);

View File

@ -82,9 +82,10 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Colead",
"SL-5868P", NULL)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Colead");
sdi->model = g_strdup("SL-5868P");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
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);
if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, "Conrad", "DIGI 35 CPU", NULL)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup("Conrad");
sdi->model = g_strdup("DIGI 35 CPU");
sdi->conn = serial;
sdi->priv = NULL;
sdi->driver = di;

View File

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

View File

@ -122,9 +122,11 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
continue;
/* Skip leading spaces in version number. */
for (s = 0; tokens[1][s] == ' '; s++);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Fluke",
tokens[0] + 6, tokens[1] + s)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
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)))) {
sr_err("Device context malloc failed.");
return NULL;

View File

@ -238,10 +238,11 @@ static GSList *scan(GSList *options)
if (!prof)
continue;
sdi = sr_dev_inst_new(SR_ST_INITIALIZING,
prof->vendor, prof->model, prof->model_version);
if (!sdi)
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);
sdi->version = g_strdup(prof->model_version);
sdi->driver = di;
sdi->serial_num = g_strdup(serial_num);
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) {
sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model));
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC,
gmc_model_str(model), NULL)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
sdi->model = g_strdup(gmc_model_str(model));
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
return NULL;
@ -303,9 +304,9 @@ static GSList *scan_2x_bd232(GSList *options)
goto exit_err;
}
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL)))
goto exit_err;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
sdi->priv = devc;
/* Send message 03 "Query multimeter version and status" */
@ -354,8 +355,9 @@ static GSList *scan_2x_bd232(GSList *options)
goto exit_err;
}
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_GMC, NULL, NULL)))
goto exit_err;
sdi = sr_dev_inst_new();
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)
goto fail;
if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE,
hw_info->manufacturer, hw_info->model,
hw_info->firmware_version))) {
goto fail;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(hw_info->manufacturer);
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->inst_type = SR_INST_SCPI;
sdi->conn = scpi;
sdi->serial_num = g_strdup(hw_info->serial_number);
sr_scpi_hw_info_free(hw_info);
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;
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;
/*

View File

@ -70,7 +70,6 @@ static GSList *scan(GSList *options)
struct sr_usb_dev_inst *usb;
struct device_info dev_info;
int ret, i;
char *fw_ver_str;
(void)options;
@ -113,34 +112,16 @@ static GSList *scan(GSList *options)
continue;
}
fw_ver_str = g_strdup_printf("%u.%u", dev_info.fw_ver_major,
dev_info.fw_ver_minor);
if (!fw_ver_str) {
sr_err("Firmware string malloc failed.");
sr_usb_dev_inst_free(usb);
libusb_free_transfer(devc->xfer_in);
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 = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(MODEL_NAME);
sdi->version = g_strdup_printf("%u.%u", dev_info.fw_ver_major, dev_info.fw_ver_minor);
sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
sdi->priv = devc;
sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
for (i = 0; channel_names[i]; i++) {
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. */
sdi = sr_dev_inst_new(SR_ST_INITIALIZING,
USB_VENDOR_NAME, USB_MODEL_NAME, NULL);
if (!sdi) {
sr_err("Failed to create device instance.");
goto err_close_ftdic;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);
sdi->driver = di;
sdi->priv = devc;
@ -147,7 +145,6 @@ static GSList *scan(GSList *options)
return devices;
err_close_ftdic:
scanaplus_close(devc);
err_free_ftdic:
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) {
if (scan_kecheng(l->data, &model) != SR_OK)
continue;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR,
model, NULL)))
return NULL;
g_free(model);
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = model; /* Already g_strndup()'d. */
sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = l->data;

View File

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

View File

@ -150,12 +150,10 @@ static GSList *scan(GSList *options)
}
/* Init device instance, etc. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Manson",
models[model_id].name, NULL))) {
sr_err("Failed to create device instance.");
return NULL;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Manson");
sdi->model = g_strdup(models[model_id].name);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
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);
/* TODO: Fill in version from protocol response. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, mic_devs[idx].vendor,
mic_devs[idx].device, NULL)))
goto scan_cleanup;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
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)))) {
sr_err("Device context malloc failed.");

View File

@ -375,9 +375,9 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
GSList *devices;
const char *conn, *serialcomm;
int cnt;
gchar buf[LINELEN_MAX];
gchar buf[LINELEN_MAX];
gchar channel[10];
char* verstr;
char *verstr;
sdi = 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. */
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->inst_type = SR_INST_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]);
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,
get_brandstr(drv), get_typestr(auxtype, drv), buf + 9)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
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)))) {
sr_err("Device context malloc failed.");
return NULL;

View File

@ -177,8 +177,11 @@ static GSList *scan(GSList *options)
} else {
/* Not an OLS -- some other board that uses the sump protocol. */
sr_info("Device does not support metadata.");
sdi = sr_dev_inst_new(SR_ST_INACTIVE,
"Sump", "Logic Analyzer", "v1.0");
sdi = sr_dev_inst_new();
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;
for (i = 0; i < 32; i++) {
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;
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;
devc = ols_dev_new();
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;
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->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,
model->series->vendor->name,
model->name,
hw_info->firmware_version))) {
if (!model) {
sr_scpi_hw_info_free(hw_info);
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->driver = di;
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)
continue;
sdi = sr_dev_inst_new(SR_ST_INITIALIZING,
"Saleae", "Logic16", NULL);
if (!sdi)
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup("Saleae");
sdi->model = g_strdup("Logic16");
sdi->driver = di;
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;
}
sdi = sr_dev_inst_new(SR_ST_ACTIVE, vendor, hw_info->model,
hw_info->firmware_version);
sdi = sr_dev_inst_new();
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->driver = di;
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);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, dmms[dmm].vendor,
dmms[dmm].device, NULL)))
goto scan_cleanup;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(dmms[dmm].vendor);
sdi->model = g_strdup(dmms[dmm].device);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");

View File

@ -99,7 +99,7 @@ static GSList *gen_channel_list(int num_channels)
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 dev_context *devc;
@ -112,13 +112,10 @@ static struct sr_dev_inst *dev_inst_new()
}
/* Register the device with libsigrok. */
sdi = sr_dev_inst_new(SR_ST_INACTIVE,
VENDOR_NAME, MODEL_NAME, NULL);
if (!sdi) {
sr_err("Failed to instantiate device.");
g_free(devc);
return NULL;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(MODEL_NAME);
/* Enable all channels to match the default channel configuration. */
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);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "EDF", "Teleinfo", NULL)))
goto scan_cleanup;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("EDF");
sdi->model = g_strdup("Teleinfo");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");

View File

@ -124,8 +124,10 @@ static GSList *scan(GSList *options)
if (strcmp(product, "testo 435/635/735"))
continue;
sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Testo",
"435/635/735", NULL);
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Testo");
sdi->model = g_strdup("435/635/735");
sdi->driver = di;
sdi->inst_type = SR_INST_USB;
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)
serialcomm = SERIALCOMM;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Tondaj",
"SL-814", NULL))) {
sr_err("Failed to create device instance.");
return NULL;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Tondaj");
sdi->model = g_strdup("SL-814");
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");

View File

@ -260,11 +260,10 @@ static GSList *scan(GSList *options, int dmm)
devc->first_run = TRUE;
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE,
udmms[dmm].vendor, udmms[dmm].device, NULL))) {
sr_err("sr_dev_inst_new returned NULL.");
return NULL;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(udmms[dmm].vendor);
sdi->model = g_strdup(udmms[dmm].device);
sdi->priv = devc;
sdi->driver = udmms[dmm].di;
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
* string. Wrap them in sr_dev_inst and we're done. */
for (l = usb_devices; l; l = l->next) {
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR,
MODEL, NULL)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = g_strdup(MODEL);
sdi->driver = di;
sdi->inst_type = SR_INST_USB;
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));
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE,
VICTOR_VENDOR, NULL, NULL)))
return NULL;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VICTOR_VENDOR);
sdi->driver = di;
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)
goto fail;
if (!(sdi = sr_dev_inst_new(SR_ST_ACTIVE, MANUFACTURER_NAME,
model_name, hw_info->firmware_version)))
goto fail;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_ACTIVE;
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);

View File

@ -222,11 +222,10 @@ static GSList *scan(GSList *options)
sr_info("Found ZEROPLUS %s.", prof->model_name);
/* Register the device with libsigrok. */
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE,
VENDOR_NAME, prof->model_name, NULL))) {
sr_err("%s: sr_dev_inst_new failed", __func__);
return NULL;
}
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(prof->model_name);
sdi->driver = di;
sdi->serial_num = g_strdup(serial_num);
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;
}
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));
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;
}
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));
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;
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));
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 /= inc->downsample;
in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL);
in->sdi = sr_dev_inst_new();
in->priv = inc;
for (i = 0; i < num_channels; i++) {

View File

@ -150,7 +150,7 @@ static int init(struct sr_input *in, GHashTable *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));
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);
if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, vendor, model, NULL)))
goto scan_cleanup;
sdi = sr_dev_inst_new();
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");

View File

@ -521,8 +521,7 @@ struct sr_dev_inst {
};
/* Generic device instances */
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status,
const char *vendor, const char *model, const char *version);
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void);
SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
#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++) {
val = g_key_file_get_string(kf, sections[i], keys[j], NULL);
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->status = SR_ST_ACTIVE;
if (!session_driver_initialized) {
/* first device, init the driver */
session_driver_initialized = 1;