root / qga / guest-agent-command-state.c @ 48ff7a62
History | View | Annotate | Download (1.6 kB)
1 | 13a286d5 | Michael Roth | /*
|
---|---|---|---|
2 | 13a286d5 | Michael Roth | * QEMU Guest Agent command state interfaces
|
3 | 13a286d5 | Michael Roth | *
|
4 | 13a286d5 | Michael Roth | * Copyright IBM Corp. 2011
|
5 | 13a286d5 | Michael Roth | *
|
6 | 13a286d5 | Michael Roth | * Authors:
|
7 | 13a286d5 | Michael Roth | * Michael Roth <mdroth@linux.vnet.ibm.com>
|
8 | 13a286d5 | Michael Roth | *
|
9 | 13a286d5 | Michael Roth | * This work is licensed under the terms of the GNU GPL, version 2 or later.
|
10 | 13a286d5 | Michael Roth | * See the COPYING file in the top-level directory.
|
11 | 13a286d5 | Michael Roth | */
|
12 | 13a286d5 | Michael Roth | #include <glib.h> |
13 | 13a286d5 | Michael Roth | #include "qga/guest-agent-core.h" |
14 | 13a286d5 | Michael Roth | |
15 | 13a286d5 | Michael Roth | struct GACommandState {
|
16 | 13a286d5 | Michael Roth | GSList *groups; |
17 | 13a286d5 | Michael Roth | }; |
18 | 13a286d5 | Michael Roth | |
19 | 13a286d5 | Michael Roth | typedef struct GACommandGroup { |
20 | 13a286d5 | Michael Roth | void (*init)(void); |
21 | 13a286d5 | Michael Roth | void (*cleanup)(void); |
22 | 13a286d5 | Michael Roth | } GACommandGroup; |
23 | 13a286d5 | Michael Roth | |
24 | 13a286d5 | Michael Roth | /* handle init/cleanup for stateful guest commands */
|
25 | 13a286d5 | Michael Roth | |
26 | 13a286d5 | Michael Roth | void ga_command_state_add(GACommandState *cs,
|
27 | 13a286d5 | Michael Roth | void (*init)(void), |
28 | 13a286d5 | Michael Roth | void (*cleanup)(void)) |
29 | 13a286d5 | Michael Roth | { |
30 | 13a286d5 | Michael Roth | GACommandGroup *cg = qemu_mallocz(sizeof(GACommandGroup));
|
31 | 13a286d5 | Michael Roth | cg->init = init; |
32 | 13a286d5 | Michael Roth | cg->cleanup = cleanup; |
33 | 13a286d5 | Michael Roth | cs->groups = g_slist_append(cs->groups, cg); |
34 | 13a286d5 | Michael Roth | } |
35 | 13a286d5 | Michael Roth | |
36 | 13a286d5 | Michael Roth | static void ga_command_group_init(gpointer opaque, gpointer unused) |
37 | 13a286d5 | Michael Roth | { |
38 | 13a286d5 | Michael Roth | GACommandGroup *cg = opaque; |
39 | 13a286d5 | Michael Roth | |
40 | 13a286d5 | Michael Roth | g_assert(cg); |
41 | 13a286d5 | Michael Roth | if (cg->init) {
|
42 | 13a286d5 | Michael Roth | cg->init(); |
43 | 13a286d5 | Michael Roth | } |
44 | 13a286d5 | Michael Roth | } |
45 | 13a286d5 | Michael Roth | |
46 | 13a286d5 | Michael Roth | void ga_command_state_init_all(GACommandState *cs)
|
47 | 13a286d5 | Michael Roth | { |
48 | 13a286d5 | Michael Roth | g_assert(cs); |
49 | 13a286d5 | Michael Roth | g_slist_foreach(cs->groups, ga_command_group_init, NULL);
|
50 | 13a286d5 | Michael Roth | } |
51 | 13a286d5 | Michael Roth | |
52 | 13a286d5 | Michael Roth | static void ga_command_group_cleanup(gpointer opaque, gpointer unused) |
53 | 13a286d5 | Michael Roth | { |
54 | 13a286d5 | Michael Roth | GACommandGroup *cg = opaque; |
55 | 13a286d5 | Michael Roth | |
56 | 13a286d5 | Michael Roth | g_assert(cg); |
57 | 13a286d5 | Michael Roth | if (cg->cleanup) {
|
58 | 13a286d5 | Michael Roth | cg->cleanup(); |
59 | 13a286d5 | Michael Roth | } |
60 | 13a286d5 | Michael Roth | } |
61 | 13a286d5 | Michael Roth | |
62 | 13a286d5 | Michael Roth | void ga_command_state_cleanup_all(GACommandState *cs)
|
63 | 13a286d5 | Michael Roth | { |
64 | 13a286d5 | Michael Roth | g_assert(cs); |
65 | 13a286d5 | Michael Roth | g_slist_foreach(cs->groups, ga_command_group_cleanup, NULL);
|
66 | 13a286d5 | Michael Roth | } |
67 | 13a286d5 | Michael Roth | |
68 | 13a286d5 | Michael Roth | GACommandState *ga_command_state_new(void)
|
69 | 13a286d5 | Michael Roth | { |
70 | 13a286d5 | Michael Roth | GACommandState *cs = qemu_mallocz(sizeof(GACommandState));
|
71 | 13a286d5 | Michael Roth | cs->groups = NULL;
|
72 | 13a286d5 | Michael Roth | return cs;
|
73 | 13a286d5 | Michael Roth | } |