VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestSessionImpl.h@ 71257

Last change on this file since 71257 was 71251, checked in by vboxsync, 7 years ago

Guest Control/[Directory|File]CopyFrom: Factored out the fileCopyFrom session task routines to also implement copying entire directories from the guest within Main. Work in progress.

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