1 | /* $Id: GuestSessionImpl.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - Guest session handling.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_GuestSessionImpl_h
|
---|
29 | #define MAIN_INCLUDED_GuestSessionImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "GuestSessionWrap.h"
|
---|
35 | #include "EventImpl.h"
|
---|
36 |
|
---|
37 | #include "GuestCtrlImplPrivate.h"
|
---|
38 | #include "GuestProcessImpl.h"
|
---|
39 | #include "GuestDirectoryImpl.h"
|
---|
40 | #include "GuestFileImpl.h"
|
---|
41 | #include "GuestFsObjInfoImpl.h"
|
---|
42 | #include "GuestSessionImplTasks.h"
|
---|
43 |
|
---|
44 | #include <iprt/asm.h> /** @todo r=bird: Needed for ASMBitSet() in GuestSession::Data constructor. Removed when
|
---|
45 | * that is moved into the class implementation file as it should be. */
|
---|
46 | #include <deque>
|
---|
47 |
|
---|
48 | class GuestSessionTaskInternalStart; /* Needed for i_startSessionThreadTask(). */
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Guest session implementation.
|
---|
52 | */
|
---|
53 | class ATL_NO_VTABLE GuestSession
|
---|
54 | : public GuestSessionWrap
|
---|
55 | , public GuestBase
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | /** @name COM and internal init/term/mapping cruft.
|
---|
59 | * @{ */
|
---|
60 | DECLARE_COMMON_CLASS_METHODS(GuestSession)
|
---|
61 |
|
---|
62 | int init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds);
|
---|
63 | void uninit(void);
|
---|
64 | HRESULT FinalConstruct(void);
|
---|
65 | void FinalRelease(void);
|
---|
66 | /** @} */
|
---|
67 |
|
---|
68 | private:
|
---|
69 |
|
---|
70 | /** Wrapped @name IGuestSession properties.
|
---|
71 | * @{ */
|
---|
72 | HRESULT getUser(com::Utf8Str &aUser);
|
---|
73 | HRESULT getDomain(com::Utf8Str &aDomain);
|
---|
74 | HRESULT getName(com::Utf8Str &aName);
|
---|
75 | HRESULT getId(ULONG *aId);
|
---|
76 | HRESULT getTimeout(ULONG *aTimeout);
|
---|
77 | HRESULT setTimeout(ULONG aTimeout);
|
---|
78 | HRESULT getProtocolVersion(ULONG *aProtocolVersion);
|
---|
79 | HRESULT getStatus(GuestSessionStatus_T *aStatus);
|
---|
80 | HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
81 | HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
82 | HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase);
|
---|
83 | HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
|
---|
84 | HRESULT getPathStyle(PathStyle_T *aPathStyle);
|
---|
85 | HRESULT getCurrentDirectory(com::Utf8Str &aCurrentDirectory);
|
---|
86 | HRESULT setCurrentDirectory(const com::Utf8Str &aCurrentDirectory);
|
---|
87 | HRESULT getUserDocuments(com::Utf8Str &aUserDocuments);
|
---|
88 | HRESULT getUserHome(com::Utf8Str &aUserHome);
|
---|
89 | HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
|
---|
90 | HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles);
|
---|
91 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 | /** Wrapped @name IGuestSession methods.
|
---|
95 | * @{ */
|
---|
96 | HRESULT close();
|
---|
97 |
|
---|
98 | HRESULT copyFromGuest(const std::vector<com::Utf8Str> &aSources,
|
---|
99 | const std::vector<com::Utf8Str> &aFilters,
|
---|
100 | const std::vector<com::Utf8Str> &aFlags,
|
---|
101 | const com::Utf8Str &aDestination,
|
---|
102 | ComPtr<IProgress> &aProgress);
|
---|
103 | HRESULT copyToGuest(const std::vector<com::Utf8Str> &aSources,
|
---|
104 | const std::vector<com::Utf8Str> &aFilters,
|
---|
105 | const std::vector<com::Utf8Str> &aFlags,
|
---|
106 | const com::Utf8Str &aDestination,
|
---|
107 | ComPtr<IProgress> &aProgress);
|
---|
108 |
|
---|
109 | HRESULT directoryCopy(const com::Utf8Str &aSource,
|
---|
110 | const com::Utf8Str &aDestination,
|
---|
111 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
112 | ComPtr<IProgress> &aProgress);
|
---|
113 | HRESULT directoryCopyFromGuest(const com::Utf8Str &aSource,
|
---|
114 | const com::Utf8Str &aDestination,
|
---|
115 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
116 | ComPtr<IProgress> &aProgress);
|
---|
117 | HRESULT directoryCopyToGuest(const com::Utf8Str &aSource,
|
---|
118 | const com::Utf8Str &aDestination,
|
---|
119 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
120 | ComPtr<IProgress> &aProgress);
|
---|
121 | HRESULT directoryCreate(const com::Utf8Str &aPath,
|
---|
122 | ULONG aMode,
|
---|
123 | const std::vector<DirectoryCreateFlag_T> &aFlags);
|
---|
124 | HRESULT directoryCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
125 | ULONG aMode,
|
---|
126 | const com::Utf8Str &aPath,
|
---|
127 | BOOL aSecure,
|
---|
128 | com::Utf8Str &aDirectory);
|
---|
129 | HRESULT directoryExists(const com::Utf8Str &aPath,
|
---|
130 | BOOL aFollowSymlinks,
|
---|
131 | BOOL *aExists);
|
---|
132 | HRESULT directoryOpen(const com::Utf8Str &aPath,
|
---|
133 | const com::Utf8Str &aFilter,
|
---|
134 | const std::vector<DirectoryOpenFlag_T> &aFlags,
|
---|
135 | ComPtr<IGuestDirectory> &aDirectory);
|
---|
136 | HRESULT directoryRemove(const com::Utf8Str &aPath);
|
---|
137 | HRESULT directoryRemoveRecursive(const com::Utf8Str &aPath,
|
---|
138 | const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
|
---|
139 | ComPtr<IProgress> &aProgress);
|
---|
140 | HRESULT environmentScheduleSet(const com::Utf8Str &aName,
|
---|
141 | const com::Utf8Str &aValue);
|
---|
142 | HRESULT environmentScheduleUnset(const com::Utf8Str &aName);
|
---|
143 | HRESULT environmentGetBaseVariable(const com::Utf8Str &aName,
|
---|
144 | com::Utf8Str &aValue);
|
---|
145 | HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName,
|
---|
146 | BOOL *aExists);
|
---|
147 |
|
---|
148 | HRESULT fileCopy(const com::Utf8Str &aSource,
|
---|
149 | const com::Utf8Str &aDestination,
|
---|
150 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
151 | ComPtr<IProgress> &aProgress);
|
---|
152 | HRESULT fileCopyToGuest(const com::Utf8Str &aSource,
|
---|
153 | const com::Utf8Str &aDestination,
|
---|
154 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
155 | ComPtr<IProgress> &aProgress);
|
---|
156 | HRESULT fileCopyFromGuest(const com::Utf8Str &aSource,
|
---|
157 | const com::Utf8Str &aDestination,
|
---|
158 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
159 | ComPtr<IProgress> &aProgress);
|
---|
160 | HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
161 | ULONG aMode,
|
---|
162 | const com::Utf8Str &aPath,
|
---|
163 | BOOL aSecure,
|
---|
164 | ComPtr<IGuestFile> &aFile);
|
---|
165 | HRESULT fileExists(const com::Utf8Str &aPath,
|
---|
166 | BOOL aFollowSymlinks,
|
---|
167 | BOOL *aExists);
|
---|
168 | HRESULT fileOpen(const com::Utf8Str &aPath,
|
---|
169 | FileAccessMode_T aAccessMode,
|
---|
170 | FileOpenAction_T aOpenAction,
|
---|
171 | ULONG aCreationMode,
|
---|
172 | ComPtr<IGuestFile> &aFile);
|
---|
173 | HRESULT fileOpenEx(const com::Utf8Str &aPath,
|
---|
174 | FileAccessMode_T aAccessMode,
|
---|
175 | FileOpenAction_T aOpenAction,
|
---|
176 | FileSharingMode_T aSharingMode,
|
---|
177 | ULONG aCreationMode,
|
---|
178 | const std::vector<FileOpenExFlag_T> &aFlags,
|
---|
179 | ComPtr<IGuestFile> &aFile);
|
---|
180 | HRESULT fileQuerySize(const com::Utf8Str &aPath,
|
---|
181 | BOOL aFollowSymlinks,
|
---|
182 | LONG64 *aSize);
|
---|
183 | HRESULT fsQueryFreeSpace(const com::Utf8Str &aPath, LONG64 *aFreeSpace);
|
---|
184 | HRESULT fsQueryInfo(const com::Utf8Str &aPath, ComPtr<IGuestFsInfo> &aInfo);
|
---|
185 | HRESULT fsObjExists(const com::Utf8Str &aPath,
|
---|
186 | BOOL aFollowSymlinks,
|
---|
187 | BOOL *pfExists);
|
---|
188 | HRESULT fsObjQueryInfo(const com::Utf8Str &aPath,
|
---|
189 | BOOL aFollowSymlinks,
|
---|
190 | ComPtr<IGuestFsObjInfo> &aInfo);
|
---|
191 | HRESULT fsObjRemove(const com::Utf8Str &aPath);
|
---|
192 | HRESULT fsObjRemoveArray(const std::vector<com::Utf8Str> &aPaths,
|
---|
193 | ComPtr<IProgress> &aProgress);
|
---|
194 | HRESULT fsObjRename(const com::Utf8Str &aOldPath,
|
---|
195 | const com::Utf8Str &aNewPath,
|
---|
196 | const std::vector<FsObjRenameFlag_T> &aFlags);
|
---|
197 | HRESULT fsObjMove(const com::Utf8Str &aSource,
|
---|
198 | const com::Utf8Str &aDestination,
|
---|
199 | const std::vector<FsObjMoveFlag_T> &aFlags,
|
---|
200 | ComPtr<IProgress> &aProgress);
|
---|
201 | HRESULT fsObjMoveArray(const std::vector<com::Utf8Str> &aSource,
|
---|
202 | const com::Utf8Str &aDestination,
|
---|
203 | const std::vector<FsObjMoveFlag_T> &aFlags,
|
---|
204 | ComPtr<IProgress> &aProgress);
|
---|
205 | HRESULT fsObjCopyArray(const std::vector<com::Utf8Str> &aSource,
|
---|
206 | const com::Utf8Str &aDestination,
|
---|
207 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
208 | ComPtr<IProgress> &aProgress);
|
---|
209 | HRESULT fsObjSetACL(const com::Utf8Str &aPath,
|
---|
210 | BOOL aFollowSymlinks,
|
---|
211 | const com::Utf8Str &aAcl,
|
---|
212 | ULONG aMode);
|
---|
213 | HRESULT processCreate(const com::Utf8Str &aCommand,
|
---|
214 | const std::vector<com::Utf8Str> &aArguments,
|
---|
215 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
216 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
217 | ULONG aTimeoutMS,
|
---|
218 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
219 | HRESULT processCreateEx(const com::Utf8Str &aCommand,
|
---|
220 | const std::vector<com::Utf8Str> &aArguments,
|
---|
221 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
222 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
223 | ULONG aTimeoutMS,
|
---|
224 | ProcessPriority_T aPriority,
|
---|
225 | const std::vector<LONG> &aAffinity,
|
---|
226 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
227 | HRESULT processGet(ULONG aPid,
|
---|
228 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
229 | HRESULT symlinkCreate(const com::Utf8Str &aSource,
|
---|
230 | const com::Utf8Str &aTarget,
|
---|
231 | SymlinkType_T aType);
|
---|
232 | HRESULT symlinkExists(const com::Utf8Str &aSymlink,
|
---|
233 | BOOL *aExists);
|
---|
234 | HRESULT symlinkRead(const com::Utf8Str &aSymlink,
|
---|
235 | const std::vector<SymlinkReadFlag_T> &aFlags,
|
---|
236 | com::Utf8Str &aTarget);
|
---|
237 | HRESULT waitFor(ULONG aWaitFor,
|
---|
238 | ULONG aTimeoutMS,
|
---|
239 | GuestSessionWaitResult_T *aReason);
|
---|
240 | HRESULT waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor,
|
---|
241 | ULONG aTimeoutMS,
|
---|
242 | GuestSessionWaitResult_T *aReason);
|
---|
243 | /** @} */
|
---|
244 |
|
---|
245 | /** Map of guest directories. The key specifies the internal directory ID. */
|
---|
246 | typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
|
---|
247 | /** Map of guest files. The key specifies the internal file ID. */
|
---|
248 | typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
|
---|
249 | /** Map of guest processes. The key specifies the internal process number.
|
---|
250 | * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
|
---|
251 | typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
|
---|
252 |
|
---|
253 | /** Guest session object type enumeration. */
|
---|
254 | enum SESSIONOBJECTTYPE
|
---|
255 | {
|
---|
256 | /** Invalid session object type. */
|
---|
257 | SESSIONOBJECTTYPE_INVALID = 0,
|
---|
258 | /** Session object. */
|
---|
259 | SESSIONOBJECTTYPE_SESSION = 1,
|
---|
260 | /** Directory object. */
|
---|
261 | SESSIONOBJECTTYPE_DIRECTORY = 2,
|
---|
262 | /** File object. */
|
---|
263 | SESSIONOBJECTTYPE_FILE = 3,
|
---|
264 | /** Process object. */
|
---|
265 | SESSIONOBJECTTYPE_PROCESS = 4
|
---|
266 | };
|
---|
267 |
|
---|
268 | struct SessionObject
|
---|
269 | {
|
---|
270 | /** Creation timestamp (in ms).
|
---|
271 | * @note not used by anyone at the moment. */
|
---|
272 | uint64_t msBirth;
|
---|
273 | /** The object type. */
|
---|
274 | SESSIONOBJECTTYPE enmType;
|
---|
275 | /** Weak pointer to the object itself.
|
---|
276 | * Is NULL for SESSIONOBJECTTYPE_SESSION because GuestSession doesn't
|
---|
277 | * inherit from GuestObject. */
|
---|
278 | GuestObject *pObject;
|
---|
279 | };
|
---|
280 |
|
---|
281 | /** Map containing all objects bound to a guest session.
|
---|
282 | * The key specifies the (global) context ID. */
|
---|
283 | typedef std::map<uint32_t, SessionObject> SessionObjects;
|
---|
284 |
|
---|
285 | public:
|
---|
286 | /** @name Public internal methods.
|
---|
287 | * @todo r=bird: Most of these are public for no real reason...
|
---|
288 | * @{ */
|
---|
289 | HRESULT i_copyFromGuest(const GuestSessionFsSourceSet &SourceSet, const com::Utf8Str &strDestination,
|
---|
290 | ComPtr<IProgress> &pProgress);
|
---|
291 | HRESULT i_copyToGuest(const GuestSessionFsSourceSet &SourceSet, const com::Utf8Str &strDestination,
|
---|
292 | ComPtr<IProgress> &pProgress);
|
---|
293 | int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc);
|
---|
294 | HRESULT i_directoryCopyFlagFromStr(const com::Utf8Str &strFlags, DirectoryCopyFlag_T *pfFlags);
|
---|
295 | bool i_directoryExists(const Utf8Str &strPath);
|
---|
296 | inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
|
---|
297 | int i_directoryUnregister(GuestDirectory *pDirectory);
|
---|
298 | int i_directoryRemove(const Utf8Str &strPath, uint32_t fFlags, int *pGuestRc);
|
---|
299 | int i_directoryCreate(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
|
---|
300 | int i_directoryOpen(const GuestDirectoryOpenInfo &openInfo,
|
---|
301 | ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc);
|
---|
302 | int i_directoryQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
303 | int i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
304 | int i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
305 | HRESULT i_fileCopyFlagFromStr(const com::Utf8Str &strFlags, FileCopyFlag_T *pfFlags);
|
---|
306 | inline bool i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile);
|
---|
307 | int i_fileUnregister(GuestFile *pFile);
|
---|
308 | int i_fileRemove(const Utf8Str &strPath, int *pGuestRc);
|
---|
309 | int i_fileOpenEx(const com::Utf8Str &aPath, FileAccessMode_T aAccessMode, FileOpenAction_T aOpenAction,
|
---|
310 | FileSharingMode_T aSharingMode, ULONG aCreationMode,
|
---|
311 | const std::vector<FileOpenExFlag_T> &aFlags,
|
---|
312 | ComObjPtr<GuestFile> &pFile, int *prcGuest);
|
---|
313 | int i_fileOpen(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
|
---|
314 | int i_fileQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
315 | int i_fileQuerySize(const Utf8Str &strPath, bool fFollowSymlinks, int64_t *pllSize, int *pGuestRc);
|
---|
316 | int i_fsCreateTemp(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory,
|
---|
317 | Utf8Str &strName, uint32_t fMode, bool fSecure, int *pGuestRc);
|
---|
318 | int i_fsQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc);
|
---|
319 | const GuestCredentials &i_getCredentials(void);
|
---|
320 | EventSource *i_getEventSource(void) { return mEventSource; }
|
---|
321 | Utf8Str i_getName(void);
|
---|
322 | ULONG i_getId(void) { return mData.mSession.mID; }
|
---|
323 | bool i_isStarted(void) const;
|
---|
324 | HRESULT i_isStartedExternal(void);
|
---|
325 | bool i_isTerminated(void) const;
|
---|
326 | int i_onRemove(void);
|
---|
327 | int i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
328 | PathStyle_T i_getPathStyle(void);
|
---|
329 | int i_startSession(int *pGuestRc);
|
---|
330 | int i_startSessionAsync(void);
|
---|
331 | Guest *i_getParent(void) { return mParent; }
|
---|
332 | uint32_t i_getProtocolVersion(void) { return mData.mProtocolVersion; }
|
---|
333 | int i_objectRegister(GuestObject *pObject, SESSIONOBJECTTYPE enmType, uint32_t *pidObject);
|
---|
334 | int i_objectUnregister(uint32_t uObjectID);
|
---|
335 | int i_objectsUnregister(void);
|
---|
336 | int i_objectsNotifyAboutStatusChange(GuestSessionStatus_T enmSessionStatus);
|
---|
337 | int i_pathRename(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, int *pGuestRc);
|
---|
338 | int i_pathUserDocuments(Utf8Str &strPath, int *prcGuest);
|
---|
339 | int i_pathUserHome(Utf8Str &strPath, int *prcGuest);
|
---|
340 | int i_processUnregister(GuestProcess *pProcess);
|
---|
341 | int i_processCreateEx(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
|
---|
342 | inline bool i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
|
---|
343 | inline int i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
|
---|
344 | int i_sendMessage(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms,
|
---|
345 | uint64_t fDst = VBOX_GUESTCTRL_DST_SESSION);
|
---|
346 | int i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc);
|
---|
347 | int i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */);
|
---|
348 | int i_shutdown(uint32_t fFlags, int *prcGuest);
|
---|
349 | int i_determineProtocolVersion(void);
|
---|
350 | int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc);
|
---|
351 | int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
352 | GuestSessionStatus_T *pSessionStatus, int *pGuestRc);
|
---|
353 | /** @} */
|
---|
354 |
|
---|
355 | public:
|
---|
356 |
|
---|
357 | /** @name Static helper methods.
|
---|
358 | * @{ */
|
---|
359 | static Utf8Str i_guestErrorToString(int guestRc);
|
---|
360 | static bool i_isTerminated(GuestSessionStatus_T enmStatus);
|
---|
361 | static int i_startSessionThreadTask(GuestSessionTaskInternalStart *pTask);
|
---|
362 | /** @} */
|
---|
363 |
|
---|
364 | private:
|
---|
365 |
|
---|
366 | /** Pointer to the parent (Guest). */
|
---|
367 | Guest *mParent;
|
---|
368 | /**
|
---|
369 | * The session's event source. This source is used for
|
---|
370 | * serving the internal listener as well as all other
|
---|
371 | * external listeners that may register to it.
|
---|
372 | *
|
---|
373 | * Note: This can safely be used without holding any locks.
|
---|
374 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
375 | * internally there is a lock providing the necessary serialization.
|
---|
376 | */
|
---|
377 | const ComObjPtr<EventSource> mEventSource;
|
---|
378 |
|
---|
379 | /** @todo r=bird: One of the core points of the DATA sub-structures in Main is
|
---|
380 | * hinding implementation details and stuff that requires including iprt/asm.h.
|
---|
381 | * The way it's used here totally defeats that purpose. You need to make it
|
---|
382 | * a pointer to a anynmous Data struct and define that structure in
|
---|
383 | * GuestSessionImpl.cpp and allocate it in the Init() function.
|
---|
384 | */
|
---|
385 | struct Data
|
---|
386 | {
|
---|
387 | /** The session credentials. */
|
---|
388 | GuestCredentials mCredentials;
|
---|
389 | /** The session's startup info. */
|
---|
390 | GuestSessionStartupInfo mSession;
|
---|
391 | /** The session's object ID.
|
---|
392 | * Needed for registering wait events which are bound directly to this session. */
|
---|
393 | uint32_t mObjectID;
|
---|
394 | /** The session's current status. */
|
---|
395 | GuestSessionStatus_T mStatus;
|
---|
396 | /** The set of environment changes for the session for use when
|
---|
397 | * creating new guest processes. */
|
---|
398 | GuestEnvironmentChanges mEnvironmentChanges;
|
---|
399 | /** Pointer to the immutable base environment for the session.
|
---|
400 | * @note This is not allocated until the guest reports it to the host. It is
|
---|
401 | * also shared with child processes.
|
---|
402 | * @todo This is actually not yet implemented, see
|
---|
403 | * GuestSession::i_onSessionStatusChange. */
|
---|
404 | GuestEnvironment const *mpBaseEnvironment;
|
---|
405 | /** Directory objects bound to this session. */
|
---|
406 | SessionDirectories mDirectories;
|
---|
407 | /** File objects bound to this session. */
|
---|
408 | SessionFiles mFiles;
|
---|
409 | /** Process objects bound to this session. */
|
---|
410 | SessionProcesses mProcesses;
|
---|
411 | /** Map of registered session objects (files, directories, ...). */
|
---|
412 | SessionObjects mObjects;
|
---|
413 | /** Guest control protocol version to be used.
|
---|
414 | * Guest Additions < VBox 4.3 have version 1,
|
---|
415 | * any newer version will have version 2. */
|
---|
416 | uint32_t mProtocolVersion;
|
---|
417 | /** Session timeout (in ms). */
|
---|
418 | uint32_t mTimeout;
|
---|
419 | /** The last returned session status
|
---|
420 | * returned from the guest side. */
|
---|
421 | int mRC;
|
---|
422 | /** Object ID allocation bitmap; clear bits are free, set bits are busy. */
|
---|
423 | uint64_t bmObjectIds[VBOX_GUESTCTRL_MAX_OBJECTS / sizeof(uint64_t) / 8];
|
---|
424 |
|
---|
425 | Data(void)
|
---|
426 | : mpBaseEnvironment(NULL)
|
---|
427 | {
|
---|
428 | RT_ZERO(bmObjectIds);
|
---|
429 | ASMBitSet(&bmObjectIds, VBOX_GUESTCTRL_MAX_OBJECTS - 1); /* Reserved for the session itself? */
|
---|
430 | ASMBitSet(&bmObjectIds, 0); /* Let's reserve this too. */
|
---|
431 | }
|
---|
432 | Data(const Data &rThat)
|
---|
433 | : mCredentials(rThat.mCredentials)
|
---|
434 | , mSession(rThat.mSession)
|
---|
435 | , mStatus(rThat.mStatus)
|
---|
436 | , mEnvironmentChanges(rThat.mEnvironmentChanges)
|
---|
437 | , mpBaseEnvironment(NULL)
|
---|
438 | , mDirectories(rThat.mDirectories)
|
---|
439 | , mFiles(rThat.mFiles)
|
---|
440 | , mProcesses(rThat.mProcesses)
|
---|
441 | , mObjects(rThat.mObjects)
|
---|
442 | , mProtocolVersion(rThat.mProtocolVersion)
|
---|
443 | , mTimeout(rThat.mTimeout)
|
---|
444 | , mRC(rThat.mRC)
|
---|
445 | {
|
---|
446 | memcpy(&bmObjectIds, &rThat.bmObjectIds, sizeof(bmObjectIds));
|
---|
447 | }
|
---|
448 | ~Data(void)
|
---|
449 | {
|
---|
450 | if (mpBaseEnvironment)
|
---|
451 | {
|
---|
452 | mpBaseEnvironment->releaseConst();
|
---|
453 | mpBaseEnvironment = NULL;
|
---|
454 | }
|
---|
455 | }
|
---|
456 | } mData;
|
---|
457 | };
|
---|
458 |
|
---|
459 | #endif /* !MAIN_INCLUDED_GuestSessionImpl_h */
|
---|
460 |
|
---|