VirtualBox

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

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

Guest Control/Main: Added stubs for IGuestSession:copy[From|To]Guest() (@bugref{9135}) and implemented internal source specification handling for sharing as much code as possible across all the guest session copy methods. Work in progress.

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