VirtualBox

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

Last change on this file since 72045 was 72045, checked in by vboxsync, 7 years ago

Guest Control/Main: CopyTo/CopyFrom bugfixes.

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