VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/GuestFileImpl.cpp@ 43200

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

Main/Guest Control 2.0: Cleanup, separated guest error handling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1
2/* $Id: GuestFileImpl.cpp 43162 2012-09-04 13:53:59Z 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
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include "GuestFileImpl.h"
24#include "GuestSessionImpl.h"
25#include "GuestCtrlImplPrivate.h"
26
27#include "Global.h"
28#include "AutoCaller.h"
29
30#include <VBox/com/array.h>
31
32#ifdef LOG_GROUP
33 #undef LOG_GROUP
34#endif
35#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
36#include <VBox/log.h>
37
38
39// constructor / destructor
40/////////////////////////////////////////////////////////////////////////////
41
42DEFINE_EMPTY_CTOR_DTOR(GuestFile)
43
44HRESULT GuestFile::FinalConstruct(void)
45{
46 LogFlowThisFunc(("\n"));
47 return BaseFinalConstruct();
48}
49
50void GuestFile::FinalRelease(void)
51{
52 LogFlowThisFuncEnter();
53 uninit();
54 BaseFinalRelease();
55 LogFlowThisFuncLeave();
56}
57
58// public initializer/uninitializer for internal purposes only
59/////////////////////////////////////////////////////////////////////////////
60
61int GuestFile::init(GuestSession *pSession, const Utf8Str &strPath,
62 const Utf8Str &strOpenMode, const Utf8Str &strDisposition, uint32_t uCreationMode,
63 int64_t iOffset, int *pGuestRc)
64{
65 /* Enclose the state transition NotReady->InInit->Ready. */
66 AutoInitSpan autoInitSpan(this);
67 AssertReturn(autoInitSpan.isOk(), E_FAIL);
68
69 mData.mSession = pSession;
70 mData.mCreationMode = uCreationMode;
71 mData.mDisposition = GuestFile::getDispositionFromString(strDisposition);
72 mData.mFileName = strPath;
73 mData.mInitialSize = 0;
74 mData.mOpenMode = GuestFile::getOpenModeFromString(strOpenMode);
75 mData.mOffset = iOffset;
76
77 /** @todo Validate parameters! */
78 /** @todo Implement guest side file handling! */
79
80 /* Confirm a successful initialization when it's the case. */
81 autoInitSpan.setSucceeded();
82
83 return VINF_SUCCESS;
84}
85
86/**
87 * Uninitializes the instance.
88 * Called from FinalRelease().
89 */
90void GuestFile::uninit(void)
91{
92 LogFlowThisFunc(("\n"));
93
94 /* Enclose the state transition Ready->InUninit->NotReady. */
95 AutoUninitSpan autoUninitSpan(this);
96 if (autoUninitSpan.uninitDone())
97 return;
98
99 LogFlowThisFuncLeave();
100}
101
102// implementation of public getters/setters for attributes
103/////////////////////////////////////////////////////////////////////////////
104
105STDMETHODIMP GuestFile::COMGETTER(CreationMode)(ULONG *aCreationMode)
106{
107#ifndef VBOX_WITH_GUEST_CONTROL
108 ReturnComNotImplemented();
109#else
110 AutoCaller autoCaller(this);
111 if (FAILED(autoCaller.rc())) return autoCaller.rc();
112
113 CheckComArgOutPointerValid(aCreationMode);
114
115 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
116
117 *aCreationMode = mData.mCreationMode;
118
119 return S_OK;
120#endif /* VBOX_WITH_GUEST_CONTROL */
121}
122
123STDMETHODIMP GuestFile::COMGETTER(Disposition)(ULONG *aDisposition)
124{
125#ifndef VBOX_WITH_GUEST_CONTROL
126 ReturnComNotImplemented();
127#else
128 AutoCaller autoCaller(this);
129 if (FAILED(autoCaller.rc())) return autoCaller.rc();
130
131 CheckComArgOutPointerValid(aDisposition);
132
133 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
134
135 *aDisposition = mData.mDisposition;
136
137 return S_OK;
138#endif /* VBOX_WITH_GUEST_CONTROL */
139}
140
141STDMETHODIMP GuestFile::COMGETTER(FileName)(BSTR *aFileName)
142{
143#ifndef VBOX_WITH_GUEST_CONTROL
144 ReturnComNotImplemented();
145#else
146 AutoCaller autoCaller(this);
147 if (FAILED(autoCaller.rc())) return autoCaller.rc();
148
149 CheckComArgOutPointerValid(aFileName);
150
151 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
152
153 mData.mFileName.cloneTo(aFileName);
154
155 return S_OK;
156#endif /* VBOX_WITH_GUEST_CONTROL */
157}
158
159STDMETHODIMP GuestFile::COMGETTER(InitialSize)(LONG64 *aInitialSize)
160{
161#ifndef VBOX_WITH_GUEST_CONTROL
162 ReturnComNotImplemented();
163#else
164 AutoCaller autoCaller(this);
165 if (FAILED(autoCaller.rc())) return autoCaller.rc();
166
167 CheckComArgOutPointerValid(aInitialSize);
168
169 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
170
171 *aInitialSize = mData.mInitialSize;
172
173 return S_OK;
174#endif /* VBOX_WITH_GUEST_CONTROL */
175}
176
177STDMETHODIMP GuestFile::COMGETTER(Offset)(LONG64 *aOffset)
178{
179#ifndef VBOX_WITH_GUEST_CONTROL
180 ReturnComNotImplemented();
181#else
182 AutoCaller autoCaller(this);
183 if (FAILED(autoCaller.rc())) return autoCaller.rc();
184
185 CheckComArgOutPointerValid(aOffset);
186
187 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
188
189 *aOffset = mData.mOffset;
190
191 return S_OK;
192#endif /* VBOX_WITH_GUEST_CONTROL */
193}
194
195STDMETHODIMP GuestFile::COMGETTER(OpenMode)(ULONG *aOpenMode)
196{
197#ifndef VBOX_WITH_GUEST_CONTROL
198 ReturnComNotImplemented();
199#else
200 AutoCaller autoCaller(this);
201 if (FAILED(autoCaller.rc())) return autoCaller.rc();
202
203 CheckComArgOutPointerValid(aOpenMode);
204
205 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
206
207 *aOpenMode = mData.mOpenMode;
208
209 return S_OK;
210#endif /* VBOX_WITH_GUEST_CONTROL */
211}
212
213// private methods
214/////////////////////////////////////////////////////////////////////////////
215
216/* static */
217uint32_t GuestFile::getDispositionFromString(const Utf8Str &strDisposition)
218{
219 return 0; /** @todo Implement me! */
220}
221
222/* static */
223uint32_t GuestFile::getOpenModeFromString(const Utf8Str &strOpenMode)
224{
225 return 0; /** @todo Implement me! */
226}
227
228// implementation of public methods
229/////////////////////////////////////////////////////////////////////////////
230
231STDMETHODIMP GuestFile::Close(void)
232{
233#ifndef VBOX_WITH_GUEST_CONTROL
234 ReturnComNotImplemented();
235#else
236 LogFlowThisFuncEnter();
237
238 AutoCaller autoCaller(this);
239 if (FAILED(autoCaller.rc())) return autoCaller.rc();
240
241 AssertPtr(mData.mSession);
242 int rc = mData.mSession->fileRemoveFromList(this);
243
244 /*
245 * Release autocaller before calling uninit.
246 */
247 autoCaller.release();
248
249 uninit();
250
251 LogFlowFuncLeaveRC(rc);
252 return S_OK;
253#endif /* VBOX_WITH_GUEST_CONTROL */
254}
255
256STDMETHODIMP GuestFile::QueryInfo(IFsObjInfo **aInfo)
257{
258#ifndef VBOX_WITH_GUEST_CONTROL
259 ReturnComNotImplemented();
260#else
261 AutoCaller autoCaller(this);
262 if (FAILED(autoCaller.rc())) return autoCaller.rc();
263
264 ReturnComNotImplemented();
265#endif /* VBOX_WITH_GUEST_CONTROL */
266}
267
268STDMETHODIMP GuestFile::Read(ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
269{
270#ifndef VBOX_WITH_GUEST_CONTROL
271 ReturnComNotImplemented();
272#else
273 AutoCaller autoCaller(this);
274 if (FAILED(autoCaller.rc())) return autoCaller.rc();
275
276 ReturnComNotImplemented();
277#endif /* VBOX_WITH_GUEST_CONTROL */
278}
279
280STDMETHODIMP GuestFile::ReadAt(LONG64 aOffset, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
281{
282#ifndef VBOX_WITH_GUEST_CONTROL
283 ReturnComNotImplemented();
284#else
285 AutoCaller autoCaller(this);
286 if (FAILED(autoCaller.rc())) return autoCaller.rc();
287
288 ReturnComNotImplemented();
289#endif /* VBOX_WITH_GUEST_CONTROL */
290}
291
292STDMETHODIMP GuestFile::Seek(LONG64 aOffset, FileSeekType_T aType)
293{
294#ifndef VBOX_WITH_GUEST_CONTROL
295 ReturnComNotImplemented();
296#else
297 AutoCaller autoCaller(this);
298 if (FAILED(autoCaller.rc())) return autoCaller.rc();
299
300 ReturnComNotImplemented();
301#endif /* VBOX_WITH_GUEST_CONTROL */
302}
303
304STDMETHODIMP GuestFile::SetACL(IN_BSTR aACL)
305{
306#ifndef VBOX_WITH_GUEST_CONTROL
307 ReturnComNotImplemented();
308#else
309 AutoCaller autoCaller(this);
310 if (FAILED(autoCaller.rc())) return autoCaller.rc();
311
312 ReturnComNotImplemented();
313#endif /* VBOX_WITH_GUEST_CONTROL */
314}
315
316STDMETHODIMP GuestFile::Write(ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten)
317{
318#ifndef VBOX_WITH_GUEST_CONTROL
319 ReturnComNotImplemented();
320#else
321 AutoCaller autoCaller(this);
322 if (FAILED(autoCaller.rc())) return autoCaller.rc();
323
324 ReturnComNotImplemented();
325#endif /* VBOX_WITH_GUEST_CONTROL */
326}
327
328STDMETHODIMP GuestFile::WriteAt(LONG64 aOffset, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten)
329{
330#ifndef VBOX_WITH_GUEST_CONTROL
331 ReturnComNotImplemented();
332#else
333 AutoCaller autoCaller(this);
334 if (FAILED(autoCaller.rc())) return autoCaller.rc();
335
336 ReturnComNotImplemented();
337#endif /* VBOX_WITH_GUEST_CONTROL */
338}
339
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