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