1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 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 ____H_GUESTIMPL
|
---|
19 | #define ____H_GUESTIMPL
|
---|
20 |
|
---|
21 | #include "VirtualBoxBase.h"
|
---|
22 | #include <iprt/list.h>
|
---|
23 | #include <VBox/ostypes.h>
|
---|
24 |
|
---|
25 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
26 | # include <VBox/HostServices/GuestControlSvc.h>
|
---|
27 | # include <hgcm/HGCM.h>
|
---|
28 | using namespace guestControl;
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | typedef enum
|
---|
32 | {
|
---|
33 | GUESTSTATTYPE_CPUUSER = 0,
|
---|
34 | GUESTSTATTYPE_CPUKERNEL = 1,
|
---|
35 | GUESTSTATTYPE_CPUIDLE = 2,
|
---|
36 | GUESTSTATTYPE_MEMTOTAL = 3,
|
---|
37 | GUESTSTATTYPE_MEMFREE = 4,
|
---|
38 | GUESTSTATTYPE_MEMBALLOON = 5,
|
---|
39 | GUESTSTATTYPE_MEMCACHE = 6,
|
---|
40 | GUESTSTATTYPE_PAGETOTAL = 7,
|
---|
41 | GUESTSTATTYPE_PAGEFREE = 8,
|
---|
42 | GUESTSTATTYPE_MAX = 9
|
---|
43 | } GUESTSTATTYPE;
|
---|
44 |
|
---|
45 | class Console;
|
---|
46 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
47 | class Progress;
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | class ATL_NO_VTABLE Guest :
|
---|
51 | public VirtualBoxBase,
|
---|
52 | VBOX_SCRIPTABLE_IMPL(IGuest)
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
|
---|
56 |
|
---|
57 | DECLARE_NOT_AGGREGATABLE(Guest)
|
---|
58 |
|
---|
59 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
60 |
|
---|
61 | BEGIN_COM_MAP(Guest)
|
---|
62 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
63 | COM_INTERFACE_ENTRY(IGuest)
|
---|
64 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
65 | END_COM_MAP()
|
---|
66 |
|
---|
67 | DECLARE_EMPTY_CTOR_DTOR (Guest)
|
---|
68 |
|
---|
69 | HRESULT FinalConstruct();
|
---|
70 | void FinalRelease();
|
---|
71 |
|
---|
72 | // Public initializer/uninitializer for internal purposes only
|
---|
73 | HRESULT init (Console *aParent);
|
---|
74 | void uninit();
|
---|
75 |
|
---|
76 | // IGuest properties
|
---|
77 | STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
|
---|
78 | STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
|
---|
79 | STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
|
---|
80 | /** @todo Remove later by replacing it by AdditionsFeatureAvailable(). */
|
---|
81 | STDMETHOD(COMGETTER(SupportsSeamless)) (BOOL *aSupportsSeamless);
|
---|
82 | STDMETHOD(COMGETTER(SupportsGraphics)) (BOOL *aSupportsGraphics);
|
---|
83 | #if 0
|
---|
84 | /** @todo Will replace SupportsSeamless, SupportsGraphics, ... */
|
---|
85 | STDMETHOD(COMGETTER(AdditionsFeatureAvailable)) (LONG64 aFeature, BOOL *aActive, BOOL *aAvailable);
|
---|
86 | #endif
|
---|
87 | STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
|
---|
88 | STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
|
---|
89 | STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
|
---|
90 | STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
|
---|
91 |
|
---|
92 | // IGuest methods
|
---|
93 | STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
|
---|
94 | STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
95 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
|
---|
96 | STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
|
---|
97 | ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
98 | IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
99 | ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
|
---|
100 | STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData));
|
---|
101 | STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ULONG *aStatus);
|
---|
102 | STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, ULONG aFlags, IProgress **aProgress);
|
---|
103 | STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
104 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
|
---|
105 | ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
|
---|
106 |
|
---|
107 | // Public methods that are not in IDL (only called internally).
|
---|
108 | void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
|
---|
109 | void setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision);
|
---|
110 | void setAdditionsStatus(VBoxGuestStatusFacility Facility, VBoxGuestStatusCurrent Status, ULONG ulFlags);
|
---|
111 | void setSupportedFeatures(uint32_t fCaps, uint32_t fActive);
|
---|
112 | HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
|
---|
113 | BOOL isPageFusionEnabled();
|
---|
114 |
|
---|
115 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
116 | /** Static callback for handling guest notifications. */
|
---|
117 | static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
118 | # endif
|
---|
119 |
|
---|
120 | private:
|
---|
121 |
|
---|
122 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
123 | struct CallbackContext
|
---|
124 | {
|
---|
125 | eVBoxGuestCtrlCallbackType mType;
|
---|
126 | /** Pointer to user-supplied data. */
|
---|
127 | void *pvData;
|
---|
128 | /** Size of user-supplied data. */
|
---|
129 | uint32_t cbData;
|
---|
130 | /** Pointer to user-supplied IProgress. */
|
---|
131 | ComObjPtr<Progress> pProgress;
|
---|
132 | };
|
---|
133 | /*
|
---|
134 | * The map key is the context ID.
|
---|
135 | */
|
---|
136 | typedef std::map< uint32_t, CallbackContext > CallbackMap;
|
---|
137 | typedef std::map< uint32_t, CallbackContext >::iterator CallbackMapIter;
|
---|
138 | typedef std::map< uint32_t, CallbackContext >::const_iterator CallbackMapIterConst;
|
---|
139 |
|
---|
140 | struct GuestProcess
|
---|
141 | {
|
---|
142 | uint32_t mStatus;
|
---|
143 | uint32_t mFlags;
|
---|
144 | uint32_t mExitCode;
|
---|
145 | };
|
---|
146 | /*
|
---|
147 | * The map key is the PID (process identifier).
|
---|
148 | */
|
---|
149 | typedef std::map< uint32_t, GuestProcess > GuestProcessMap;
|
---|
150 | typedef std::map< uint32_t, GuestProcess >::iterator GuestProcessMapIter;
|
---|
151 | typedef std::map< uint32_t, GuestProcess >::const_iterator GuestProcessMapIterConst;
|
---|
152 |
|
---|
153 | #ifdef VBOX_WITH_COPYTOGUEST
|
---|
154 | /*
|
---|
155 | *
|
---|
156 | */
|
---|
157 | struct DirEntry
|
---|
158 | {
|
---|
159 | char *pszPath;
|
---|
160 | RTLISTNODE Node;
|
---|
161 | };
|
---|
162 |
|
---|
163 | int directoryEntryAppend(const char *pszPath, PRTLISTNODE pList);
|
---|
164 | int directoryRead(const char *pszDirectory, const char *pszFilter, ULONG uFlags, ULONG *pcObjects, PRTLISTNODE pList);
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
|
---|
168 | /** Handler for guest execution control notifications. */
|
---|
169 | int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
|
---|
170 | int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
|
---|
171 | int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
|
---|
172 | CallbackMapIter getCtrlCallbackContextByID(uint32_t u32ContextID);
|
---|
173 | GuestProcessMapIter getProcessByPID(uint32_t u32PID);
|
---|
174 | void destroyCtrlCallbackContext(CallbackMapIter it);
|
---|
175 | uint32_t addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress* pProgress);
|
---|
176 | # endif
|
---|
177 |
|
---|
178 | struct Data
|
---|
179 | {
|
---|
180 | Data() : mAdditionsRunLevel (AdditionsRunLevelType_None),
|
---|
181 | mSupportsSeamless (FALSE),
|
---|
182 | mSupportsGraphics (FALSE) {}
|
---|
183 |
|
---|
184 | Bstr mOSTypeId;
|
---|
185 | AdditionsRunLevelType_T mAdditionsRunLevel;
|
---|
186 | Bstr mAdditionsVersion;
|
---|
187 | Bstr mInterfaceVersion;
|
---|
188 | BOOL mSupportsSeamless;
|
---|
189 | BOOL mSupportsGraphics;
|
---|
190 | };
|
---|
191 |
|
---|
192 | ULONG mMemoryBalloonSize;
|
---|
193 | ULONG mStatUpdateInterval;
|
---|
194 | ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
|
---|
195 | BOOL mfPageFusionEnabled;
|
---|
196 |
|
---|
197 | Console *mParent;
|
---|
198 | Data mData;
|
---|
199 |
|
---|
200 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
201 | /** General extension callback for guest control. */
|
---|
202 | HGCMSVCEXTHANDLE mhExtCtrl;
|
---|
203 |
|
---|
204 | volatile uint32_t mNextContextID;
|
---|
205 | CallbackMap mCallbackMap;
|
---|
206 | GuestProcessMap mGuestProcessMap;
|
---|
207 | # endif
|
---|
208 | };
|
---|
209 |
|
---|
210 | #endif // ____H_GUESTIMPL
|
---|
211 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|