]> sigrok.org Git - sigrok-util.git/blobdiff - source/drv-api.c
sr_hw_info() shouldn't log invalid requests.
[sigrok-util.git] / source / drv-api.c
index f9e990b8db3a80fad4e97cedd8437d417b5bacef..64f5ee18601abe1d922a00a4a6319b0d9beed092 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}>
  *
 #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. */
@@ -34,7 +33,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;
@@ -52,17 +53,18 @@ 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;
+               sr_err("Driver context malloc failed.");
+               return SR_ERR_MALLOC;
        }
 
        /* TODO */
 
+       drvc->sr_ctx = sr_ctx;
        di->priv = drvc;
 
        return SR_OK;
@@ -133,13 +135,16 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
 {
        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) {
        /* TODO */
        default:
+               sr_err("Unknown hardware capability: %d.", hwcap);
                ret = SR_ERR_ARG;
        }
 
@@ -154,13 +159,14 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        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 */