Eliminate sr_dev_inst_new().

This commit is contained in:
Uwe Hermann 2014-11-21 02:01:36 +01:00
parent a9b2283fd0
commit aac29cc192
52 changed files with 65 additions and 84 deletions

View File

@ -201,44 +201,23 @@ SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key)
return ret;
}
/** @private
* Allocate and init a new device instance struct.
*
* @retval struct sr_dev_inst *. Dynamically allocated, free using
* sr_dev_inst_free().
*/
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(void)
{
struct sr_dev_inst *sdi;
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->driver = NULL;
sdi->status = -1;
sdi->inst_type = -1;
sdi->vendor = NULL;
sdi->model = NULL;
sdi->version = NULL;
sdi->serial_num = NULL;
sdi->connection_id = NULL;
sdi->channels = NULL;
sdi->channel_groups = NULL;
sdi->session = NULL;
sdi->conn = NULL;
sdi->priv = NULL;
return sdi;
}
/**
* Allocate and init a new user-generated device instance.
*
* @param vendor Device vendor
* @param model Device model
* @param version Device version
*
* @retval struct sr_dev_inst *. Dynamically allocated, free using
* sr_dev_inst_free().
*/
SR_API struct sr_dev_inst *sr_dev_inst_user_new(const char *vendor,
const char *model, const char *version)
{
struct sr_dev_inst *sdi;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);
sdi->version = g_strdup(version);

View File

@ -139,7 +139,7 @@ static GSList *scan(GSList *options)
for (i = 0; supported_agdmm[i].model; i++) {
if (strcmp(supported_agdmm[i].modelname, tokens[1]))
continue;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Agilent");
sdi->model = g_strdup(tokens[1]);

View File

@ -99,7 +99,7 @@ static GSList *scan(GSList *options)
sr_info("Found device on port %s.", conn);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("APPA");
sdi->model = g_strdup("55II");

View File

@ -380,7 +380,7 @@ static GSList *scan(GSList *options)
devc->use_triggers = 0;
/* Register SIGMA device. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);

View File

@ -164,7 +164,7 @@ static GSList *scan(GSList *options, int modelid)
return NULL;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Atten");
sdi->model = g_strdup(model->name);

View File

@ -97,7 +97,7 @@ static GSList *scan(GSList *options)
if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
return NULL;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->model = g_strdup("BeagleLogic");
sdi->version = g_strdup("1.0");

View File

@ -73,7 +73,7 @@ static GSList *scan(GSList *options)
for (l = usb_devices; l; l = l->next) {
usb = l->data;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Brymen");
sdi->model = g_strdup("BM869");

View File

@ -75,7 +75,7 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm)
sr_info("Found device on port %s.", conn);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Brymen");
sdi->model = g_strdup("BM85x");

View File

@ -109,7 +109,7 @@ 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. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("CEM");
sdi->model = g_strdup("DT-885x");

View File

@ -88,7 +88,7 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
sr_info("Found device on port %s.", conn);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(center_devs[idx].vendor);
sdi->model = g_strdup(center_devs[idx].device);

View File

@ -120,7 +120,7 @@ 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();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup("ChronoVu");
sdi->model = g_strdup(devc->prof->modelname);

View File

@ -82,7 +82,7 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Colead");
sdi->model = g_strdup("SL-5868P");

View File

@ -94,7 +94,7 @@ static GSList *scan(GSList *options)
sr_spew("Conrad DIGI 35 CPU assumed at %s.", conn);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup("Conrad");
sdi->model = g_strdup("DIGI 35 CPU");

View File

@ -290,7 +290,7 @@ static GSList *scan(GSList *options)
devices = NULL;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_ACTIVE;
sdi->model = g_strdup("Demo device");
sdi->driver = di;

View File

@ -122,7 +122,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
continue;
/* Skip leading spaces in version number. */
for (s = 0; tokens[1][s] == ' '; s++);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Fluke");
sdi->model = g_strdup(tokens[0] + 6);

View File

@ -241,7 +241,7 @@ static GSList *scan(GSList *options)
if (!prof)
continue;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(prof->vendor);
sdi->model = g_strdup(prof->model);

View File

@ -223,7 +223,7 @@ static GSList *scan_1x_2x_rs232(GSList *options)
if (model != METRAHIT_NONE) {
sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model));
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
sdi->model = g_strdup(gmc_model_str(model));
@ -304,7 +304,7 @@ static GSList *scan_2x_bd232(GSList *options)
goto exit_err;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
sdi->priv = devc;
@ -355,7 +355,7 @@ static GSList *scan_2x_bd232(GSList *options)
goto exit_err;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_GMC);
}

View File

@ -79,7 +79,7 @@ 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;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(hw_info->manufacturer);
sdi->model = g_strdup(hw_info->model);

View File

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

View File

@ -112,7 +112,7 @@ static GSList *scan(GSList *options)
continue;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(MODEL_NAME);

View File

