VirtualBox

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

Last change on this file since 86223 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1/* $Id: VBoxAutostart.h 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBoxAutostart - VirtualBox Autostart service.
4 */
5
6/*
7 * Copyright (C) 2012-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_VBoxAutostart_VBoxAutostart_h
19#define VBOX_INCLUDED_SRC_VBoxAutostart_VBoxAutostart_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <iprt/getopt.h>
28#include <iprt/types.h>
29
30#include <VBox/cdefs.h>
31#include <VBox/types.h>
32
33#include <VBox/com/com.h>
34#include <VBox/com/VirtualBox.h>
35
36/*******************************************************************************
37* Constants And Macros, Structures and Typedefs *
38*******************************************************************************/
39
40/**
41 * Config AST node types.
42 */
43typedef enum CFGASTNODETYPE
44{
45 /** Invalid. */
46 CFGASTNODETYPE_INVALID = 0,
47 /** Key/Value pair. */
48 CFGASTNODETYPE_KEYVALUE,
49 /** Compound type. */
50 CFGASTNODETYPE_COMPOUND,
51 /** List type. */
52 CFGASTNODETYPE_LIST,
53 /** 32bit hack. */
54 CFGASTNODETYPE_32BIT_HACK = 0x7fffffff
55} CFGASTNODETYPE;
56/** Pointer to a config AST node type. */
57typedef CFGASTNODETYPE *PCFGASTNODETYPE;
58/** Pointer to a const config AST node type. */
59typedef const CFGASTNODETYPE *PCCFGASTNODETYPE;
60
61/**
62 * Config AST.
63 */
64typedef struct CFGAST
65{
66 /** AST node type. */
67 CFGASTNODETYPE enmType;
68 /** Key or scope id. */
69 char *pszKey;
70 /** Type dependent data. */
71 union
72 {
73 /** Key value pair. */
74 struct
75 {
76 /** Number of characters in the value - excluding terminator. */
77 size_t cchValue;
78 /** Value string - variable in size. */
79 char aszValue[1];
80 } KeyValue;
81 /** Compound type. */
82 struct
83 {
84 /** Number of AST node entries in the array. */
85 unsigned cAstNodes;
86 /** AST node array - variable in size. */
87 struct CFGAST *apAstNodes[1];
88 } Compound;
89 /** List type. */
90 struct
91 {
92 /** Number of entries in the list. */
93 unsigned cListEntries;
94 /** Array of list entries - variable in size. */
95 char *apszEntries[1];
96 } List;
97 } u;
98} CFGAST, *PCFGAST;
99
100/** Flag whether we are in verbose logging mode. */
101extern bool g_fVerbose;
102/** Handle to the VirtualBox interface. */
103extern ComPtr<IVirtualBox> g_pVirtualBox;
104/** Handle to the session interface. */
105extern ComPtr<ISession> g_pSession;
106/** handle to the VirtualBox interface. */
107extern ComPtr<IVirtualBoxClient> g_pVirtualBoxClient;
108/**
109 * System log type.
110 */
111typedef enum AUTOSTARTLOGTYPE
112{
113 /** Invalid log type. */
114 AUTOSTARTLOGTYPE_INVALID = 0,
115 /** Log info message. */
116 AUTOSTARTLOGTYPE_INFO,
117 /** Log error message. */
118 AUTOSTARTLOGTYPE_ERROR,
119 /** Log warning message. */
120 AUTOSTARTLOGTYPE_WARNING,
121 /** Log verbose message, only if verbose mode is activated. */
122 AUTOSTARTLOGTYPE_VERBOSE,
123 /** Famous 32bit hack. */
124 AUTOSTARTLOGTYPE_32BIT_HACK = 0x7fffffff
125} AUTOSTARTLOGTYPE;
126
127/**
128 * Log messages to the system and release log.
129 *
130 * @returns nothing.
131 * @param pszMsg Message to log.
132 * @param enmLogType Log type to use.
133 */
134DECLHIDDEN(void) autostartSvcOsLogStr(const char *pszMsg, AUTOSTARTLOGTYPE enmLogType);
135
136/**
137 * Print out progress on the console.
138 *
139 * This runs the main event queue every now and then to prevent piling up
140 * unhandled things (which doesn't cause real problems, just makes things
141 * react a little slower than in the ideal case).
142 */
143DECLHIDDEN(HRESULT) showProgress(ComPtr<IProgress> progress);
144
145/**
146 * Converts the machine state to a human readable string.
147 *
148 * @returns Pointer to the human readable state.
149 * @param enmMachineState Machine state to convert.
150 * @param fShort Flag whether to return a short form.
151 */
152DECLHIDDEN(const char *) machineStateToName(MachineState_T enmMachineState, bool fShort);
153
154/**
155 * Parse the given configuration file and return the interesting config parameters.
156 *
157 * @returns VBox status code.
158 * @param pszFilename The config file to parse.
159 * @param ppCfgAst Where to store the pointer to the root AST node on success.
160 */
161DECLHIDDEN(int) autostartParseConfig(const char *pszFilename, PCFGAST *ppCfgAst);
162
163/**
164 * Destroys the config AST and frees all resources.
165 *
166 * @returns nothing.
167 * @param pCfgAst The config AST.
168 */
169DECLHIDDEN(void) autostartConfigAstDestroy(PCFGAST pCfgAst);
170
171/**
172 * Return the config AST node with the given name or NULL if it doesn't exist.
173 *
174 * @returns Matching config AST node for the given name or NULL if not found.
175 * @param pCfgAst The config ASt to search.
176 * @param pszName The name to search for.
177 */
178DECLHIDDEN(PCFGAST) autostartConfigAstGetByName(PCFGAST pCfgAst, const char *pszName);
179
180/**
181 * Main routine for the autostart daemon.
182 *
183 * @returns exit status code.
184 * @param pCfgAst Config AST for the startup part of the autostart daemon.
185 */
186DECLHIDDEN(RTEXITCODE) autostartStartMain(PCFGAST pCfgAst);
187
188/**
189 * Main routine for the autostart daemon when stopping virtual machines
190 * during system shutdown.
191 *
192 * @returns exit status code.
193 * @param pCfgAst Config AST for the shutdown part of the autostart daemon.
194 */
195DECLHIDDEN(RTEXITCODE) autostartStopMain(PCFGAST pCfgAst);
196
197/**
198 * Logs a verbose message to the appropriate system log.
199 *
200 * @param pszFormat The log string. No trailing newline.
201 * @param ... Format arguments.
202 */
203DECLHIDDEN(void) autostartSvcLogVerboseV(const char *pszFormat, va_list va);
204
205/**
206 * Logs a verbose message to the appropriate system log.
207 *
208 * @param pszFormat The log string. No trailing newline.
209 * @param ... Format arguments.
210 */
211DECLHIDDEN(void) autostartSvcLogVerbose(const char *pszFormat, ...);
212
213/**
214 * Logs a warning message to the appropriate system log.
215 *
216 * @param pszFormat The log string. No trailing newline.
217 * @param ... Format arguments.
218 */
219DECLHIDDEN(void) autostartSvcLogWarningV(const char *pszFormat, va_list va);
220
221/**
222 * Logs a warning message to the appropriate system log.
223 *
224 * @param pszFormat The log string. No trailing newline.
225 * @param ... Format arguments.
226 */
227DECLHIDDEN(void) autostartSvcLogWarning(const char *pszFormat, ...);
228
229/**
230 * Logs a info message to the appropriate system log.
231 *
232 * @param pszFormat The log string. No trailing newline.
233 * @param ... Format arguments.
234 */
235DECLHIDDEN(void) autostartSvcLogInfoV(const char *pszFormat, va_list va);
236
237/**
238 * Logs a info message to the appropriate system log.
239 *
240 * @param pszFormat The log string. No trailing newline.
241 * @param ... Format arguments.
242 */
243DECLHIDDEN(void) autostartSvcLogInfo(const char *pszFormat, ...);
244
245/**
246 * Logs the message to the appropriate system log.
247 *
248 * In debug builds this will also put it in the debug log.
249 *
250 * @param pszFormat The log string. No trailing newline.
251 * @param ... Format arguments.
252 *
253 * @todo This should later be replaced by the release logger and callback destination(s).
254 */
255DECLHIDDEN(RTEXITCODE) autostartSvcLogErrorV(const char *pszFormat, va_list va);
256
257/**
258 * Logs the error message to the appropriate system log.
259 *
260 * In debug builds this will also put it in the debug log.
261 *
262 * @param pszFormat The log string. No trailing newline.
263 * @param ... Format arguments.
264 *
265 * @todo This should later be replaced by the release logger and callback destination(s).
266 */
267DECLHIDDEN(RTEXITCODE) autostartSvcLogError(const char *pszFormat, ...);
268
269/**
270 * Deals with RTGetOpt failure, bitching in the system log.
271 *
272 * @returns 1
273 * @param pszAction The action name.
274 * @param rc The RTGetOpt return value.
275 * @param argc The argument count.
276 * @param argv The argument vector.
277 * @param iArg The argument index.
278 * @param pValue The value returned by RTGetOpt.
279 */
280DECLHIDDEN(RTEXITCODE) autostartSvcLogGetOptError(const char *pszAction, int rc, int argc, char **argv, int iArg, PCRTGETOPTUNION pValue);
281
282/**
283 * Bitch about too many arguments (after RTGetOpt stops) in the system log.
284 *
285 * @returns 1
286 * @param pszAction The action name.
287 * @param argc The argument count.
288 * @param argv The argument vector.
289 * @param iArg The argument index.
290 */
291DECLHIDDEN(RTEXITCODE) autostartSvcLogTooManyArgsError(const char *pszAction, int argc, char **argv, int iArg);
292
293/**
294 * Prints an error message to the screen.
295 *
296 * @param pszFormat The message format string.
297 * @param va Format arguments.
298 */
299DECLHIDDEN(RTEXITCODE) autostartSvcDisplayErrorV(const char *pszFormat, va_list va);
300
301/**
302 * Prints an error message to the screen.
303 *
304 * @param pszFormat The message format string.
305 * @param ... Format arguments.
306 */
307DECLHIDDEN(RTEXITCODE) autostartSvcDisplayError(const char *pszFormat, ...);
308
309/**
310 * Deals with RTGetOpt failure, i.e. an syntax error.
311 *
312 * @returns RTEXITCODE_SYNTAX
313 * @param pszAction The action name.
314 * @param rc The RTGetOpt return value.
315 * @param pValue The value returned by RTGetOpt.
316 */
317DECLHIDDEN(RTEXITCODE) autostartSvcDisplayGetOptError(const char *pszAction, int rc, PCRTGETOPTUNION pValue);
318
319DECLHIDDEN(int) autostartSetup();
320
321DECLHIDDEN(void) autostartShutdown();
322
323#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