VirtualBox

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

Last change on this file since 85442 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

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