Various subsystems: Use message logging helpers.

This commit is contained in:
Uwe Hermann 2012-11-11 12:44:16 +01:00
parent a944a84b17
commit a885ce3ee9
6 changed files with 111 additions and 67 deletions

View File

@ -24,6 +24,15 @@
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
/* Message logging helpers with driver-specific prefix string. */
#define DRIVER_LOG_DOMAIN "datastore: "
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
/** /**
* @file * @file
* *
@ -65,18 +74,18 @@ static gpointer new_chunk(struct sr_datastore **ds);
SR_API int sr_datastore_new(int unitsize, struct sr_datastore **ds) SR_API int sr_datastore_new(int unitsize, struct sr_datastore **ds)
{ {
if (!ds) { if (!ds) {
sr_err("ds: %s: ds was NULL", __func__); sr_err("%s: ds was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (unitsize <= 0) { if (unitsize <= 0) {
sr_err("ds: %s: unitsize was %d, but it must be >= 1", sr_err("%s: unitsize was %d, but it must be >= 1",
__func__, unitsize); __func__, unitsize);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!(*ds = g_try_malloc(sizeof(struct sr_datastore)))) { if (!(*ds = g_try_malloc(sizeof(struct sr_datastore)))) {
sr_err("ds: %s: ds malloc failed", __func__); sr_err("%s: ds malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
@ -102,7 +111,7 @@ SR_API int sr_datastore_destroy(struct sr_datastore *ds)
GSList *chunk; GSList *chunk;
if (!ds) { if (!ds) {
sr_err("ds: %s: ds was NULL", __func__); sr_err("%s: ds was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
@ -149,36 +158,36 @@ SR_API int sr_datastore_put(struct sr_datastore *ds, void *data,
gpointer chunk; gpointer chunk;
if (!ds) { if (!ds) {
sr_err("ds: %s: ds was NULL", __func__); sr_err("%s: ds was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
/* Unitsize must not be 0, we'll divide by 0 otherwise. */ /* Unitsize must not be 0, we'll divide by 0 otherwise. */
if (ds->ds_unitsize == 0) { if (ds->ds_unitsize == 0) {
sr_err("ds: %s: ds->ds_unitsize was 0", __func__); sr_err("%s: ds->ds_unitsize was 0", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!data) { if (!data) {
sr_err("ds: %s: data was NULL", __func__); sr_err("%s: data was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (in_unitsize < 1) { if (in_unitsize < 1) {
sr_err("ds: %s: in_unitsize was %d, but it must be >= 1", sr_err("%s: in_unitsize was %d, but it must be >= 1",
__func__, in_unitsize); __func__, in_unitsize);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!probelist) { if (!probelist) {
sr_err("ds: %s: probelist was NULL", __func__); sr_err("%s: probelist was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
/* Get the last chunk in the list, or create a new one if needed. */ /* Get the last chunk in the list, or create a new one if needed. */
if (ds->chunklist == NULL) { if (ds->chunklist == NULL) {
if (!(chunk = new_chunk(&ds))) { if (!(chunk = new_chunk(&ds))) {
sr_err("ds: %s: couldn't allocate new chunk", __func__); sr_err("%s: couldn't allocate new chunk", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
} else { } else {
@ -197,7 +206,7 @@ SR_API int sr_datastore_put(struct sr_datastore *ds, void *data,
/* No more free space left, allocate a new chunk. */ /* No more free space left, allocate a new chunk. */
if (chunk_bytes_free == 0) { if (chunk_bytes_free == 0) {
if (!(chunk = new_chunk(&ds))) { if (!(chunk = new_chunk(&ds))) {
sr_err("ds: %s: couldn't allocate new chunk", sr_err("%s: couldn't allocate new chunk",
__func__); __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
@ -246,7 +255,7 @@ static gpointer new_chunk(struct sr_datastore **ds)
chunk = g_try_malloc0(DATASTORE_CHUNKSIZE * (*ds)->ds_unitsize); chunk = g_try_malloc0(DATASTORE_CHUNKSIZE * (*ds)->ds_unitsize);
if (!chunk) { if (!chunk) {
sr_err("ds: %s: chunk malloc failed (ds_unitsize was %u)", sr_err("%s: chunk malloc failed (ds_unitsize was %u)",
__func__, (*ds)->ds_unitsize); __func__, (*ds)->ds_unitsize);
return NULL; /* TODO: SR_ERR_MALLOC later? */ return NULL; /* TODO: SR_ERR_MALLOC later? */
} }

View File

@ -23,6 +23,15 @@
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
/* Message logging helpers with driver-specific prefix string. */
#define DRIVER_LOG_DOMAIN "device: "
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
/** /**
* @file * @file
* *
@ -44,7 +53,7 @@ SR_PRIV struct sr_probe *sr_probe_new(int index, int type,
struct sr_probe *probe; struct sr_probe *probe;
if (!(probe = g_try_malloc0(sizeof(struct sr_probe)))) { if (!(probe = g_try_malloc0(sizeof(struct sr_probe)))) {
sr_err("hwdriver: probe malloc failed"); sr_err("Probe malloc failed.");
return NULL; return NULL;
} }
@ -208,7 +217,7 @@ SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int index, int status,
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
if (!(sdi = g_try_malloc(sizeof(struct sr_dev_inst)))) { if (!(sdi = g_try_malloc(sizeof(struct sr_dev_inst)))) {
sr_err("hwdriver: %s: sdi malloc failed", __func__); sr_err("%s: sdi malloc failed", __func__);
return NULL; return NULL;
} }
@ -254,7 +263,7 @@ SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
struct sr_usb_dev_inst *udi; struct sr_usb_dev_inst *udi;
if (!(udi = g_try_malloc(sizeof(struct sr_usb_dev_inst)))) { if (!(udi = g_try_malloc(sizeof(struct sr_usb_dev_inst)))) {
sr_err("hwdriver: %s: udi malloc failed", __func__); sr_err("%s: udi malloc failed", __func__);
return NULL; return NULL;
} }
@ -282,7 +291,7 @@ SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
struct sr_serial_dev_inst *serial; struct sr_serial_dev_inst *serial;
if (!(serial = g_try_malloc(sizeof(struct sr_serial_dev_inst)))) { if (!(serial = g_try_malloc(sizeof(struct sr_serial_dev_inst)))) {
sr_err("hwdriver: %s: serial malloc failed", __func__); sr_err("%s: serial malloc failed", __func__);
return NULL; return NULL;
} }
@ -304,7 +313,7 @@ SR_API int sr_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
int ret; int ret;
if (!sdi || !sdi->driver || !sdi->driver->dev_config_set) { if (!sdi || !sdi->driver || !sdi->driver->dev_config_set) {
sr_err("hwdriver: unable to set config option"); sr_err("Unable to set config option.");
return SR_ERR; return SR_ERR;
} }

View File

@ -23,6 +23,15 @@
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
/* Message logging helpers with driver-specific prefix string. */
#define DRIVER_LOG_DOMAIN "filter: "
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
/** /**
* @file * @file
* *
@ -96,22 +105,22 @@ SR_API int sr_filter_probes(int in_unitsize, int out_unitsize,
uint64_t sample_in, sample_out; uint64_t sample_in, sample_out;
if (!probelist) { if (!probelist) {
sr_err("filter: %s: probelist was NULL", __func__); sr_err("%s: probelist was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!data_in) { if (!data_in) {
sr_err("filter: %s: data_in was NULL", __func__); sr_err("%s: data_in was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!data_out) { if (!data_out) {
sr_err("filter: %s: data_out was NULL", __func__); sr_err("%s: data_out was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!length_out) { if (!length_out) {
sr_err("filter: %s: length_out was NULL", __func__); sr_err("%s: length_out was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
@ -121,13 +130,13 @@ SR_API int sr_filter_probes(int in_unitsize, int out_unitsize,
/* Are there more probes than the target unit size supports? */ /* Are there more probes than the target unit size supports? */
if (num_enabled_probes > out_unitsize * 8) { if (num_enabled_probes > out_unitsize * 8) {
sr_err("filter: %s: too many probes (%d) for the target unit " sr_err("%s: too many probes (%d) for the target unit "
"size (%d)", __func__, num_enabled_probes, out_unitsize); "size (%d)", __func__, num_enabled_probes, out_unitsize);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!(*data_out = g_try_malloc(length_in))) { if (!(*data_out = g_try_malloc(length_in))) {
sr_err("filter: %s: data_out malloc failed", __func__); sr_err("%s: data_out malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }

View File

@ -26,6 +26,15 @@
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
/* Message logging helpers with driver-specific prefix string. */
#define DRIVER_LOG_DOMAIN "virtual-session: "
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
/* size of payloads sent across the session bus */ /* size of payloads sent across the session bus */
/** @cond PRIVATE */ /** @cond PRIVATE */
#define CHUNKSIZE (512 * 1024) #define CHUNKSIZE (512 * 1024)
@ -62,7 +71,7 @@ static int receive_data(int fd, int revents, void *cb_data)
(void)fd; (void)fd;
(void)revents; (void)revents;
sr_dbg("session_driver: feed chunk"); sr_dbg("Feed chunk.");
got_data = FALSE; got_data = FALSE;
for (l = dev_insts; l; l = l->next) { for (l = dev_insts; l; l = l->next) {
@ -73,7 +82,7 @@ static int receive_data(int fd, int revents, void *cb_data)
continue; continue;
if (!(buf = g_try_malloc(CHUNKSIZE))) { if (!(buf = g_try_malloc(CHUNKSIZE))) {
sr_err("session driver: %s: buf malloc failed", __func__); sr_err("%s: buf malloc failed", __func__);
return FALSE; return FALSE;
} }
@ -110,7 +119,6 @@ static int hw_cleanup(void);
static int hw_init(void) static int hw_init(void)
{ {
return SR_OK; return SR_OK;
} }
@ -128,9 +136,8 @@ static int hw_cleanup(void)
static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_open(struct sr_dev_inst *sdi)
{ {
if (!(sdi->priv = g_try_malloc0(sizeof(struct session_vdev)))) { if (!(sdi->priv = g_try_malloc0(sizeof(struct session_vdev)))) {
sr_err("session driver: %s: sdi->priv malloc failed", __func__); sr_err("%s: sdi->priv malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
@ -174,18 +181,15 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
case SR_HWCAP_SAMPLERATE: case SR_HWCAP_SAMPLERATE:
tmp_u64 = value; tmp_u64 = value;
vdev->samplerate = *tmp_u64; vdev->samplerate = *tmp_u64;
sr_info("session driver: setting samplerate to %" PRIu64, sr_info("Setting samplerate to %" PRIu64 ".", vdev->samplerate);
vdev->samplerate);
break; break;
case SR_HWCAP_SESSIONFILE: case SR_HWCAP_SESSIONFILE:
vdev->sessionfile = g_strdup(value); vdev->sessionfile = g_strdup(value);
sr_info("session driver: setting sessionfile to %s", sr_info("Setting sessionfile to '%s'.", vdev->sessionfile);
vdev->sessionfile);
break; break;
case SR_HWCAP_CAPTUREFILE: case SR_HWCAP_CAPTUREFILE:
vdev->capturefile = g_strdup(value); vdev->capturefile = g_strdup(value);
sr_info("session driver: setting capturefile to %s", sr_info("Setting capturefile to '%s'.", vdev->capturefile);
vdev->capturefile);
break; break;
case SR_HWCAP_CAPTURE_UNITSIZE: case SR_HWCAP_CAPTURE_UNITSIZE:
tmp_u64 = value; tmp_u64 = value;
@ -196,8 +200,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
vdev->num_probes = *tmp_u64; vdev->num_probes = *tmp_u64;
break; break;
default: default:
sr_err("session driver: %s: unknown capability %d requested", sr_err("Unknown capability: %d.", hwcap);
__func__, hwcap);
return SR_ERR; return SR_ERR;
} }
@ -216,23 +219,23 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
vdev = sdi->priv; vdev = sdi->priv;
sr_info("session_driver: opening archive %s file %s", vdev->sessionfile, sr_info("Opening archive %s file %s", vdev->sessionfile,
vdev->capturefile); vdev->capturefile);
if (!(vdev->archive = zip_open(vdev->sessionfile, 0, &ret))) { if (!(vdev->archive = zip_open(vdev->sessionfile, 0, &ret))) {
sr_err("session driver: Failed to open session file '%s': " sr_err("Failed to open session file '%s': "
"zip error %d\n", vdev->sessionfile, ret); "zip error %d\n", vdev->sessionfile, ret);
return SR_ERR; return SR_ERR;
} }
if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) == -1) { if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) == -1) {
sr_err("session driver: Failed to check capture file '%s' in " sr_err("Failed to check capture file '%s' in "
"session file '%s'.", vdev->capturefile, vdev->sessionfile); "session file '%s'.", vdev->capturefile, vdev->sessionfile);
return SR_ERR; return SR_ERR;
} }
if (!(vdev->capfile = zip_fopen(vdev->archive, vdev->capturefile, 0))) { if (!(vdev->capfile = zip_fopen(vdev->archive, vdev->capturefile, 0))) {
sr_err("session driver: Failed to open capture file '%s' in " sr_err("Failed to open capture file '%s' in "
"session file '%s'.", vdev->capturefile, vdev->sessionfile); "session file '%s'.", vdev->capturefile, vdev->sessionfile);
return SR_ERR; return SR_ERR;
} }
@ -241,12 +244,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
sr_session_source_add(-1, 0, 0, receive_data, cb_data); sr_session_source_add(-1, 0, 0, receive_data, cb_data);
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
sr_err("session driver: %s: packet malloc failed", __func__); sr_err("%s: packet malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) { if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
sr_err("session driver: %s: header malloc failed", __func__); sr_err("%s: header malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
@ -272,7 +275,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
/** @private */ /** @private */
SR_PRIV struct sr_dev_driver session_driver = { SR_PRIV struct sr_dev_driver session_driver = {
.name = "session", .name = "virtual-session",
.longname = "Session-emulating driver", .longname = "Session-emulating driver",
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,

View File

@ -27,6 +27,15 @@
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
/* Message logging helpers with driver-specific prefix string. */
#define DRIVER_LOG_DOMAIN "session-file: "
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
/** /**
* @file * @file
* *
@ -66,42 +75,41 @@ SR_API int sr_session_load(const char *filename)
char probename[SR_MAX_PROBENAME_LEN + 1]; char probename[SR_MAX_PROBENAME_LEN + 1];
if (!filename) { if (!filename) {
sr_err("session file: %s: filename was NULL", __func__); sr_err("%s: filename was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
if (!(archive = zip_open(filename, 0, &ret))) { if (!(archive = zip_open(filename, 0, &ret))) {
sr_dbg("session file: Failed to open session file: zip " sr_dbg("Failed to open session file: zip error %d", ret);
"error %d", ret);
return SR_ERR; return SR_ERR;
} }
/* check "version" */ /* check "version" */
version = 0; version = 0;
if (!(zf = zip_fopen(archive, "version", 0))) { if (!(zf = zip_fopen(archive, "version", 0))) {
sr_dbg("session file: Not a sigrok session file."); sr_dbg("Not a sigrok session file.");
return SR_ERR; return SR_ERR;
} }
if ((ret = zip_fread(zf, s, 10)) == -1) { if ((ret = zip_fread(zf, s, 10)) == -1) {
sr_dbg("session file: Not a valid sigrok session file."); sr_dbg("Not a valid sigrok session file.");
return SR_ERR; return SR_ERR;
} }
zip_fclose(zf); zip_fclose(zf);
s[ret] = 0; s[ret] = 0;
version = strtoull(s, NULL, 10); version = strtoull(s, NULL, 10);
if (version != 1) { if (version != 1) {
sr_dbg("session file: Not a valid sigrok session file version."); sr_dbg("Not a valid sigrok session file version.");
return SR_ERR; return SR_ERR;
} }
/* read "metadata" */ /* read "metadata" */
if (zip_stat(archive, "metadata", 0, &zs) == -1) { if (zip_stat(archive, "metadata", 0, &zs) == -1) {
sr_dbg("session file: Not a valid sigrok session file."); sr_dbg("Not a valid sigrok session file.");
return SR_ERR; return SR_ERR;
} }
if (!(metafile = g_try_malloc(zs.size))) { if (!(metafile = g_try_malloc(zs.size))) {
sr_err("session file: %s: metafile malloc failed", __func__); sr_err("%s: metafile malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
@ -111,7 +119,7 @@ SR_API int sr_session_load(const char *filename)
kf = g_key_file_new(); kf = g_key_file_new();
if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) { if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) {
sr_dbg("session file: Failed to parse metadata."); sr_dbg("Failed to parse metadata.");
return SR_ERR; return SR_ERR;
} }
@ -206,7 +214,7 @@ SR_API int sr_session_save(const char *filename,
char version[1], rawname[16], metafile[32], *buf, *s; char version[1], rawname[16], metafile[32], *buf, *s;
if (!filename) { if (!filename) {
sr_err("session file: %s: filename was NULL", __func__); sr_err("%s: filename was NULL", __func__);
return SR_ERR_ARG; return SR_ERR_ARG;
} }
@ -220,7 +228,7 @@ SR_API int sr_session_save(const char *filename,
if (!(versrc = zip_source_buffer(zipfile, version, 1, 0))) if (!(versrc = zip_source_buffer(zipfile, version, 1, 0)))
return SR_ERR; return SR_ERR;
if (zip_add(zipfile, "version", versrc) == -1) { if (zip_add(zipfile, "version", versrc) == -1) {
sr_info("session file: error saving version into zipfile: %s", sr_info("error saving version into zipfile: %s",
zip_strerror(zipfile)); zip_strerror(zipfile));
return SR_ERR; return SR_ERR;
} }
@ -267,8 +275,7 @@ SR_API int sr_session_save(const char *filename,
buf = g_try_malloc(ds->num_units * ds->ds_unitsize + buf = g_try_malloc(ds->num_units * ds->ds_unitsize +
DATASTORE_CHUNKSIZE); DATASTORE_CHUNKSIZE);
if (!buf) { if (!buf) {
sr_err("session file: %s: buf malloc failed", sr_err("%s: buf malloc failed", __func__);
__func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
@ -292,8 +299,7 @@ SR_API int sr_session_save(const char *filename,
return SR_ERR; return SR_ERR;
if ((ret = zip_close(zipfile)) == -1) { if ((ret = zip_close(zipfile)) == -1) {
sr_info("session file: error saving zipfile: %s", sr_info("error saving zipfile: %s", zip_strerror(zipfile));
zip_strerror(zipfile));
return SR_ERR; return SR_ERR;
} }

View File

@ -24,6 +24,15 @@
#include "libsigrok.h" #include "libsigrok.h"
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
/* Message logging helpers with driver-specific prefix string. */
#define DRIVER_LOG_DOMAIN "strutil: "
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
/** /**
* @file * @file
* *
@ -55,7 +64,7 @@
*/ */
SR_API char *sr_si_string_u64(uint64_t x, const char *unit) SR_API char *sr_si_string_u64(uint64_t x, const char *unit)
{ {
if(unit == NULL) if (unit == NULL)
unit = ""; unit = "";
if ((x >= SR_GHZ(1)) && (x % SR_GHZ(1) == 0)) { if ((x >= SR_GHZ(1)) && (x % SR_GHZ(1) == 0)) {
@ -79,8 +88,7 @@ SR_API char *sr_si_string_u64(uint64_t x, const char *unit)
return g_strdup_printf("%" PRIu64 " %s", x, unit); return g_strdup_printf("%" PRIu64 " %s", x, unit);
} }
sr_err("strutil: %s: Error creating SI units string.", sr_err("%s: Error creating SI units string.", __func__);
__func__);
return NULL; return NULL;
} }
@ -120,7 +128,7 @@ SR_API char *sr_period_string(uint64_t frequency)
/* Allocate enough for a uint64_t as string + " ms". */ /* Allocate enough for a uint64_t as string + " ms". */
if (!(o = g_try_malloc0(30 + 1))) { if (!(o = g_try_malloc0(30 + 1))) {
sr_err("strutil: %s: o malloc failed", __func__); sr_err("%s: o malloc failed", __func__);
return NULL; return NULL;
} }
@ -161,7 +169,7 @@ SR_API char *sr_voltage_string(struct sr_rational *voltage)
int r; int r;
if (!(o = g_try_malloc0(30 + 1))) { if (!(o = g_try_malloc0(30 + 1))) {
sr_err("strutil: %s: o malloc failed", __func__); sr_err("%s: o malloc failed", __func__);
return NULL; return NULL;
} }
@ -218,13 +226,13 @@ SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi,
error = FALSE; error = FALSE;
if (!(triggerlist = g_try_malloc0(max_probes * sizeof(char *)))) { if (!(triggerlist = g_try_malloc0(max_probes * sizeof(char *)))) {
sr_err("strutil: %s: triggerlist malloc failed", __func__); sr_err("%s: triggerlist malloc failed", __func__);
return NULL; return NULL;
} }
if (sdi->driver->info_get(SR_DI_TRIGGER_TYPES, if (sdi->driver->info_get(SR_DI_TRIGGER_TYPES,
(const void **)&trigger_types, sdi) != SR_OK) { (const void **)&trigger_types, sdi) != SR_OK) {
sr_err("strutil: %s: Device doesn't support any triggers.", __func__); sr_err("%s: Device doesn't support any triggers.", __func__);
return NULL; return NULL;
} }
@ -242,7 +250,7 @@ SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi,
} }
if (probenum < 0 || probenum >= max_probes) { if (probenum < 0 || probenum >= max_probes) {
sr_err("strutil: Invalid probe."); sr_err("Invalid probe.");
error = TRUE; error = TRUE;
break; break;
} }
@ -250,7 +258,7 @@ SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi,
if ((trigger = strchr(tokens[i], '='))) { if ((trigger = strchr(tokens[i], '='))) {
for (tc = ++trigger; *tc; tc++) { for (tc = ++trigger; *tc; tc++) {
if (strchr(trigger_types, *tc) == NULL) { if (strchr(trigger_types, *tc) == NULL) {
sr_err("strutil: Unsupported trigger " sr_err("Unsupported trigger "
"type '%c'.", *tc); "type '%c'.", *tc);
error = TRUE; error = TRUE;
break; break;