VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdogInternal.h@ 40286

Last change on this file since 40286 was 40010, checked in by vboxsync, 13 years ago

VBoxBalloonCtrl: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: VBoxWatchdogInternal.h 40010 2012-02-06 22:23:09Z 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 <iprt/getopt.h>
23# include <iprt/time.h>
24
25# include <VBox/err.h>
26# include <VBox/com/com.h>
27# include <VBox/com/string.h>
28# include <VBox/com/Guid.h>
29# include <VBox/com/array.h>
30# include <VBox/com/ErrorInfo.h>
31# include <VBox/com/VirtualBox.h>
32#endif /* !VBOX_ONLY_DOCS */
33
34#include <map>
35#include <vector>
36
37using namespace com;
38
39////////////////////////////////////////////////////////////////////////////////
40//
41// definitions
42//
43////////////////////////////////////////////////////////////////////////////////
44
45/** Command handler argument. */
46struct HandlerArg
47{
48 int argc;
49 char **argv;
50};
51
52/**
53 * A module's payload for a machine entry.
54 * The payload data is not (yet) thread safe -- so only
55 * use this in one module at a time only!
56 */
57typedef struct VBOXWATCHDOG_MODULE_PAYLOAD
58{
59 /* Pointer to allocated payload. Can be NULL if
60 * a module doesn't have an own payload. */
61 void *pvData;
62 /* Size of payload (in bytes). */
63 size_t cbData;
64 /** @todo Add mutex for locking + getPayloadLocked(). */
65} VBOXWATCHDOG_MODULE_PAYLOAD, *PVBOXWATCHDOG_MODULE_PAYLOAD;
66
67/**
68 * Map containing a module's individual payload -- the module itself
69 * is responsible for allocating/handling/destroying this payload.
70 * Primary key is the module name.
71 */
72typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD> mapPayload;
73typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD>::iterator mapPayloadIter;
74typedef std::map<const char*, VBOXWATCHDOG_MODULE_PAYLOAD>::const_iterator mapPayloadIterConst;
75
76struct VBOXWATCHDOG_VM_GROUP;
77
78/** A machine's internal entry.
79 * Primary key is the machine's UUID. */
80typedef struct VBOXWATCHDOG_MACHINE
81{
82 ComPtr<IMachine> machine;
83#ifndef VBOX_WATCHDOG_GLOBAL_PERFCOL
84 ComPtr<IPerformanceCollector> collector;
85#endif
86 /** The machine's VM group(s). */
87 Bstr group;
88 /** Map containing the individual
89 * module payloads. */
90 mapPayload payload;
91} VBOXWATCHDOG_MACHINE, *PVBOXWATCHDOG_MACHINE;
92typedef std::map<Bstr, VBOXWATCHDOG_MACHINE> mapVM;
93typedef std::map<Bstr, VBOXWATCHDOG_MACHINE>::iterator mapVMIter;
94typedef std::map<Bstr, VBOXWATCHDOG_MACHINE>::const_iterator mapVMIterConst;
95
96/** Members of a VM group; currently only represented by the machine's UUID. */
97typedef std::vector<Bstr> vecGroupMembers;
98typedef std::vector<Bstr>::iterator vecGroupMembersIter;
99typedef std::vector<Bstr>::const_iterator vecGroupMembersIterConst;
100
101/** A VM group. Can contain none, one or more group members. */
102typedef std::map<Bstr, vecGroupMembers> mapGroup;
103typedef std::map<Bstr, vecGroupMembers>::iterator mapGroupIter;
104typedef std::map<Bstr, vecGroupMembers>::const_iterator mapGroupIterConst;
105
106/**
107 * A module descriptor.
108 */
109typedef struct
110{
111 /** The short module name. */
112 const char *pszName;
113 /** The longer module name. */
114 const char *pszDescription;
115 /** A comma-separated list of modules this module
116 * depends on. Might be NULL if no dependencies. */
117 const char *pszDepends;
118 /** Priority (lower is higher, 0 is invalid) of
119 * module execution. */
120 uint32_t uPriority;
121 /** The usage options stuff for the --help screen. */
122 const char *pszUsage;
123 /** The option descriptions for the --help screen. */
124 const char *pszOptions;
125
126 /**
127 * Called before parsing arguments.
128 * @returns VBox status code.
129 */
130 DECLCALLBACKMEMBER(int, pfnPreInit)(void);
131
132 /**
133 * Tries to parse the given command line options.
134 *
135 * @returns 0 if we parsed, -1 if it didn't and anything else means exit.
136 * @param argc Argument count.
137 * @param argv Arguments.
138 */
139 DECLCALLBACKMEMBER(int, pfnOption)(int argc, char **argv);
140
141 /**
142 * Called before parsing arguments.
143 * @returns VBox status code.
144 */
145 DECLCALLBACKMEMBER(int, pfnInit)(void);
146
147 /** Called from the watchdog's main function. Non-blocking.
148 *
149 * @returns VBox status code.
150 */
151 DECLCALLBACKMEMBER(int, pfnMain)(void);
152
153 /**
154 * Stop the module.
155 */
156 DECLCALLBACKMEMBER(int, pfnStop)(void);
157
158 /**
159 * Does termination cleanups.
160 *
161 * @remarks This may be called even if pfnInit hasn't been called!
162 */
163 DECLCALLBACKMEMBER(void, pfnTerm)(void);
164
165 /**
166 * Callbacks.
167 */
168
169 /**
170 *
171 * @returns VBox status code.
172 */
173 DECLCALLBACKMEMBER(int, pfnOnMachineRegistered)(const Bstr &strUuid);
174
175 /**
176 *
177 * @returns VBox status code.
178 */
179 DECLCALLBACKMEMBER(int, pfnOnMachineUnregistered)(const Bstr &strUuid);
180
181 /**
182 *
183 * @returns VBox status code.
184 */
185 DECLCALLBACKMEMBER(int, pfnOnMachineStateChanged)(const Bstr &strUuid, MachineState_T enmState);
186
187 /**
188 *
189 * @returns VBox status code.
190 */
191 DECLCALLBACKMEMBER(int, pfnOnServiceStateChanged)(bool fAvailable);
192
193} VBOXMODULE;
194/** Pointer to a VBOXMODULE. */
195typedef VBOXMODULE *PVBOXMODULE;
196/** Pointer to a const VBOXMODULE. */
197typedef VBOXMODULE const *PCVBOXMODULE;
198
199RT_C_DECLS_BEGIN
200
201extern bool g_fDryrun;
202extern bool g_fVerbose;
203extern ComPtr<IVirtualBox> g_pVirtualBox;
204extern ComPtr<ISession> g_pSession;
205extern mapVM g_mapVM;
206extern mapGroup g_mapGroup;
207# ifdef VBOX_WATCHDOG_GLOBAL_PERFCOL
208extern ComPtr<IPerformanceCollector> g_pPerfCollector;
209# endif
210
211extern VBOXMODULE g_ModBallooning;
212extern VBOXMODULE g_ModAPIMonitor;
213
214extern void serviceLog(const char *pszFormat, ...);
215#define serviceLogVerbose(a) if (g_fVerbose) { serviceLog a; }
216
217extern int getMetric(PVBOXWATCHDOG_MACHINE pMachine, const Bstr& strName, LONG *pulData);
218void* getPayload(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule);
219int payloadAlloc(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule, size_t cbSize, void **ppszPayload);
220void payloadFree(PVBOXWATCHDOG_MACHINE pMachine, const char *pszModule);
221PVBOXWATCHDOG_MACHINE getMachine(const Bstr& strUuid);
222MachineState_T getMachineState(const PVBOXWATCHDOG_MACHINE pMachine);
223
224RT_C_DECLS_END
225
226#endif /* !___H_VBOXWATCHDOG */
227
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette