VirtualBox

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

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

Build fix.

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