.name = "meep",
.description = "meep description",
.icon_file = "meep.png",
- .n_options = 1,
- .options = options,
};
int device_handler_get_current_devices(struct device_handler *handler,
struct device_handler *device_handler_init(struct discover_server *server)
{
struct device_handler *handler;
+ int i;
handler = talloc(NULL, struct device_handler);
handler->devices = NULL;
/* set up our mount point base */
mkdir_recursive(mount_base());
+ /* setup out test objects */
+ list_init(&device.boot_options);
+
+ for (i = 0; i < sizeof(options) / sizeof(options[0]); i++)
+ list_add(&device.boot_options, &options[i].list);
+
return handler;
}
#include <asm/byteorder.h>
#include <talloc/talloc.h>
+#include <list/list.h>
#include "pb-protocol.h"
int pb_protocol_device_len(struct device *dev)
{
- int len, i;
+ struct boot_option *opt;
+ int len;
len = 4 + optional_strlen(dev->id) +
4 + optional_strlen(dev->name) +
4 + optional_strlen(dev->icon_file) +
4;
- for (i = 0; i < dev->n_options; i++) {
- struct boot_option *opt = &dev->options[i];
+ list_for_each_entry(&dev->boot_options, opt, list) {
len += 4 + optional_strlen(opt->id) +
4 + optional_strlen(opt->name) +
4 + optional_strlen(opt->description) +
int pb_protocol_serialise_device(struct device *dev, char *buf, int buf_len)
{
+ struct boot_option *opt;
+ uint32_t n;
char *pos;
- int i;
pos = buf;
pos += pb_protocol_serialise_string(pos, dev->icon_file);
/* write option count */
- *(uint32_t *)pos = __cpu_to_be32(dev->n_options);
+ n = 0;
+
+ list_for_each_entry(&dev->boot_options, opt, list)
+ n++;
+
+ *(uint32_t *)pos = __cpu_to_be32(n);
pos += sizeof(uint32_t);
/* write each option */
- for (i = 0; i < dev->n_options; i++) {
- struct boot_option *opt = &dev->options[i];
+ list_for_each_entry(&dev->boot_options, opt, list) {
pos += pb_protocol_serialise_string(pos, opt->id);
pos += pb_protocol_serialise_string(pos, opt->name);
pos += pb_protocol_serialise_string(pos, opt->description);
{
struct device *dev;
char *pos;
- int i, len;
+ int i, n_options, len;
len = message->payload_len;
pos = message->payload;
if (read_string(dev, &pos, &len, &dev->icon_file))
goto out_err;
- dev->n_options = __be32_to_cpu(*(uint32_t *)pos);
- dev->options = talloc_array(dev, struct boot_option, dev->n_options);
+ n_options = __be32_to_cpu(*(uint32_t *)pos);
pos += sizeof(uint32_t);
- for (i = 0; i < dev->n_options; i++) {
- struct boot_option *opt = &dev->options[i];
+ list_init(&dev->boot_options);
+
+ for (i = 0; i < n_options; i++) {
+ struct boot_option *opt;
+
+ opt = talloc(dev, struct boot_option);
if (read_string(opt, &pos, &len, &opt->id))
goto out_err;
if (read_string(opt, &pos, &len,
&opt->boot_args))
goto out_err;
+
+ list_add(&dev->boot_options, &opt->list);
}
return dev;
static int print_device_add(struct device *device)
{
- int i;
+ struct boot_option *opt;
printf("new device:\n");
printf("\tid: %s\n", device->id);
printf("\tdesc: %s\n", device->description);
printf("\ticon: %s\n", device->icon_file);
- printf("\t%d boot options:\n", device->n_options);
- for (i = 0; i < device->n_options; i++) {
- struct boot_option *opt = &device->options[i];
+ printf("\tboot options:\n");
+ list_for_each_entry(&device->boot_options, opt, list) {
printf("\t\tid: %s\n", opt->id);
printf("\t\tname: %s\n", opt->name);
printf("\t\tdesc: %s\n", opt->description);