VirtualBox

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

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

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