VirtualBox

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

Last change on this file since 86506 was 84648, checked in by vboxsync, 4 years ago

Guest Control/Main: Big guest error information revamp, to show more information about the actual context in which an error occurred. bugref:9320

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1/* $Id: GuestSessionImplTasks.h 84648 2020-06-03 08:11:04Z 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(const Utf8Str &strSrcFile, ComObjPtr<GuestFile> &srcFile,
207 const Utf8Str &strDstFile, PRTFILE phDstFile,
208 FileCopyFlag_T fFileCopyFlags, uint64_t offCopy, uint64_t cbSize);
209 int fileCopyFromGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
210 int fileCopyToGuestInner(const Utf8Str &strSrcFile, RTVFSFILE hSrcFile,
211 const Utf8Str &strDstFile, ComObjPtr<GuestFile> &dstFile,
212 FileCopyFlag_T fFileCopyFlags, uint64_t offCopy, uint64_t cbSize);
213
214 int fileCopyToGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
215 /** @} */
216
217 /** @name Guest property handling primitives.
218 * @{ */
219 int getGuestProperty(const ComObjPtr<Guest> &pGuest, const Utf8Str &strPath, Utf8Str &strValue);
220 /** @} */
221
222 int setProgress(ULONG uPercent);
223 int setProgressSuccess(void);
224 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
225 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg, const GuestErrorInfo &guestErrorInfo);
226
227 inline void setTaskDesc(const Utf8Str &strTaskDesc) throw()
228 {
229 mDesc = strTaskDesc;
230 }
231
232 int createAndSetProgressObject(ULONG cOperations = 1);
233
234protected:
235
236 Utf8Str mDesc;
237 /** The guest session object this task is working on. */
238 ComObjPtr<GuestSession> mSession;
239 /** Progress object for getting updated when running
240 * asynchronously. Optional. */
241 ComObjPtr<Progress> mProgress;
242 /** The guest's path style (depending on the guest OS type set). */
243 uint32_t mfPathStyle;
244 /** The guest's path style as string representation (depending on the guest OS type set). */
245 Utf8Str mPathStyle;
246};
247
248/**
249 * Task for opening a guest session.
250 */
251class GuestSessionTaskOpen : public GuestSessionTask
252{
253public:
254
255 GuestSessionTaskOpen(GuestSession *pSession,
256 uint32_t uFlags,
257 uint32_t uTimeoutMS);
258 virtual ~GuestSessionTaskOpen(void);
259 int Run(void);
260
261protected:
262
263 /** Session creation flags. */
264 uint32_t mFlags;
265 /** Session creation timeout (in ms). */
266 uint32_t mTimeoutMS;
267};
268
269class GuestSessionCopyTask : public GuestSessionTask
270{
271public:
272
273 GuestSessionCopyTask(GuestSession *pSession);
274 virtual ~GuestSessionCopyTask();
275
276protected:
277
278 /** Source set. */
279 GuestSessionFsSourceSet mSources;
280 /** Destination to copy to. */
281 Utf8Str mDest;
282 /** Vector of file system lists to handle.
283 * This either can be from the guest or the host side. */
284 FsLists mVecLists;
285};
286
287/**
288 * Guest session task for copying files / directories from guest to the host.
289 */
290class GuestSessionTaskCopyFrom : public GuestSessionCopyTask
291{
292public:
293
294 GuestSessionTaskCopyFrom(GuestSession *pSession, GuestSessionFsSourceSet const &vecSrc, const Utf8Str &strDest);
295 virtual ~GuestSessionTaskCopyFrom(void);
296
297 HRESULT Init(const Utf8Str &strTaskDesc);
298 int Run(void);
299};
300
301/**
302 * Task for copying directories from host to the guest.
303 */
304class GuestSessionTaskCopyTo : public GuestSessionCopyTask
305{
306public:
307
308 GuestSessionTaskCopyTo(GuestSession *pSession, GuestSessionFsSourceSet const &vecSrc, const Utf8Str &strDest);
309 virtual ~GuestSessionTaskCopyTo(void);
310
311 HRESULT Init(const Utf8Str &strTaskDesc);
312 int Run(void);
313};
314
315/**
316 * Guest session task for automatically updating the Guest Additions on the guest.
317 */
318class GuestSessionTaskUpdateAdditions : public GuestSessionTask
319{
320public:
321
322 GuestSessionTaskUpdateAdditions(GuestSession *pSession, const Utf8Str &strSource,
323 const ProcessArguments &aArguments, uint32_t fFlags);
324 virtual ~GuestSessionTaskUpdateAdditions(void);
325 int Run(void);
326
327protected:
328
329 /**
330 * Suported OS types for automatic updating.
331 */
332 enum eOSType
333 {
334 eOSType_Unknown = 0,
335 eOSType_Windows = 1,
336 eOSType_Linux = 2,
337 eOSType_Solaris = 3
338 };
339
340 /**
341 * Structure representing a file to
342 * get off the .ISO, copied to the guest.
343 */
344 struct ISOFile
345 {
346 ISOFile(const Utf8Str &aSource,
347 const Utf8Str &aDest,
348 uint32_t aFlags = 0)
349 : strSource(aSource),
350 strDest(aDest),
351 fFlags(aFlags) { }
352
353 ISOFile(const Utf8Str &aSource,
354 const Utf8Str &aDest,
355 uint32_t aFlags,
356 const GuestProcessStartupInfo &aStartupInfo)
357 : strSource(aSource),
358 strDest(aDest),
359 fFlags(aFlags),
360 mProcInfo(aStartupInfo)
361 {
362 mProcInfo.mExecutable = strDest;
363 if (mProcInfo.mName.isEmpty())
364 mProcInfo.mName = strDest;
365 }
366
367 /** Source file on .ISO. */
368 Utf8Str strSource;
369 /** Destination file on the guest. */
370 Utf8Str strDest;
371 /** ISO file flags (see ISOFILE_FLAG_ defines). */
372 uint32_t fFlags;
373 /** Optional arguments if this file needs to be
374 * executed. */
375 GuestProcessStartupInfo mProcInfo;
376 };
377
378 int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
379 int copyFileToGuest(GuestSession *pSession, RTVFS hVfsIso, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional);
380 int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
381
382 /** Files to handle. */
383 std::vector<ISOFile> mFiles;
384 /** The (optionally) specified Guest Additions .ISO on the host
385 * which will be used for the updating process. */
386 Utf8Str mSource;
387 /** (Optional) installer command line arguments. */
388 ProcessArguments mArguments;
389 /** Update flags. */
390 uint32_t mFlags;
391};
392#endif /* !MAIN_INCLUDED_GuestSessionImplTasks_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use