VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h@ 42194

Last change on this file since 42194 was 42194, checked in by vboxsync, 13 years ago

Guest Control 2.0: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/** @file
2 *
3 * Internal helpers/structures for guest control functionality.
4 */
5
6/*
7 * Copyright (C) 2011-2012 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 ____H_GUESTIMPLPRIVATE
19#define ____H_GUESTIMPLPRIVATE
20
21#include <iprt/semaphore.h>
22
23#include <VBox/com/com.h>
24#include <VBox/com/ErrorInfo.h>
25#include <VBox/com/string.h>
26#include <VBox/com/VirtualBox.h>
27
28#include <map>
29#include <vector>
30
31using namespace com;
32
33#ifdef VBOX_WITH_GUEST_CONTROL
34# include <VBox/HostServices/GuestControlSvc.h>
35using namespace guestControl;
36#endif
37
38
39/* Builds a context ID out of the session ID, process ID and an
40 * increasing count. */
41#define VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession, uProcess, uCount) \
42 ( (uint32_t)((uSession) & 0xff) << 24 \
43 | (uint32_t)((uProcess) & 0xff) << 16 \
44 | (uint32_t)((uCount) & 0xffff) \
45 )
46
47
48typedef std::vector <LONG> ProcessAffinity;
49typedef std::vector <Utf8Str> ProcessArguments;
50
51
52/**
53 * Generic class for a all guest control callbacks.
54 */
55class GuestCtrlCallback
56{
57public:
58
59 GuestCtrlCallback(void);
60
61 GuestCtrlCallback(eVBoxGuestCtrlCallbackType enmType);
62
63 virtual ~GuestCtrlCallback(void);
64
65 /** @todo Copy/comparison operator? */
66
67public:
68
69 int Init(eVBoxGuestCtrlCallbackType enmType);
70
71 void Destroy(void);
72
73 eVBoxGuestCtrlCallbackType Type(void);
74
75 int Wait(RTMSINTERVAL timeoutMS);
76
77protected:
78
79 /** The callback type. */
80 eVBoxGuestCtrlCallbackType mType;
81 /** Callback flags. */
82 uint32_t mFlags;
83 /** Pointer to user-supplied data. */
84 void *pvData;
85 /** Size of user-supplied data. */
86 size_t cbData;
87 /** The event semaphore triggering the*/
88 RTSEMEVENT mEventSem;
89 /** Extended error information, if any. */
90 ErrorInfo mErrorInfo;
91};
92typedef std::map <uint32_t, GuestCtrlCallback> GuestCtrlCallbacks;
93
94/**
95 * Simple structure mantaining guest credentials.
96 */
97class GuestCredentials
98{
99public:
100
101
102public:
103
104 Utf8Str mUser;
105 Utf8Str mPassword;
106 Utf8Str mDomain;
107};
108
109typedef std::vector <Utf8Str> GuestEnvironmentArray;
110class GuestEnvironment
111{
112public:
113
114 int BuildEnvironmentBlock(void **ppvEnv, uint32_t *pcbEnv, uint32_t *pcEnvVars);
115
116 void Clear(void);
117
118 int CopyFrom(const GuestEnvironmentArray &environment);
119
120 int CopyTo(GuestEnvironmentArray &environment);
121
122 static void FreeEnvironmentBlock(void *pvEnv);
123
124 Utf8Str Get(const Utf8Str &strKey);
125
126 Utf8Str Get(size_t nPos);
127
128 bool Has(const Utf8Str &strKey);
129
130 int Set(const Utf8Str &strKey, const Utf8Str &strValue);
131
132 int Set(const Utf8Str &strPair);
133
134 size_t Size(void);
135
136 int Unset(const Utf8Str &strKey);
137
138public:
139
140 GuestEnvironment& operator=(const GuestEnvironmentArray &that);
141
142 GuestEnvironment& operator=(const GuestEnvironment &that);
143
144protected:
145
146 int appendToEnvBlock(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnvVars);
147
148protected:
149
150 std::map <Utf8Str, Utf8Str> mEnvironment;
151};
152
153
154/**
155 * Structure for keeping all the relevant process
156 * starting parameters around.
157 */
158struct GuestProcessInfo
159{
160 Utf8Str mCommand;
161 ProcessArguments mArguments;
162 GuestEnvironment mEnvironment;
163 uint32_t mFlags;
164 ULONG mTimeoutMS;
165 ProcessPriority_T mPriority;
166 ProcessAffinity mAffinity;
167};
168
169/**
170 * Class representing the "value" side of a "key=value" pair.
171 */
172class GuestProcessStreamValue
173{
174public:
175
176 GuestProcessStreamValue() { }
177 GuestProcessStreamValue(const char *pszValue)
178 : mValue(pszValue) {}
179
180 GuestProcessStreamValue(const GuestProcessStreamValue& aThat)
181 : mValue(aThat.mValue) {}
182
183 Utf8Str mValue;
184};
185
186/** Map containing "key=value" pairs of a guest process stream. */
187typedef std::pair< Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPair;
188typedef std::map < Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPairMap;
189typedef std::map < Utf8Str, GuestProcessStreamValue >::iterator GuestCtrlStreamPairMapIter;
190typedef std::map < Utf8Str, GuestProcessStreamValue >::const_iterator GuestCtrlStreamPairMapIterConst;
191
192/**
193 * Class representing a block of stream pairs (key=value). Each block in a raw guest
194 * output stream is separated by "\0\0", each pair is separated by "\0". The overall
195 * end of a guest stream is marked by "\0\0\0\0".
196 */
197class GuestProcessStreamBlock
198{
199public:
200
201 GuestProcessStreamBlock();
202
203 //GuestProcessStreamBlock(GuestProcessStreamBlock &);
204
205 virtual ~GuestProcessStreamBlock();
206
207public:
208
209 void Clear();
210
211#ifdef DEBUG
212 void Dump();
213#endif
214
215 int GetInt64Ex(const char *pszKey, int64_t *piVal);
216
217 int64_t GetInt64(const char *pszKey);
218
219 size_t GetCount();
220
221 const char* GetString(const char *pszKey);
222
223 int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
224
225 uint32_t GetUInt32(const char *pszKey);
226
227 int SetValue(const char *pszKey, const char *pszValue);
228
229protected:
230
231 GuestCtrlStreamPairMap m_mapPairs;
232};
233
234/** Vector containing multiple allocated stream pair objects. */
235typedef std::vector< GuestProcessStreamBlock > GuestCtrlStreamObjects;
236typedef std::vector< GuestProcessStreamBlock >::iterator GuestCtrlStreamObjectsIter;
237typedef std::vector< GuestProcessStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
238
239/**
240 * Class for parsing machine-readable guest process output by VBoxService'
241 * toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
242 */
243class GuestProcessStream
244{
245
246public:
247
248 GuestProcessStream();
249
250 virtual ~GuestProcessStream();
251
252public:
253
254 int AddData(const BYTE *pbData, size_t cbData);
255
256 void Destroy();
257
258#ifdef DEBUG
259 void Dump(const char *pszFile);
260#endif
261
262 uint32_t GetOffset();
263
264 uint32_t GetSize();
265
266 int ParseBlock(GuestProcessStreamBlock &streamBlock);
267
268protected:
269
270 /** Currently allocated size of internal stream buffer. */
271 uint32_t m_cbAllocated;
272 /** Currently used size of allocated internal stream buffer. */
273 uint32_t m_cbSize;
274 /** Current offset within the internal stream buffer. */
275 uint32_t m_cbOffset;
276 /** Internal stream buffer. */
277 BYTE *m_pbBuffer;
278};
279
280class Guest;
281class Progress;
282
283class GuestTask
284{
285
286public:
287
288 enum TaskType
289 {
290 /** Copies a file from host to the guest. */
291 TaskType_CopyFileToGuest = 50,
292 /** Copies a file from guest to the host. */
293 TaskType_CopyFileFromGuest = 55,
294 /** Update Guest Additions by directly copying the required installer
295 * off the .ISO file, transfer it to the guest and execute the installer
296 * with system privileges. */
297 TaskType_UpdateGuestAdditions = 100
298 };
299
300 GuestTask(TaskType aTaskType, Guest *aThat, Progress *aProgress);
301
302 virtual ~GuestTask();
303
304 int startThread();
305
306 static int taskThread(RTTHREAD aThread, void *pvUser);
307 static int uploadProgress(unsigned uPercent, void *pvUser);
308 static HRESULT setProgressSuccess(ComObjPtr<Progress> pProgress);
309 static HRESULT setProgressErrorMsg(HRESULT hr,
310 ComObjPtr<Progress> pProgress, const char * pszText, ...);
311 static HRESULT setProgressErrorParent(HRESULT hr,
312 ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest);
313
314 TaskType taskType;
315 ComObjPtr<Guest> pGuest;
316 ComObjPtr<Progress> pProgress;
317 HRESULT rc;
318
319 /* Task data. */
320 Utf8Str strSource;
321 Utf8Str strDest;
322 Utf8Str strUserName;
323 Utf8Str strPassword;
324 ULONG uFlags;
325};
326#endif // ____H_GUESTIMPLPRIVATE
327
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette