VirtualBox

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

Last change on this file since 76553 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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