1 | /* $Id: GuestSessionImpl.h 71231 2018-03-06 10:08:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - Guest session handling.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2018 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_GUESTSESSIONIMPL
|
---|
19 | #define ____H_GUESTSESSIONIMPL
|
---|
20 |
|
---|
21 | #include "GuestSessionWrap.h"
|
---|
22 | #include "EventImpl.h"
|
---|
23 |
|
---|
24 | #include "GuestCtrlImplPrivate.h"
|
---|
25 | #include "GuestProcessImpl.h"
|
---|
26 | #include "GuestDirectoryImpl.h"
|
---|
27 | #include "GuestFileImpl.h"
|
---|
28 | #include "GuestFsObjInfoImpl.h"
|
---|
29 | #include "ThreadTask.h"
|
---|
30 |
|
---|
31 | #include <iprt/isofs.h> /* For UpdateAdditions. */
|
---|
32 |
|
---|
33 | class Guest;
|
---|
34 | class GuestSessionTaskInternalOpen;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Abstract base class for a lenghtly per-session operation which
|
---|
38 | * runs in a Main worker thread.
|
---|
39 | */
|
---|
40 | class GuestSessionTask : public ThreadTask
|
---|
41 | {
|
---|
42 | public:
|
---|
43 |
|
---|
44 | GuestSessionTask(GuestSession *pSession);
|
---|
45 |
|
---|
46 | virtual ~GuestSessionTask(void);
|
---|
47 |
|
---|
48 | public:
|
---|
49 |
|
---|
50 | virtual int Run(void) = 0;
|
---|
51 | void handler()
|
---|
52 | {
|
---|
53 | int vrc = Run();
|
---|
54 | NOREF(vrc);
|
---|
55 | /** @todo
|
---|
56 | *
|
---|
57 | * r=bird: what was your idea WRT to Run status code and async tasks?
|
---|
58 | *
|
---|
59 | */
|
---|
60 | }
|
---|
61 |
|
---|
62 | int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
|
---|
63 |
|
---|
64 | HRESULT Init(const Utf8Str &strTaskDesc)
|
---|
65 | {
|
---|
66 | HRESULT hr = S_OK;
|
---|
67 | setTaskDesc(strTaskDesc);
|
---|
68 | hr = createAndSetProgressObject();
|
---|
69 | return hr;
|
---|
70 | }
|
---|
71 |
|
---|
72 | const ComObjPtr<Progress>& GetProgressObject() const { return mProgress; }
|
---|
73 |
|
---|
74 | protected:
|
---|
75 |
|
---|
76 | /** @name Directory handling primitives.
|
---|
77 | * @{ */
|
---|
78 | int directoryCreate(const com::Utf8Str &strPath, DirectoryCreateFlag_T enmDirecotryCreateFlags, uint32_t uMode,
|
---|
79 | bool fFollowSymlinks);
|
---|
80 | /** @} */
|
---|
81 |
|
---|
82 | /** @name File handling primitives.
|
---|
83 | * @{ */
|
---|
84 | int fileCopyToGuestEx(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags, PRTFILE pFile,
|
---|
85 | uint64_t cbOffset, uint64_t cbSize); /**< r=bird: 'cbOffset' makes no sense what so ever. It should be 'off', or do you mean sizeof(uint64_t)? */
|
---|
86 | int fileCopyToGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
87 | /** @} */
|
---|
88 |
|
---|
89 | /** @name Guest property handling primitives.
|
---|
90 | * @{ */
|
---|
91 | int getGuestProperty(const ComObjPtr<Guest> &pGuest, const Utf8Str &strPath, Utf8Str &strValue);
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 | /** @name Path handling primitives.
|
---|
95 | * @{ */
|
---|
96 | int pathConstructOnGuest(const Utf8Str &strSourceRoot, const Utf8Str &strSource, const Utf8Str &strDest, Utf8Str &strOut);
|
---|
97 | /** @} */
|
---|
98 |
|
---|
99 | int setProgress(ULONG uPercent);
|
---|
100 | int setProgressSuccess(void);
|
---|
101 | HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
|
---|
102 |
|
---|
103 | inline void setTaskDesc(const Utf8Str &strTaskDesc) throw()
|
---|
104 | {
|
---|
105 | mDesc = strTaskDesc;
|
---|
106 | }
|
---|
107 |
|
---|
108 | HRESULT createAndSetProgressObject();
|
---|
109 |
|
---|
110 | protected:
|
---|
111 |
|
---|
112 | Utf8Str mDesc;
|
---|
113 | /** The guest session object this task is working on. */
|
---|
114 | ComObjPtr<GuestSession> mSession;
|
---|
115 | /** Progress object for getting updated when running
|
---|
116 | * asynchronously. Optional. */
|
---|
117 | ComObjPtr<Progress> mProgress;
|
---|
118 | };
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Task for opening a guest session.
|
---|
122 | */
|
---|
123 | class SessionTaskOpen : public GuestSessionTask
|
---|
124 | {
|
---|
125 | public:
|
---|
126 |
|
---|
127 | SessionTaskOpen(GuestSession *pSession,
|
---|
128 | uint32_t uFlags,
|
---|
129 | uint32_t uTimeoutMS);
|
---|
130 | virtual ~SessionTaskOpen(void);
|
---|
131 | int Run(void);
|
---|
132 |
|
---|
133 | protected:
|
---|
134 |
|
---|
135 | /** Session creation flags. */
|
---|
136 | uint32_t mFlags;
|
---|
137 | /** Session creation timeout (in ms). */
|
---|
138 | uint32_t mTimeoutMS;
|
---|
139 | };
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Task for copying directories from guest to the host.
|
---|
143 | */
|
---|
144 | class SessionTaskCopyDirFrom : public GuestSessionTask
|
---|
145 | {
|
---|
146 | public:
|
---|
147 |
|
---|
148 | SessionTaskCopyDirFrom(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
|
---|
149 | DirectoryCopyFlag_T enmDirCopyFlags);
|
---|
150 | virtual ~SessionTaskCopyDirFrom(void);
|
---|
151 | int Run(void);
|
---|
152 |
|
---|
153 | protected:
|
---|
154 |
|
---|
155 | int directoryCopyToHost(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
|
---|
156 | bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
|
---|
157 | protected:
|
---|
158 |
|
---|
159 | Utf8Str mSource;
|
---|
160 | Utf8Str mDest;
|
---|
161 | Utf8Str mFilter;
|
---|
162 | DirectoryCopyFlag_T mDirCopyFlags;
|
---|
163 | };
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Task for copying directories from host to the guest.
|
---|
167 | */
|
---|
168 | class SessionTaskCopyDirTo : public GuestSessionTask
|
---|
169 | {
|
---|
170 | public:
|
---|
171 |
|
---|
172 | SessionTaskCopyDirTo(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
|
---|
173 | DirectoryCopyFlag_T enmDirCopyFlags);
|
---|
174 | virtual ~SessionTaskCopyDirTo(void);
|
---|
175 | int Run(void);
|
---|
176 |
|
---|
177 | protected:
|
---|
178 |
|
---|
179 | int directoryCopyToGuest(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
|
---|
180 | bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
|
---|
181 | protected:
|
---|
182 |
|
---|
183 | Utf8Str mSource;
|
---|
184 | Utf8Str mDest;
|
---|
185 | Utf8Str mFilter;
|
---|
186 | DirectoryCopyFlag_T mDirCopyFlags;
|
---|
187 | };
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Task for copying files from host to the guest.
|
---|
191 | */
|
---|
192 | class SessionTaskCopyFileTo : public GuestSessionTask
|
---|
193 | {
|
---|
194 | public:
|
---|
195 |
|
---|
196 | SessionTaskCopyFileTo(GuestSession *pSession,
|
---|
197 | const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
|
---|
198 | SessionTaskCopyFileTo(GuestSession *pSession,
|
---|
199 | PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
|
---|
200 | const Utf8Str &strDest, uint32_t uFlags);
|
---|
201 | virtual ~SessionTaskCopyFileTo(void);
|
---|
202 | int Run(void);
|
---|
203 |
|
---|
204 | protected:
|
---|
205 |
|
---|
206 | Utf8Str mSource;
|
---|
207 | PRTFILE mSourceFile;
|
---|
208 | size_t mSourceOffset;
|
---|
209 | uint64_t mSourceSize;
|
---|
210 | Utf8Str mDest;
|
---|
211 | uint32_t mCopyFileFlags;
|
---|
212 | };
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Task for copying files from guest to the host.
|
---|
216 | */
|
---|
217 | class SessionTaskCopyFileFrom : public GuestSessionTask
|
---|
218 | {
|
---|
219 | public:
|
---|
220 |
|
---|
221 | SessionTaskCopyFileFrom(GuestSession *pSession,
|
---|
222 | const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
|
---|
223 | virtual ~SessionTaskCopyFileFrom(void);
|
---|
224 | int Run(void);
|
---|
225 |
|
---|
226 | protected:
|
---|
227 |
|
---|
228 | Utf8Str mSource;
|
---|
229 | Utf8Str mDest;
|
---|
230 | uint32_t mFlags;
|
---|
231 | };
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Task for automatically updating the Guest Additions on the guest.
|
---|
235 | */
|
---|
236 | class SessionTaskUpdateAdditions : public GuestSessionTask
|
---|
237 | {
|
---|
238 | public:
|
---|
239 |
|
---|
240 | SessionTaskUpdateAdditions(GuestSession *pSession,
|
---|
241 | const Utf8Str &strSource, const ProcessArguments &aArguments,
|
---|
242 | uint32_t uFlags);
|
---|
243 | virtual ~SessionTaskUpdateAdditions(void);
|
---|
244 | int Run(void);
|
---|
245 |
|
---|
246 | protected:
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Suported OS types for automatic updating.
|
---|
250 | */
|
---|
251 | enum eOSType
|
---|
252 | {
|
---|
253 | eOSType_Unknown = 0,
|
---|
254 | eOSType_Windows = 1,
|
---|
255 | eOSType_Linux = 2,
|
---|
256 | eOSType_Solaris = 3
|
---|
257 | };
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Structure representing a file to
|
---|
261 | * get off the .ISO, copied to the guest.
|
---|
262 | */
|
---|
263 | struct InstallerFile
|
---|
264 | {
|
---|
265 | InstallerFile(const Utf8Str &aSource,
|
---|
266 | const Utf8Str &aDest,
|
---|
267 | uint32_t aFlags = 0)
|
---|
268 | : strSource(aSource),
|
---|
269 | strDest(aDest),
|
---|
270 | fFlags(aFlags) { }
|
---|
271 |
|
---|
272 | InstallerFile(const Utf8Str &aSource,
|
---|
273 | const Utf8Str &aDest,
|
---|
274 | uint32_t aFlags,
|
---|
275 | const GuestProcessStartupInfo &aStartupInfo)
|
---|
276 | : strSource(aSource),
|
---|
277 | strDest(aDest),
|
---|
278 | fFlags(aFlags),
|
---|
279 | mProcInfo(aStartupInfo)
|
---|
280 | {
|
---|
281 | mProcInfo.mExecutable = strDest;
|
---|
282 | if (mProcInfo.mName.isEmpty())
|
---|
283 | mProcInfo.mName = strDest;
|
---|
284 | }
|
---|
285 |
|
---|
286 | /** Source file on .ISO. */
|
---|
287 | Utf8Str strSource;
|
---|
288 | /** Destination file on the guest. */
|
---|
289 | Utf8Str strDest;
|
---|
290 | /** File flags. */
|
---|
291 | uint32_t fFlags;
|
---|
292 | /** Optional arguments if this file needs to be
|
---|
293 | * executed. */
|
---|
294 | GuestProcessStartupInfo mProcInfo;
|
---|
295 | };
|
---|
296 |
|
---|
297 | int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
|
---|
298 | int copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional, uint32_t *pcbSize);
|
---|
299 | int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
|
---|
300 |
|
---|
301 | /** Files to handle. */
|
---|
302 | std::vector<InstallerFile> mFiles;
|
---|
303 | /** The (optionally) specified Guest Additions .ISO on the host
|
---|
304 | * which will be used for the updating process. */
|
---|
305 | Utf8Str mSource;
|
---|
306 | /** (Optional) installer command line arguments. */
|
---|
307 | ProcessArguments mArguments;
|
---|
308 | /** Update flags. */
|
---|
309 | uint32_t mFlags;
|
---|
310 | };
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Guest session implementation.
|
---|
314 | */
|
---|
315 | class ATL_NO_VTABLE GuestSession :
|
---|
316 | public GuestSessionWrap,
|
---|
317 | public GuestBase
|
---|
318 | {
|
---|
319 | public:
|
---|
320 | /** @name COM and internal init/term/mapping cruft.
|
---|
321 | * @{ */
|
---|
322 | DECLARE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
323 |
|
---|
324 | int init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds);
|
---|
325 | void uninit(void);
|
---|
326 | HRESULT FinalConstruct(void);
|
---|
327 | void FinalRelease(void);
|
---|
328 | /** @} */
|
---|
329 |
|
---|
330 | private:
|
---|
331 |
|
---|
332 | /** Wrapped @name IGuestSession properties.
|
---|
333 | * @{ */
|
---|
334 | HRESULT getUser(com::Utf8Str &aUser);
|
---|
335 | HRESULT getDomain(com::Utf8Str &aDomain);
|
---|
336 | HRESULT getName(com::Utf8Str &aName);
|
---|
337 | HRESULT getId(ULONG *aId);
|
---|
338 | HRESULT getTimeout(ULONG *aTimeout);
|
---|
339 | HRESULT setTimeout(ULONG aTimeout);
|
---|
340 | HRESULT getProtocolVersion(ULONG *aProtocolVersion);
|
---|
341 | HRESULT getStatus(GuestSessionStatus_T *aStatus);
|
---|
342 | HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
343 | HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
344 | HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase);
|
---|
345 | HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
|
---|
346 | HRESULT getPathStyle(PathStyle_T *aPathStyle);
|
---|
347 | HRESULT getCurrentDirectory(com::Utf8Str &aCurrentDirectory);
|
---|
348 | HRESULT setCurrentDirectory(const com::Utf8Str &aCurrentDirectory);
|
---|
349 | HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
|
---|
350 | HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles);
|
---|
351 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
352 | /** @} */
|
---|
353 |
|
---|
354 | /** Wrapped @name IGuestSession methods.
|
---|
355 | * @{ */
|
---|
356 | HRESULT close();
|
---|
357 |
|
---|
358 | HRESULT directoryCopy(const com::Utf8Str &aSource,
|
---|
359 | const com::Utf8Str &aDestination,
|
---|
360 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
361 | ComPtr<IProgress> &aProgress);
|
---|
362 | HRESULT directoryCopyFromGuest(const com::Utf8Str &aSource,
|
---|
363 | const com::Utf8Str &aDestination,
|
---|
364 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
365 | ComPtr<IProgress> &aProgress);
|
---|
366 | HRESULT directoryCopyToGuest(const com::Utf8Str &aSource,
|
---|
367 | const com::Utf8Str &aDestination,
|
---|
368 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
369 | ComPtr<IProgress> &aProgress);
|
---|
370 | HRESULT directoryCreate(const com::Utf8Str &aPath,
|
---|
371 | ULONG aMode,
|
---|
372 | const std::vector<DirectoryCreateFlag_T> &aFlags);
|
---|
373 | HRESULT directoryCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
374 | ULONG aMode,
|
---|
375 | const com::Utf8Str &aPath,
|
---|
376 | BOOL aSecure,
|
---|
377 | com::Utf8Str &aDirectory);
|
---|
378 | HRESULT directoryExists(const com::Utf8Str &aPath,
|
---|
379 | BOOL aFollowSymlinks,
|
---|
380 | BOOL *aExists);
|
---|
381 | HRESULT directoryOpen(const com::Utf8Str &aPath,
|
---|
382 | const com::Utf8Str &aFilter,
|
---|
383 | const std::vector<DirectoryOpenFlag_T> &aFlags,
|
---|
384 | ComPtr<IGuestDirectory> &aDirectory);
|
---|
385 | HRESULT directoryRemove(const com::Utf8Str &aPath);
|
---|
386 | HRESULT directoryRemoveRecursive(const com::Utf8Str &aPath,
|
---|
387 | const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
|
---|
388 | ComPtr<IProgress> &aProgress);
|
---|
389 | HRESULT environmentScheduleSet(const com::Utf8Str &aName,
|
---|
390 | const com::Utf8Str &aValue);
|
---|
391 | HRESULT environmentScheduleUnset(const com::Utf8Str &aName);
|
---|
392 | HRESULT environmentGetBaseVariable(const com::Utf8Str &aName,
|
---|
393 | com::Utf8Str &aValue);
|
---|
394 | HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName,
|
---|
395 | BOOL *aExists);
|
---|
396 |
|
---|
397 | HRESULT fileCopy(const com::Utf8Str &aSource,
|
---|
398 | const com::Utf8Str &aDestination,
|
---|
399 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
400 | ComPtr<IProgress> &aProgress);
|
---|
401 | HRESULT fileCopyToGuest(const com::Utf8Str &aSource,
|
---|
402 | const com::Utf8Str &aDestination,
|
---|
403 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
404 | ComPtr<IProgress> &aProgress);
|
---|
405 | HRESULT fileCopyFromGuest(const com::Utf8Str &aSource,
|
---|
406 | const com::Utf8Str &aDestination,
|
---|
407 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
408 | ComPtr<IProgress> &aProgress);
|
---|
409 | HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
410 | ULONG aMode,
|
---|
411 | const com::Utf8Str &aPath,
|
---|
412 | BOOL aSecure,
|
---|
413 | ComPtr<IGuestFile> &aFile);
|
---|
414 | HRESULT fileExists(const com::Utf8Str &aPath,
|
---|
415 | BOOL aFollowSymlinks,
|
---|
416 | BOOL *aExists);
|
---|
417 | HRESULT fileOpen(const com::Utf8Str &aPath,
|
---|
418 | FileAccessMode_T aAccessMode,
|
---|
419 | FileOpenAction_T aOpenAction,
|
---|
420 | ULONG aCreationMode,
|
---|
421 | ComPtr<IGuestFile> &aFile);
|
---|
422 | HRESULT fileOpenEx(const com::Utf8Str &aPath,
|
---|
423 | FileAccessMode_T aAccessMode,
|
---|
424 | FileOpenAction_T aOpenAction,
|
---|
425 | FileSharingMode_T aSharingMode,
|
---|
426 | ULONG aCreationMode,
|
---|
427 | const std::vector<FileOpenExFlag_T> &aFlags,
|
---|
428 | ComPtr<IGuestFile> &aFile);
|
---|
429 | HRESULT fileQuerySize(const com::Utf8Str &aPath,
|
---|
430 | BOOL aFollowSymlinks,
|
---|
431 | LONG64 *aSize);
|
---|
432 | HRESULT fsObjExists(const com::Utf8Str &aPath,
|
---|
433 | BOOL aFollowSymlinks,
|
---|
434 | BOOL *pfExists);
|
---|
435 | HRESULT fsObjQueryInfo(const com::Utf8Str &aPath,
|
---|
436 | BOOL aFollowSymlinks,
|
---|
437 | ComPtr<IGuestFsObjInfo> &aInfo);
|
---|
438 | HRESULT fsObjRemove(const com::Utf8Str &aPath);
|
---|
439 | HRESULT fsObjRename(const com::Utf8Str &aOldPath,
|
---|
440 | const com::Utf8Str &aNewPath,
|
---|
441 | const std::vector<FsObjRenameFlag_T> &aFlags);
|
---|
442 | HRESULT fsObjMove(const com::Utf8Str &aSource,
|
---|
443 | const com::Utf8Str &aDestination,
|
---|
444 | const std::vector<FsObjMoveFlag_T> &aFlags,
|
---|
445 | ComPtr<IProgress> &aProgress);
|
---|
446 | HRESULT fsObjSetACL(const com::Utf8Str &aPath,
|
---|
447 | BOOL aFollowSymlinks,
|
---|
448 | const com::Utf8Str &aAcl,
|
---|
449 | ULONG aMode);
|
---|
450 | HRESULT processCreate(const com::Utf8Str &aCommand,
|
---|
451 | const std::vector<com::Utf8Str> &aArguments,
|
---|
452 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
453 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
454 | ULONG aTimeoutMS,
|
---|
455 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
456 | HRESULT processCreateEx(const com::Utf8Str &aCommand,
|
---|
457 | const std::vector<com::Utf8Str> &aArguments,
|
---|
458 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
459 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
460 | ULONG aTimeoutMS,
|
---|
461 | ProcessPriority_T aPriority,
|
---|
462 | const std::vector<LONG> &aAffinity,
|
---|
463 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
464 | HRESULT processGet(ULONG aPid,
|
---|
465 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
466 | HRESULT symlinkCreate(const com::Utf8Str &aSource,
|
---|
467 | const com::Utf8Str &aTarget,
|
---|
468 | SymlinkType_T aType);
|
---|
469 | HRESULT symlinkExists(const com::Utf8Str &aSymlink,
|
---|
470 | BOOL *aExists);
|
---|
471 | HRESULT symlinkRead(const com::Utf8Str &aSymlink,
|
---|
472 | const std::vector<SymlinkReadFlag_T> &aFlags,
|
---|
473 | com::Utf8Str &aTarget);
|
---|
474 | HRESULT waitFor(ULONG aWaitFor,
|
---|
475 | ULONG aTimeoutMS,
|
---|
476 | GuestSessionWaitResult_T *aReason);
|
---|
477 | HRESULT waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor,
|
---|
478 | ULONG aTimeoutMS,
|
---|
479 | GuestSessionWaitResult_T *aReason);
|
---|
480 | /** @} */
|
---|
481 |
|
---|
482 | /** Map of guest directories. The key specifies the internal directory ID. */
|
---|
483 | typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
|
---|
484 | /** Map of guest files. The key specifies the internal file ID. */
|
---|
485 | typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
|
---|
486 | /** Map of guest processes. The key specifies the internal process number.
|
---|
487 | * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
|
---|
488 | typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
|
---|
489 |
|
---|
490 | public:
|
---|
491 | /** @name Public internal methods.
|
---|
492 | * @todo r=bird: Most of these are public for no real reason...
|
---|
493 | * @{ */
|
---|
494 | int i_copyToGuestCreateDir(const com::Utf8Str &aDestination, uint32_t fFlags, int *pGuestRc);
|
---|
495 | int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc);
|
---|
496 | inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
|
---|
497 | int i_directoryRemoveFromList(GuestDirectory *pDirectory);
|
---|
498 | int i_directoryRemoveInternal(const Utf8Str &strPath, uint32_t uFlags, int *pGuestRc);
|
---|
499 | int i_directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
|
---|
500 | int i_objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory,
|
---|
501 | Utf8Str &strName, int *pGuestRc);
|
---|
502 | int i_directoryOpenInternal(const GuestDirectoryOpenInfo &openInfo,
|
---|
503 | ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc);
|
---|
504 | int i_directoryQueryInfoInternal(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
505 | int i_dispatchToDirectory(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
506 | int i_dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
507 | int i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
508 | int i_dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
509 | int i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
510 | inline bool i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile);
|
---|
511 | int i_fileRemoveFromList(GuestFile *pFile);
|
---|
512 | int i_fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc);
|
---|
513 | int i_fileOpenInternal(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
|
---|
514 | int i_fileQueryInfoInternal(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
515 | int i_fileQuerySizeInternal(const Utf8Str &strPath, bool fFollowSymlinks, int64_t *pllSize, int *pGuestRc);
|
---|
516 | int i_fsQueryInfoInternal(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
517 | const GuestCredentials &i_getCredentials(void);
|
---|
518 | EventSource *i_getEventSource(void) { return mEventSource; }
|
---|
519 | Utf8Str i_getName(void);
|
---|
520 | ULONG i_getId(void) { return mData.mSession.mID; }
|
---|
521 | static Utf8Str i_guestErrorToString(int guestRc);
|
---|
522 | HRESULT i_isReadyExternal(void);
|
---|
523 | int i_onRemove(void);
|
---|
524 | int i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
525 | int i_startSessionInternal(int *pGuestRc);
|
---|
526 | int i_startSessionAsync(void);
|
---|
527 | static void i_startSessionThreadTask(GuestSessionTaskInternalOpen *pTask);
|
---|
528 | Guest *i_getParent(void) { return mParent; }
|
---|
529 | uint32_t i_getProtocolVersion(void) { return mData.mProtocolVersion; }
|
---|
530 | int i_pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags,
|
---|
531 | int *pGuestRc);
|
---|
532 | int i_processRemoveFromList(GuestProcess *pProcess);
|
---|
533 | int i_processCreateExInternal(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
|
---|
534 | inline bool i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
|
---|
535 | inline int i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
|
---|
536 | int i_sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
|
---|
537 | static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
|
---|
538 | int i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc);
|
---|
539 | int i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */);
|
---|
540 | int i_determineProtocolVersion(void);
|
---|
541 | int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc);
|
---|
542 | int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
543 | GuestSessionStatus_T *pSessionStatus, int *pGuestRc);
|
---|
544 | /** @} */
|
---|
545 |
|
---|
546 | private:
|
---|
547 |
|
---|
548 | /** Pointer to the parent (Guest). */
|
---|
549 | Guest *mParent;
|
---|
550 | /**
|
---|
551 | * The session's event source. This source is used for
|
---|
552 | * serving the internal listener as well as all other
|
---|
553 | * external listeners that may register to it.
|
---|
554 | *
|
---|
555 | * Note: This can safely be used without holding any locks.
|
---|
556 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
557 | * internally there is a lock providing the necessary serialization.
|
---|
558 | */
|
---|
559 | const ComObjPtr<EventSource> mEventSource;
|
---|
560 |
|
---|
561 | struct Data
|
---|
562 | {
|
---|
563 | /** The session credentials. */
|
---|
564 | GuestCredentials mCredentials;
|
---|
565 | /** The session's startup info. */
|
---|
566 | GuestSessionStartupInfo mSession;
|
---|
567 | /** The session's current status. */
|
---|
568 | GuestSessionStatus_T mStatus;
|
---|
569 | /** The set of environment changes for the session for use when
|
---|
570 | * creating new guest processes. */
|
---|
571 | GuestEnvironmentChanges mEnvironmentChanges;
|
---|
572 | /** Pointer to the immutable base environment for the session.
|
---|
573 | * @note This is not allocated until the guest reports it to the host. It is
|
---|
574 | * also shared with child processes. */
|
---|
575 | GuestEnvironment const *mpBaseEnvironment;
|
---|
576 | /** Directory objects bound to this session. */
|
---|
577 | SessionDirectories mDirectories;
|
---|
578 | /** File objects bound to this session. */
|
---|
579 | SessionFiles mFiles;
|
---|
580 | /** Process objects bound to this session. */
|
---|
581 | SessionProcesses mProcesses;
|
---|
582 | /** Guest control protocol version to be used.
|
---|
583 | * Guest Additions < VBox 4.3 have version 1,
|
---|
584 | * any newer version will have version 2. */
|
---|
585 | uint32_t mProtocolVersion;
|
---|
586 | /** Session timeout (in ms). */
|
---|
587 | uint32_t mTimeout;
|
---|
588 | /** Total number of session objects (processes,
|
---|
589 | * files, ...). */
|
---|
590 | uint32_t mNumObjects;
|
---|
591 | /** The last returned session status
|
---|
592 | * returned from the guest side. */
|
---|
593 | int mRC;
|
---|
594 |
|
---|
595 | Data(void)
|
---|
596 | : mpBaseEnvironment(NULL)
|
---|
597 | { }
|
---|
598 | Data(const Data &rThat)
|
---|
599 | : mCredentials(rThat.mCredentials)
|
---|
600 | , mSession(rThat.mSession)
|
---|
601 | , mStatus(rThat.mStatus)
|
---|
602 | , mEnvironmentChanges(rThat.mEnvironmentChanges)
|
---|
603 | , mpBaseEnvironment(NULL)
|
---|
604 | , mDirectories(rThat.mDirectories)
|
---|
605 | , mFiles(rThat.mFiles)
|
---|
606 | , mProcesses(rThat.mProcesses)
|
---|
607 | , mProtocolVersion(rThat.mProtocolVersion)
|
---|
608 | , mTimeout(rThat.mTimeout)
|
---|
609 | , mNumObjects(rThat.mNumObjects)
|
---|
610 | , mRC(rThat.mRC)
|
---|
611 | { }
|
---|
612 | ~Data(void)
|
---|
613 | {
|
---|
614 | if (mpBaseEnvironment)
|
---|
615 | {
|
---|
616 | mpBaseEnvironment->releaseConst();
|
---|
617 | mpBaseEnvironment = NULL;
|
---|
618 | }
|
---|
619 | }
|
---|
620 | } mData;
|
---|
621 | };
|
---|
622 |
|
---|
623 | #endif /* !____H_GUESTSESSIONIMPL */
|
---|
624 |
|
---|