]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/api.c
std: Drop hw_ from function names.
[libsigrok.git] / hardware / openbench-logic-sniffer / api.c
index 60a6fe6a3d6e310bd623b60d833a8ee77e6aa7dc..04a06b2e1c0878f213796b72ccaa4f01e5deda46 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
  *
@@ -53,12 +53,12 @@ static const uint64_t samplerates[] = {
 SR_PRIV struct sr_dev_driver ols_driver_info;
 static struct sr_dev_driver *di = &ols_driver_info;
 
-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 GSList *hw_scan(GSList *options)
+static GSList *scan(GSList *options)
 {
        struct sr_config *src;
        struct sr_dev_inst *sdi;
@@ -72,8 +72,6 @@ static GSList *hw_scan(GSList *options)
        const char *conn, *serialcomm;
        char buf[8];
 
-       (void)options;
-
        drvc = di->priv;
 
        devices = NULL;
@@ -178,12 +176,12 @@ static GSList *hw_scan(GSList *options)
        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)
 {
        struct sr_serial_dev_inst *serial;
 
@@ -196,7 +194,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
        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;
 
@@ -209,41 +207,9 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_cleanup(void)
+static int dev_clear(void)
 {
-       GSList *l;
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
-       struct dev_context *devc;
-       struct sr_serial_dev_inst *serial;
-       int ret = SR_OK;
-
-       if (!(drvc = di->priv))
-               return SR_OK;
-
-       /* Properly close and free all devices. */
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("%s: sdi was NULL, continuing", __func__);
-                       ret = SR_ERR_BUG;
-                       continue;
-               }
-               if (!(devc = sdi->priv)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("%s: sdi->priv was NULL, continuing", __func__);
-                       ret = SR_ERR_BUG;
-                       continue;
-               }
-               hw_dev_close(sdi);
-               serial = sdi->conn;
-               sr_serial_dev_inst_free(serial);
-               sr_dev_inst_free(sdi);
-       }
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
-
-       return ret;
+       return std_dev_clear(di, NULL);
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
@@ -280,6 +246,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        int ret;
        uint64_t tmp_u64;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
 
        switch (id) {
@@ -354,7 +323,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
+static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                void *cb_data)
 {
        struct dev_context *devc;
@@ -366,12 +335,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int num_channels;
        int i;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
        serial = sdi->conn;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR;
-
        if (ols_configure_probes(sdi) != SR_OK) {
                sr_err("Failed to configure probes.");
                return SR_ERR;
@@ -484,16 +453,15 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        devc->num_transfers = devc->num_samples = devc->num_bytes = 0;
 
        /* 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);
 
        sr_source_add(serial->fd, G_IO_IN, -1, ols_receive_data, cb_data);
 
        return SR_OK;
 }
 
-static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       /* Avoid compiler warnings. */
        (void)cb_data;
 
        abort_acquisition(sdi);
@@ -505,17 +473,17 @@ SR_PRIV struct sr_dev_driver ols_driver_info = {
        .name = "ols",
        .longname = "Openbench Logic Sniffer",
        .api_version = 1,
-       .init = hw_init,
-       .cleanup = hw_cleanup,
-       .scan = hw_scan,
-       .dev_list = hw_dev_list,
-       .dev_clear = hw_cleanup,
+       .init = init,
+       .cleanup = dev_clear,
+       .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_acquisition_start = hw_dev_acquisition_start,
-       .dev_acquisition_stop = hw_dev_acquisition_stop,
+       .dev_open = dev_open,
+       .dev_close = dev_close,
+       .dev_acquisition_start = dev_acquisition_start,
+       .dev_acquisition_stop = dev_acquisition_stop,
        .priv = NULL,
 };