VirtualBox

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

Last change on this file since 53517 was 51321, checked in by vboxsync, 11 years ago

Main: Fixed broken documentation due to wrapper changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.5 KB
Line 
1/* $Id: GuestSessionImpl.h 51321 2014-05-21 13:02:44Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Guest session handling.
4 */
5
6/*
7 * Copyright (C) 2012-2013 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
30#include <iprt/isofs.h> /* For UpdateAdditions. */
31
32class Guest;
33
34/**
35 * Abstract base class for a lenghtly per-session operation which
36 * runs in a Main worker thread.
37 */
38class GuestSessionTask
39{
40public:
41
42 GuestSessionTask(GuestSession *pSession);
43
44 virtual ~GuestSessionTask(void);
45
46public:
47
48 virtual int Run(void) = 0;
49 virtual int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress) = 0;
50
51protected:
52
53 int getGuestProperty(const ComObjPtr<Guest> &pGuest,
54 const Utf8Str &strPath, Utf8Str &strValue);
55 int setProgress(ULONG uPercent);
56 int setProgressSuccess(void);
57 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
58
59protected:
60
61 Utf8Str mDesc;
62 GuestSession *mSession;
63 /** Progress object for getting updated when running
64 * asynchronously. Optional. */
65 ComObjPtr<Progress> mProgress;
66};
67
68/**
69 * Task for opening a guest session.
70 */
71class SessionTaskOpen : public GuestSessionTask
72{
73public:
74
75 SessionTaskOpen(GuestSession *pSession,
76 uint32_t uFlags,
77 uint32_t uTimeoutMS);
78
79 virtual ~SessionTaskOpen(void);
80
81public:
82
83 int Run(int *pGuestRc);
84 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
85 static int taskThread(RTTHREAD Thread, void *pvUser);
86
87protected:
88
89 /** Session creation flags. */
90 uint32_t mFlags;
91 /** Session creation timeout (in ms). */
92 uint32_t mTimeoutMS;
93};
94
95/**
96 * Task for copying files from host to the guest.
97 */
98class SessionTaskCopyTo : public GuestSessionTask
99{
100public:
101
102 SessionTaskCopyTo(GuestSession *pSession,
103 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
104
105 SessionTaskCopyTo(GuestSession *pSession,
106 PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
107 const Utf8Str &strDest, uint32_t uFlags);
108
109 virtual ~SessionTaskCopyTo(void);
110
111public:
112
113 int Run(void);
114 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
115 static int taskThread(RTTHREAD Thread, void *pvUser);
116
117protected:
118
119 Utf8Str mSource;
120 PRTFILE mSourceFile;
121 size_t mSourceOffset;
122 uint64_t mSourceSize;
123 Utf8Str mDest;
124 uint32_t mCopyFileFlags;
125};
126
127/**
128 * Task for copying files from guest to the host.
129 */
130class SessionTaskCopyFrom : public GuestSessionTask
131{
132public:
133
134 SessionTaskCopyFrom(GuestSession *pSession,
135 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
136
137 virtual ~SessionTaskCopyFrom(void);
138
139public:
140
141 int Run(void);
142 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
143 static int taskThread(RTTHREAD Thread, void *pvUser);
144
145protected:
146
147 Utf8Str mSource;
148 Utf8Str mDest;
149 uint32_t mFlags;
150};
151
152/**
153 * Task for automatically updating the Guest Additions on the guest.
154 */
155class SessionTaskUpdateAdditions : public GuestSessionTask
156{
157public:
158
159 SessionTaskUpdateAdditions(GuestSession *pSession,
160 const Utf8Str &strSource, const ProcessArguments &aArguments,
161 uint32_t uFlags);
162
163 virtual ~SessionTaskUpdateAdditions(void);
164
165public:
166
167 int Run(void);
168 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
169 static int taskThread(RTTHREAD Thread, void *pvUser);
170
171protected:
172
173 /**
174 * Suported OS types for automatic updating.
175 */
176 enum eOSType
177 {
178 eOSType_Unknown = 0,
179 eOSType_Windows = 1,
180 eOSType_Linux = 2,
181 eOSType_Solaris = 3
182 };
183
184 /**
185 * Structure representing a file to
186 * get off the .ISO, copied to the guest.
187 */
188 struct InstallerFile
189 {
190 InstallerFile(const Utf8Str &aSource,
191 const Utf8Str &aDest,
192 uint32_t aFlags = 0)
193 : strSource(aSource),
194 strDest(aDest),
195 fFlags(aFlags) { }
196
197 InstallerFile(const Utf8Str &aSource,
198 const Utf8Str &aDest,
199 uint32_t aFlags,
200 GuestProcessStartupInfo startupInfo)
201 : strSource(aSource),
202 strDest(aDest),
203 fFlags(aFlags),
204 mProcInfo(startupInfo)
205 {
206 mProcInfo.mCommand = strDest;
207 if (mProcInfo.mName.isEmpty())
208 mProcInfo.mName = strDest;
209 }
210
211 /** Source file on .ISO. */
212 Utf8Str strSource;
213 /** Destination file on the guest. */
214 Utf8Str strDest;
215 /** File flags. */
216 uint32_t fFlags;
217 /** Optional arguments if this file needs to be
218 * executed. */
219 GuestProcessStartupInfo mProcInfo;
220 };
221
222 int i_addProcessArguments(ProcessArguments &aArgumentsDest,
223 const ProcessArguments &aArgumentsSource);
224 int i_copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO,
225 Utf8Str const &strFileSource, const Utf8Str &strFileDest,
226 bool fOptional, uint32_t *pcbSize);
227 int i_runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
228
229 /** Files to handle. */
230 std::vector<InstallerFile> mFiles;
231 /** The (optionally) specified Guest Additions .ISO on the host
232 * which will be used for the updating process. */
233 Utf8Str mSource;
234 /** (Optional) installer command line arguments. */
235 ProcessArguments mArguments;
236 /** Update flags. */
237 uint32_t mFlags;
238};
239
240/**
241 * Guest session implementation.
242 */
243class ATL_NO_VTABLE GuestSession :
244 public GuestSessionWrap,
245 public GuestBase
246{
247public:
248 /** @name COM and internal init/term/mapping cruft.
249 * @{ */
250 DECLARE_EMPTY_CTOR_DTOR(GuestSession)
251
252 int init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds);
253 void uninit(void);
254 HRESULT FinalConstruct(void);
255 void FinalRelease(void);
256 /** @} */
257
258private:
259
260 /** Wrapped @name IGuestSession properties.
261 * @{ */
262 HRESULT getUser(com::Utf8Str &aUser);
263 HRESULT getDomain(com::Utf8Str &aDomain);
264 HRESULT getName(com::Utf8Str &aName);
265 HRESULT getId(ULONG *aId);
266 HRESULT getTimeout(ULONG *aTimeout);
267 HRESULT setTimeout(ULONG aTimeout);
268 HRESULT getProtocolVersion(ULONG *aProtocolVersion);
269 HRESULT getStatus(GuestSessionStatus_T *aStatus);
270 HRESULT getEnvironment(std::vector<com::Utf8Str> &aEnvironment);
271 HRESULT setEnvironment(const std::vector<com::Utf8Str> &aEnvironment);
272 HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
273 HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
274 HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles);
275 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
276 /** @} */
277
278 /** Wrapped @name IGuestSession methods.
279 * @{ */
280 HRESULT close();
281 HRESULT copyFrom(const com::Utf8Str &aSource,
282 const com::Utf8Str &aDest,
283 const std::vector<CopyFileFlag_T> &aFlags,
284 ComPtr<IProgress> &aProgress);
285 HRESULT copyTo(const com::Utf8Str &aSource,
286 const com::Utf8Str &aDest,
287 const std::vector<CopyFileFlag_T> &aFlags,
288 ComPtr<IProgress> &aProgress);
289 HRESULT directoryCreate(const com::Utf8Str &aPath,
290 ULONG aMode,
291 const std::vector<DirectoryCreateFlag_T> &aFlags);
292 HRESULT directoryCreateTemp(const com::Utf8Str &aTemplateName,
293 ULONG aMode,
294 const com::Utf8Str &aPath,
295 BOOL aSecure,
296 com::Utf8Str &aDirectory);
297 HRESULT directoryExists(const com::Utf8Str &aPath,
298 BOOL *aExists);
299 HRESULT directoryOpen(const com::Utf8Str &aPath,
300 const com::Utf8Str &aFilter,
301 const std::vector<DirectoryOpenFlag_T> &aFlags,
302 ComPtr<IGuestDirectory> &aDirectory);
303 HRESULT directoryQueryInfo(const com::Utf8Str &aPath,
304 ComPtr<IGuestFsObjInfo> &aInfo);
305 HRESULT directoryRemove(const com::Utf8Str &aPath);
306 HRESULT directoryRemoveRecursive(const com::Utf8Str &aPath,
307 const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
308 ComPtr<IProgress> &aProgress);
309 HRESULT directoryRename(const com::Utf8Str &aSource,
310 const com::Utf8Str &aDest,
311 const std::vector<PathRenameFlag_T> &aFlags);
312 HRESULT directorySetACL(const com::Utf8Str &aPath,
313 const com::Utf8Str &aAcl);
314 HRESULT environmentClear();
315 HRESULT environmentGet(const com::Utf8Str &aName,
316 com::Utf8Str &aValue);
317 HRESULT environmentSet(const com::Utf8Str &aName,
318 const com::Utf8Str &aValue);
319 HRESULT environmentUnset(const com::Utf8Str &aName);
320 HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
321 ULONG aMode,
322 const com::Utf8Str &aPath,
323 BOOL aSecure,
324 ComPtr<IGuestFile> &aFile);
325 HRESULT fileExists(const com::Utf8Str &aPath,
326 BOOL *aExists);
327 HRESULT fileRemove(const com::Utf8Str &aPath);
328 HRESULT fileOpen(const com::Utf8Str &aPath,
329 const com::Utf8Str &aOpenMode,
330 const com::Utf8Str &aDisposition,
331 ULONG aCreationMode,
332 ComPtr<IGuestFile> &aFile);
333 HRESULT fileOpenEx(const com::Utf8Str &aPath,
334 const com::Utf8Str &aOpenMode,
335 const com::Utf8Str &aDisposition,
336 const com::Utf8Str &aSharingMode,
337 ULONG aCreationMode,
338 LONG64 aOffset,
339 ComPtr<IGuestFile> &aFile);
340 HRESULT fileQueryInfo(const com::Utf8Str &aPath,
341 ComPtr<IGuestFsObjInfo> &aInfo);
342 HRESULT fileQuerySize(const com::Utf8Str &aPath,
343 LONG64 *aSize);
344 HRESULT fileRename(const com::Utf8Str &aSource,
345 const com::Utf8Str &aDest,
346 const std::vector<PathRenameFlag_T> &aFlags);
347 HRESULT fileSetACL(const com::Utf8Str &aFile,
348 const com::Utf8Str &aAcl);
349 HRESULT processCreate(const com::Utf8Str &aCommand,
350 const std::vector<com::Utf8Str> &aArguments,
351 const std::vector<com::Utf8Str> &aEnvironment,
352 const std::vector<ProcessCreateFlag_T> &aFlags,
353 ULONG aTimeoutMS,
354 ComPtr<IGuestProcess> &aGuestProcess);
355 HRESULT processCreateEx(const com::Utf8Str &aCommand,
356 const std::vector<com::Utf8Str> &aArguments,
357 const std::vector<com::Utf8Str> &aEnvironment,
358 const std::vector<ProcessCreateFlag_T> &aFlags,
359 ULONG aTimeoutMS,
360 ProcessPriority_T aPriority,
361 const std::vector<LONG> &aAffinity,
362 ComPtr<IGuestProcess> &aGuestProcess);
363 HRESULT processGet(ULONG aPid,
364 ComPtr<IGuestProcess> &aGuestProcess);
365 HRESULT symlinkCreate(const com::Utf8Str &aSource,
366 const com::Utf8Str &aTarget,
367 SymlinkType_T aType);
368 HRESULT symlinkExists(const com::Utf8Str &aSymlink,
369 BOOL *aExists);
370 HRESULT symlinkRead(const com::Utf8Str &aSymlink,
371 const std::vector<SymlinkReadFlag_T> &aFlags,
372 com::Utf8Str &aTarget);
373 HRESULT symlinkRemoveDirectory(const com::Utf8Str &aPath);
374 HRESULT symlinkRemoveFile(const com::Utf8Str &aFile);
375 HRESULT waitFor(ULONG aWaitFor,
376 ULONG aTimeoutMS,
377 GuestSessionWaitResult_T *aReason);
378 HRESULT waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor,
379 ULONG aTimeoutMS,
380 GuestSessionWaitResult_T *aReason);
381 /** @} */
382
383 /** Map of guest directories. The key specifies the internal directory ID. */
384 typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
385 /** Map of guest files. The key specifies the internal file ID. */
386 typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
387 /** Map of guest processes. The key specifies the internal process number.
388 * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
389 typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
390
391public:
392 /** @name Public internal methods.
393 * @{ */
394 int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc);
395 inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
396 int i_directoryRemoveFromList(GuestDirectory *pDirectory);
397 int i_directoryRemoveInternal(const Utf8Str &strPath, uint32_t uFlags, int *pGuestRc);
398 int i_directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
399 int i_objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory,
400 Utf8Str &strName, int *pGuestRc);
401 int i_directoryOpenInternal(const GuestDirectoryOpenInfo &openInfo,
402 ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc);
403 int i_directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
404 int i_dispatchToDirectory(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
405 int i_dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
406 int i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
407 int i_dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
408 int i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
409 inline bool i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile);
410 int i_fileRemoveFromList(GuestFile *pFile);
411 int i_fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc);
412 int i_fileOpenInternal(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
413 int i_fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
414 int i_fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc);
415 int i_fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
416 const GuestCredentials &i_getCredentials(void);
417 const GuestEnvironment &i_getEnvironment(void);
418 EventSource *i_getEventSource(void) { return mEventSource; }
419 Utf8Str i_getName(void);
420 ULONG i_getId(void) { return mData.mSession.mID; }
421 static Utf8Str i_guestErrorToString(int guestRc);
422 HRESULT i_isReadyExternal(void);
423 int i_onRemove(void);
424 int i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
425 int i_startSessionInternal(int *pGuestRc);
426 int i_startSessionAsync(void);
427 static DECLCALLBACK(int)
428 i_startSessionThread(RTTHREAD Thread, void *pvUser);
429 Guest *i_getParent(void) { return mParent; }
430 uint32_t i_getProtocolVersion(void) { return mData.mProtocolVersion; }
431 int i_pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags,
432 int *pGuestRc);
433 int i_processRemoveFromList(GuestProcess *pProcess);
434 int i_processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
435 inline bool i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
436 inline int i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
437 int i_sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
438 static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
439 int i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc);
440 int i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */);
441 int i_startTaskAsync(const Utf8Str &strTaskDesc, GuestSessionTask *pTask,
442 ComObjPtr<Progress> &pProgress);
443 int i_queryInfo(void);
444 int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc);
445 int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
446 GuestSessionStatus_T *pSessionStatus, int *pGuestRc);
447 /** @} */
448
449private:
450
451 /** Pointer to the parent (Guest). */
452 Guest *mParent;
453 /**
454 * The session's event source. This source is used for
455 * serving the internal listener as well as all other
456 * external listeners that may register to it.
457 *
458 * Note: This can safely be used without holding any locks.
459 * An AutoCaller suffices to prevent it being destroy while in use and
460 * internally there is a lock providing the necessary serialization.
461 */
462 const ComObjPtr<EventSource> mEventSource;
463
464 struct Data
465 {
466 /** The session credentials. */
467 GuestCredentials mCredentials;
468 /** The session's startup info. */
469 GuestSessionStartupInfo mSession;
470 /** The session's current status. */
471 GuestSessionStatus_T mStatus;
472 /** The session's environment block. Can be
473 * overwritten/extended by ProcessCreate(Ex). */
474 GuestEnvironment mEnvironment;
475 /** Directory objects bound to this session. */
476 SessionDirectories mDirectories;
477 /** File objects bound to this session. */
478 SessionFiles mFiles;
479 /** Process objects bound to this session. */
480 SessionProcesses mProcesses;
481 /** Guest control protocol version to be used.
482 * Guest Additions < VBox 4.3 have version 1,
483 * any newer version will have version 2. */
484 uint32_t mProtocolVersion;
485 /** Session timeout (in ms). */
486 uint32_t mTimeout;
487 /** Total number of session objects (processes,
488 * files, ...). */
489 uint32_t mNumObjects;
490 /** The last returned session status
491 * returned from the guest side. */
492 int mRC;
493 } mData;
494};
495
496#endif /* !____H_GUESTSESSIONIMPL */
497
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