VirtualBox

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

Last change on this file since 64739 was 62493, checked in by vboxsync, 8 years ago

(C) 2016

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