1 | /* $Id: VBoxWatchdogInternal.h 39942 2012-02-01 19:50:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxWatchdog - VirtualBox Watchdog Service.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___H_VBOXWATCHDOG
|
---|
19 | #define ___H_VBOXWATCHDOG
|
---|
20 |
|
---|
21 | #ifndef VBOX_ONLY_DOCS
|
---|
22 | #include <VBox/com/com.h>
|
---|
23 | #include <VBox/com/string.h>
|
---|
24 | #include <VBox/com/VirtualBox.h>
|
---|
25 |
|
---|
26 | #include <iprt/getopt.h>
|
---|
27 | #include <iprt/time.h>
|
---|
28 | #endif /* !VBOX_ONLY_DOCS */
|
---|
29 |
|
---|
30 | #include <map>
|
---|
31 | #include <vector>
|
---|
32 |
|
---|
33 | using namespace com;
|
---|
34 |
|
---|
35 | ////////////////////////////////////////////////////////////////////////////////
|
---|
36 | //
|
---|
37 | // definitions
|
---|
38 | //
|
---|
39 | ////////////////////////////////////////////////////////////////////////////////
|
---|
40 |
|
---|
41 | /** Command handler argument. */
|
---|
42 | struct HandlerArg
|
---|
43 | {
|
---|
44 | int argc;
|
---|
45 | char **argv;
|
---|
46 | };
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * A module's payload for a machine entry.
|
---|
50 | * The payload data is not (yet) thread safe -- so only
|
---|
51 | * use this in one module at a time only!
|
---|
52 | */
|
---|
53 | typedef struct VBOXWATCHDOG_MODULE_PAYLOAD
|
---|
54 | {
|
---|
55 | /* Pointer to allocated payload. Can be NULL if
|
---|
56 | * a module doesn't have an own payload. */
|
---|
57 | void *pvPayload;
|
---|
58 | /* Size of payload (in bytes). */
|
---|
59 | size_t cbPayload;
|
---|
60 | /** @todo Add mutex for locking + getPayloadLocked(). */
|
---|
61 | } VBOXWATCHDOG_MODULE_PAYLOAD, *PVBOXWATCHDOG_MODULE_PAYLOAD;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Map containing a module's individual payload -- the module itself
|
---|
65 | * is responsible for allocating/handling/destroying this payload.
|
---|
66 | * Primary key is the module name.
|
---|
67 | */
|
---|
68 | typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD> mapPayload;
|
---|
69 | typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD>::iterator mapPayloadIter;
|
---|
70 | typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD>::const_iterator mapPayloadIterConst;
|
---|
71 |
|
---|
72 | struct VBOXWATCHDOG_VM_GROUP;
|
---|
73 |
|
---|
74 | /** A machine's internal entry.
|
---|
75 | * Primary key is the machine's UUID. */
|
---|
76 | typedef struct VBOXWATCHDOG_MACHINE
|
---|
77 | {
|
---|
78 | ComPtr<IMachine> machine;
|
---|
79 | #ifndef VBOX_WATCHDOG_GLOBAL_PERFCOL
|
---|
80 | ComPtr<IPerformanceCollector> collector;
|
---|
81 | #endif
|
---|
82 | /** Map containing the individual
|
---|
83 | * module payloads. */
|
---|
84 | mapPayload payload;
|
---|
85 | } VBOXWATCHDOG_MACHINE, *PVBOXWATCHDOG_MACHINE;
|
---|
86 | typedef std::map<Bstr, VBOXWATCHDOG_MACHINE> mapVM;
|
---|
87 | typedef std::map<Bstr, VBOXWATCHDOG_MACHINE>::iterator mapVMIter;
|
---|
88 | typedef std::map<Bstr, VBOXWATCHDOG_MACHINE>::const_iterator mapVMIterConst;
|
---|
89 |
|
---|
90 | /** A VM group entry. Note that a machine can belong
|
---|
91 | * to more than one group. */
|
---|
92 | typedef struct VBOXWATCHDOG_VM_GROUP
|
---|
93 | {
|
---|
94 | /** UUIDs of machines belonging to this group. */
|
---|
95 | std::vector<Bstr> machine;
|
---|
96 | } VBOXWATCHDOG_VM_GROUP;
|
---|
97 | typedef std::map<Bstr, VBOXWATCHDOG_VM_GROUP> mapGroup;
|
---|
98 | typedef std::map<Bstr, VBOXWATCHDOG_VM_GROUP>::iterator mapGroupIter;
|
---|
99 | typedef std::map<Bstr, VBOXWATCHDOG_VM_GROUP>::const_iterator mapGroupIterConst;
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * A module descriptor.
|
---|
103 | */
|
---|
104 | typedef struct
|
---|
105 | {
|
---|
106 | /** The short module name. */
|
---|
107 | const char *pszName;
|
---|
108 | /** A comma-separated list of modules this module
|
---|
109 | * depends on. Might be NULL if no dependencies. */
|
---|
110 | const char *pszDepends;
|
---|
111 | /** Priority (lower is higher, 0 is invalid) of
|
---|
112 | * module execution. */
|
---|
113 | uint32_t uPriority;
|
---|
114 | /** The longer module name. */
|
---|
115 | const char *pszDescription;
|
---|
116 | /** The usage options stuff for the --help screen. */
|
---|
117 | const char *pszUsage;
|
---|
118 | /** The option descriptions for the --help screen. */
|
---|
119 | const char *pszOptions;
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Called before parsing arguments.
|
---|
123 | * @returns VBox status code.
|
---|
124 | */
|
---|
125 | DECLCALLBACKMEMBER(int, pfnPreInit)(void);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Tries to parse the given command line options.
|
---|
129 | *
|
---|
130 | * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
|
---|
131 | * @param argc Argument count.
|
---|
132 | * @param argv Arguments.
|
---|
133 | */
|
---|
134 | DECLCALLBACKMEMBER(int, pfnOption)(int argc, char **argv);
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Called before parsing arguments.
|
---|
138 | * @returns VBox status code.
|
---|
139 | */
|
---|
140 | DECLCALLBACKMEMBER(int, pfnInit)(void);
|
---|
141 |
|
---|
142 | /** Called from the watchdog's main function. Non-blocking.
|
---|
143 | *
|
---|
144 | * @returns VBox status code.
|
---|
145 | */
|
---|
146 | DECLCALLBACKMEMBER(int, pfnMain)(void);
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Stop the module.
|
---|
150 | */
|
---|
151 | DECLCALLBACKMEMBER(int, pfnStop)(void);
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Does termination cleanups.
|
---|
155 | *
|
---|
156 | * @remarks This may be called even if pfnInit hasn't been called!
|
---|
157 | */
|
---|
158 | DECLCALLBACKMEMBER(void, pfnTerm)(void);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Callbacks.
|
---|
162 | */
|
---|
163 |
|
---|
164 | /**
|
---|
165 | *
|
---|
166 | * @returns VBox status code.
|
---|
167 | */
|
---|
168 | DECLCALLBACKMEMBER(int, pfnOnMachineRegistered)(const Bstr &strUuid);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | *
|
---|
172 | * @returns VBox status code.
|
---|
173 | */
|
---|
174 | DECLCALLBACKMEMBER(int, pfnOnMachineUnregistered)(const Bstr &strUuid);
|
---|
175 |
|
---|
176 | /**
|
---|
177 | *
|
---|
178 | * @returns VBox status code.
|
---|
179 | */
|
---|
180 | DECLCALLBACKMEMBER(int, pfnOnMachineStateChanged)(const Bstr &strUuid, MachineState_T enmState);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | *
|
---|
184 | * @returns VBox status code.
|
---|
185 | */
|
---|
186 | DECLCALLBACKMEMBER(int, pfnOnServiceStateChanged)(bool fAvailable);
|
---|
187 |
|
---|
188 | } VBOXMODULE;
|
---|
189 | /** Pointer to a VBOXMODULE. */
|
---|
190 | typedef VBOXMODULE *PVBOXMODULE;
|
---|
191 | /** Pointer to a const VBOXMODULE. */
|
---|
192 | typedef VBOXMODULE const *PCVBOXMODULE;
|
---|
193 |
|
---|
194 | RT_C_DECLS_BEGIN
|
---|
195 |
|
---|
196 | extern bool g_fVerbose;
|
---|
197 | extern ComPtr<IVirtualBox> g_pVirtualBox;
|
---|
198 | extern ComPtr<ISession> g_pSession;
|
---|
199 |
|
---|
200 | extern VBOXMODULE g_ModBallooning;
|
---|
201 |
|
---|
202 | extern void serviceLog(const char *pszFormat, ...);
|
---|
203 | #define serviceLogVerbose(a) if (g_fVerbose) { serviceLog a; }
|
---|
204 |
|
---|
205 | extern int getMetric(PVBOXWATCHDOG_MACHINE pMachine, const Bstr& strName, LONG *pulData);
|
---|
206 | void* getPayload(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule);
|
---|
207 |
|
---|
208 | RT_C_DECLS_END
|
---|
209 |
|
---|
210 | #endif /* !___H_VBOXWATCHDOG */
|
---|
211 |
|
---|