1 | /** @file
|
---|
2 | * VirtualBox COM class implementation
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ____H_GUESTIMPL
|
---|
18 | #define ____H_GUESTIMPL
|
---|
19 |
|
---|
20 | #include "VirtualBoxBase.h"
|
---|
21 | #include <iprt/list.h>
|
---|
22 | #include <iprt/time.h>
|
---|
23 | #include <VBox/ostypes.h>
|
---|
24 |
|
---|
25 | #include "AdditionsFacilityImpl.h"
|
---|
26 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
27 | # include <VBox/HostServices/GuestControlSvc.h>
|
---|
28 | # include "HGCM.h"
|
---|
29 | using namespace guestControl;
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | typedef enum
|
---|
33 | {
|
---|
34 | GUESTSTATTYPE_CPUUSER = 0,
|
---|
35 | GUESTSTATTYPE_CPUKERNEL = 1,
|
---|
36 | GUESTSTATTYPE_CPUIDLE = 2,
|
---|
37 | GUESTSTATTYPE_MEMTOTAL = 3,
|
---|
38 | GUESTSTATTYPE_MEMFREE = 4,
|
---|
39 | GUESTSTATTYPE_MEMBALLOON = 5,
|
---|
40 | GUESTSTATTYPE_MEMCACHE = 6,
|
---|
41 | GUESTSTATTYPE_PAGETOTAL = 7,
|
---|
42 | GUESTSTATTYPE_PAGEFREE = 8,
|
---|
43 | GUESTSTATTYPE_MAX = 9
|
---|
44 | } GUESTSTATTYPE;
|
---|
45 |
|
---|
46 | class Console;
|
---|
47 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
48 | class Progress;
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | class ATL_NO_VTABLE Guest :
|
---|
52 | public VirtualBoxBase,
|
---|
53 | VBOX_SCRIPTABLE_IMPL(IGuest)
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
|
---|
57 |
|
---|
58 | DECLARE_NOT_AGGREGATABLE(Guest)
|
---|
59 |
|
---|
60 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
61 |
|
---|
62 | BEGIN_COM_MAP(Guest)
|
---|
63 | VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
|
---|
64 | END_COM_MAP()
|
---|
65 |
|
---|
66 | DECLARE_EMPTY_CTOR_DTOR (Guest)
|
---|
67 |
|
---|
68 | HRESULT FinalConstruct();
|
---|
69 | void FinalRelease();
|
---|
70 |
|
---|
71 | // Public initializer/uninitializer for internal purposes only
|
---|
72 | HRESULT init (Console *aParent);
|
---|
73 | void uninit();
|
---|
74 |
|
---|
75 | // IGuest properties
|
---|
76 | STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
|
---|
77 | STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
|
---|
78 | STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
|
---|
79 | STDMETHOD(COMGETTER(Facilities)) (ComSafeArrayOut(IAdditionsFacility*, aFacilities));
|
---|
80 | STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
|
---|
81 | STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
|
---|
82 | STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
|
---|
83 | STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
|
---|
84 |
|
---|
85 | // IGuest methods
|
---|
86 | STDMETHOD(GetFacilityStatus)(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus);
|
---|
87 | STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
|
---|
88 | STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
89 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
|
---|
90 | STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
|
---|
91 | ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
92 | IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
93 | ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
|
---|
94 | STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData));
|
---|
95 | STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten);
|
---|
96 | STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ExecuteProcessStatus_T *aStatus);
|
---|
97 | STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
|
---|
98 | STDMETHOD(CreateDirectory)(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aMode, ULONG aFlags, IProgress **aProgress);
|
---|
99 | STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
100 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
|
---|
101 | ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
|
---|
102 | STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ULONG aFlags, IProgress **aProgress);
|
---|
103 |
|
---|
104 | // Public methods that are not in IDL (only called internally).
|
---|
105 | HRESULT executeProcessInternal(IN_BSTR aCommand, ULONG aFlags,
|
---|
106 | ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
107 | IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
108 | ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress, int *pRC);
|
---|
109 | HRESULT createDirectoryInternal(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
110 | ULONG aMode, ULONG aFlags, IProgress **aProgress, int *pRC);
|
---|
111 | void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
|
---|
112 | void setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision);
|
---|
113 | bool facilityIsActive(VBoxGuestFacilityType enmFacility);
|
---|
114 | HRESULT facilityUpdate(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus);
|
---|
115 | void setAdditionsStatus(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus, ULONG aFlags);
|
---|
116 | void setSupportedFeatures(uint32_t aCaps);
|
---|
117 | HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
|
---|
118 | BOOL isPageFusionEnabled();
|
---|
119 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
120 | /** Static callback for handling guest notifications. */
|
---|
121 | static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
122 | # endif
|
---|
123 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
124 | const Utf8Str &aText)
|
---|
125 | {
|
---|
126 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
127 | }
|
---|
128 |
|
---|
129 | private:
|
---|
130 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
131 | // Internal tasks.
|
---|
132 | struct TaskGuest; /* Worker thread helper. */
|
---|
133 | HRESULT taskCopyFile(TaskGuest *aTask);
|
---|
134 | HRESULT taskUpdateGuestAdditions(TaskGuest *aTask);
|
---|
135 |
|
---|
136 | // Internal callback context handling.
|
---|
137 | struct CallbackContext
|
---|
138 | {
|
---|
139 | eVBoxGuestCtrlCallbackType mType;
|
---|
140 | /** Pointer to user-supplied data. */
|
---|
141 | void *pvData;
|
---|
142 | /** Size of user-supplied data. */
|
---|
143 | uint32_t cbData;
|
---|
144 | /** Pointer to user-supplied IProgress. */
|
---|
145 | ComObjPtr<Progress> pProgress;
|
---|
146 | };
|
---|
147 | /*
|
---|
148 | * The map key is the context ID.
|
---|
149 | */
|
---|
150 | typedef std::map< uint32_t, CallbackContext > CallbackMap;
|
---|
151 | typedef std::map< uint32_t, CallbackContext >::iterator CallbackMapIter;
|
---|
152 | typedef std::map< uint32_t, CallbackContext >::const_iterator CallbackMapIterConst;
|
---|
153 |
|
---|
154 | struct GuestProcess
|
---|
155 | {
|
---|
156 | ExecuteProcessStatus_T mStatus;
|
---|
157 | uint32_t mFlags;
|
---|
158 | uint32_t mExitCode;
|
---|
159 | };
|
---|
160 | /*
|
---|
161 | * The map key is the PID (process identifier).
|
---|
162 | */
|
---|
163 | typedef std::map< uint32_t, GuestProcess > GuestProcessMap;
|
---|
164 | typedef std::map< uint32_t, GuestProcess >::iterator GuestProcessMapIter;
|
---|
165 | typedef std::map< uint32_t, GuestProcess >::const_iterator GuestProcessMapIterConst;
|
---|
166 |
|
---|
167 | int directoryEntryAppend(const char *pszPath, PRTLISTNODE pList);
|
---|
168 | int directoryRead(const char *pszDirectory, const char *pszFilter, ULONG uFlags, ULONG *pcObjects, PRTLISTNODE pList);
|
---|
169 |
|
---|
170 | int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
|
---|
171 | /** Handler for guest execution control notifications. */
|
---|
172 | int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
|
---|
173 | int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
|
---|
174 | int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
|
---|
175 | int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
|
---|
176 | CallbackMapIter getCtrlCallbackContextByID(uint32_t u32ContextID);
|
---|
177 | GuestProcessMapIter getProcessByPID(uint32_t u32PID);
|
---|
178 | void notifyCtrlCallbackContext(Guest::CallbackMapIter it, const char *pszText);
|
---|
179 | void destroyCtrlCallbackContext(CallbackMapIter it);
|
---|
180 | uint32_t addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress* pProgress);
|
---|
181 | HRESULT waitForProcessStatusChange(ULONG uPID, ExecuteProcessStatus_T *pRetStatus, ULONG *puRetExitCode, ULONG uTimeoutMS);
|
---|
182 | # endif
|
---|
183 |
|
---|
184 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> > FacilityMap;
|
---|
185 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::iterator FacilityMapIter;
|
---|
186 | typedef std::map< AdditionsFacilityType_T, ComObjPtr<AdditionsFacility> >::const_iterator FacilityMapIterConst;
|
---|
187 |
|
---|
188 | struct Data
|
---|
189 | {
|
---|
190 | Data() : mAdditionsRunLevel (AdditionsRunLevelType_None) {}
|
---|
191 |
|
---|
192 | Bstr mOSTypeId;
|
---|
193 | FacilityMap mFacilityMap;
|
---|
194 | AdditionsRunLevelType_T mAdditionsRunLevel;
|
---|
195 | Bstr mAdditionsVersion;
|
---|
196 | Bstr mInterfaceVersion;
|
---|
197 | };
|
---|
198 |
|
---|
199 | ULONG mMemoryBalloonSize;
|
---|
200 | ULONG mStatUpdateInterval;
|
---|
201 | ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
|
---|
202 | BOOL mfPageFusionEnabled;
|
---|
203 |
|
---|
204 | Console *mParent;
|
---|
205 | Data mData;
|
---|
206 |
|
---|
207 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
208 | /** General extension callback for guest control. */
|
---|
209 | HGCMSVCEXTHANDLE mhExtCtrl;
|
---|
210 |
|
---|
211 | volatile uint32_t mNextContextID;
|
---|
212 | CallbackMap mCallbackMap;
|
---|
213 | GuestProcessMap mGuestProcessMap;
|
---|
214 | # endif
|
---|
215 | };
|
---|
216 |
|
---|
217 | #endif // ____H_GUESTIMPL
|
---|
218 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|