/* $Id: GuestFileImpl.cpp 42818 2012-08-15 09:45:06Z vboxsync $ */ /** @file * VirtualBox Main - XXX. */ /* * Copyright (C) 2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. */ /******************************************************************************* * Header Files * *******************************************************************************/ #include "GuestFileImpl.h" #include "GuestSessionImpl.h" #include "GuestCtrlImplPrivate.h" #include "Global.h" #include "AutoCaller.h" #include // constructor / destructor ///////////////////////////////////////////////////////////////////////////// DEFINE_EMPTY_CTOR_DTOR(GuestFile) HRESULT GuestFile::FinalConstruct() { LogFlowThisFunc(("\n")); return BaseFinalConstruct(); } void GuestFile::FinalRelease(void) { LogFlowThisFuncEnter(); uninit(); BaseFinalRelease(); LogFlowThisFuncLeave(); } // public initializer/uninitializer for internal purposes only ///////////////////////////////////////////////////////////////////////////// int GuestFile::init(GuestSession *pSession, const Utf8Str &strPath, const Utf8Str &strOpenMode, const Utf8Str &strDisposition, uint32_t uCreationMode, int64_t iOffset) { /* Enclose the state transition NotReady->InInit->Ready. */ AutoInitSpan autoInitSpan(this); AssertReturn(autoInitSpan.isOk(), E_FAIL); mData.mSession = pSession; mData.mCreationMode = uCreationMode; mData.mDisposition = getDispositionFromString(strDisposition); mData.mFileName = strPath; mData.mInitialSize = 0; mData.mOpenMode = getOpenModeFromString(strOpenMode); mData.mOffset = iOffset; /** @todo Validate parameters! */ /* Confirm a successful initialization when it's the case. */ autoInitSpan.setSucceeded(); return VINF_SUCCESS; } /** * Uninitializes the instance. * Called from FinalRelease(). */ void GuestFile::uninit(void) { LogFlowThisFunc(("\n")); /* Enclose the state transition Ready->InUninit->NotReady. */ AutoUninitSpan autoUninitSpan(this); if (autoUninitSpan.uninitDone()) return; mData.mSession->fileClose(this); } // implementation of public getters/setters for attributes ///////////////////////////////////////////////////////////////////////////// STDMETHODIMP GuestFile::COMGETTER(CreationMode)(ULONG *aCreationMode) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); CheckComArgOutPointerValid(aCreationMode); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); *aCreationMode = mData.mCreationMode; return S_OK; #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::COMGETTER(Disposition)(ULONG *aDisposition) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); CheckComArgOutPointerValid(aDisposition); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); *aDisposition = mData.mDisposition; return S_OK; #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::COMGETTER(FileName)(BSTR *aFileName) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); CheckComArgOutPointerValid(aFileName); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); mData.mFileName.cloneTo(aFileName); return S_OK; #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::COMGETTER(InitialSize)(LONG64 *aInitialSize) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); CheckComArgOutPointerValid(aInitialSize); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); *aInitialSize = mData.mInitialSize; return S_OK; #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::COMGETTER(Offset)(LONG64 *aOffset) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); CheckComArgOutPointerValid(aOffset); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); *aOffset = mData.mOffset; return S_OK; #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::COMGETTER(OpenMode)(ULONG *aOpenMode) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); CheckComArgOutPointerValid(aOpenMode); AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); *aOpenMode = mData.mOpenMode; return S_OK; #endif /* VBOX_WITH_GUEST_CONTROL */ } // private methods ///////////////////////////////////////////////////////////////////////////// /* static */ uint32_t GuestFile::getDispositionFromString(const Utf8Str &strDisposition) { return 0; /** @todo Implement me! */ } /* static */ uint32_t GuestFile::getOpenModeFromString(const Utf8Str &strOpenMode) { return 0; /** @todo Implement me! */ } // implementation of public methods ///////////////////////////////////////////////////////////////////////////// STDMETHODIMP GuestFile::Close(void) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::QueryInfo(IFsObjInfo **aInfo) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::Read(ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData)) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::ReadAt(LONG64 aOffset, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData)) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::Seek(LONG64 aOffset, FileSeekType_T aType) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::SetACL(IN_BSTR aACL) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::Write(ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ } STDMETHODIMP GuestFile::WriteAt(LONG64 aOffset, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten) { #ifndef VBOX_WITH_GUEST_CONTROL ReturnComNotImplemented(); #else AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); ReturnComNotImplemented(); #endif /* VBOX_WITH_GUEST_CONTROL */ }