VirtualBox

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

Last change on this file since 42748 was 42702, checked in by vboxsync, 13 years ago

Main/GuestSession: build fix (please review).

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