intel_iommu: remove X86_IOMMU_PCI_DEVFN_MAX
[qemu.git] / qga / guest-agent-command-state.c
blobe609d320f0d2231cf2861bd2900b22e0efc099c5
1 /*
2 * QEMU Guest Agent command state interfaces
4 * Copyright IBM Corp. 2011
6 * Authors:
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
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.
12 #include "qemu/osdep.h"
13 #include "qga/guest-agent-core.h"
15 struct GACommandState {
16 GSList *groups;
19 typedef struct GACommandGroup {
20 void (*init)(void);
21 void (*cleanup)(void);
22 } GACommandGroup;
24 /* handle init/cleanup for stateful guest commands */
26 void ga_command_state_add(GACommandState *cs,
27 void (*init)(void),
28 void (*cleanup)(void))
30 GACommandGroup *cg = g_new0(GACommandGroup, 1);
31 cg->init = init;
32 cg->cleanup = cleanup;
33 cs->groups = g_slist_append(cs->groups, cg);
36 static void ga_command_group_init(gpointer opaque, gpointer unused)
38 GACommandGroup *cg = opaque;
40 g_assert(cg);
41 if (cg->init) {
42 cg->init();
46 void ga_command_state_init_all(GACommandState *cs)
48 g_assert(cs);
49 g_slist_foreach(cs->groups, ga_command_group_init, NULL);
52 static void ga_command_group_cleanup(gpointer opaque, gpointer unused)
54 GACommandGroup *cg = opaque;
56 g_assert(cg);
57 if (cg->cleanup) {
58 cg->cleanup();
62 void ga_command_state_cleanup_all(GACommandState *cs)
64 g_assert(cs);
65 g_slist_foreach(cs->groups, ga_command_group_cleanup, NULL);
68 GACommandState *ga_command_state_new(void)
70 GACommandState *cs = g_new0(GACommandState, 1);
71 cs->groups = NULL;
72 return cs;
75 void ga_command_state_free(GACommandState *cs)
77 g_slist_free_full(cs->groups, g_free);
78 g_free(cs);