diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-07-22 16:43:03 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-07-27 14:08:23 -0500 |
commit | e27c88fe9eb26648e4fb282cb3761c41f06ff18a (patch) | |
tree | bcddf5a894b07e84ebb72de7e439404613ab240b /qemu-option.h | |
parent | 7695019bce7f0b552203229e7b89494462ac286f (diff) | |
download | qemu-e27c88fe9eb26648e4fb282cb3761c41f06ff18a.tar.gz qemu-e27c88fe9eb26648e4fb282cb3761c41f06ff18a.tar.bz2 qemu-e27c88fe9eb26648e4fb282cb3761c41f06ff18a.zip |
QemuOpts: framework for storing and parsing options.
This stores device parameters in a better way than unparsed strings.
New types:
QemuOpt - one key-value pair.
QemuOpts - group of key-value pairs, belonging to one
device, i.e. one drive.
QemuOptsList - list of some kind of devices, i.e. all drives.
Functions are provided to work with these types. The plan is that some
day we will pass around QemuOpts pointers instead of strings filled with
"key1=value1,key2=value2".
Check out the next patch to see all this in action ;)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-option.h')
-rw-r--r-- | qemu-option.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/qemu-option.h b/qemu-option.h index 267abae297..428c947946 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -26,6 +26,8 @@ #ifndef QEMU_OPTIONS_H #define QEMU_OPTIONS_H +#include "sys-queue.h" + enum QEMUOptionParType { OPT_FLAG, OPT_NUMBER, @@ -72,4 +74,47 @@ void free_option_parameters(QEMUOptionParameter *list); void print_option_parameters(QEMUOptionParameter *list); void print_option_help(QEMUOptionParameter *list); +/* ------------------------------------------------------------------ */ + +typedef struct QemuOpt QemuOpt; +typedef struct QemuOpts QemuOpts; +typedef struct QemuOptsList QemuOptsList; + +enum QemuOptType { + QEMU_OPT_STRING = 0, /* no parsing (use string as-is) */ + QEMU_OPT_BOOL, /* on/off */ + QEMU_OPT_NUMBER, /* simple number */ + QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */ +}; + +typedef struct QemuOptDesc { + const char *name; + enum QemuOptType type; + const char *help; +} QemuOptDesc; + +struct QemuOptsList { + const char *name; + TAILQ_HEAD(, QemuOpts) head; + QemuOptDesc desc[]; +}; + +const char *qemu_opt_get(QemuOpts *opts, const char *name); +int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval); +uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); +uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); +int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); + +QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id); +QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists); +int qemu_opts_set(QemuOptsList *list, const char *id, + const char *name, const char *value); +void qemu_opts_del(QemuOpts *opts); +QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname); + +typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); +int qemu_opts_print(QemuOpts *opts, void *dummy); +int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, + int abort_on_failure); + #endif |