VirtualBox

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

Last change on this file since 78327 was 77531, checked in by vboxsync, 6 years ago

Guest Control/Main: Fixed directory creation / mode flags for session tasks.

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