VirtualBox

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

Last change on this file since 92822 was 92822, checked in by vboxsync, 3 years ago

Guest Control: Resolved a @todo: Implemented DirectoryCopyFlag_Recursive + DirectoryCopyFlag_FollowLinks and no longer do this implicitly internally.

  • 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 92822 2021-12-08 14:55:45Z 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 } Dir;
70 /** File-specific data. */
71 struct
72 {
73 /** File copy flags. */
74 FileCopyFlag_T fCopyFlags;
75 /** Source file offset to start copying from. */
76 size_t offStart;
77 /** Host file handle to use for reading from / writing to.
78 * Optional and can be NULL if not used. */
79 PRTFILE phFile;
80 /** Source size (in bytes) to copy. */
81 uint64_t cbSize;
82 } File;
83 } Type;
84};
85
86/** A set of GuestSessionFsSourceSpec sources. */
87typedef std::vector<GuestSessionFsSourceSpec> GuestSessionFsSourceSet;
88
89/**
90 * Structure for keeping a file system entry.
91 */
92struct FsEntry
93{
94 /** The entrie's file mode. */
95 RTFMODE fMode;
96 /** The entrie's path, relative to the list's root path. */
97 Utf8Str strPath;
98};
99
100/** A vector of FsEntry entries. */
101typedef std::vector<FsEntry *> FsEntries;
102
103/**
104 * Class for storing and handling file system entries, neeed for doing
105 * internal file / directory operations to / from the guest.
106 */
107class FsList
108{
109public:
110
111 FsList(const GuestSessionTask &Task);
112 virtual ~FsList();
113
114public:
115
116 int Init(const Utf8Str &strSrcRootAbs, const Utf8Str &strDstRootAbs, const GuestSessionFsSourceSpec &SourceSpec);
117 void Destroy(void);
118
119 int AddEntryFromGuest(const Utf8Str &strFile, const GuestFsObjData &fsObjData);
120 int AddDirFromGuest(const Utf8Str &strPath, const Utf8Str &strSubDir = "");
121
122 int AddEntryFromHost(const Utf8Str &strFile, PCRTFSOBJINFO pcObjInfo);
123 int AddDirFromHost(const Utf8Str &strPath, const Utf8Str &strSubDir = "");
124
125public:
126
127 /** The guest session task object this list is working on. */
128 const GuestSessionTask &mTask;
129 /** File system filter / options to use for this task. */
130 GuestSessionFsSourceSpec mSourceSpec;
131 /** The source' root path.
132 * For a single file list this is the full (absolute) path to a file,
133 * for a directory list this is the source root directory. */
134 Utf8Str mSrcRootAbs;
135 /** The destinations's 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 destination root directory. */
138 Utf8Str mDstRootAbs;
139 /** Total size (in bytes) of all list entries together. */
140 uint64_t mcbTotalSize;
141 /** List of file system entries this list contains. */
142 FsEntries mVecEntries;
143};
144
145/** A set of FsList lists. */
146typedef std::vector<FsList *> FsLists;
147
148/**
149 * Abstract base class for a lenghtly per-session operation which
150 * runs in a Main worker thread.
151 */
152class GuestSessionTask
153 : public ThreadTask
154{
155public:
156 DECLARE_TRANSLATE_METHODS(GuestSessionTask)
157
158 GuestSessionTask(GuestSession *pSession);
159
160 virtual ~GuestSessionTask(void);
161
162public:
163
164 virtual int Run(void) = 0;
165 void handler()
166 {
167 int vrc = Run();
168 NOREF(vrc);
169 /** @todo
170 *
171 * r=bird: what was your idea WRT to Run status code and async tasks?
172 *
173 */
174 }
175
176 // unused: int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
177
178 virtual HRESULT Init(const Utf8Str &strTaskDesc)
179 {
180 setTaskDesc(strTaskDesc);
181 int rc = createAndSetProgressObject(); /* Single operation by default. */
182 if (RT_FAILURE(rc))
183 return E_FAIL;
184
185 return S_OK;
186 }
187
188 const ComObjPtr<Progress>& GetProgressObject(void) const { return mProgress; }
189
190 const ComObjPtr<GuestSession>& GetSession(void) const { return mSession; }
191
192protected:
193
194 /** @name Directory handling primitives.
195 * @{ */
196 int directoryCreateOnGuest(const com::Utf8Str &strPath,
197 DirectoryCreateFlag_T enmDirectoryCreateFlags, uint32_t fMode,
198 bool fFollowSymlinks, bool fCanExist);
199 int directoryCreateOnHost(const com::Utf8Str &strPath, uint32_t fCreate, uint32_t fMode, bool fCanExist);
200 /** @} */
201
202 /** @name File handling primitives.
203 * @{ */
204 int fileCopyFromGuestInner(const Utf8Str &strSrcFile, ComObjPtr<GuestFile> &srcFile,
205 const Utf8Str &strDstFile, PRTFILE phDstFile,
206 FileCopyFlag_T fFileCopyFlags, uint64_t offCopy, uint64_t cbSize);
207 int fileCopyFromGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
208 int fileCopyToGuestInner(const Utf8Str &strSrcFile, RTVFSFILE hSrcFile,
209 const Utf8Str &strDstFile, ComObjPtr<GuestFile> &dstFile,
210 FileCopyFlag_T fFileCopyFlags, 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 hr, const Utf8Str &strMsg, const GuestErrorInfo &guestErrorInfo);
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 DECLARE_TRANSLATE_METHODS(GuestSessionCopyTask)
271
272 GuestSessionCopyTask(GuestSession *pSession);
273 virtual ~GuestSessionCopyTask();
274
275protected:
276
277 /** Source set. */
278 GuestSessionFsSourceSet mSources;
279 /** Destination to copy to. */
280 Utf8Str mDest;
281 /** Vector of file system lists to handle.
282 * This either can be from the guest or the host side. */
283 FsLists mVecLists;
284};
285
286/**
287 * Guest session task for copying files / directories from guest to the host.
288 */
289class GuestSessionTaskCopyFrom : public GuestSessionCopyTask
290{
291public:
292 DECLARE_TRANSLATE_METHODS(GuestSessionTaskCopyFrom)
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 DECLARE_TRANSLATE_METHODS(GuestSessionTaskCopyTo)
308
309 GuestSessionTaskCopyTo(GuestSession *pSession, GuestSessionFsSourceSet const &vecSrc, const Utf8Str &strDest);
310 virtual ~GuestSessionTaskCopyTo(void);
311
312 HRESULT Init(const Utf8Str &strTaskDesc);
313 int Run(void);
314};
315
316/**
317 * Guest session task for automatically updating the Guest Additions on the guest.
318 */
319class GuestSessionTaskUpdateAdditions : public GuestSessionTask
320{
321public:
322 DECLARE_TRANSLATE_METHODS(GuestSessionTaskUpdateAdditions)
323
324 GuestSessionTaskUpdateAdditions(GuestSession *pSession, const Utf8Str &strSource,
325 const ProcessArguments &aArguments, uint32_t fFlags);
326 virtual ~GuestSessionTaskUpdateAdditions(void);
327 int Run(void);
328
329protected:
330
331 /**
332 * Suported OS types for automatic updating.
333 */
334 enum eOSType
335 {
336 eOSType_Unknown = 0,
337 eOSType_Windows = 1,
338 eOSType_Linux = 2,
339 eOSType_Solaris = 3
340 };
341
342 /**
343 * Structure representing a file to
344 * get off the .ISO, copied to the guest.
345 */
346 struct ISOFile
347 {
348 ISOFile(const Utf8Str &aSource,
349 const Utf8Str &aDest,
350 uint32_t aFlags = 0)
351 : strSource(aSource),
352 strDest(aDest),
353 fFlags(aFlags) { }
354
355 ISOFile(const Utf8Str &aSource,
356 const Utf8Str &aDest,
357 uint32_t aFlags,
358 const GuestProcessStartupInfo &aStartupInfo)
359 : strSource(aSource),
360 strDest(aDest),
361 fFlags(aFlags),
362 mProcInfo(aStartupInfo)
363 {
364 mProcInfo.mExecutable = strDest;
365 if (mProcInfo.mName.isEmpty())
366 mProcInfo.mName = strDest;
367 }
368
369 /** Source file on .ISO. */
370 Utf8Str strSource;
371 /** Destination file on the guest. */
372 Utf8Str strDest;
373 /** ISO file flags (see ISOFILE_FLAG_ defines). */
374 uint32_t fFlags;
375 /** Optional arguments if this file needs to be
376 * executed. */
377 GuestProcessStartupInfo mProcInfo;
378 };
379
380 int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
381 int copyFileToGuest(GuestSession *pSession, RTVFS hVfsIso, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional);
382 int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
383
384 /** Files to handle. */
385 std::vector<ISOFile> mFiles;
386 /** The (optionally) specified Guest Additions .ISO on the host
387 * which will be used for the updating process. */
388 Utf8Str mSource;
389 /** (Optional) installer command line arguments. */
390 ProcessArguments mArguments;
391 /** Update flags. */
392 uint32_t mFlags;
393};
394#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