VirtualBox

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

最後變更 在這個檔案從96407是 96407,由 vboxsync 提交於 3 年 前

scm copyright and license note update

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette