std: Add and use std_dev_clear() where possible.

Be explicit and consistent in the drivers about which dev_clear function
will be called to avoid confusion and inconsistencies.

Drop some open-coded implementations of std_dev_clear().
This commit is contained in:
Uwe Hermann 2017-07-11 22:14:01 +02:00
parent 6e43c3d531
commit f778bf02ea
43 changed files with 52 additions and 49 deletions

View File

@ -309,7 +309,10 @@ static int sanity_check_all_drivers(const struct sr_context *ctx)
sr_err("No dev_list in driver %d ('%s').", i, d);
errors++;
}
/* Note: dev_clear() is optional. */
if (!drivers[i]->dev_clear) {
sr_err("No dev_clear in driver %d ('%s').", i, d);
errors++;
}
/* Note: config_get() is optional. */
if (!drivers[i]->config_set) {
sr_err("No config_set in driver %d ('%s').", i, d);

View File

@ -529,8 +529,6 @@ SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver)
*/
SR_API int sr_dev_clear(const struct sr_dev_driver *driver)
{
int ret;
if (!driver) {
sr_err("Invalid driver.");
return SR_ERR_ARG;
@ -548,12 +546,7 @@ SR_API int sr_dev_clear(const struct sr_dev_driver *driver)
/* No log message here, too verbose and not very useful. */
if (driver->dev_clear)
ret = driver->dev_clear(driver);
else
ret = std_dev_clear_with_callback(driver, NULL);
return ret;
return driver->dev_clear(driver);
}
/**

View File

@ -348,7 +348,7 @@ static struct sr_dev_driver agdmm_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -218,7 +218,7 @@ static struct sr_dev_driver appa_55ii_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -337,6 +337,7 @@ static struct sr_dev_driver arachnid_labs_re_load_pro_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -475,7 +475,7 @@ static struct sr_dev_driver atten_pps3203_driver_info = {
.cleanup = std_cleanup,
.scan = scan_3203,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -358,6 +358,7 @@ static struct sr_dev_driver baylibre_acme_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -343,6 +343,7 @@ static struct sr_dev_driver beaglelogic_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -221,7 +221,7 @@ static struct sr_dev_driver brymen_bm86x_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -178,7 +178,7 @@ static struct sr_dev_driver brymen_bm857_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -366,7 +366,7 @@ static struct sr_dev_driver cem_dt_885x_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -196,6 +196,7 @@ static struct sr_dev_driver ID##_driver_info = { \
.cleanup = std_cleanup, \
.scan = scan_##ID_UPPER, \
.dev_list = std_dev_list, \
.dev_clear = std_dev_clear, \
.config_get = NULL, \
.config_set = config_set, \
.config_list = config_list, \

View File

@ -139,7 +139,7 @@ static struct sr_dev_driver colead_slm_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -166,7 +166,7 @@ static struct sr_dev_driver conrad_digi_35_cpu_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -246,7 +246,7 @@ static struct sr_dev_driver flukedmm_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -463,7 +463,7 @@ static struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = {
.cleanup = std_cleanup,
.scan = scan_1x_2x_rs232,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list_sm,
@ -483,7 +483,7 @@ static struct sr_dev_driver gmc_mh_2x_bd232_driver_info = {
.cleanup = std_cleanup,
.scan = scan_2x_bd232,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list_bd,

View File

@ -229,6 +229,7 @@ static struct sr_dev_driver gwinstek_gds_800_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -432,6 +432,7 @@ static struct sr_dev_driver hp_3457a_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -494,7 +494,7 @@ static struct sr_dev_driver kecheng_kc_330b_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -178,6 +178,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
.cleanup = std_cleanup, \
.scan = scan, \
.dev_list = std_dev_list, \
.dev_clear = std_dev_clear, \
.config_get = NULL, \
.config_set = config_set, \
.config_list = config_list, \

View File

@ -364,6 +364,7 @@ static struct sr_dev_driver korad_kaxxxxp_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -402,7 +402,7 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -488,6 +488,7 @@ static struct sr_dev_driver lecroy_logicstudio_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -399,6 +399,7 @@ static struct sr_dev_driver link_mso19_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -374,6 +374,7 @@ static struct sr_dev_driver manson_hcs_3xxx_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -458,6 +458,7 @@ static struct sr_dev_driver maynuo_m97_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -213,6 +213,7 @@ static struct sr_dev_driver ID##_driver_info = { \
.cleanup = std_cleanup, \
.scan = scan_##ID_UPPER, \
.dev_list = std_dev_list, \
.dev_clear = std_dev_clear, \
.config_get = NULL, \
.config_set = config_set, \
.config_list = config_list_##ID_UPPER, \

View File

@ -221,7 +221,7 @@ static struct sr_dev_driver norma_dmm_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,
@ -241,7 +241,7 @@ static struct sr_dev_driver siemens_b102x_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -564,7 +564,7 @@ static struct sr_dev_driver ols_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -103,11 +103,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
return std_scan_complete(di, g_slist_append(NULL, sdi));
}
static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear_with_callback(di, NULL);
}
static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
@ -347,7 +342,7 @@ static struct sr_dev_driver pce_322a_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = dev_clear,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -155,11 +155,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
return sr_scpi_scan(di->context, options, rs_probe_serial_device);
}
static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear_with_callback(di, NULL);
}
static int dev_open(struct sr_dev_inst *sdi)
{
return sr_scpi_open(sdi->conn);
@ -256,7 +251,7 @@ SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = dev_clear,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -180,11 +180,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
return std_scan_complete(di, devices);
}
static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear_with_callback(di, NULL);
}
static int dev_open(struct sr_dev_inst *sdi)
{
struct sr_dev_driver *di = sdi->driver;
@ -407,7 +402,7 @@ SR_PRIV struct sr_dev_driver saleae_logic_pro_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = dev_clear,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -786,7 +786,7 @@ static struct sr_dev_driver saleae_logic16_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -200,6 +200,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
.cleanup = std_cleanup, \
.scan = scan, \
.dev_list = std_dev_list, \
.dev_clear = std_dev_clear, \
.config_get = NULL, \
.config_set = config_set, \
.config_list = config_list, \

View File

@ -181,7 +181,7 @@ static struct sr_dev_driver teleinfo_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -415,6 +415,7 @@ static struct sr_dev_driver testo_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -150,7 +150,7 @@ static struct sr_dev_driver tondaj_sl_814_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = NULL,
.config_set = config_set,
.config_list = config_list,

View File

@ -175,6 +175,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
.cleanup = std_cleanup, \
.scan = scan, \
.dev_list = std_dev_list, \
.dev_clear = std_dev_clear, \
.config_get = NULL, \
.config_set = config_set, \
.config_list = config_list, \

View File

@ -302,7 +302,7 @@ static struct sr_dev_driver uni_t_ut32x_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -326,7 +326,7 @@ static struct sr_dev_driver victor_dmm_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -658,7 +658,7 @@ static struct sr_dev_driver zeroplus_logic_cube_driver_info = {
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
.dev_clear = NULL,
.dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,

View File

@ -942,6 +942,7 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
std_dev_clear_callback clear_private);
SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver);
SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);

View File

@ -404,6 +404,11 @@ SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
return ret;
}
SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver)
{
return std_dev_clear_with_callback(driver, NULL);
}
/**
* Standard driver dev_list() callback API helper.
*