VirtualBox

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

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

Guest Control: Use maps instead of lists; should boost performance a bit.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 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 <VBox/ostypes.h>
23
24#ifdef VBOX_WITH_GUEST_CONTROL
25# include <VBox/HostServices/GuestControlSvc.h>
26# include <hgcm/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 VirtualBoxSupportErrorInfoImpl<Guest, IGuest>,
51 public VirtualBoxSupportTranslation<Guest>,
52 public VirtualBoxBase,
53 VBOX_SCRIPTABLE_IMPL(IGuest)
54{
55public:
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(AdditionsActive)) (BOOL *aAdditionsActive);
79 STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
80 STDMETHOD(COMGETTER(SupportsSeamless)) (BOOL *aSupportsSeamless);
81 STDMETHOD(COMGETTER(SupportsGraphics)) (BOOL *aSupportsGraphics);
82 STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
83 STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
84 STDMETHOD(COMGETTER(PageFusionEnabled)) (BOOL *aPageFusionEnabled);
85 STDMETHOD(COMSETTER(PageFusionEnabled)) (BOOL aPageFusionEnabled);
86 STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
87 STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
88
89 // IGuest methods
90 STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
91 IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
92 STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
93 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
94 IN_BSTR aUserName, IN_BSTR aPassword,
95 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress);
96 STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ULONG64 aSize, ComSafeArrayOut(BYTE, aData));
97 STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ULONG *aStatus);
98 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
99 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
100 ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal);
101
102 // public methods that are not in IDL
103 void setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType);
104
105 void setSupportsSeamless (BOOL aSupportsSeamless);
106
107 void setSupportsGraphics (BOOL aSupportsGraphics);
108
109 HRESULT SetStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
110
111 // for VirtualBoxSupportErrorInfoImpl
112 static const wchar_t *getComponentName() { return L"Guest"; }
113
114# ifdef VBOX_WITH_GUEST_CONTROL
115 /** Static callback for handling guest notifications. */
116 static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
117# endif
118
119private:
120
121# ifdef VBOX_WITH_GUEST_CONTROL
122 struct CallbackContext
123 {
124 eVBoxGuestCtrlCallbackType mType;
125 /** Pointer to user-supplied data. */
126 void *pvData;
127 /** Size of user-supplied data. */
128 uint32_t cbData;
129 /** Pointer to user-supplied IProgress. */
130 ComObjPtr<Progress> pProgress;
131 };
132 /*
133 * The map key is the context ID.
134 */
135 typedef std::map< uint32_t, CallbackContext > CallbackMap;
136 typedef std::map< uint32_t, CallbackContext >::iterator CallbackMapIter;
137 typedef std::map< uint32_t, CallbackContext >::const_iterator CallbackMapIterConst;
138
139 struct GuestProcess
140 {
141 uint32_t mStatus;
142 uint32_t mFlags;
143 uint32_t mExitCode;
144 };
145 /*
146 * The map key is the PID (process identifier).
147 */
148 typedef std::map< uint32_t, GuestProcess > GuestProcessMap;
149 typedef std::map< uint32_t, GuestProcess >::iterator GuestProcessMapIter;
150 typedef std::map< uint32_t, GuestProcess >::const_iterator GuestProcessMapIterConst;
151
152 int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
153 /** Handler for guest execution control notifications. */
154 int notifyCtrlClientDisconnected(uint32_t u32Function, PCALLBACKDATACLIENTDISCONNECTED pData);
155 int notifyCtrlExecStatus(uint32_t u32Function, PCALLBACKDATAEXECSTATUS pData);
156 int notifyCtrlExecOut(uint32_t u32Function, PCALLBACKDATAEXECOUT pData);
157 CallbackMapIter getCtrlCallbackContextByID(uint32_t u32ContextID);
158 GuestProcessMapIter getProcessByPID(uint32_t u32PID);
159 void destroyCtrlCallbackContext(CallbackMapIter it);
160 uint32_t addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress* pProgress);
161# endif
162
163 struct Data
164 {
165 Data() : mAdditionsActive (FALSE), mSupportsSeamless (FALSE),
166 mSupportsGraphics (FALSE) {}
167
168 Bstr mOSTypeId;
169 BOOL mAdditionsActive;
170 Bstr mAdditionsVersion;
171 BOOL mSupportsSeamless;
172 BOOL mSupportsGraphics;
173 };
174
175 ULONG mMemoryBalloonSize;
176 ULONG mStatUpdateInterval;
177 ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
178 BOOL mfPageFusionEnabled;
179
180 Console *mParent;
181 Data mData;
182
183# ifdef VBOX_WITH_GUEST_CONTROL
184 /** General extension callback for guest control. */
185 HGCMSVCEXTHANDLE mhExtCtrl;
186
187 volatile uint32_t mNextContextID;
188 CallbackMap mCallbackMap;
189 GuestProcessMap mGuestProcessMap;
190# endif
191};
192
193#endif // ____H_GUESTIMPL
194/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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