Revision 13a286d5

b/Makefile
182 182
test-qmp-commands.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h test-qmp-marshal.c test-qmp-commands.h) $(qapi-obj-y)
183 183
test-qmp-commands: test-qmp-commands.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o qemu-malloc.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o $(qapi-dir)/test-qmp-marshal.o module.o
184 184

  
185
QGALIB=qga/guest-agent-command-state.o
186

  
185 187
QEMULIBS=libhw32 libhw64 libuser libdis libdis-user
186 188

  
187 189
clean:
......
190 192
	rm -f qemu-options.def
191 193
	rm -f *.o *.d *.a *.lo $(TOOLS) TAGS cscope.* *.pod *~ */*~
192 194
	rm -Rf .libs
193
	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d
195
	rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d qga/*.o qga/*.d
194 196
	rm -f qemu-img-cmds.h
195 197
	rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
196 198
	rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp
b/configure
3487 3487
DIRS="$DIRS roms/seabios roms/vgabios"
3488 3488
DIRS="$DIRS fsdev ui"
3489 3489
DIRS="$DIRS qapi"
3490
DIRS="$DIRS qga"
3490 3491
FILES="Makefile tests/Makefile"
3491 3492
FILES="$FILES tests/cris/Makefile tests/cris/.gdbinit"
3492 3493
FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
b/qga/guest-agent-command-state.c
1
/*
2
 * QEMU Guest Agent command state interfaces
3
 *
4
 * Copyright IBM Corp. 2011
5
 *
6
 * Authors:
7
 *  Michael Roth      <mdroth@linux.vnet.ibm.com>
8
 *
9
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10
 * See the COPYING file in the top-level directory.
11
 */
12
#include <glib.h>
13
#include "qga/guest-agent-core.h"
14

  
15
struct GACommandState {
16
    GSList *groups;
17
};
18

  
19
typedef struct GACommandGroup {
20
    void (*init)(void);
21
    void (*cleanup)(void);
22
} GACommandGroup;
23

  
24
/* handle init/cleanup for stateful guest commands */
25

  
26
void ga_command_state_add(GACommandState *cs,
27
                          void (*init)(void),
28
                          void (*cleanup)(void))
29
{
30
    GACommandGroup *cg = qemu_mallocz(sizeof(GACommandGroup));
31
    cg->init = init;
32
    cg->cleanup = cleanup;
33
    cs->groups = g_slist_append(cs->groups, cg);
34
}
35

  
36
static void ga_command_group_init(gpointer opaque, gpointer unused)
37
{
38
    GACommandGroup *cg = opaque;
39

  
40
    g_assert(cg);
41
    if (cg->init) {
42
        cg->init();
43
    }
44
}
45

  
46
void ga_command_state_init_all(GACommandState *cs)
47
{
48
    g_assert(cs);
49
    g_slist_foreach(cs->groups, ga_command_group_init, NULL);
50
}
51

  
52
static void ga_command_group_cleanup(gpointer opaque, gpointer unused)
53
{
54
    GACommandGroup *cg = opaque;
55

  
56
    g_assert(cg);
57
    if (cg->cleanup) {
58
        cg->cleanup();
59
    }
60
}
61

  
62
void ga_command_state_cleanup_all(GACommandState *cs)
63
{
64
    g_assert(cs);
65
    g_slist_foreach(cs->groups, ga_command_group_cleanup, NULL);
66
}
67

  
68
GACommandState *ga_command_state_new(void)
69
{
70
    GACommandState *cs = qemu_mallocz(sizeof(GACommandState));
71
    cs->groups = NULL;
72
    return cs;
73
}
b/qga/guest-agent-core.h
1
/*
2
 * QEMU Guest Agent core declarations
3
 *
4
 * Copyright IBM Corp. 2011
5
 *
6
 * Authors:
7
 *  Adam Litke        <aglitke@linux.vnet.ibm.com>
8
 *  Michael Roth      <mdroth@linux.vnet.ibm.com>
9
 *
10
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11
 * See the COPYING file in the top-level directory.
12
 */
13
#include "qapi/qmp-core.h"
14
#include "qemu-common.h"
15

  
16
#define QGA_VERSION "1.0"
17

  
18
typedef struct GACommandState GACommandState;
19

  
20
void ga_command_state_add(GACommandState *cs,
21
                          void (*init)(void),
22
                          void (*cleanup)(void));
23
void ga_command_state_init_all(GACommandState *cs);
24
void ga_command_state_cleanup_all(GACommandState *cs);
25
GACommandState *ga_command_state_new(void);

Also available in: Unified diff