@ -123,7 +123,7 @@ static GSList *scan(GSList *options)
}
/* Register the device with libsigrok. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup(USB_VENDOR_NAME);
sdi->model = g_strdup(USB_MODEL_NAME);

View File

@ -129,7 +129,7 @@ static GSList *scan(GSList *options)
for (l = usb_devices; l; l = l->next) {
if (scan_kecheng(l->data, &model) != SR_OK)
continue;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = model; /* Already g_strndup()'d. */

View File

@ -323,7 +323,7 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
return NULL;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(LASCAR_VENDOR);
sdi->model = g_strdup(profile->modelname);

View File

@ -203,8 +203,11 @@ static GSList *scan(GSList *options)
return devices;
}
struct sr_dev_inst *sdi = sr_dev_inst_new(SR_ST_INACTIVE,
manufacturer, product, hwrev);
struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(manufacturer);
sdi->model = g_strdup(product);
sdi->version = g_strdup(hwrev);
if (!sdi) {
sr_err("Unable to create device instance for %s",

View File

@ -155,7 +155,7 @@ static GSList *scan(GSList *options)
}
/* Init device instance, etc. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Manson");
sdi->model = g_strdup(models[model_id].name);

View File

@ -91,7 +91,7 @@ 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. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(mic_devs[idx].vendor);
sdi->model = g_strdup(mic_devs[idx].device);

View File

@ -450,7 +450,7 @@ 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();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_MOTECH);
sdi->model = g_strdup(models[modelid].modelstr);

View File

@ -144,7 +144,7 @@ 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);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(get_brandstr(drv));
sdi->model = g_strdup(get_typestr(auxtype, drv));

View File

@ -180,7 +180,7 @@ 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();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Sump");
sdi->model = g_strdup("Logic Analyzer");

View File

@ -152,7 +152,7 @@ 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();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->driver = di;
devc = ols_dev_new();

View File

@ -226,7 +226,7 @@ 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();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->driver = di;
sdi->priv = devc;

View File

@ -296,7 +296,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
return NULL;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(model->series->vendor->name);
sdi->model = g_strdup(model->name);

View File

@ -198,7 +198,7 @@ static GSList *scan(GSList *options)
if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
continue;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INITIALIZING;
sdi->vendor = g_strdup("Saleae");
sdi->model = g_strdup("Logic16");

View File

@ -89,7 +89,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
return NULL;
}
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(hw_info->model);

View File

@ -456,7 +456,7 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm)
sr_info("Found device on port %s.", conn);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(dmms[dmm].vendor);
sdi->model = g_strdup(dmms[dmm].device);

View File

@ -112,7 +112,7 @@ static struct sr_dev_inst *dev_inst_new(void)
}
/* Register the device with libsigrok. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(MODEL_NAME);

View File

@ -92,7 +92,7 @@ static GSList *scan(GSList *options)
sr_info("Found device on port %s.", conn);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("EDF");
sdi->model = g_strdup("Teleinfo");

View File

@ -124,7 +124,7 @@ static GSList *scan(GSList *options)
if (strcmp(product, "testo 435/635/735"))
continue;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Testo");
sdi->model = g_strdup("435/635/735");

View File

@ -84,7 +84,7 @@ static GSList *scan(GSList *options)
if (!serialcomm)
serialcomm = SERIALCOMM;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Tondaj");
sdi->model = g_strdup("SL-814");

View File

@ -260,7 +260,7 @@ static GSList *scan(GSList *options, int dmm)
devc->first_run = TRUE;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(udmms[dmm].vendor);
sdi->model = g_strdup(udmms[dmm].device);

View File

@ -79,7 +79,7 @@ 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) {
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR);
sdi->model = g_strdup(MODEL);

View File

@ -84,7 +84,7 @@ static GSList *scan(GSList *options)
usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VICTOR_VENDOR);
sdi->driver = di;

View File

@ -67,7 +67,7 @@ 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;
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_ACTIVE;
sdi->vendor = g_strdup(MANUFACTURER_NAME);
sdi->model = g_strdup(model_name);

View File

@ -222,7 +222,7 @@ static GSList *scan(GSList *options)
sr_info("Found ZEROPLUS %s.", prof->model_name);
/* Register the device with libsigrok. */
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(VENDOR_NAME);
sdi->model = g_strdup(prof->model_name);

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();
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
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();
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
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();
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
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();
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
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();
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
in->priv = g_malloc0(sizeof(struct context));
return SR_OK;

View File

@ -843,7 +843,7 @@ SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
sr_info("Found device on port %s.", serial->port);
sdi = sr_dev_inst_new();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup(vendor);
sdi->model = g_strdup(model);

View File

@ -521,7 +521,6 @@ struct sr_dev_inst {
};
/* Generic device instances */
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,7 +170,7 @@ 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();
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->driver = &session_driver;
sdi->status = SR_ST_ACTIVE;
if (!session_driver_initialized) {