VirtualBox

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

Last change on this file since 42618 was 42618, checked in by vboxsync, 12 years ago

Main/GuestCtrl: add FileRemove API. Untested.

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