VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestSessionImplTasks.h@ 72958

Last change on this file since 72958 was 72958, checked in by vboxsync, 6 years ago

Main/GuestCtrl: Move the guest additions update code from RTIsoFs* to the appropriate RTVfs* APIs (not tested because of bugref:8078)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1/* $Id: GuestSessionImplTasks.h 72958 2018-07-07 21:27:53Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Guest session tasks header.
4 */
5
6/*
7 * Copyright (C) 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_TASKS
19#define ____H_GUESTSESSIONIMPL_TASKS
20
21#include "GuestSessionWrap.h"
22#include "EventImpl.h"
23
24#include "GuestCtrlImplPrivate.h"
25#include "GuestSessionImpl.h"
26#include "ThreadTask.h"
27
28#include <iprt/vfs.h>
29
30#include <vector>
31
32class Guest;
33class GuestSessionTask;
34class GuestSessionTaskInternalOpen;
35
36
37/**
38 * Structure for keeping a file system source specification,
39 * along with options.
40 */
41struct GuestSessionFsSourceSpec
42{
43 GuestSessionFsSourceSpec()
44 : enmType(FsObjType_Unknown)
45 , enmPathStyle(PathStyle_Unknown)
46 , fDryRun(false)
47 , fFollowSymlinks(false) { }
48
49 Utf8Str strSource;
50 Utf8Str strFilter;
51 FsObjType_T enmType;
52 PathStyle_T enmPathStyle;
53 bool fDryRun;
54 bool fFollowSymlinks;
55 union
56 {
57 /** Directory-specific data. */
58 struct
59 {
60 /** Directory copy flags. */
61 DirectoryCopyFlag_T fCopyFlags;
62 bool fRecursive;
63 } Dir;
64 /** File-specific data. */
65 struct
66 {
67 /** File copy flags. */
68 FileCopyFlag_T fCopyFlags;
69 /** Host file handle to use for reading from / writing to.
70 * Optional and can be NULL if not used. */
71 PRTFILE phFile;
72 /** Source file offset to start copying from. */
73 size_t offStart;
74 /** Source size (in bytes) to copy. */
75 uint64_t cbSize;
76 } File;
77 } Type;
78};
79
80/** A set of GuestSessionFsSourceSpec sources. */
81typedef std::vector<GuestSessionFsSourceSpec> GuestSessionFsSourceSet;
82
83/**
84 * Structure for keeping a file system entry.
85 */
86struct FsEntry
87{
88 /** The entrie's file mode. */
89 RTFMODE fMode;
90 /** The entrie's path, relative to the list's root path. */
91 Utf8Str strPath;
92};
93
94/** A vector of FsEntry entries. */
95typedef std::vector<FsEntry *> FsEntries;
96
97/**
98 * Class for storing and handling file system entries, neeed for doing
99 * internal file / directory operations to / from the guest.
100 */
101class FsList
102{
103public:
104
105 FsList(const GuestSessionTask &Task);
106 virtual ~FsList();
107
108public:
109
110 int Init(const Utf8Str &strSrcRootAbs, const Utf8Str &strDstRootAbs, const GuestSessionFsSourceSpec &SourceSpec);
111 void Destroy(void);
112
113 int AddEntryFromGuest(const Utf8Str &strFile, const GuestFsObjData &fsObjData);
114 int AddDirFromGuest(const Utf8Str &strPath, const Utf8Str &strSubDir = "");
115
116 int AddEntryFromHost(const Utf8Str &strFile, PCRTFSOBJINFO pcObjInfo);
117 int AddDirFromHost(const Utf8Str &strPath, const Utf8Str &strSubDir = "");
118
119public:
120
121 /** The guest session task object this list is working on. */
122 const GuestSessionTask &mTask;
123 /** File system filter / options to use for this task. */
124 GuestSessionFsSourceSpec mSourceSpec;
125 /** The source' root path.
126 * For a single file list this is the full (absolute) path to a file,
127 * for a directory list this is the source root directory. */
128 Utf8Str mSrcRootAbs;
129 /** The destinations's root path.
130 * For a single file list this is the full (absolute) path to a file,
131 * for a directory list this is the destination root directory. */
132 Utf8Str mDstRootAbs;
133 /** Total size (in bytes) of all list entries together. */
134 uint64_t mcbTotalSize;
135 /** List of file system entries this list contains. */
136 FsEntries mVecEntries;
137};
138
139/** A set of FsList lists. */
140typedef std::vector<FsList *> FsLists;
141
142/**
143 * Abstract base class for a lenghtly per-session operation which
144 * runs in a Main worker thread.
145 */
146class GuestSessionTask : public ThreadTask
147{
148public:
149
150 GuestSessionTask(GuestSession *pSession);
151
152 virtual ~GuestSessionTask(void);
153
154public:
155
156 virtual int Run(void) = 0;
157 void handler()
158 {
159 int vrc = Run();
160 NOREF(vrc);
161 /** @todo
162 *
163 * r=bird: what was your idea WRT to Run status code and async tasks?
164 *
165 */
166 }
167
168 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
169
170 virtual HRESULT Init(const Utf8Str &strTaskDesc)
171 {
172 setTaskDesc(strTaskDesc);
173 int rc = createAndSetProgressObject(); /* Single operation by default. */
174 if (RT_FAILURE(rc))
175 return E_FAIL;
176
177 return S_OK;
178 }
179
180 const ComObjPtr<Progress>& GetProgressObject(void) const { return mProgress; }
181
182 const ComObjPtr<GuestSession>& GetSession(void) const { return mSession; }
183
184protected:
185
186 /** @name Directory handling primitives.
187 * @{ */
188 int directoryCreate(const com::Utf8Str &strPath, DirectoryCreateFlag_T enmDirecotryCreateFlags, uint32_t uMode,
189 bool fFollowSymlinks);
190 /** @} */
191
192 /** @name File handling primitives.
193 * @{ */
194 int fileCopyFromGuestInner(ComObjPtr<GuestFile> &srcFile, PRTFILE phDstFile, FileCopyFlag_T fFileCopyFlags,
195 uint64_t offCopy, uint64_t cbSize);
196 int fileCopyFromGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
197 int fileCopyToGuestInner(RTVFSFILE hSrcFile, ComObjPtr<GuestFile> &dstFile, FileCopyFlag_T fFileCopyFlags,
198 uint64_t offCopy, uint64_t cbSize);
199
200 int fileCopyToGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
201 /** @} */
202
203 /** @name Guest property handling primitives.
204 * @{ */
205 int getGuestProperty(const ComObjPtr<Guest> &pGuest, const Utf8Str &strPath, Utf8Str &strValue);
206 /** @} */
207
208 int setProgress(ULONG uPercent);
209 int setProgressSuccess(void);
210 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
211
212 inline void setTaskDesc(const Utf8Str &strTaskDesc) throw()
213 {
214 mDesc = strTaskDesc;
215 }
216
217 int createAndSetProgressObject(ULONG cOperations = 1);
218
219protected:
220
221 Utf8Str mDesc;
222 /** The guest session object this task is working on. */
223 ComObjPtr<GuestSession> mSession;
224 /** Progress object for getting updated when running
225 * asynchronously. Optional. */
226 ComObjPtr<Progress> mProgress;
227 /** The guest's path style (depending on the guest OS type set). */
228 uint32_t mfPathStyle;
229 /** The guest's path style as string representation (depending on the guest OS type set). */
230 Utf8Str mPathStyle;
231};
232
233/**
234 * Task for opening a guest session.
235 */
236class GuestSessionTaskOpen : public GuestSessionTask
237{
238public:
239
240 GuestSessionTaskOpen(GuestSession *pSession,
241 uint32_t uFlags,
242 uint32_t uTimeoutMS);
243 virtual ~GuestSessionTaskOpen(void);
244 int Run(void);
245
246protected:
247
248 /** Session creation flags. */
249 uint32_t mFlags;
250 /** Session creation timeout (in ms). */
251 uint32_t mTimeoutMS;
252};
253
254class GuestSessionCopyTask : public GuestSessionTask
255{
256public:
257
258 GuestSessionCopyTask(GuestSession *pSession);
259 virtual ~GuestSessionCopyTask();
260
261protected:
262
263 /** Source set. */
264 GuestSessionFsSourceSet mSources;
265 /** Destination to copy to. */
266 Utf8Str mDest;
267 /** Vector of file system lists to handle.
268 * This either can be from the guest or the host side. */
269 FsLists mVecLists;
270};
271
272/**
273 * Guest session task for copying files / directories from guest to the host.
274 */
275class GuestSessionTaskCopyFrom : public GuestSessionCopyTask
276{
277public:
278
279 GuestSessionTaskCopyFrom(GuestSession *pSession, GuestSessionFsSourceSet vecSrc, const Utf8Str &strDest);
280 virtual ~GuestSessionTaskCopyFrom(void);
281
282 HRESULT Init(const Utf8Str &strTaskDesc);
283 int Run(void);
284};
285
286/**
287 * Task for copying directories from host to the guest.
288 */
289class GuestSessionTaskCopyTo : public GuestSessionCopyTask
290{
291public:
292
293 GuestSessionTaskCopyTo(GuestSession *pSession, GuestSessionFsSourceSet vecSrc, const Utf8Str &strDest);
294 virtual ~GuestSessionTaskCopyTo(void);
295
296 HRESULT Init(const Utf8Str &strTaskDesc);
297 int Run(void);
298};
299
300/**
301 * Guest session task for automatically updating the Guest Additions on the guest.
302 */
303class GuestSessionTaskUpdateAdditions : public GuestSessionTask
304{
305public:
306
307 GuestSessionTaskUpdateAdditions(GuestSession *pSession,
308 const Utf8Str &strSource, const ProcessArguments &aArguments,
309 uint32_t fFlags);
310 virtual ~GuestSessionTaskUpdateAdditions(void);
311 int Run(void);
312
313protected:
314
315 /**
316 * Suported OS types for automatic updating.
317 */
318 enum eOSType
319 {
320 eOSType_Unknown = 0,
321 eOSType_Windows = 1,
322 eOSType_Linux = 2,
323 eOSType_Solaris = 3
324 };
325
326 /**
327 * Structure representing a file to
328 * get off the .ISO, copied to the guest.
329 */
330 struct ISOFile
331 {
332 ISOFile(const Utf8Str &aSource,
333 const Utf8Str &aDest,
334 uint32_t aFlags = 0)
335 : strSource(aSource),
336 strDest(aDest),
337 fFlags(aFlags) { }
338
339 ISOFile(const Utf8Str &aSource,
340 const Utf8Str &aDest,
341 uint32_t aFlags,
342 const GuestProcessStartupInfo &aStartupInfo)
343 : strSource(aSource),
344 strDest(aDest),
345 fFlags(aFlags),
346 mProcInfo(aStartupInfo)
347 {
348 mProcInfo.mExecutable = strDest;
349 if (mProcInfo.mName.isEmpty())
350 mProcInfo.mName = strDest;
351 }
352
353 /** Source file on .ISO. */
354 Utf8Str strSource;
355 /** Destination file on the guest. */
356 Utf8Str strDest;
357 /** ISO file flags (see ISOFILE_FLAG_ defines). */
358 uint32_t fFlags;
359 /** Optional arguments if this file needs to be
360 * executed. */
361 GuestProcessStartupInfo mProcInfo;
362 };
363
364 int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
365 int copyFileToGuest(GuestSession *pSession, RTVFS hVfsIso, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional);
366 int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
367
368 /** Files to handle. */
369 std::vector<ISOFile> mFiles;
370 /** The (optionally) specified Guest Additions .ISO on the host
371 * which will be used for the updating process. */
372 Utf8Str mSource;
373 /** (Optional) installer command line arguments. */
374 ProcessArguments mArguments;
375 /** Update flags. */
376 uint32_t mFlags;
377};
378#endif /* !____H_GUESTSESSIONIMPL_TASKS */
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