VirtualBox

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

Last change on this file since 44824 was 43162, checked in by vboxsync, 12 years ago

Main/Guest Control 2.0: Cleanup, separated guest error handling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1
2/* $Id: GuestSessionImpl.h 43162 2012-09-04 13:53:59Z vboxsync $ */
3/** @file
4 * VirtualBox Main - XXX.
5 */
6
7/*
8 * Copyright (C) 2012 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ____H_GUESTSESSIONIMPL
20#define ____H_GUESTSESSIONIMPL
21
22#include "VirtualBoxBase.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 copying files from host to the guest.
70 */
71class SessionTaskCopyTo : public GuestSessionTask
72{
73public:
74
75 SessionTaskCopyTo(GuestSession *pSession,
76 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
77
78 SessionTaskCopyTo(GuestSession *pSession,
79 PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
80 const Utf8Str &strDest, uint32_t uFlags);
81
82 virtual ~SessionTaskCopyTo(void);
83
84public:
85
86 int Run(void);
87 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
88 static int taskThread(RTTHREAD Thread, void *pvUser);
89
90protected:
91
92 Utf8Str mSource;
93 PRTFILE mSourceFile;
94 size_t mSourceOffset;
95 uint64_t mSourceSize;
96 Utf8Str mDest;
97 uint32_t mCopyFileFlags;
98};
99
100/**
101 * Task for copying files from guest to the host.
102 */
103class SessionTaskCopyFrom : public GuestSessionTask
104{
105public:
106
107 SessionTaskCopyFrom(GuestSession *pSession,
108 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
109
110 virtual ~SessionTaskCopyFrom(void);
111
112public:
113
114 int Run(void);
115 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
116 static int taskThread(RTTHREAD Thread, void *pvUser);
117
118protected:
119
120 Utf8Str mSource;
121 Utf8Str mDest;
122 uint32_t mFlags;
123};
124
125/**
126 * Task for automatically updating the Guest Additions on the guest.
127 */
128class SessionTaskUpdateAdditions : public GuestSessionTask
129{
130public:
131
132 SessionTaskUpdateAdditions(GuestSession *pSession,
133 const Utf8Str &strSource, uint32_t uFlags);
134
135 virtual ~SessionTaskUpdateAdditions(void);
136
137public:
138
139 int Run(void);
140 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
141 static int taskThread(RTTHREAD Thread, void *pvUser);
142
143protected:
144
145 /**
146 * Suported OS types for automatic updating.
147 */
148 enum eOSType
149 {
150 eOSType_Unknown = 0,
151 eOSType_Windows = 1,
152 eOSType_Linux = 2,
153 eOSType_Solaris = 3
154 };
155
156 /**
157 * Structure representing a file to
158 * get off the .ISO, copied to the guest.
159 */
160 struct InstallerFile
161 {
162 InstallerFile(const Utf8Str &aSource,
163 const Utf8Str &aDest,
164 uint32_t aFlags = 0)
165 : strSource(aSource),
166 strDest(aDest),
167 fFlags(aFlags) { }
168
169 InstallerFile(const Utf8Str &aSource,
170 const Utf8Str &aDest,
171 uint32_t aFlags,
172 GuestProcessStartupInfo startupInfo)
173 : strSource(aSource),
174 strDest(aDest),
175 fFlags(aFlags),
176 mProcInfo(startupInfo)
177 {
178 mProcInfo.mCommand = strDest;
179 if (mProcInfo.mName.isEmpty())
180 mProcInfo.mName = strDest;
181 }
182
183 /** Source file on .ISO. */
184 Utf8Str strSource;
185 /** Destination file on the guest. */
186 Utf8Str strDest;
187 /** File flags. */
188 uint32_t fFlags;
189 /** Optional arguments if this file needs to be
190 * executed. */
191 GuestProcessStartupInfo mProcInfo;
192 };
193
194 int copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO,
195 Utf8Str const &strFileSource, const Utf8Str &strFileDest,
196 bool fOptional, uint32_t *pcbSize);
197 int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
198
199 /** Files to handle. */
200 std::vector<InstallerFile> mFiles;
201 /** The (optionally) specified Guest Additions .ISO on the host
202 * which will be used for the updating process. */
203 Utf8Str mSource;
204 /** Update flags. */
205 uint32_t mFlags;
206};
207
208/**
209 * Guest session implementation.
210 */
211class ATL_NO_VTABLE GuestSession :
212 public VirtualBoxBase,
213 VBOX_SCRIPTABLE_IMPL(IGuestSession)
214{
215public:
216 /** @name COM and internal init/term/mapping cruft.
217 * @{ */
218 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestSession, IGuestSession)
219 DECLARE_NOT_AGGREGATABLE(GuestSession)
220 DECLARE_PROTECT_FINAL_CONSTRUCT()
221 BEGIN_COM_MAP(GuestSession)
222 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestSession)
223 END_COM_MAP()
224 DECLARE_EMPTY_CTOR_DTOR(GuestSession)
225
226 int init(Guest *aGuest, ULONG aSessionID, Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName);
227 void uninit(void);
228 HRESULT FinalConstruct(void);
229 void FinalRelease(void);
230 /** @} */
231
232 /** @name IGuestSession properties.
233 * @{ */
234 STDMETHOD(COMGETTER(User))(BSTR *aName);
235 STDMETHOD(COMGETTER(Domain))(BSTR *aDomain);
236 STDMETHOD(COMGETTER(Name))(BSTR *aName);
237 STDMETHOD(COMGETTER(Id))(ULONG *aId);
238 STDMETHOD(COMGETTER(Timeout))(ULONG *aTimeout);
239 STDMETHOD(COMSETTER(Timeout))(ULONG aTimeout);
240 STDMETHOD(COMGETTER(Environment))(ComSafeArrayOut(BSTR, aEnvironment));
241 STDMETHOD(COMSETTER(Environment))(ComSafeArrayIn(IN_BSTR, aEnvironment));
242 STDMETHOD(COMGETTER(Processes))(ComSafeArrayOut(IGuestProcess *, aProcesses));
243 STDMETHOD(COMGETTER(Directories))(ComSafeArrayOut(IGuestDirectory *, aDirectories));
244 STDMETHOD(COMGETTER(Files))(ComSafeArrayOut(IGuestFile *, aFiles));
245 /** @} */
246
247 /** @name IGuestSession methods.
248 * @{ */
249 STDMETHOD(Close)(void);
250 STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress);
251 STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress);
252 STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ComSafeArrayIn(DirectoryCreateFlag_T, aFlags));
253 STDMETHOD(DirectoryCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, BSTR *aDirectory);
254 STDMETHOD(DirectoryExists)(IN_BSTR aPath, BOOL *aExists);
255 STDMETHOD(DirectoryOpen)(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory);
256 STDMETHOD(DirectoryQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
257 STDMETHOD(DirectoryRemove)(IN_BSTR aPath);
258 STDMETHOD(DirectoryRemoveRecursive)(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress);
259 STDMETHOD(DirectoryRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
260 STDMETHOD(DirectorySetACL)(IN_BSTR aPath, IN_BSTR aACL);
261 STDMETHOD(EnvironmentClear)(void);
262 STDMETHOD(EnvironmentGet)(IN_BSTR aName, BSTR *aValue);
263 STDMETHOD(EnvironmentSet)(IN_BSTR aName, IN_BSTR aValue);
264 STDMETHOD(EnvironmentUnset)(IN_BSTR aName);
265 STDMETHOD(FileCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, IGuestFile **aFile);
266 STDMETHOD(FileExists)(IN_BSTR aPath, BOOL *aExists);
267 STDMETHOD(FileRemove)(IN_BSTR aPath);
268 STDMETHOD(FileOpen)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile);
269 STDMETHOD(FileQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
270 STDMETHOD(FileQuerySize)(IN_BSTR aPath, LONG64 *aSize);
271 STDMETHOD(FileRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
272 STDMETHOD(FileSetACL)(IN_BSTR aPath, IN_BSTR aACL);
273 STDMETHOD(ProcessCreate)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
274 ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess);
275 STDMETHOD(ProcessCreateEx)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
276 ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
277 ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
278 IGuestProcess **aProcess);
279 STDMETHOD(ProcessGet)(ULONG aPID, IGuestProcess **aProcess);
280 STDMETHOD(SymlinkCreate)(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType);
281 STDMETHOD(SymlinkExists)(IN_BSTR aSymlink, BOOL *aExists);
282 STDMETHOD(SymlinkRead)(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget);
283 STDMETHOD(SymlinkRemoveDirectory)(IN_BSTR aPath);
284 STDMETHOD(SymlinkRemoveFile)(IN_BSTR aFile);
285 /** @} */
286
287private:
288
289 typedef std::vector <ComObjPtr<GuestDirectory> > SessionDirectories;
290 typedef std::vector <ComObjPtr<GuestFile> > SessionFiles;
291 /** Map of guest processes. The key specifies the internal process number.
292 * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
293 typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
294
295public:
296 /** @name Public internal methods.
297 * @{ */
298 int directoryRemoveFromList(GuestDirectory *pDirectory);
299 int directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc);
300 int objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory, const Utf8Str &strName, int *pGuestRc);
301 int directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
302 int directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
303 int dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
304 int fileRemoveFromList(GuestFile *pFile);
305 int fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc);
306 int fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
307 uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile, int *pGuestRc);
308 int fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
309 int fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc);
310 int fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc);
311 const GuestCredentials &getCredentials(void);
312 const GuestEnvironment &getEnvironment(void);
313 Utf8Str getName(void);
314 ULONG getId(void) { return mData.mId; }
315 Guest *getParent(void) { return mData.mParent; }
316 uint32_t getProtocolVersion(void) { return mData.mProtocolVersion; }
317 int processRemoveFromList(GuestProcess *pProcess);
318 int processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
319 inline bool processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
320 inline int processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
321 int startTaskAsync(const Utf8Str &strTaskDesc, GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress);
322 int queryInfo(void);
323 /** @} */
324
325private:
326
327 struct Data
328 {
329 /** Guest control protocol version to be used.
330 * Guest Additions < VBox 4.2 have version 1,
331 * any newer version will have version 2. */
332 uint32_t mProtocolVersion;
333 /** Flag indicating if this is an internal session
334 * or not. Internal session are not accessible by clients. */
335 bool fInternal;
336 /** Pointer to the parent (Guest). */
337 Guest *mParent;
338 /** The session credentials. */
339 GuestCredentials mCredentials;
340 /** The (optional) session name. */
341 Utf8Str mName;
342 /** The session ID. */
343 ULONG mId;
344 /** The session timeout. Default is 30s. */
345 ULONG mTimeout;
346 /** The session's environment block. Can be
347 * overwritten/extended by ProcessCreate(Ex). */
348 GuestEnvironment mEnvironment;
349 /** Directory objects bound to this session. */
350 SessionDirectories mDirectories;
351 /** File objects bound to this session. */
352 SessionFiles mFiles;
353 /** Process objects bound to this session. */
354 SessionProcesses mProcesses;
355 /** Total number of session objects (processes,
356 * files, ...). */
357 uint32_t mNumObjects;
358 } mData;
359};
360
361#endif /* !____H_GUESTSESSIONIMPL */
362
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