VirtualBox

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

Last change on this file since 97446 was 97446, checked in by vboxsync, 2 years ago

Guest Control/Main: Backed out r154417, r154418, r154419, r154420, r154433 + r154434 (temporary release logging) again. bugref:10286

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