]> git.ozlabs.org Git - petitboot/commitdiff
types: Add device_type to struct device
authorJeremy Kerr <jk@ozlabs.org>
Wed, 18 Sep 2013 03:03:17 +0000 (11:03 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 18 Sep 2013 03:43:27 +0000 (11:43 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/pb-protocol/pb-protocol.c
lib/types/types.h

index bcc7230a0060c062600ed69c66aadfde2cdf2f25..681b250e20135ee334c0822a500eae0ea50f2973 100644 (file)
@@ -22,6 +22,7 @@
  * action = 0x1: device add message
  *  payload:
  *   4-byte len, id
+ *   1-byte type
  *   4-byte len, name
  *   4-byte len, description
  *   4-byte len, icon_file
@@ -166,6 +167,7 @@ static int optional_strlen(const char *str)
 int pb_protocol_device_len(const struct device *dev)
 {
        return  4 + optional_strlen(dev->id) +
+               sizeof(dev->type) +
                4 + optional_strlen(dev->name) +
                4 + optional_strlen(dev->description) +
                4 + optional_strlen(dev->icon_file);
@@ -209,6 +211,8 @@ int pb_protocol_serialise_device(const struct device *dev,
        char *pos = buf;
 
        pos += pb_protocol_serialise_string(pos, dev->id);
+       *(enum device_type *)pos = dev->type;
+       pos += sizeof(enum device_type);
        pos += pb_protocol_serialise_string(pos, dev->name);
        pos += pb_protocol_serialise_string(pos, dev->description);
        pos += pb_protocol_serialise_string(pos, dev->icon_file);
@@ -384,6 +388,12 @@ int pb_protocol_deserialise_device(struct device *dev,
        if (read_string(dev, &pos, &len, &dev->id))
                goto out;
 
+       if (len < sizeof(enum device_type))
+               goto out;
+       dev->type = *(enum device_type *)(pos);
+       pos += sizeof(enum device_type);
+       len -= sizeof(enum device_type);
+
        if (read_string(dev, &pos, &len, &dev->name))
                goto out;
 
index 9fed7aaaba65d3a5948d248c6482299197cde3e9..bb4b23ca5f601d61e083041580de45a53880eb63 100644 (file)
@@ -4,8 +4,16 @@
 #include <stdbool.h>
 #include <list/list.h>
 
+enum device_type {
+       DEVICE_TYPE_NETWORK,
+       DEVICE_TYPE_DISK,
+       DEVICE_TYPE_OPTICAL,
+       DEVICE_TYPE_UNKNOWN,
+};
+
 struct device {
        char            *id;
+       enum device_type type;
        char            *name;
        char            *description;
        char            *icon_file;