VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart.h@ 97395

Last change on this file since 97395 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1/* $Id: VBoxAutostart.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBoxAutostart - VirtualBox Autostart service.
4 */
5
6/*
7 * Copyright (C) 2012-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef VBOX_INCLUDED_SRC_VBoxAutostart_VBoxAutostart_h
29#define VBOX_INCLUDED_SRC_VBoxAutostart_VBoxAutostart_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/*******************************************************************************
35* Header Files *
36*******************************************************************************/
37#include <iprt/getopt.h>
38#include <iprt/types.h>
39
40#include <VBox/cdefs.h>
41#include <VBox/types.h>
42
43#include <VBox/com/com.h>
44#include <VBox/com/VirtualBox.h>
45
46/*******************************************************************************
47* Constants And Macros, Structures and Typedefs *
48*******************************************************************************/
49
50/**
51 * Config AST node types.
52 */
53typedef enum CFGASTNODETYPE
54{
55 /** Invalid. */
56 CFGASTNODETYPE_INVALID = 0,
57 /** Key/Value pair. */
58 CFGASTNODETYPE_KEYVALUE,
59 /** Compound type. */
60 CFGASTNODETYPE_COMPOUND,
61 /** List type. */
62 CFGASTNODETYPE_LIST,
63 /** 32bit hack. */
64 CFGASTNODETYPE_32BIT_HACK = 0x7fffffff
65} CFGASTNODETYPE;
66/** Pointer to a config AST node type. */
67typedef CFGASTNODETYPE *PCFGASTNODETYPE;
68/** Pointer to a const config AST node type. */
69typedef const CFGASTNODETYPE *PCCFGASTNODETYPE;
70
71/**
72 * Config AST.
73 */
74typedef struct CFGAST
75{
76 /** AST node type. */
77 CFGASTNODETYPE enmType;
78 /** Key or scope id. */
79 char *pszKey;
80 /** Type dependent data. */
81 union
82 {
83 /** Key value pair. */
84 struct
85 {
86 /** Number of characters in the value - excluding terminator. */
87 size_t cchValue;
88 /** Value string - variable in size. */
89 char aszValue[1];
90 } KeyValue;
91 /** Compound type. */
92 struct
93 {
94 /** Number of AST node entries in the array. */
95 unsigned cAstNodes;
96 /** AST node array - variable in size. */
97 struct CFGAST *apAstNodes[1];
98 } Compound;
99 /** List type. */
100 struct
101 {
102 /** Number of entries in the list. */
103 unsigned cListEntries;
104 /** Array of list entries - variable in size. */
105 char *apszEntries[1];
106 } List;
107 } u;
108} CFGAST, *PCFGAST;
109
110/** Flag whether we are in verbose logging mode. */
111extern bool g_fVerbose;
112/** Handle to the VirtualBox interface. */
113extern ComPtr<IVirtualBox> g_pVirtualBox;
114/** Handle to the session interface. */
115extern ComPtr<ISession> g_pSession;
116/** handle to the VirtualBox interface. */
117extern ComPtr<IVirtualBoxClient> g_pVirtualBoxClient;
118/**
119 * System log type.
120 */
121typedef enum AUTOSTARTLOGTYPE
122{
123 /** Invalid log type. */
124 AUTOSTARTLOGTYPE_INVALID = 0,
125 /** Log info message. */
126 AUTOSTARTLOGTYPE_INFO,
127 /** Log error message. */
128 AUTOSTARTLOGTYPE_ERROR,
129 /** Log warning message. */
130 AUTOSTARTLOGTYPE_WARNING,
131 /** Log verbose message, only if verbose mode is activated. */
132 AUTOSTARTLOGTYPE_VERBOSE,
133 /** Famous 32bit hack. */
134 AUTOSTARTLOGTYPE_32BIT_HACK = 0x7fffffff
135} AUTOSTARTLOGTYPE;
136
137/**
138 * Prints the service header header (product name, version, ++) to stdout.
139 */
140DECLHIDDEN(void) autostartSvcShowHeader(void);
141
142/**
143 * Prints the service version information header to stdout.
144 *
145 * @param fBrief Whether to show brief information or not.
146 */
147DECLHIDDEN(void) autostartSvcShowVersion(bool fBrief);
148
149/**
150 * Log messages to the system and release log.
151 *
152 * @returns nothing.
153 * @param pszMsg Message to log.
154 * @param enmLogType Log type to use.
155 */
156DECLHIDDEN(void) autostartSvcOsLogStr(const char *pszMsg, AUTOSTARTLOGTYPE enmLogType);
157
158/**
159 * Print out progress on the console.
160 *
161 * This runs the main event queue every now and then to prevent piling up
162 * unhandled things (which doesn't cause real problems, just makes things
163 * react a little slower than in the ideal case).
164 */
165DECLHIDDEN(HRESULT) showProgress(ComPtr<IProgress> progress);
166
167/**
168 * Converts the machine state to a human readable string.
169 *
170 * @returns Pointer to the human readable state.
171 * @param enmMachineState Machine state to convert.
172 * @param fShort Flag whether to return a short form.
173 */
174DECLHIDDEN(const char *) machineStateToName(MachineState_T enmMachineState, bool fShort);
175
176/**
177 * Parse the given configuration file and return the interesting config parameters.
178 *
179 * @returns VBox status code.
180 * @param pszFilename The config file to parse.
181 * @param ppCfgAst Where to store the pointer to the root AST node on success.
182 */
183DECLHIDDEN(int) autostartParseConfig(const char *pszFilename, PCFGAST *ppCfgAst);
184
185/**
186 * Destroys the config AST and frees all resources.
187 *
188 * @returns nothing.
189 * @param pCfgAst The config AST.
190 */
191DECLHIDDEN(void) autostartConfigAstDestroy(PCFGAST pCfgAst);
192
193/**
194 * Return the config AST node with the given name or NULL if it doesn't exist.
195 *
196 * @returns Matching config AST node for the given name or NULL if not found.
197 * @param pCfgAst The config ASt to search.
198 * @param pszName The name to search for.
199 */
200DECLHIDDEN(PCFGAST) autostartConfigAstGetByName(PCFGAST pCfgAst, const char *pszName);
201
202/**
203 * Main routine for the autostart daemon.
204 *
205 * @returns VBox status code.
206 * @param pCfgAst Config AST for the startup part of the autostart daemon.
207 */
208DECLHIDDEN(int) autostartStartMain(PCFGAST pCfgAst);
209
210/**
211 * Main routine for the autostart daemon when stopping virtual machines
212 * during system shutdown.
213 *
214 * @returns VBox status code.
215 * @param pCfgAst Config AST for the shutdown part of the autostart daemon.
216 */
217DECLHIDDEN(int) autostartStopMain(PCFGAST pCfgAst);
218
219/**
220 * Logs a verbose message to the appropriate system log and stdout + release log (if configured).
221 *
222 * @param cVerbosity Verbosity level when logging should happen.
223 * @param pszFormat The log string. No trailing newline.
224 * @param ... Format arguments.
225 */
226DECLHIDDEN(void) autostartSvcLogVerboseV(unsigned cVerbosity, const char *pszFormat, va_list va);
227
228/**
229 * Logs a verbose message to the appropriate system log and stdout + release log (if configured).
230 *
231 * @param cVerbosity Verbosity level when logging should happen.
232 * @param pszFormat The log string. No trailing newline.
233 * @param ... Format arguments.
234 */
235DECLHIDDEN(void) autostartSvcLogVerbose(unsigned cVerbosity, const char *pszFormat, ...);
236
237/**
238 * Logs a warning message to the appropriate system log and stdout + release log (if configured).
239 *
240 * @param pszFormat The log string. No trailing newline.
241 * @param ... Format arguments.
242 */
243DECLHIDDEN(void) autostartSvcLogWarningV(const char *pszFormat, va_list va);
244
245/**
246 * Logs a warning message to the appropriate system log and stdout + release log (if configured).
247 *
248 * @param pszFormat The log string. No trailing newline.
249 * @param ... Format arguments.
250 */
251DECLHIDDEN(void) autostartSvcLogWarning(const char *pszFormat, ...);
252
253/**
254 * Logs a info message to the appropriate system log and stdout + release log (if configured).
255 *
256 * @param pszFormat The log string. No trailing newline.
257 * @param ... Format arguments.
258 */
259DECLHIDDEN(void) autostartSvcLogInfoV(const char *pszFormat, va_list va);
260
261/**
262 * Logs a info message to the appropriate system log and stdout + release log (if configured).
263 *
264 * @param pszFormat The log string. No trailing newline.
265 * @param ... Format arguments.
266 */
267DECLHIDDEN(void) autostartSvcLogInfo(const char *pszFormat, ...);
268
269/**
270 * Logs the message to the appropriate system log and stderr + release log (if configured).
271 *
272 * In debug builds this will also put it in the debug log.
273 *
274 * @returns VBox status code.
275 * @param pszFormat The log string. No trailing newline.
276 * @param ... Format arguments.
277 */
278DECLHIDDEN(int) autostartSvcLogErrorV(const char *pszFormat, va_list va);
279
280/**
281 * Logs the message to the appropriate system log and stderr + release log (if configured).
282 *
283 * In debug builds this will also put it in the debug log.
284 *
285 * @returns VBox status code.
286 * @param pszFormat The log string. No trailing newline.
287 * @param ... Format arguments.
288 */
289DECLHIDDEN(int) autostartSvcLogError(const char *pszFormat, ...);
290
291/**
292 * Logs the message to the appropriate system log.
293 *
294 * In debug builds this will also put it in the debug log.
295 *
296 * @returns VBox status code specified by \a rc.
297 * @param pszFormat The log string. No trailing newline.
298 * @param ... Format arguments.
299 *
300 * @note Convenience function to return directly with the specified \a rc.
301 */
302DECLHIDDEN(int) autostartSvcLogErrorRcV(int rc, const char *pszFormat, va_list va);
303
304/**
305 * Logs the error message to the appropriate system log.
306 *
307 * In debug builds this will also put it in the debug log.
308 *
309 * @returns VBox status code specified by \a rc.
310 * @param pszFormat The log string. No trailing newline.
311 * @param ... Format arguments.
312 *
313 * @note Convenience function to return directly with the specified \a rc.
314 */
315DECLHIDDEN(int) autostartSvcLogErrorRc(int rc, const char *pszFormat, ...);
316
317/**
318 * Deals with RTGetOpt failure, bitching in the system log.
319 *
320 * @returns VBox status code specified by \a rc.
321 * @param pszAction The action name.
322 * @param rc The RTGetOpt return value.
323 * @param argc The argument count.
324 * @param argv The argument vector.
325 * @param iArg The argument index.
326 * @param pValue The value returned by RTGetOpt.
327 */
328DECLHIDDEN(int) autostartSvcLogGetOptError(const char *pszAction, int rc, int argc, char **argv, int iArg, PCRTGETOPTUNION pValue);
329
330/**
331 * Bitch about too many arguments (after RTGetOpt stops) in the system log.
332 *
333 * @returns VERR_INVALID_PARAMETER
334 * @param pszAction The action name.
335 * @param argc The argument count.
336 * @param argv The argument vector.
337 * @param iArg The argument index.
338 */
339DECLHIDDEN(int) autostartSvcLogTooManyArgsError(const char *pszAction, int argc, char **argv, int iArg);
340
341/**
342 * Prints an error message to the screen.
343 *
344 * @returns RTEXITCODE
345 * @param pszFormat The message format string.
346 * @param va Format arguments.
347 */
348DECLHIDDEN(RTEXITCODE) autostartSvcDisplayErrorV(const char *pszFormat, va_list va);
349
350/**
351 * Prints an error message to the screen.
352 *
353 * @returns RTEXITCODE
354 * @param pszFormat The message format string.
355 * @param ... Format arguments.
356 */
357DECLHIDDEN(RTEXITCODE) autostartSvcDisplayError(const char *pszFormat, ...);
358
359/**
360 * Deals with RTGetOpt failure, i.e. an syntax error.
361 *
362 * @returns RTEXITCODE_SYNTAX
363 * @param pszAction The action name.
364 * @param rc The RTGetOpt return value.
365 * @param pValue The value returned by RTGetOpt.
366 */
367DECLHIDDEN(RTEXITCODE) autostartSvcDisplayGetOptError(const char *pszAction, int rc, PCRTGETOPTUNION pValue);
368
369/**
370 * Starts the autostart environment by initializing all needed (global) objects.
371 *
372 * @returns VBox status code.
373 *
374 * @note This currently does NOT support multiple instances, be aware of this!
375 */
376DECLHIDDEN(int) autostartSetup(void);
377
378/**
379 * Stops the autostart environment.
380 *
381 * @note This currently does NOT support multiple instances, be aware of this!
382 */
383DECLHIDDEN(void) autostartShutdown(void);
384
385#endif /* !VBOX_INCLUDED_SRC_VBoxAutostart_VBoxAutostart_h */
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