VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestFileImpl.h@ 78296

Last change on this file since 78296 was 77587, checked in by vboxsync, 6 years ago

Guest Control/Main: Implemented virtual guest object methods for session status changes to allow guest objects set their internal state accordingly. The guest session's object map now also keeps a (weak) pointer to the guest objects for handling the callbacks.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: GuestFileImpl.h 77587 2019-03-06 16:40:18Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Guest file handling implementation.
4 */
5
6/*
7 * Copyright (C) 2012-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_GuestFileImpl_h
19#define MAIN_INCLUDED_GuestFileImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "VirtualBoxBase.h"
25#include "EventImpl.h"
26
27#include "GuestCtrlImplPrivate.h"
28#include "GuestFileWrap.h"
29
30class Console;
31class GuestSession;
32class GuestProcess;
33
34class ATL_NO_VTABLE GuestFile :
35 public GuestFileWrap,
36 public GuestObject
37{
38public:
39 /** @name COM and internal init/term/mapping cruft.
40 * @{ */
41 DECLARE_EMPTY_CTOR_DTOR(GuestFile)
42
43 int init(Console *pConsole, GuestSession *pSession, ULONG uFileID, const GuestFileOpenInfo &openInfo);
44 void uninit(void);
45
46 HRESULT FinalConstruct(void);
47 void FinalRelease(void);
48 /** @} */
49
50public:
51 /** @name Implemented virtual methods from GuestObject.
52 * @{ */
53 int i_callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
54 int i_onUnregister(void);
55 int i_onSessionStatusChange(GuestSessionStatus_T enmSessionStatus);
56 /** @} */
57
58public:
59 /** @name Public internal methods.
60 * @{ */
61 int i_closeFile(int *pGuestRc);
62 EventSource *i_getEventSource(void) { return mEventSource; }
63 static Utf8Str i_guestErrorToString(int guestRc);
64 int i_onFileNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
65 int i_onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
66 int i_openFile(uint32_t uTimeoutMS, int *pGuestRc);
67 int i_queryInfo(GuestFsObjData &objData, int *prcGuest);
68 int i_readData(uint32_t uSize, uint32_t uTimeoutMS, void* pvData, uint32_t cbData, uint32_t* pcbRead);
69 int i_readDataAt(uint64_t uOffset, uint32_t uSize, uint32_t uTimeoutMS,
70 void* pvData, size_t cbData, size_t* pcbRead);
71 int i_seekAt(int64_t iOffset, GUEST_FILE_SEEKTYPE eSeekType, uint32_t uTimeoutMS, uint64_t *puOffset);
72 static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
73 int i_setFileStatus(FileStatus_T fileStatus, int fileRc);
74 int i_waitForOffsetChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint64_t *puOffset);
75 int i_waitForRead(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead);
76 int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, FileStatus_T *pFileStatus, int *pGuestRc);
77 int i_waitForWrite(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint32_t *pcbWritten);
78 int i_writeData(uint32_t uTimeoutMS, const void *pvData, uint32_t cbData, uint32_t *pcbWritten);
79 int i_writeDataAt(uint64_t uOffset, uint32_t uTimeoutMS, const void *pvData, uint32_t cbData, uint32_t *pcbWritten);
80 /** @} */
81
82private:
83
84 /** @name Wrapped IGuestFile properties.
85 * @{ */
86 HRESULT getCreationMode(ULONG *aCreationMode);
87 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
88 HRESULT getId(ULONG *aId);
89 HRESULT getInitialSize(LONG64 *aInitialSize);
90 HRESULT getOffset(LONG64 *aOffset);
91 HRESULT getStatus(FileStatus_T *aStatus);
92 HRESULT getFilename(com::Utf8Str &aFilename);
93 HRESULT getAccessMode(FileAccessMode_T *aAccessMode);
94 HRESULT getOpenAction(FileOpenAction_T *aOpenAction);
95 /** @} */
96
97 /** @name Wrapped IGuestFile methods.
98 * @{ */
99 HRESULT close();
100 HRESULT queryInfo(ComPtr<IFsObjInfo> &aObjInfo);
101 HRESULT querySize(LONG64 *aSize);
102 HRESULT read(ULONG aToRead,
103 ULONG aTimeoutMS,
104 std::vector<BYTE> &aData);
105 HRESULT readAt(LONG64 aOffset,
106 ULONG aToRead,
107 ULONG aTimeoutMS,
108 std::vector<BYTE> &aData);
109 HRESULT seek(LONG64 aOffset,
110 FileSeekOrigin_T aWhence,
111 LONG64 *aNewOffset);
112 HRESULT setACL(const com::Utf8Str &aAcl,
113 ULONG aMode);
114 HRESULT setSize(LONG64 aSize);
115 HRESULT write(const std::vector<BYTE> &aData,
116 ULONG aTimeoutMS,
117 ULONG *aWritten);
118 HRESULT writeAt(LONG64 aOffset,
119 const std::vector<BYTE> &aData,
120 ULONG aTimeoutMS,
121 ULONG *aWritten);
122 /** @} */
123
124 /** This can safely be used without holding any locks.
125 * An AutoCaller suffices to prevent it being destroy while in use and
126 * internally there is a lock providing the necessary serialization. */
127 const ComObjPtr<EventSource> mEventSource;
128
129 struct Data
130 {
131 /** The file's open info. */
132 GuestFileOpenInfo mOpenInfo;
133 /** The file's initial size on open. */
134 uint64_t mInitialSize;
135 /** The current file status. */
136 FileStatus_T mStatus;
137 /** The last returned process status
138 * returned from the guest side. */
139 int mLastError;
140 /** The file's current offset. */
141 uint64_t mOffCurrent;
142 } mData;
143};
144
145#endif /* !MAIN_INCLUDED_GuestFileImpl_h */
146
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