]> sigrok.org Git - sigrok-util.git/blobdiff - source/drv-api.c
new-driver: *.c: Only #include protocol.h.
[sigrok-util.git] / source / drv-api.c
index e9b046c271f3a75220a06b63bde72172dbea83d0..df3e3ece451b3bdbf2e221d639342bc22bc724de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) ${year} ${author} <${email}>
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <glib.h>
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-#include "config.h"
 #include "protocol.h"
 
-
-SR_PRIV struct sr_dev_driver driver_info;
+SR_PRIV struct sr_dev_driver ${lib}_driver_info;
 static struct sr_dev_driver *di = &${lib}_driver_info;
 
-
 /* Properly close and free all devices. */
 static int clear_instances(void)
 {
@@ -36,7 +30,9 @@ static int clear_instances(void)
        struct dev_context *devc;
        GSList *l;
 
-       drvc = di->priv;
+       if (!(drvc = di->priv))
+               return SR_OK;
+
        for (l = drvc->instances; l; l = l->next) {
                if (!(sdi = l->data))
                        continue;
@@ -54,20 +50,9 @@ static int clear_instances(void)
        return SR_OK;
 }
 
-static int hw_init(void)
+static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("${short}: driver context malloc failed.");
-               return SR_ERR;
-       }
-
-       /* TODO */
-
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -76,6 +61,7 @@ static GSList *hw_scan(GSList *options)
        GSList *devices;
 
        (void)options;
+
        devices = NULL;
        drvc = di->priv;
        drvc->instances = NULL;
@@ -96,6 +82,7 @@ static GSList *hw_dev_list(void)
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
+       (void)sdi;
 
        /* TODO */
 
@@ -104,6 +91,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 
 static int hw_dev_close(struct sr_dev_inst *sdi)
 {
+       (void)sdi;
 
        /* TODO */
 
@@ -112,7 +100,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
 static int hw_cleanup(void)
 {
-
        clear_instances();
 
        /* TODO */
@@ -120,12 +107,13 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static int hw_info_get(int info_id, const void **data,
-       const struct sr_dev_inst *sdi)
+static int hw_config_get(int id, const void **value,
+                        const struct sr_dev_inst *sdi)
 {
+       (void)sdi;
+       (void)value;
 
-
-       switch (info_id) {
+       switch (id) {
        /* TODO */
        default:
                return SR_ERR_ARG;
@@ -134,41 +122,62 @@ static int hw_info_get(int info_id, const void **data,
        return SR_OK;
 }
 
-static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
-               const void *value)
+static int hw_config_set(int id, const void *value,
+                        const struct sr_dev_inst *sdi)
 {
+       (void)value;
+
        int ret;
 
-       if (sdi->status != SR_ST_ACTIVE)
+       if (sdi->status != SR_ST_ACTIVE) {
+               sr_err("Device inactive, can't set config options.");
                return SR_ERR;
+       }
 
        ret = SR_OK;
-       switch (hwcap) {
+       switch (id) {
        /* TODO */
        default:
+               sr_err("Unknown hardware capability: %d.", id);
                ret = SR_ERR_ARG;
        }
 
        return ret;
 }
 
+static int hw_config_list(int key, const void **data,
+                         const struct sr_dev_inst *sdi)
+{
+       (void)sdi;
+       (void)data;
+
+       switch (key) {
+       default:
+               return SR_ERR_ARG;
+       }
+
+       return SR_OK;
+}
+
 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
-               void *cb_data)
+                                   void *cb_data)
 {
+       (void)sdi;
+       (void)cb_data;
 
        /* TODO */
 
        return SR_OK;
 }
 
-static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
-               void *cb_data)
+static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-
        (void)cb_data;
 
-       if (sdi->status != SR_ST_ACTIVE)
+       if (sdi->status != SR_ST_ACTIVE) {
+               sr_err("Device inactive, can't stop acquisition.");
                return SR_ERR;
+       }
 
        /* TODO */
 
@@ -184,10 +193,11 @@ SR_PRIV struct sr_dev_driver ${lib}_driver_info = {
        .scan = hw_scan,
        .dev_list = hw_dev_list,
        .dev_clear = clear_instances,
+       .config_get = hw_config_get,
+       .config_set = hw_config_set,
+       .config_list = hw_config_list,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
-       .info_get = hw_info_get,
-       .dev_config_set = hw_dev_config_set,
        .dev_acquisition_start = hw_dev_acquisition_start,
        .dev_acquisition_stop = hw_dev_acquisition_stop,
        .priv = NULL,