VirtualBox

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

Last change on this file since 81784 was 76582, checked in by vboxsync, 6 years ago

Frontends: scm header guard alignment.

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