1 | /* $Id$ */
|
---|
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 | class Guest;
|
---|
31 | class GuestSessionTaskInternalOpen;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Abstract base class for a lenghtly per-session operation which
|
---|
35 | * runs in a Main worker thread.
|
---|
36 | */
|
---|
37 | class GuestSessionTask : public ThreadTask
|
---|
38 | {
|
---|
39 | public:
|
---|
40 |
|
---|
41 | GuestSessionTask(GuestSession *pSession);
|
---|
42 |
|
---|
43 | virtual ~GuestSessionTask(void);
|
---|
44 |
|
---|
45 | public:
|
---|
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 |
|
---|
71 | protected:
|
---|
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 fileCopyFromEx(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags,
|
---|
82 | PRTFILE pFile, uint64_t cbOffset, uint64_t cbSize);
|
---|
83 | int fileCopyFrom(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
84 | int fileCopyToEx(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags, PRTFILE pFile,
|
---|
85 | uint64_t cbOffset, uint64_t cbSize); /**< r=bird: 'cbOffset' makes no sense what so ever. It should be 'off', or do you mean sizeof(uint64_t)? */
|
---|
86 | int fileCopyTo(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
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 |
|
---|
110 | protected:
|
---|
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 | };
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Task for opening a guest session.
|
---|
122 | */
|
---|
123 | class SessionTaskOpen : public GuestSessionTask
|
---|
124 | {
|
---|
125 | public:
|
---|
126 |
|
---|
127 | SessionTaskOpen(GuestSession *pSession,
|
---|
128 | uint32_t uFlags,
|
---|
129 | uint32_t uTimeoutMS);
|
---|
130 | virtual ~SessionTaskOpen(void);
|
---|
131 | int Run(void);
|
---|
132 |
|
---|
133 | protected:
|
---|
134 |
|
---|
135 | /** Session creation flags. */
|
---|
136 | uint32_t mFlags;
|
---|
137 | /** Session creation timeout (in ms). */
|
---|
138 | uint32_t mTimeoutMS;
|
---|
139 | };
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Task for copying directories from guest to the host.
|
---|
143 | */
|
---|
144 | class SessionTaskCopyDirFrom : public GuestSessionTask
|
---|
145 | {
|
---|
146 | public:
|
---|
147 |
|
---|
148 | SessionTaskCopyDirFrom(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
|
---|
149 | DirectoryCopyFlag_T enmDirCopyFlags);
|
---|
150 | virtual ~SessionTaskCopyDirFrom(void);
|
---|
151 | int Run(void);
|
---|
152 |
|
---|
153 | protected:
|
---|
154 |
|
---|
155 | int directoryCopyToHost(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
|
---|
156 | bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
|
---|
157 | protected:
|
---|
158 |
|
---|
159 | Utf8Str mSource;
|
---|
160 | Utf8Str mDest;
|
---|
161 | Utf8Str mFilter;
|
---|
162 | DirectoryCopyFlag_T mDirCopyFlags;
|
---|
163 | };
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Task for copying directories from host to the guest.
|
---|
167 | */
|
---|
168 | class SessionTaskCopyDirTo : public GuestSessionTask
|
---|
169 | {
|
---|
170 | public:
|
---|
171 |
|
---|
172 | SessionTaskCopyDirTo(GuestSession *pSession, const Utf8Str &strSource, const Utf8Str &strDest, const Utf8Str &strFilter,
|
---|
173 | DirectoryCopyFlag_T enmDirCopyFlags);
|
---|
174 | virtual ~SessionTaskCopyDirTo(void);
|
---|
175 | int Run(void);
|
---|
176 |
|
---|
177 | protected:
|
---|
178 |
|
---|
179 | int directoryCopyToGuest(const Utf8Str &strSource, const Utf8Str &strFilter, const Utf8Str &strDest, bool fRecursive,
|
---|
180 | bool fFollowSymlinks, const Utf8Str &strSubDir /* For recursion. */);
|
---|
181 | protected:
|
---|
182 |
|
---|
183 | Utf8Str mSource;
|
---|
184 | Utf8Str mDest;
|
---|
185 | Utf8Str mFilter;
|
---|
186 | DirectoryCopyFlag_T mDirCopyFlags;
|
---|
187 | };
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Task for copying files from host to the guest.
|
---|
191 | */
|
---|
192 | class SessionTaskCopyFileTo : public GuestSessionTask
|
---|
193 | {
|
---|
194 | public:
|
---|
195 |
|
---|
196 | SessionTaskCopyFileTo(GuestSession *pSession,
|
---|
197 | const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
198 | SessionTaskCopyFileTo(GuestSession *pSession,
|
---|
199 | PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
|
---|
200 | const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
201 | virtual ~SessionTaskCopyFileTo(void);
|
---|
202 | int Run(void);
|
---|
203 |
|
---|
204 | protected:
|
---|
205 |
|
---|
206 | Utf8Str mSource;
|
---|
207 | PRTFILE mSourceFile;
|
---|
208 | size_t mSourceOffset;
|
---|
209 | uint64_t mSourceSize;
|
---|
210 | Utf8Str mDest;
|
---|
211 | FileCopyFlag_T mFileCopyFlags;
|
---|
212 | };
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Task for copying files from guest to the host.
|
---|
216 | */
|
---|
217 | class SessionTaskCopyFileFrom : public GuestSessionTask
|
---|
218 | {
|
---|
219 | public:
|
---|
220 |
|
---|
221 | SessionTaskCopyFileFrom(GuestSession *pSession,
|
---|
222 | const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags);
|
---|
223 | virtual ~SessionTaskCopyFileFrom(void);
|
---|
224 | int Run(void);
|
---|
225 |
|
---|
226 | protected:
|
---|
227 |
|
---|
228 | Utf8Str mSource;
|
---|
229 | Utf8Str mDest;
|
---|
230 | FileCopyFlag_T mFileCopyFlags;
|
---|
231 | };
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Task for automatically updating the Guest Additions on the guest.
|
---|
235 | */
|
---|
236 | class SessionTaskUpdateAdditions : public GuestSessionTask
|
---|
237 | {
|
---|
238 | public:
|
---|
239 |
|
---|
240 | SessionTaskUpdateAdditions(GuestSession *pSession,
|
---|
241 | const Utf8Str &strSource, const ProcessArguments &aArguments,
|
---|
242 | uint32_t uFlags);
|
---|
243 | virtual ~SessionTaskUpdateAdditions(void);
|
---|
244 | int Run(void);
|
---|
245 |
|
---|
246 | protected:
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Suported OS types for automatic updating.
|
---|
250 | */
|
---|
251 | enum eOSType
|
---|
252 | {
|
---|
253 | eOSType_Unknown = 0,
|
---|
254 | eOSType_Windows = 1,
|
---|
255 | eOSType_Linux = 2,
|
---|
256 | eOSType_Solaris = 3
|
---|
257 | };
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Structure representing a file to
|
---|
261 | * get off the .ISO, copied to the guest.
|
---|
262 | */
|
---|
263 | struct InstallerFile
|
---|
264 | {
|
---|
265 | InstallerFile(const Utf8Str &aSource,
|
---|
266 | const Utf8Str &aDest,
|
---|
267 | uint32_t aFlags = 0)
|
---|
268 | : strSource(aSource),
|
---|
269 | strDest(aDest),
|
---|
270 | fFlags(aFlags) { }
|
---|
271 |
|
---|
272 | InstallerFile(const Utf8Str &aSource,
|
---|
273 | const Utf8Str &aDest,
|
---|
274 | uint32_t aFlags,
|
---|
275 | const GuestProcessStartupInfo &aStartupInfo)
|
---|
276 | : strSource(aSource),
|
---|
277 | strDest(aDest),
|
---|
278 | fFlags(aFlags),
|
---|
279 | mProcInfo(aStartupInfo)
|
---|
280 | {
|
---|
281 | mProcInfo.mExecutable = strDest;
|
---|
282 | if (mProcInfo.mName.isEmpty())
|
---|
283 | mProcInfo.mName = strDest;
|
---|
284 | }
|
---|
285 |
|
---|
286 | /** Source file on .ISO. */
|
---|
287 | Utf8Str strSource;
|
---|
288 | /** Destination file on the guest. */
|
---|
289 | Utf8Str strDest;
|
---|
290 | /** File flags. */
|
---|
291 | uint32_t fFlags;
|
---|
292 | /** Optional arguments if this file needs to be
|
---|
293 | * executed. */
|
---|
294 | GuestProcessStartupInfo mProcInfo;
|
---|
295 | };
|
---|
296 |
|
---|
297 | int addProcessArguments(ProcessArguments &aArgumentsDest, const ProcessArguments &aArgumentsSource);
|
---|
298 | int copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO, Utf8Str const &strFileSource, const Utf8Str &strFileDest, bool fOptional, uint32_t *pcbSize);
|
---|
299 | int runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
|
---|
300 |
|
---|
301 | /** Files to handle. */
|
---|
302 | std::vector<InstallerFile> mFiles;
|
---|
303 | /** The (optionally) specified Guest Additions .ISO on the host
|
---|
304 | * which will be used for the updating process. */
|
---|
305 | Utf8Str mSource;
|
---|
306 | /** (Optional) installer command line arguments. */
|
---|
307 | ProcessArguments mArguments;
|
---|
308 | /** Update flags. */
|
---|
309 | uint32_t mFlags;
|
---|
310 | };
|
---|
311 | #endif /* !____H_GUESTSESSIONIMPL_TASKS */
|
---|