1
2
3
4
5
6
7
8
9
10
11
12#include "qemu/osdep.h"
13#include <glib.h>
14#include "qga/guest-agent-core.h"
15
16struct GACommandState {
17 GSList *groups;
18};
19
20typedef struct GACommandGroup {
21 void (*init)(void);
22 void (*cleanup)(void);
23} GACommandGroup;
24
25
26
27void ga_command_state_add(GACommandState *cs,
28 void (*init)(void),
29 void (*cleanup)(void))
30{
31 GACommandGroup *cg = g_new0(GACommandGroup, 1);
32 cg->init = init;
33 cg->cleanup = cleanup;
34 cs->groups = g_slist_append(cs->groups, cg);
35}
36
37static void ga_command_group_init(gpointer opaque, gpointer unused)
38{
39 GACommandGroup *cg = opaque;
40
41 g_assert(cg);
42 if (cg->init) {
43 cg->init();
44 }
45}
46
47void ga_command_state_init_all(GACommandState *cs)
48{
49 g_assert(cs);
50 g_slist_foreach(cs->groups, ga_command_group_init, NULL);
51}
52
53static void ga_command_group_cleanup(gpointer opaque, gpointer unused)
54{
55 GACommandGroup *cg = opaque;
56
57 g_assert(cg);
58 if (cg->cleanup) {
59 cg->cleanup();
60 }
61}
62
63void ga_command_state_cleanup_all(GACommandState *cs)
64{
65 g_assert(cs);
66 g_slist_foreach(cs->groups, ga_command_group_cleanup, NULL);
67}
68
69GACommandState *ga_command_state_new(void)
70{
71 GACommandState *cs = g_new0(GACommandState, 1);
72 cs->groups = NULL;
73 return cs;
74}
75