VirtualBox

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

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

Guest Control/Main: Cleaned up internal symlink handling for copyTo / copyFrom tasks.

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