VirtualBox

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

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

Guest Control/Main: More bugfixes for copyTo/copyFrom tasks, along with test cases.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
1/* $Id: GuestSessionImplTasks.h 71847 2018-04-12 12:23:29Z 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
30class Guest;
31class GuestSessionTaskInternalOpen;
32
33/**
34 * Abstract base class for a lenghtly per-session operation which
35 * runs in a Main worker thread.
36 */
37class GuestSessionTask : public ThreadTask
38{
39public:
40
41 GuestSessionTask(GuestSession *pSession);
42
43 virtual ~GuestSessionTask(void);
44
45public:
46
47 virtual int Run(void) = 0;
48 void handler()
49 {
50 int vrc = Run();
51 NOREF(vrc);
52 /** @todo
53 *
54 * r=bird: what was your idea WRT to Run status code and async tasks?
55 *
56 */
57 }
58
59 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
60
61 HRESULT Init(const Utf8Str &strTaskDesc)
62 {
63 HRESULT hr = S_OK;
64 setTaskDesc(strTaskDesc);
65 hr = createAndSetProgressObject();
66 return hr;
67 }
68
69 const ComObjPtr<Progress>& GetProgressObject() const { return mProgress; }
70
71protected:
72
73 /** @name Directory handling primitives.
74 * @{ */
75 int directoryCreate(const com::Utf8Str &strPath, DirectoryCreateFlag_T enmDirecotryCreateFlags, uint32_t uMode,
76 bool fFollowSymlinks);
77 /** @} */
78
79 /** @name File handling primitives.
80 * @{ */
81 int fileCopyFromGuestInner(ComObjPtr<GuestFile> &srcFile, PRTFILE phDstFile, FileCopyFlag_T fFileCopyFlags,
82 uint64_t offCopy, uint64_t cbSize);
83 int fileCopyFromGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
84 int fileCopyToGuestInner(PRTFILE phSrcFile, ComObjPtr<GuestFile> &dstFile, FileCopyFlag_T fFileCopyFlags,
85 uint64_t offCopy, uint64_t cbSize);
86 int fileCopyToGuest(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
87 /** @} */
88
89 /** @name Guest property handling primitives.
90 * @{ */
91 int getGuestProperty(const ComObjPtr<Guest> &pGuest, const Utf8Str &strPath, Utf8Str &strValue);
92 /** @} */
93
94 /** @name Path handling primitives.
95 * @{ */
96 int pathConstructOnGuest(const Utf8Str &strSourceRoot, const Utf8Str &strSource, const Utf8Str &strDest, Utf8Str &strOut);
97 /** @} */
98
99 int setProgress(ULONG uPercent);
100 int setProgressSuccess(void);
101 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
102
103 inline void setTaskDesc(const Utf8Str &strTaskDesc) throw()
104 {
105 mDesc = strTaskDesc;
106 }
107
108 HRESULT createAndSetProgressObject();
109
110protected:
111
112 Utf8Str mDesc;
113 /** The guest session object this task is working on. */
114 ComObjPtr<GuestSession> mSession;
115 /** Progress object for getting updated when running
116 * asynchronously. Optional. */
117 ComObjPtr<Progress> mProgress;
118 /** The guest's path style (depending on the guest OS type set). */
119 uint32_t mfPathStyle;
120};
121
122/**
123 * Task for opening a guest session.
124 */
125class SessionTaskOpen : public GuestSessionTask
126{
127public:
128
129 SessionTaskOpen(GuestSession *pSession,
130 uint32_t uFlags,
131 uint32_t uTimeoutMS);
132 virtual ~SessionTaskOpen(void);
133 int Run(void);
134
135protected:
136
137 /** Session creation flags. */
138 uint32_t mFlags;
139 /** Session creation timeout (in ms). */
140 uint32_t mTimeoutMS;
141};
142
143class GuestSessionCopyTask : public GuestSessionTask
144{
145public:
146
147 GuestSessionCopyTask(GuestSession *pSession)
148 : GuestSessionTask(pSession)
149 {
150 RT_ZERO(u);
151 }
152
153 virtual ~GuestSessionCopyTask() { }
154
155protected:
156
157 /** Source to copy from. */
158 Utf8Str mSource;
159 /** Destination to copy to. */
160 Utf8Str mDest;
161 /** Filter (wildcard-style) when copying directories. */
162 Utf8Str mFilter;
163
164 union
165 {
166 /** Directory-specific data. */
167 struct
168 {
169 /** Directory copy flags. */
170 DirectoryCopyFlag_T fCopyFlags;
171 } Dir;
172 /** File-specific data. */
173 struct
174 {
175 /** File copy flags. */
176 FileCopyFlag_T fCopyFlags;
177 /** Host file handle to use for reading from / writing to.
178 * Optional and can be NULL if not used. */
179 PRTFILE phFile;
180 /** Source file offset to start copying from. */
181 size_t offStart;
182 /** Source size (in bytes) to copy. */
183 uint64_t cbSize;
184 } File;
185 } u;
186};
187
188/**
189 * Task for copying directories from guest to the host.
190 */
191class SessionTaskCopyDirFrom : public GuestSessionCopyTask
192{
193public:
194
195 SessionTaskCopyDirFrom(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
196 DirectoryCopyFlag_T fDirCopyFlags);
197 virtual ~SessionTaskCopyDirFrom(void);
198 int Run(void);
199
200protected:
201
202 int directoryCopyToHost(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
203 bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
204};
205
206/**
207 * Task for copying directories from host to the guest.
208 */
209class SessionTaskCopyDirTo : public GuestSessionCopyTask
210{
211public:
212
213 SessionTaskCopyDirTo(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
214 DirectoryCopyFlag_T fDirCopyFlags);
215 virtual ~SessionTaskCopyDirTo(void);
216 int Run(void);
217
218protected:
219
220 int directoryCopyToGuest(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
221 bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
222};
223
224/**
225 * Task for copying files from host to the guest.
226 */
227class SessionTaskCopyFileTo : public GuestSessionCopyTask
228{
229public:
230
231 SessionTaskCopyFileTo(GuestSession *pSession,
232 const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
233 virtual ~SessionTaskCopyFileTo(void);
234 int Run(void);
235};
236
237/**
238 * Task for copying files from guest to the host.
239 */
240class SessionTaskCopyFileFrom : public GuestSessionCopyTask
241{
242public:
243
244 SessionTaskCopyFileFrom(GuestSession *pSession,
245 const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags);
246 virtual ~SessionTaskCopyFileFrom(void);
247 int Run(void);
248};
249
250/**
251 * Task for automatically updating the Guest Additions on the guest.
252 */
253class SessionTaskUpdateAdditions : public GuestSessionTask
254{
255public:
256
257 SessionTaskUpdateAdditions(GuestSession *pSession,
258 const Utf8Str &strSource, const ProcessArguments &aArguments,
259 uint32_t fFlags);
260 virtual ~SessionTaskUpdateAdditions(void);
261 int Run(void);
262
263protected:
264
265 /**
266 * Suported OS types for automatic updating.
267 */
268 enum eOSType
269 {
270 eOSType_Unknown = 0,
271 eOSType_Windows = 1,
272 eOSType_Linux = 2,
273 eOSType_Solaris = 3
274 };
275
276 /**
277 * Structure representing a file to
278 * get off the .ISO, copied to the guest.
279 */
280 struct ISOFile
281 {
282 ISOFile(const Utf8Str &aSource,
283 const Utf8Str &aDest,
284 uint32_t aFlags = 0)
285 : strSource(aSource),
286 strDest(aDest),
287 fFlags(aFlags) { }
288
289 ISOFile(const Utf8Str &aSource,
290 const Utf8Str &aDest,
291 uint32_t aFlags,
292 const GuestProcessStartupInfo &aStartupInfo)
293 : strSource(aSource),
294 strDest(aDest),
295 fFlags(aFlags),
296 mProcInfo(aStartupInfo)
297 {
298 mProcInfo.mExecutable = strDest;
299 if (mProcInfo.mName.isEmpty())
300 mProcInfo.mName = strDest;
301 }
302
303 /** Source file on .ISO. */
304 Utf8Str strSource;
305 /** Destination file on the guest. */
306 Utf8Str strDest;
307 /** ISO file flags (see ISOFILE_FLAG_ defines). */
308 uint32_t fFlags;
309 /** Optional arguments if this file needs to be
310 * executed. */
311 GuestProcessStartupInfo mProcInfo;
312 };
313
314 int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
315 int copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional);
316 int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
317
318 /** Files to handle. */
319 std::vector<ISOFile> mFiles;
320 /** The (optionally) specified Guest Additions .ISO on the host
321 * which will be used for the updating process. */
322 Utf8Str mSource;
323 /** (Optional) installer command line arguments. */
324 ProcessArguments mArguments;
325 /** Update flags. */
326 uint32_t mFlags;
327};
328#endif /* !____H_GUESTSESSIONIMPL_TASKS */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette