SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info;
-/* Properly close and free all devices. */
-static int clear_instances(void)
+static void clear_helper(void *priv)
{
- struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
- GSList *l;
-
- if (!(drvc = di->priv))
- return SR_OK;
-
- for (l = drvc->instances; l; l = l->next) {
- if (!(sdi = l->data))
- continue;
- if (sdi->conn)
- sr_serial_dev_inst_free(sdi->conn);
+ devc = priv;
- if ((devc = sdi->priv)) {
- g_free(devc->coupling[0]);
- g_free(devc->coupling[1]);
- g_free(devc->trigger_source);
- g_free(devc->trigger_slope);
- }
- sr_dev_inst_free(sdi);
- }
-
- g_slist_free(drvc->instances);
- drvc->instances = NULL;
+ g_free(devc->coupling[0]);
+ g_free(devc->coupling[1]);
+ g_free(devc->trigger_source);
+ g_free(devc->trigger_slope);
+}
- return SR_OK;
+static int dev_clear(void)
+{
+ return std_dev_clear(di, clear_helper);
}
static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
return SR_OK;
}
-static int hw_init(struct sr_context *sr_ctx)
+static int init(struct sr_context *sr_ctx)
{
- return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
+ return std_init(sr_ctx, di, LOG_PREFIX);
}
static int probe_port(const char *port, GSList **devices)
char buf[256];
gchar **tokens, *channel_name;
- *devices = NULL;
+ *devices = NULL;
if (!(serial = sr_serial_dev_inst_new(port, NULL)))
return SR_ERR_MALLOC;
return SR_ERR_NA;
}
- matched = has_digital = FALSE;
+ matched = has_digital = FALSE;
for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
if (!strcmp(model, supported_models[i])) {
matched = TRUE;
if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL)))
return SR_ERR_MALLOC;
sdi->driver = di;
+ sdi->inst_type = SR_INST_SERIAL;
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
return SR_ERR_MALLOC;
return SR_OK;
}
-static GSList *hw_scan(GSList *options)
+static GSList *scan(GSList *options)
{
struct drv_context *drvc;
struct sr_config *src;
}
}
- devices = NULL;
+ devices = NULL;
if (port) {
if (probe_port(port, &devices) == SR_ERR_MALLOC)
return NULL;
g_dir_close(dir);
}
- /* Tack a copy of the newly found devices onto the driver list. */
- l = g_slist_copy(devices);
- drvc->instances = g_slist_concat(drvc->instances, l);
+ /* Tack a copy of the newly found devices onto the driver list. */
+ l = g_slist_copy(devices);
+ drvc->instances = g_slist_concat(drvc->instances, l);
return devices;
}
-static GSList *hw_dev_list(void)
+static GSList *dev_list(void)
{
return ((struct drv_context *)(di->priv))->instances;
}
-static int hw_dev_open(struct sr_dev_inst *sdi)
+static int dev_open(struct sr_dev_inst *sdi)
{
if (serial_open(sdi->conn, SERIAL_RDWR) != SR_OK)
if (rigol_ds1xx2_get_dev_cfg(sdi) != SR_OK)
return SR_ERR;
- sdi->status = SR_ST_ACTIVE;
+ sdi->status = SR_ST_ACTIVE;
return SR_OK;
}
-static int hw_dev_close(struct sr_dev_inst *sdi)
+static int dev_close(struct sr_dev_inst *sdi)
{
struct sr_serial_dev_inst *serial;
return SR_OK;
}
-static int hw_cleanup(void)
+static int cleanup(void)
{
- clear_instances();
-
- return SR_OK;
+ return dev_clear();
}
static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
devc = sdi->priv;
- if (sdi->status != SR_ST_ACTIVE) {
- sr_err("Device inactive, can't set config options.");
- return SR_ERR;
- }
+ if (sdi->status != SR_ST_ACTIVE)
+ return SR_ERR_DEV_CLOSED;
ret = SR_OK;
switch (id) {
GSList *l;
char cmd[256];
- (void)cb_data;
+ if (sdi->status != SR_ST_ACTIVE)
+ return SR_ERR_DEV_CLOSED;
serial = sdi->conn;
devc = sdi->priv;
sr_source_add(serial->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi);
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+ std_session_send_df_header(cb_data, LOG_PREFIX);
/* Fetch the first frame. */
if (devc->enabled_analog_probes) {
.name = "rigol-ds1xx2",
.longname = "Rigol DS1xx2",
.api_version = 1,
- .init = hw_init,
- .cleanup = hw_cleanup,
- .scan = hw_scan,
- .dev_list = hw_dev_list,
- .dev_clear = clear_instances,
+ .init = init,
+ .cleanup = cleanup,
+ .scan = scan,
+ .dev_list = dev_list,
+ .dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
- .dev_open = hw_dev_open,
- .dev_close = hw_dev_close,
+ .dev_open = dev_open,
+ .dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
.priv = NULL,