VirtualBox

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

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

Main: bugref:1909: Prepared the API translation engine to using in ExtPacks and VBoxManage. Added using API translation engine in ExtPacks. Allowed VBox compilation with NLS enabled and GUI disabled. Allowed ExtPacks only compilation with NLS translation enabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1/* $Id: GuestSessionImplTasks.h 91312 2021-09-20 11:06:57Z 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
157 : public ThreadTask
158{
159public:
160 DECLARE_TRANSLATE_METHODS(GuestSessionTask)
161
162 GuestSessionTask(GuestSession *pSession);
163
164 virtual ~GuestSessionTask(void);
165
166public:
167
168 virtual int Run(void) = 0;
169 void handler()
170 {
171 int vrc = Run();
172 NOREF(vrc);
173 /** @todo
174 *
175 * r=bird: what was your idea WRT to Run status code and async tasks?
176 *
177 */
178 }
179
180 // unused: int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
181
182 virtual HRESULT Init(const Utf8Str &strTaskDesc)
183 {
184 setTaskDesc(strTaskDesc);
185 int rc = createAndSetProgressObject(); /* Single operation by default. */
186 if (RT_FAILURE(rc))
187 return E_FAIL;
188
189 return S_OK;
190 }
191
192 const ComObjPtr<Progress>& GetProgressObject(void) const { return mProgress; }
193
194 const ComObjPtr<GuestSession>& GetSession(void) const { return mSession; }
195
196protected:
197
198 /** @name Directory handling primitives.
199 * @{ */
200 int directoryCreateOnGuest(const com::Utf8Str &strPath,
201 DirectoryCreateFlag_T enmDirectoryCreateFlags, uint32_t fMode,
202 bool fFollowSymlinks, bool fCanExist);
203 int directoryCreateOnHost(const com::Utf8Str &strPath, uint32_t fCreate, uint32_t fMode, bool fCanExist);
204 /** @} */
205
206 /** @name File handling primitives.
207 * @{ */
208 int fileCopyFromGuestInner(const Utf8Str &strSrcFile, ComObjPtr<GuestFile> &srcFile,
209 const Utf8Str &strDstFile, PRTFILE phDstFile,
210 FileCopyFlag_T fFileCopyFlags, uint64_t offCopy, uint64_t cbSize);
211 int fileCopyFromGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
212 int fileCopyToGuestInner(const Utf8Str &strSrcFile, RTVFSFILE hSrcFile,
213 const Utf8Str &strDstFile, ComObjPtr<GuestFile> &dstFile,
214 FileCopyFlag_T fFileCopyFlags, uint64_t offCopy, uint64_t cbSize);
215
216 int fileCopyToGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
217 /** @} */
218
219 /** @name Guest property handling primitives.
220 * @{ */
221 int getGuestProperty(const ComObjPtr<Guest> &pGuest, const Utf8Str &strPath, Utf8Str &strValue);
222 /** @} */
223
224 int setProgress(ULONG uPercent);
225 int setProgressSuccess(void);
226 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
227 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg, const GuestErrorInfo &guestErrorInfo);
228
229 inline void setTaskDesc(const Utf8Str &strTaskDesc) throw()
230 {
231 mDesc = strTaskDesc;
232 }
233
234 int createAndSetProgressObject(ULONG cOperations = 1);
235
236protected:
237
238 Utf8Str mDesc;
239 /** The guest session object this task is working on. */
240 ComObjPtr<GuestSession> mSession;
241 /** Progress object for getting updated when running
242 * asynchronously. Optional. */
243 ComObjPtr<Progress> mProgress;
244 /** The guest's path style (depending on the guest OS type set). */
245 uint32_t mfPathStyle;
246 /** The guest's path style as string representation (depending on the guest OS type set). */
247 Utf8Str mPathStyle;
248};
249
250/**
251 * Task for opening a guest session.
252 */
253class GuestSessionTaskOpen : public GuestSessionTask
254{
255public:
256
257 GuestSessionTaskOpen(GuestSession *pSession,
258 uint32_t uFlags,
259 uint32_t uTimeoutMS);
260 virtual ~GuestSessionTaskOpen(void);
261 int Run(void);
262
263protected:
264
265 /** Session creation flags. */
266 uint32_t mFlags;
267 /** Session creation timeout (in ms). */
268 uint32_t mTimeoutMS;
269};
270
271class GuestSessionCopyTask : public GuestSessionTask
272{
273public:
274 DECLARE_TRANSLATE_METHODS(GuestSessionCopyTask)
275
276 GuestSessionCopyTask(GuestSession *pSession);
277 virtual ~GuestSessionCopyTask();
278
279protected:
280
281 /** Source set. */
282 GuestSessionFsSourceSet mSources;
283 /** Destination to copy to. */
284 Utf8Str mDest;
285 /** Vector of file system lists to handle.
286 * This either can be from the guest or the host side. */
287 FsLists mVecLists;
288};
289
290/**
291 * Guest session task for copying files / directories from guest to the host.
292 */
293class GuestSessionTaskCopyFrom : public GuestSessionCopyTask
294{
295public:
296 DECLARE_TRANSLATE_METHODS(GuestSessionTaskCopyFrom)
297
298 GuestSessionTaskCopyFrom(GuestSession *pSession, GuestSessionFsSourceSet const &vecSrc, const Utf8Str &strDest);
299 virtual ~GuestSessionTaskCopyFrom(void);
300
301 HRESULT Init(const Utf8Str &strTaskDesc);
302 int Run(void);
303};
304
305/**
306 * Task for copying directories from host to the guest.
307 */
308class GuestSessionTaskCopyTo : public GuestSessionCopyTask
309{
310public:
311 DECLARE_TRANSLATE_METHODS(GuestSessionTaskCopyTo)
312
313 GuestSessionTaskCopyTo(GuestSession *pSession, GuestSessionFsSourceSet const &vecSrc, const Utf8Str &strDest);
314 virtual ~GuestSessionTaskCopyTo(void);
315
316 HRESULT Init(const Utf8Str &strTaskDesc);
317 int Run(void);
318};
319
320/**
321 * Guest session task for automatically updating the Guest Additions on the guest.
322 */
323class GuestSessionTaskUpdateAdditions : public GuestSessionTask
324{
325public:
326 DECLARE_TRANSLATE_METHODS(GuestSessionTaskUpdateAdditions)
327
328 GuestSessionTaskUpdateAdditions(GuestSession *pSession, const Utf8Str &strSource,
329 const ProcessArguments &aArguments, uint32_t fFlags);
330 virtual ~GuestSessionTaskUpdateAdditions(void);
331 int Run(void);
332
333protected:
334
335 /**
336 * Suported OS types for automatic updating.
337 */
338 enum eOSType
339 {
340 eOSType_Unknown = 0,
341 eOSType_Windows = 1,
342 eOSType_Linux = 2,
343 eOSType_Solaris = 3
344 };
345
346 /**
347 * Structure representing a file to
348 * get off the .ISO, copied to the guest.
349 */
350 struct ISOFile
351 {
352 ISOFile(const Utf8Str &aSource,
353 const Utf8Str &aDest,
354 uint32_t aFlags = 0)
355 : strSource(aSource),
356 strDest(aDest),
357 fFlags(aFlags) { }
358
359 ISOFile(const Utf8Str &aSource,
360 const Utf8Str &aDest,
361 uint32_t aFlags,
362 const GuestProcessStartupInfo &aStartupInfo)
363 : strSource(aSource),
364 strDest(aDest),
365 fFlags(aFlags),
366 mProcInfo(aStartupInfo)
367 {
368 mProcInfo.mExecutable = strDest;
369 if (mProcInfo.mName.isEmpty())
370 mProcInfo.mName = strDest;
371 }
372
373 /** Source file on .ISO. */
374 Utf8Str strSource;
375 /** Destination file on the guest. */
376 Utf8Str strDest;
377 /** ISO file flags (see ISOFILE_FLAG_ defines). */
378 uint32_t fFlags;
379 /** Optional arguments if this file needs to be
380 * executed. */
381 GuestProcessStartupInfo mProcInfo;
382 };
383
384 int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
385 int copyFileToGuest(GuestSession *pSession, RTVFS hVfsIso, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional);
386 int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
387
388 /** Files to handle. */
389 std::vector<ISOFile> mFiles;
390 /** The (optionally) specified Guest Additions .ISO on the host
391 * which will be used for the updating process. */
392 Utf8Str mSource;
393 /** (Optional) installer command line arguments. */
394 ProcessArguments mArguments;
395 /** Update flags. */
396 uint32_t mFlags;
397};
398#endif /* !MAIN_INCLUDED_GuestSessionImplTasks_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use