VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestSessionImpl.h@ 42865

Last change on this file since 42865 was 42808, checked in by vboxsync, 13 years ago

Guest Control 2.0: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1
2/* $Id: GuestSessionImpl.h 42808 2012-08-14 14:01:11Z vboxsync $ */
3/** @file
4 * VirtualBox Main - XXX.
5 */
6
7/*
8 * Copyright (C) 2012 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef ____H_GUESTSESSIONIMPL
20#define ____H_GUESTSESSIONIMPL
21
22#include "VirtualBoxBase.h"
23
24#include "GuestCtrlImplPrivate.h"
25#include "GuestProcessImpl.h"
26#include "GuestDirectoryImpl.h"
27#include "GuestFileImpl.h"
28#include "GuestFsObjInfoImpl.h"
29
30#include <iprt/isofs.h> /* For UpdateAdditions. */
31
32class Guest;
33
34/**
35 * Abstract base class for a lenghtly per-session operation which
36 * runs in a Main worker thread.
37 */
38class GuestSessionTask
39{
40public:
41
42 GuestSessionTask(GuestSession *pSession);
43
44 virtual ~GuestSessionTask(void);
45
46public:
47
48 virtual int Run(void) = 0;
49 virtual int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress) = 0;
50
51 int setProgress(ULONG uPercent);
52 int setProgressSuccess(void);
53 HRESULT setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg);
54
55protected:
56
57 Utf8Str mDesc;
58 GuestSession *mSession;
59 /** Progress object for getting updated when running
60 * asynchronously. Optional. */
61 ComObjPtr<Progress> mProgress;
62};
63
64/**
65 * Task for copying files from host to the guest.
66 */
67class SessionTaskCopyTo : public GuestSessionTask
68{
69public:
70
71 SessionTaskCopyTo(GuestSession *pSession,
72 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
73
74 SessionTaskCopyTo(GuestSession *pSession,
75 PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
76 const Utf8Str &strDest, uint32_t uFlags);
77
78 virtual ~SessionTaskCopyTo(void);
79
80public:
81
82 int Run(void);
83 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
84 static int taskThread(RTTHREAD Thread, void *pvUser);
85
86protected:
87
88 Utf8Str mSource;
89 PRTFILE mSourceFile;
90 size_t mSourceOffset;
91 uint64_t mSourceSize;
92 Utf8Str mDest;
93 uint32_t mCopyFileFlags;
94};
95
96/**
97 * Task for copying files from guest to the host.
98 */
99class SessionTaskCopyFrom : public GuestSessionTask
100{
101public:
102
103 SessionTaskCopyFrom(GuestSession *pSession,
104 const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags);
105
106 virtual ~SessionTaskCopyFrom(void);
107
108public:
109
110 int Run(void);
111 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
112 static int taskThread(RTTHREAD Thread, void *pvUser);
113
114protected:
115
116 Utf8Str mSource;
117 Utf8Str mDest;
118 uint32_t mFlags;
119};
120
121/**
122 * Task for automatically updating the Guest Additions on the guest.
123 */
124class SessionTaskUpdateAdditions : public GuestSessionTask
125{
126public:
127
128 SessionTaskUpdateAdditions(GuestSession *pSession,
129 const Utf8Str &strSource, uint32_t uFlags);
130
131 virtual ~SessionTaskUpdateAdditions(void);
132
133public:
134
135 int Run(void);
136 int RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress);
137 static int taskThread(RTTHREAD Thread, void *pvUser);
138
139protected:
140
141 int copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO,
142 Utf8Str const &strFileSource, const Utf8Str &strFileDest,
143 bool fOptional, uint32_t *pcbSize);
144 int runFile(GuestSession *pSession, GuestProcessStartupInfo &procInfo);
145
146 /** The (optionally) specified Guest Additions .ISO on the host
147 * which will be used for the updating process. */
148 Utf8Str mSource;
149 /** Update flags. */
150 uint32_t mFlags;
151};
152
153/**
154 * Guest session implementation.
155 */
156class ATL_NO_VTABLE GuestSession :
157 public VirtualBoxBase,
158 VBOX_SCRIPTABLE_IMPL(IGuestSession)
159{
160public:
161 /** @name COM and internal init/term/mapping cruft.
162 * @{ */
163 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestSession, IGuestSession)
164 DECLARE_NOT_AGGREGATABLE(GuestSession)
165 DECLARE_PROTECT_FINAL_CONSTRUCT()
166 BEGIN_COM_MAP(GuestSession)
167 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestSession)
168 END_COM_MAP()
169 DECLARE_EMPTY_CTOR_DTOR(GuestSession)
170
171 int init(Guest *aGuest, ULONG aSessionID, Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName);
172 void uninit(void);
173 HRESULT FinalConstruct(void);
174 void FinalRelease(void);
175 /** @} */
176
177 /** @name IGuestSession properties.
178 * @{ */
179 STDMETHOD(COMGETTER(User))(BSTR *aName);
180 STDMETHOD(COMGETTER(Domain))(BSTR *aDomain);
181 STDMETHOD(COMGETTER(Name))(BSTR *aName);
182 STDMETHOD(COMGETTER(Id))(ULONG *aId);
183 STDMETHOD(COMGETTER(Timeout))(ULONG *aTimeout);
184 STDMETHOD(COMSETTER(Timeout))(ULONG aTimeout);
185 STDMETHOD(COMGETTER(Environment))(ComSafeArrayOut(BSTR, aEnvironment));
186 STDMETHOD(COMSETTER(Environment))(ComSafeArrayIn(IN_BSTR, aEnvironment));
187 STDMETHOD(COMGETTER(Processes))(ComSafeArrayOut(IGuestProcess *, aProcesses));
188 STDMETHOD(COMGETTER(Directories))(ComSafeArrayOut(IGuestDirectory *, aDirectories));
189 STDMETHOD(COMGETTER(Files))(ComSafeArrayOut(IGuestFile *, aFiles));
190 /** @} */
191
192 /** @name IGuestSession methods.
193 * @{ */
194 STDMETHOD(Close)(void);
195 STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress);
196 STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress);
197 STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ComSafeArrayIn(DirectoryCreateFlag_T, aFlags));
198 STDMETHOD(DirectoryCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, BSTR *aDirectory);
199 STDMETHOD(DirectoryExists)(IN_BSTR aPath, BOOL *aExists);
200 STDMETHOD(DirectoryOpen)(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory);
201 STDMETHOD(DirectoryQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
202 STDMETHOD(DirectoryRemove)(IN_BSTR aPath);
203 STDMETHOD(DirectoryRemoveRecursive)(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress);
204 STDMETHOD(DirectoryRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
205 STDMETHOD(DirectorySetACL)(IN_BSTR aPath, IN_BSTR aACL);
206 STDMETHOD(EnvironmentClear)(void);
207 STDMETHOD(EnvironmentGet)(IN_BSTR aName, BSTR *aValue);
208 STDMETHOD(EnvironmentSet)(IN_BSTR aName, IN_BSTR aValue);
209 STDMETHOD(EnvironmentUnset)(IN_BSTR aName);
210 STDMETHOD(FileCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, IGuestFile **aFile);
211 STDMETHOD(FileExists)(IN_BSTR aPath, BOOL *aExists);
212 STDMETHOD(FileRemove)(IN_BSTR aPath);
213 STDMETHOD(FileOpen)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile);
214 STDMETHOD(FileQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
215 STDMETHOD(FileQuerySize)(IN_BSTR aPath, LONG64 *aSize);
216 STDMETHOD(FileRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
217 STDMETHOD(FileSetACL)(IN_BSTR aPath, IN_BSTR aACL);
218 STDMETHOD(ProcessCreate)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
219 ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess);
220 STDMETHOD(ProcessCreateEx)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
221 ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
222 ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
223 IGuestProcess **aProcess);
224 STDMETHOD(ProcessGet)(ULONG aPID, IGuestProcess **aProcess);
225#if 0
226 STDMETHOD(SetTimeout)(ULONG aTimeoutMS);
227#endif
228 STDMETHOD(SymlinkCreate)(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType);
229 STDMETHOD(SymlinkExists)(IN_BSTR aSymlink, BOOL *aExists);
230 STDMETHOD(SymlinkRead)(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget);
231 STDMETHOD(SymlinkRemoveDirectory)(IN_BSTR aPath);
232 STDMETHOD(SymlinkRemoveFile)(IN_BSTR aFile);
233 /** @} */
234
235private:
236
237 typedef std::vector <ComObjPtr<GuestDirectory> > SessionDirectories;
238 typedef std::vector <ComObjPtr<GuestFile> > SessionFiles;
239 /** Map of guest processes. The key specifies the internal process number.
240 * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
241 typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
242
243public:
244 /** @name Public internal methods.
245 * @{ */
246 int directoryClose(ComObjPtr<GuestDirectory> pDirectory);
247 int directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags);
248 int objectCreateTempInternal(Utf8Str strTemplate,
249 Utf8Str strPath,
250 bool fDirectory,
251 Utf8Str &strName,
252 int *prc);
253 int directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
254 int directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
255 int dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
256 int fileClose(ComObjPtr<GuestFile> pFile);
257 int fileRemoveInternal(Utf8Str strPath, int *prc);
258 int fileOpenInternal(const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition,
259 uint32_t uCreationMode, int64_t iOffset, ComObjPtr<GuestFile> &pFile);
260 int fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
261 int fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize);
262 int fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
263 const GuestCredentials &getCredentials(void);
264 const GuestEnvironment &getEnvironment(void);
265 Utf8Str getName(void);
266 Guest *getParent(void) { return mData.mParent; }
267 uint32_t getProtocolVersion(void) { return mData.mProtocolVersion; }
268 int processClose(ComObjPtr<GuestProcess> pProcess);
269 int processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
270 inline bool processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
271 inline int processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
272 int startTaskAsync(const Utf8Str &strTaskDesc, GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress);
273 int queryInfo(void);
274 /** @} */
275
276private:
277
278 struct Data
279 {
280 /** Guest control protocol version to be used.
281 * Guest Additions < VBox 4.2 have version 1,
282 * any newer version will have version 2. */
283 uint32_t mProtocolVersion;
284 /** Flag indicating if this is an internal session
285 * or not. Internal session are not accessible by clients. */
286 bool fInternal;
287 /** Pointer to the parent (Guest). */
288 Guest *mParent;
289 /** The session credentials. */
290 GuestCredentials mCredentials;
291 /** The (optional) session name. */
292 Utf8Str mName;
293 /** The session ID. */
294 ULONG mId;
295 /** The session timeout. Default is 30s. */
296 ULONG mTimeout;
297 /** The session's environment block. Can be
298 * overwritten/extended by ProcessCreate(Ex). */
299 GuestEnvironment mEnvironment;
300 /** Directory objects bound to this session. */
301 SessionDirectories mDirectories;
302 /** File objects bound to this session. */
303 SessionFiles mFiles;
304 /** Process objects bound to this session. */
305 SessionProcesses mProcesses;
306 } mData;
307};
308
309#endif /* !____H_GUESTSESSIONIMPL */
310
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