discover: Add device-specific status reporting functions
authorJeremy Kerr <jk@ozlabs.org>
Mon, 12 Dec 2016 07:43:21 +0000 (15:43 +0800)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 20 Dec 2016 05:40:21 +0000 (16:40 +1100)
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
discover/device-handler.h

index 281a3c4e7e3345c5edf4b20835a3ae37699794e8..87a46c72a0e2f8a5b0fa71309ee922ce28d07e78 100644 (file)
@@ -429,6 +429,38 @@ 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->device->id : "unknown", 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, ...)
 {
index f4022e764d2d57cf60ae282aabbe44155e6e05e6..fe8a3b07de9691c39e82cc6dff3b17dbcc4039c6 100644 (file)
@@ -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,