#include "libsigrok.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
*
SR_API int sr_datastore_new(int unitsize, struct sr_datastore **ds)
{
if (!ds) {
- sr_err("ds: %s: ds was NULL", __func__);
+ sr_err("%s: ds was NULL", __func__);
return SR_ERR_ARG;
}
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);
return SR_ERR_ARG;
}
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;
}
GSList *chunk;
if (!ds) {
- sr_err("ds: %s: ds was NULL", __func__);
+ sr_err("%s: ds was NULL", __func__);
return SR_ERR_ARG;
}
gpointer chunk;
if (!ds) {
- sr_err("ds: %s: ds was NULL", __func__);
+ sr_err("%s: ds was NULL", __func__);
return SR_ERR_ARG;
}
/* Unitsize must not be 0, we'll divide by 0 otherwise. */
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;
}
if (!data) {
- sr_err("ds: %s: data was NULL", __func__);
+ sr_err("%s: data was NULL", __func__);
return SR_ERR_ARG;
}
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);
return SR_ERR_ARG;
}
if (!probelist) {
- sr_err("ds: %s: probelist was NULL", __func__);
+ sr_err("%s: probelist was NULL", __func__);
return SR_ERR_ARG;
}
/* Get the last chunk in the list, or create a new one if needed. */
if (ds->chunklist == NULL) {
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;
}
} else {
/* No more free space left, allocate a new chunk. */
if (chunk_bytes_free == 0) {
if (!(chunk = new_chunk(&ds))) {
- sr_err("ds: %s: couldn't allocate new chunk",
+ sr_err("%s: couldn't allocate new chunk",
__func__);
return SR_ERR_MALLOC;
}
chunk = g_try_malloc0(DATASTORE_CHUNKSIZE * (*ds)->ds_unitsize);
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);
return NULL; /* TODO: SR_ERR_MALLOC later? */
}
#include "libsigrok.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
*
struct sr_probe *probe;
if (!(probe = g_try_malloc0(sizeof(struct sr_probe)))) {
- sr_err("hwdriver: probe malloc failed");
+ sr_err("Probe malloc failed.");
return NULL;
}
struct sr_dev_inst *sdi;
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;
}
struct sr_usb_dev_inst *udi;
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;
}
struct sr_serial_dev_inst *serial;
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;
}
int ret;
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;
}
#include "libsigrok.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
*
uint64_t sample_in, sample_out;
if (!probelist) {
- sr_err("filter: %s: probelist was NULL", __func__);
+ sr_err("%s: probelist was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_in) {
- sr_err("filter: %s: data_in was NULL", __func__);
+ sr_err("%s: data_in was NULL", __func__);
return SR_ERR_ARG;
}
if (!data_out) {
- sr_err("filter: %s: data_out was NULL", __func__);
+ sr_err("%s: data_out was NULL", __func__);
return SR_ERR_ARG;
}
if (!length_out) {
- sr_err("filter: %s: length_out was NULL", __func__);
+ sr_err("%s: length_out was NULL", __func__);
return SR_ERR_ARG;
}
/* Are there more probes than the target unit size supports? */
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);
return SR_ERR_ARG;
}
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;
}
#include "libsigrok.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 */
/** @cond PRIVATE */
#define CHUNKSIZE (512 * 1024)
(void)fd;
(void)revents;
- sr_dbg("session_driver: feed chunk");
+ sr_dbg("Feed chunk.");
got_data = FALSE;
for (l = dev_insts; l; l = l->next) {
continue;
if (!(buf = g_try_malloc(CHUNKSIZE))) {
- sr_err("session driver: %s: buf malloc failed", __func__);
+ sr_err("%s: buf malloc failed", __func__);
return FALSE;
}
static int hw_init(void)
{
-
return SR_OK;
}
static int hw_dev_open(struct sr_dev_inst *sdi)
{
-
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;
}
case SR_HWCAP_SAMPLERATE:
tmp_u64 = value;
vdev->samplerate = *tmp_u64;
- sr_info("session driver: setting samplerate to %" PRIu64,
- vdev->samplerate);
+ sr_info("Setting samplerate to %" PRIu64 ".", vdev->samplerate);
break;
case SR_HWCAP_SESSIONFILE:
vdev->sessionfile = g_strdup(value);
- sr_info("session driver: setting sessionfile to %s",
- vdev->sessionfile);
+ sr_info("Setting sessionfile to '%s'.", vdev->sessionfile);
break;
case SR_HWCAP_CAPTUREFILE:
vdev->capturefile = g_strdup(value);
- sr_info("session driver: setting capturefile to %s",
- vdev->capturefile);
+ sr_info("Setting capturefile to '%s'.", vdev->capturefile);
break;
case SR_HWCAP_CAPTURE_UNITSIZE:
tmp_u64 = value;
vdev->num_probes = *tmp_u64;
break;
default:
- sr_err("session driver: %s: unknown capability %d requested",
- __func__, hwcap);
+ sr_err("Unknown capability: %d.", hwcap);
return SR_ERR;
}
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);
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);
return SR_ERR;
}
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);
return SR_ERR;
}
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);
return SR_ERR;
}
sr_session_source_add(-1, 0, 0, receive_data, cb_data);
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;
}
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;
}
/** @private */
SR_PRIV struct sr_dev_driver session_driver = {
- .name = "session",
+ .name = "virtual-session",
.longname = "Session-emulating driver",
.api_version = 1,
.init = hw_init,
#include "libsigrok.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
*
char probename[SR_MAX_PROBENAME_LEN + 1];
if (!filename) {
- sr_err("session file: %s: filename was NULL", __func__);
+ sr_err("%s: filename was NULL", __func__);
return SR_ERR_ARG;
}
if (!(archive = zip_open(filename, 0, &ret))) {
- sr_dbg("session file: Failed to open session file: zip "
- "error %d", ret);
+ sr_dbg("Failed to open session file: zip error %d", ret);
return SR_ERR;
}
/* check "version" */
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;
}
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;
}
zip_fclose(zf);
s[ret] = 0;
version = strtoull(s, NULL, 10);
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;
}
/* read "metadata" */
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;
}
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;
}
kf = g_key_file_new();
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;
}
char version[1], rawname[16], metafile[32], *buf, *s;
if (!filename) {
- sr_err("session file: %s: filename was NULL", __func__);
+ sr_err("%s: filename was NULL", __func__);
return SR_ERR_ARG;
}
if (!(versrc = zip_source_buffer(zipfile, version, 1, 0)))
return SR_ERR;
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));
return SR_ERR;
}
buf = g_try_malloc(ds->num_units * ds->ds_unitsize +
DATASTORE_CHUNKSIZE);
if (!buf) {
- sr_err("session file: %s: buf malloc failed",
- __func__);
+ sr_err("%s: buf malloc failed", __func__);
return SR_ERR_MALLOC;
}
return SR_ERR;
if ((ret = zip_close(zipfile)) == -1) {
- sr_info("session file: error saving zipfile: %s",
- zip_strerror(zipfile));
+ sr_info("error saving zipfile: %s", zip_strerror(zipfile));
return SR_ERR;
}
#include "libsigrok.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
*
*/
SR_API char *sr_si_string_u64(uint64_t x, const char *unit)
{
- if(unit == NULL)
+ if (unit == NULL)
unit = "";
if ((x >= SR_GHZ(1)) && (x % SR_GHZ(1) == 0)) {
return g_strdup_printf("%" PRIu64 " %s", x, unit);
}
- sr_err("strutil: %s: Error creating SI units string.",
- __func__);
+ sr_err("%s: Error creating SI units string.", __func__);
return NULL;
}
/* Allocate enough for a uint64_t as string + " ms". */
if (!(o = g_try_malloc0(30 + 1))) {
- sr_err("strutil: %s: o malloc failed", __func__);
+ sr_err("%s: o malloc failed", __func__);
return NULL;
}
int r;
if (!(o = g_try_malloc0(30 + 1))) {
- sr_err("strutil: %s: o malloc failed", __func__);
+ sr_err("%s: o malloc failed", __func__);
return NULL;
}
error = FALSE;
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;
}
if (sdi->driver->info_get(SR_DI_TRIGGER_TYPES,
(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;
}
}
if (probenum < 0 || probenum >= max_probes) {
- sr_err("strutil: Invalid probe.");
+ sr_err("Invalid probe.");
error = TRUE;
break;
}
if ((trigger = strchr(tokens[i], '='))) {
for (tc = ++trigger; *tc; tc++) {
if (strchr(trigger_types, *tc) == NULL) {
- sr_err("strutil: Unsupported trigger "
+ sr_err("Unsupported trigger "
"type '%c'.", *tc);
error = TRUE;
break;