VirtualBox

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

Last change on this file since 83563 was 83336, checked in by vboxsync, 5 years ago

Guest Control/Main + Validation Kit: More bugfixing for the "copy_to" testcases, enabled more (before known-to-be-buggy) tests. bugref:9320

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