VirtualBox

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

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

Build fix.

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