[08/29] discover: Add device-specific status reporting functions
diff mbox

Message ID 20161219041915.30497-9-sam@mendozajonas.com
State Accepted
Headers show

Commit Message

Samuel Mendoza-Jonas Dec. 19, 2016, 4:18 a.m. UTC
From: Jeremy Kerr <jk@ozlabs.org>

Most of our status reporting is against a specific device, so add
status reporting functions that take a struct discover_device and use a
stnadard prefix.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/device-handler.c | 31 +++++++++++++++++++++++++++++++
 discover/device-handler.h |  4 ++++
 2 files changed, 35 insertions(+)

Patch
diff mbox

diff --git a/discover/device-handler.c b/discover/device-handler.c
index 281a3c4..aa693e4 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -429,6 +429,37 @@  static void _device_handler_vstatus(struct device_handler *handler,
 	talloc_free(status.message);
 }
 
+static void _device_handler_vdevstatus(struct device_handler *handler,
+		struct discover_device *device, enum status_type type,
+		const char *fmt, va_list ap)
+{
+	char *msg;
+
+	msg = talloc_asprintf(handler, "(%s): %s", device->device->id, fmt);
+	_device_handler_vstatus(handler, type, msg, ap);
+	talloc_free(msg);
+}
+
+void device_handler_status_dev_info(struct device_handler *handler,
+		struct discover_device *dev, const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	_device_handler_vdevstatus(handler, dev, STATUS_INFO, fmt, ap);
+	va_end(ap);
+}
+
+void device_handler_status_dev_err(struct device_handler *handler,
+		struct discover_device *dev, const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	_device_handler_vdevstatus(handler, dev, STATUS_ERROR, fmt, ap);
+	va_end(ap);
+}
+
 void device_handler_status_info(struct device_handler *handler,
 		const char *fmt, ...)
 {
diff --git a/discover/device-handler.h b/discover/device-handler.h
index f4022e7..fe8a3b0 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -102,6 +102,10 @@  void device_handler_status_info(struct device_handler *handler,
 		const char *fmt, ...);
 void device_handler_status_err(struct device_handler *handler,
 		const char *fmt, ...);
+void device_handler_status_dev_info(struct device_handler *handler,
+		struct discover_device *dev, const char *fmt, ...);
+void device_handler_status_dev_err(struct device_handler *handler,
+		struct discover_device *dev, const char *fmt, ...);
 
 struct discover_context *device_handler_discover_context_create(
 		struct device_handler *handler,