VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestImpl.h@ 35638

Last change on this file since 35638 was 35638, checked in by vboxsync, 14 years ago

Main. QT/FE: fix long standing COM issue

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/** @file
2 * VirtualBox COM class implementation
3 */
4
5/*
6 * Copyright (C) 2006-2010 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.215389.xyz. 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 <VBox/ostypes.h>
23
24#ifdef VBOX_WITH_GUEST_CONTROL
25# include <VBox/HostServices/GuestControlSvc.h>
26# include "HGCM.h"
27using namespace guestControl;
28#endif
29
30typedef enum
31{
32 GUESTSTATTYPE_CPUUSER = 0,
33 GUESTSTATTYPE_CPUKERNEL = 1,
34 GUESTSTATTYPE_CPUIDLE = 2,
35 GUESTSTATTYPE_MEMTOTAL = 3,
36 GUESTSTATTYPE_MEMFREE = 4,
37 GUESTSTATTYPE_MEMBALLOON = 5,
38 GUESTSTATTYPE_MEMCACHE = 6,
39 GUESTSTATTYPE_PAGETOTAL = 7,
40 GUESTSTATTYPE_PAGEFREE = 8,
41 GUESTSTATTYPE_MAX = 9
42} GUESTSTATTYPE;
43
44class Console;
45#ifdef VBOX_WITH_GUEST_CONTROL
46class Progress;
47#endif
48
49class ATL_NO_VTABLE Guest :
50 public VirtualBoxBase,
51 VBOX_SCRIPTABLE_IMPL(IGuest)
52{
53public:
54 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Guest, IGuest)
55
56 DECLARE_NOT_AGGREGATABLE(Guest)
57
58 DECLARE_PROTECT_FINAL_CONSTRUCT()
59
60 BEGIN_COM_MAP(Guest)
61 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuest)
62 END_COM_MAP()
63
64 DECLARE_EMPTY_CTOR_DTOR (Guest)
65
66 HRESULT FinalConstruct();
67 void FinalRelease();
68
69 // Public initializer/uninitializer for internal purposes only
70 HRESULT init (Console *aParent);
71 void uninit();
72
73 // IGuest properties
74 STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
75 STDMETHOD(COMGETTER(AdditionsRunLevel)) (AdditionsRunLevelType_T *aRunLevel);
76 STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
77 /** @todo Remove later by replacing it by AdditionsFeatureAvailable(). */
78 STDMETHOD(COMGETTER(SupportsSeamless)) (BOOL *aSupportsSeamless);
79 STDMETHOD(COMGETTER(SupportsGraphics)) (BOOL *aSupportsGraphics);
80#if 0
81 /** @todo Will replace SupportsSeamless, SupportsGraphics, ... */
82 STDMETHOD(COMGETTER(AdditionsFeatureAvailable)) (LONG64 aFeature, BOOL *aActive, BOOL *aAvailable);
83#endif
84 STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
85 STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
86 STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
87 STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
88
89 // IGuest methods
90 STDMETHOD(GetAdditionsStatus)(AdditionsRunLevelType_T aLevel, BOOL *aActive);
91 STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
92 IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
93 STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
94 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
95 IN_BSTR aUserName, IN_BSTR aPassword,
96 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
97 STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, LONG64 aSize, ComSafeArrayOut(BYTE, aData));
98 STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten);
99 STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ULONG *aStatus);
100 STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
101 STDMETHOD(CreateDirectory)(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aMode, ULONG aFlags, IProgress **aProgress);
102 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
103 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
104 ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
105 STDMETHOD(UpdateGuestAdditions)(IN_BSTR aSource, ULONG aFlags, IProgress **aProgress);
106
107 // Public methods that are not in IDL (only called internally).
108 HRESULT executeProcessInternal(IN_BSTR aCommand, ULONG aFlags,
109 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
110 IN_BSTR aUserName, IN_BSTR aPassword,
111 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress, int *pRC);
112 HRESULT createDirectoryInternal(IN_BSTR aDirectory, IN_BSTR aUserName, IN_BSTR aPassword,
113 ULONG aMode, ULONG aFlags, IProgress **aProgress, int *pRC);
114 void setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType);
115 void setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision);
116 void setAdditionsStatus(VBoxGuestStatusFacility Facility, VBoxGuestStatusCurrent Status, ULONG ulFlags);
117 void setSupportedFeatures(uint32_t fCaps, uint32_t fActive);
118 HRESULT setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
119 BOOL isPageFusionEnabled();
120# ifdef VBOX_WITH_GUEST_CONTROL
121 /** Static callback for handling guest notifications. */
122 static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
123# endif
124 static HRESULT setErrorStatic(HRESULT aResultCode,
125 const Utf8Str &aText)
126 {
127 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
128 }
129
130private:
131
132 // Internal tasks
133 struct TaskGuest; /* Worker thread helper. */
134#ifdef VBOX_WITH_GUEST_CONTROL
135 HRESULT taskCopyFile(TaskGuest *aTask);
136 HRESULT taskUpdateGuestAdditions(TaskGuest *aTask);
137
138 struct CallbackContext
139 {
140 eVBoxGuestCtrlCallbackType mType;
141 /** Pointer to user-supplied data. */
142 void *pvData;
143 /** Size of user-supplied data. */
144 uint32_t cbData;
145 /** Pointer to user-supplied IProgress. */
146 ComObjPtr<Progress> pProgress;
147 };
148 /*
149 * The map key is the context ID.
150 */
151 typedef std::map< uint32_t, CallbackContext > CallbackMap;
152 typedef std::map< uint32_t, CallbackContext >::iterator CallbackMapIter;
153 typedef std::map< uint32_t, CallbackContext >::const_iterator CallbackMapIterConst;
154
155 struct GuestProcess
156 {
157 uint32_t mStatus;
158 uint32_t mFlags;
159 uint32_t mExitCode;
160 };
161 /*
162 * The map key is the PID (process identifier).
163 */
164 typedef std::map< uint32_t, GuestProcess > GuestProcessMap;
165 typedef std::map< uint32_t, GuestProcess >::iterator GuestProcessMapIter;
166 typedef std::map< uint32_t, GuestProcess >::const_iterator GuestProcessMapIterConst;
167
168 int directoryEntryAppend(const char *pszPath, PRTLISTNODE pList);
169 int directoryRead(const char *pszDirectory, const char *pszFilter, ULONG uFlags, ULONG *pcObjects, PRTLISTNODE pList);
170
171 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
172 /** Handler for guest execution control notifications. */
173 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
174 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
175 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
176 int notifyCtrlExecInStatus(uint32_t u32Function, PCALLBACKDATAEXECINSTATUS pData);
177 CallbackMapIter getCtrlCallbackContextByID(uint32_t u32ContextID);
178 GuestProcessMapIter getProcessByPID(uint32_t u32PID);
179 void notifyCtrlCallbackContext(Guest::CallbackMapIter it, const char *pszText);
180 void destroyCtrlCallbackContext(CallbackMapIter it);
181 uint32_t addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress* pProgress);
182 HRESULT waitForProcessStatusChange(ULONG uPID, ULONG *puRetStatus, ULONG *puRetExitCode, ULONG uTimeoutMS);
183# endif
184
185 struct Data
186 {
187 Data() : mAdditionsRunLevel (AdditionsRunLevelType_None),
188 mSupportsSeamless (FALSE),
189 mSupportsGraphics (FALSE) {}
190
191 Bstr mOSTypeId;
192 AdditionsRunLevelType_T mAdditionsRunLevel;
193 Bstr mAdditionsVersion;
194 Bstr mInterfaceVersion;
195 BOOL mSupportsSeamless;
196 BOOL mSupportsGraphics;
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: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette