VirtualBox

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

Last change on this file since 42160 was 42160, checked in by vboxsync, 12 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: 7.1 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;
50typedef std::map <Utf8Str, Utf8Str> ProcessEnvironmentMap;
51
52
53/**
54 * Generic class for a all guest control callbacks.
55 */
56class GuestCtrlCallback
57{
58public:
59
60 GuestCtrlCallback(void);
61
62 GuestCtrlCallback(eVBoxGuestCtrlCallbackType enmType);
63
64 virtual ~GuestCtrlCallback(void);
65
66 /** @todo Copy/comparison operator? */
67
68public:
69
70 int Init(eVBoxGuestCtrlCallbackType enmType);
71
72 void Destroy(void);
73
74 eVBoxGuestCtrlCallbackType Type(void);
75
76 int Wait(RTMSINTERVAL timeoutMS);
77
78protected:
79
80 /** The callback type. */
81 eVBoxGuestCtrlCallbackType mType;
82 /** Callback flags. */
83 uint32_t mFlags;
84 /** Pointer to user-supplied data. */
85 void *pvData;
86 /** Size of user-supplied data. */
87 size_t cbData;
88 /** The event semaphore triggering the*/
89 RTSEMEVENT mEventSem;
90 /** Extended error information, if any. */
91 ErrorInfo mErrorInfo;
92};
93typedef std::map <uint32_t, GuestCtrlCallback> GuestCtrlCallbacks;
94
95/**
96 * Simple structure mantaining guest credentials.
97 */
98class GuestCredentials
99{
100public:
101
102
103public:
104
105 Utf8Str mUser;
106 Utf8Str mPassword;
107 Utf8Str mDomain;
108};
109
110/**
111 * Structure for keeping all the relevant process
112 * starting parameters around.
113 */
114struct GuestProcessInfo
115{
116 Utf8Str mCommand;
117 ProcessArguments mArguments;
118 ProcessEnvironmentMap mEnvironment;
119 uint32_t mFlags;
120 ULONG mTimeoutMS;
121 ProcessPriority_T mPriority;
122 ProcessAffinity mAffinity;
123};
124
125/**
126 * Class representing the "value" side of a "key=value" pair.
127 */
128class GuestProcessStreamValue
129{
130public:
131
132 GuestProcessStreamValue() { }
133 GuestProcessStreamValue(const char *pszValue)
134 : mValue(pszValue) {}
135
136 GuestProcessStreamValue(const GuestProcessStreamValue& aThat)
137 : mValue(aThat.mValue) {}
138
139 Utf8Str mValue;
140};
141
142/** Map containing "key=value" pairs of a guest process stream. */
143typedef std::pair< Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPair;
144typedef std::map < Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPairMap;
145typedef std::map < Utf8Str, GuestProcessStreamValue >::iterator GuestCtrlStreamPairMapIter;
146typedef std::map < Utf8Str, GuestProcessStreamValue >::const_iterator GuestCtrlStreamPairMapIterConst;
147
148/**
149 * Class representing a block of stream pairs (key=value). Each block in a raw guest
150 * output stream is separated by "\0\0", each pair is separated by "\0". The overall
151 * end of a guest stream is marked by "\0\0\0\0".
152 */
153class GuestProcessStreamBlock
154{
155public:
156
157 GuestProcessStreamBlock();
158
159 //GuestProcessStreamBlock(GuestProcessStreamBlock &);
160
161 virtual ~GuestProcessStreamBlock();
162
163public:
164
165 void Clear();
166
167#ifdef DEBUG
168 void Dump();
169#endif
170
171 int GetInt64Ex(const char *pszKey, int64_t *piVal);
172
173 int64_t GetInt64(const char *pszKey);
174
175 size_t GetCount();
176
177 const char* GetString(const char *pszKey);
178
179 int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
180
181 uint32_t GetUInt32(const char *pszKey);
182
183 int SetValue(const char *pszKey, const char *pszValue);
184
185protected:
186
187 GuestCtrlStreamPairMap m_mapPairs;
188};
189
190/** Vector containing multiple allocated stream pair objects. */
191typedef std::vector< GuestProcessStreamBlock > GuestCtrlStreamObjects;
192typedef std::vector< GuestProcessStreamBlock >::iterator GuestCtrlStreamObjectsIter;
193typedef std::vector< GuestProcessStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
194
195/**
196 * Class for parsing machine-readable guest process output by VBoxService'
197 * toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
198 */
199class GuestProcessStream
200{
201
202public:
203
204 GuestProcessStream();
205
206 virtual ~GuestProcessStream();
207
208public:
209
210 int AddData(const BYTE *pbData, size_t cbData);
211
212 void Destroy();
213
214#ifdef DEBUG
215 void Dump(const char *pszFile);
216#endif
217
218 uint32_t GetOffset();
219
220 uint32_t GetSize();
221
222 int ParseBlock(GuestProcessStreamBlock &streamBlock);
223
224protected:
225
226 /** Currently allocated size of internal stream buffer. */
227 uint32_t m_cbAllocated;
228 /** Currently used size of allocated internal stream buffer. */
229 uint32_t m_cbSize;
230 /** Current offset within the internal stream buffer. */
231 uint32_t m_cbOffset;
232 /** Internal stream buffer. */
233 BYTE *m_pbBuffer;
234};
235
236class Guest;
237class Progress;
238
239class GuestTask
240{
241
242public:
243
244 enum TaskType
245 {
246 /** Copies a file from host to the guest. */
247 TaskType_CopyFileToGuest = 50,
248 /** Copies a file from guest to the host. */
249 TaskType_CopyFileFromGuest = 55,
250 /** Update Guest Additions by directly copying the required installer
251 * off the .ISO file, transfer it to the guest and execute the installer
252 * with system privileges. */
253 TaskType_UpdateGuestAdditions = 100
254 };
255
256 GuestTask(TaskType aTaskType, Guest *aThat, Progress *aProgress);
257
258 virtual ~GuestTask();
259
260 int startThread();
261
262 static int taskThread(RTTHREAD aThread, void *pvUser);
263 static int uploadProgress(unsigned uPercent, void *pvUser);
264 static HRESULT setProgressSuccess(ComObjPtr<Progress> pProgress);
265 static HRESULT setProgressErrorMsg(HRESULT hr,
266 ComObjPtr<Progress> pProgress, const char * pszText, ...);
267 static HRESULT setProgressErrorParent(HRESULT hr,
268 ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest);
269
270 TaskType taskType;
271 ComObjPtr<Guest> pGuest;
272 ComObjPtr<Progress> pProgress;
273 HRESULT rc;
274
275 /* Task data. */
276 Utf8Str strSource;
277 Utf8Str strDest;
278 Utf8Str strUserName;
279 Utf8Str strPassword;
280 ULONG uFlags;
281};
282#endif // ____H_GUESTIMPLPRIVATE
283
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