1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ____H_GUESTIMPL
|
---|
23 | #define ____H_GUESTIMPL
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 | #include <VBox/ostypes.h>
|
---|
27 |
|
---|
28 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
29 | # include <VBox/HostServices/GuestControlSvc.h>
|
---|
30 | # include <hgcm/HGCM.h>
|
---|
31 | using namespace guestControl;
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | typedef enum
|
---|
35 | {
|
---|
36 | GUESTSTATTYPE_CPUUSER = 0,
|
---|
37 | GUESTSTATTYPE_CPUKERNEL = 1,
|
---|
38 | GUESTSTATTYPE_CPUIDLE = 2,
|
---|
39 | GUESTSTATTYPE_MEMTOTAL = 3,
|
---|
40 | GUESTSTATTYPE_MEMFREE = 4,
|
---|
41 | GUESTSTATTYPE_MEMBALLOON = 5,
|
---|
42 | GUESTSTATTYPE_MEMCACHE = 6,
|
---|
43 | GUESTSTATTYPE_PAGETOTAL = 7,
|
---|
44 | GUESTSTATTYPE_PAGEFREE = 8,
|
---|
45 | GUESTSTATTYPE_MAX = 9
|
---|
46 | } GUESTSTATTYPE;
|
---|
47 |
|
---|
48 | class Console;
|
---|
49 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
50 | class Progress;
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | class ATL_NO_VTABLE Guest :
|
---|
54 | public VirtualBoxSupportErrorInfoImpl<Guest, IGuest>,
|
---|
55 | public VirtualBoxSupportTranslation<Guest>,
|
---|
56 | public VirtualBoxBase,
|
---|
57 | VBOX_SCRIPTABLE_IMPL(IGuest)
|
---|
58 | {
|
---|
59 | public:
|
---|
60 |
|
---|
61 | DECLARE_NOT_AGGREGATABLE(Guest)
|
---|
62 |
|
---|
63 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
64 |
|
---|
65 | BEGIN_COM_MAP(Guest)
|
---|
66 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
67 | COM_INTERFACE_ENTRY(IGuest)
|
---|
68 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
69 | END_COM_MAP()
|
---|
70 |
|
---|
71 | DECLARE_EMPTY_CTOR_DTOR (Guest)
|
---|
72 |
|
---|
73 | HRESULT FinalConstruct();
|
---|
74 | void FinalRelease();
|
---|
75 |
|
---|
76 | // public initializer/uninitializer for internal purposes only
|
---|
77 | HRESULT init (Console *aParent);
|
---|
78 | void uninit();
|
---|
79 |
|
---|
80 | // IGuest properties
|
---|
81 | STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
|
---|
82 | STDMETHOD(COMGETTER(AdditionsActive)) (BOOL *aAdditionsActive);
|
---|
83 | STDMETHOD(COMGETTER(AdditionsVersion)) (BSTR *aAdditionsVersion);
|
---|
84 | STDMETHOD(COMGETTER(SupportsSeamless)) (BOOL *aSupportsSeamless);
|
---|
85 | STDMETHOD(COMGETTER(SupportsGraphics)) (BOOL *aSupportsGraphics);
|
---|
86 | STDMETHOD(COMGETTER(MemoryBalloonSize)) (ULONG *aMemoryBalloonSize);
|
---|
87 | STDMETHOD(COMSETTER(MemoryBalloonSize)) (ULONG aMemoryBalloonSize);
|
---|
88 | STDMETHOD(COMGETTER(StatisticsUpdateInterval)) (ULONG *aUpdateInterval);
|
---|
89 | STDMETHOD(COMSETTER(StatisticsUpdateInterval)) (ULONG aUpdateInterval);
|
---|
90 |
|
---|
91 | // IGuest methods
|
---|
92 | STDMETHOD(SetCredentials)(IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
93 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon);
|
---|
94 | STDMETHOD(ExecuteProcess)(IN_BSTR aCommand, ULONG aFlags,
|
---|
95 | ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
96 | IN_BSTR aStdIn, IN_BSTR aStdOut, IN_BSTR aStdErr,
|
---|
97 | IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
98 | ULONG aTimeoutMS, ULONG* aPID, IProgress **aProgress);
|
---|
99 | STDMETHOD(GetProcessOutput)(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ULONG64 aSize, ComSafeArrayOut(BYTE, aData));
|
---|
100 | STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
101 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemCache,
|
---|
102 | ULONG *aPageTotal, ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal);
|
---|
103 |
|
---|
104 | // public methods that are not in IDL
|
---|
105 | void setAdditionsVersion (Bstr aVersion, VBOXOSTYPE aOsType);
|
---|
106 |
|
---|
107 | void setSupportsSeamless (BOOL aSupportsSeamless);
|
---|
108 |
|
---|
109 | void setSupportsGraphics (BOOL aSupportsGraphics);
|
---|
110 |
|
---|
111 | HRESULT SetStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal);
|
---|
112 |
|
---|
113 | // for VirtualBoxSupportErrorInfoImpl
|
---|
114 | static const wchar_t *getComponentName() { return L"Guest"; }
|
---|
115 |
|
---|
116 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
117 | /** Static callback for handling guest notifications. */
|
---|
118 | static DECLCALLBACK(int) doGuestCtrlNotification(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
119 | # endif
|
---|
120 |
|
---|
121 | private:
|
---|
122 |
|
---|
123 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
124 | struct CallbackContext
|
---|
125 | {
|
---|
126 | uint32_t mContextID;
|
---|
127 | void *pvData;
|
---|
128 | uint32_t cbData;
|
---|
129 | /** Atomic flag whether callback was called. */
|
---|
130 | volatile bool bCalled;
|
---|
131 | /** Pointer to user-supplied IProgress. */
|
---|
132 | ComObjPtr<Progress> pProgress;
|
---|
133 | };
|
---|
134 | typedef std::list< CallbackContext > CallbackList;
|
---|
135 | typedef std::list< CallbackContext >::iterator CallbackListIter;
|
---|
136 | typedef std::list< CallbackContext >::const_iterator CallbackListIterConst;
|
---|
137 |
|
---|
138 | int prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv);
|
---|
139 | /** Handler for guest execution control notifications. */
|
---|
140 | int notifyCtrlExec(uint32_t u32Function, PHOSTEXECCALLBACKDATA pData);
|
---|
141 | int notifyCtrlExecOut(uint32_t u32Function, PHOSTEXECOUTCALLBACKDATA pData);
|
---|
142 | CallbackListIter getCtrlCallbackContextByID(uint32_t u32ContextID);
|
---|
143 | CallbackListIter getCtrlCallbackContextByPID(uint32_t u32PID);
|
---|
144 | void removeCtrlCallbackContext(CallbackListIter it);
|
---|
145 | uint32_t addCtrlCallbackContext(void *pvData, uint32_t cbData, Progress* pProgress);
|
---|
146 | # endif
|
---|
147 |
|
---|
148 | struct Data
|
---|
149 | {
|
---|
150 | Data() : mAdditionsActive (FALSE), mSupportsSeamless (FALSE),
|
---|
151 | mSupportsGraphics (FALSE) {}
|
---|
152 |
|
---|
153 | Bstr mOSTypeId;
|
---|
154 | BOOL mAdditionsActive;
|
---|
155 | Bstr mAdditionsVersion;
|
---|
156 | BOOL mSupportsSeamless;
|
---|
157 | BOOL mSupportsGraphics;
|
---|
158 | };
|
---|
159 |
|
---|
160 | ULONG mMemoryBalloonSize;
|
---|
161 | ULONG mStatUpdateInterval;
|
---|
162 | ULONG mCurrentGuestStat[GUESTSTATTYPE_MAX];
|
---|
163 |
|
---|
164 | Console *mParent;
|
---|
165 | Data mData;
|
---|
166 |
|
---|
167 | # ifdef VBOX_WITH_GUEST_CONTROL
|
---|
168 | /** General extension callback for guest control. */
|
---|
169 | HGCMSVCEXTHANDLE mhExtCtrl;
|
---|
170 |
|
---|
171 | volatile uint32_t mNextContextID;
|
---|
172 | CallbackList mCallbackList;
|
---|
173 | # endif
|
---|
174 | };
|
---|
175 |
|
---|
176 | #endif // ____H_GUESTIMPL
|
---|
177 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|