1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "GuestImpl.h"
|
---|
19 | #include "ConsoleImpl.h"
|
---|
20 | #include "VMMDev.h"
|
---|
21 |
|
---|
22 | #include "Logging.h"
|
---|
23 |
|
---|
24 | #include <VBox/VBoxDev.h>
|
---|
25 | #include <iprt/cpputils.h>
|
---|
26 |
|
---|
27 | // defines
|
---|
28 | /////////////////////////////////////////////////////////////////////////////
|
---|
29 |
|
---|
30 | // constructor / destructor
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | DEFINE_EMPTY_CTOR_DTOR (Guest)
|
---|
34 |
|
---|
35 | HRESULT Guest::FinalConstruct()
|
---|
36 | {
|
---|
37 | return S_OK;
|
---|
38 | }
|
---|
39 |
|
---|
40 | void Guest::FinalRelease()
|
---|
41 | {
|
---|
42 | uninit ();
|
---|
43 | }
|
---|
44 |
|
---|
45 | // public methods only for internal purposes
|
---|
46 | /////////////////////////////////////////////////////////////////////////////
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Initializes the guest object.
|
---|
50 | */
|
---|
51 | HRESULT Guest::init (Console *aParent)
|
---|
52 | {
|
---|
53 | LogFlowThisFunc (("aParent=%p\n", aParent));
|
---|
54 |
|
---|
55 | ComAssertRet (aParent, E_INVALIDARG);
|
---|
56 |
|
---|
57 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
58 | AutoInitSpan autoInitSpan (this);
|
---|
59 | AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
|
---|
60 |
|
---|
61 | unconst (mParent) = aParent;
|
---|
62 |
|
---|
63 | /* mData.mAdditionsActive is FALSE */
|
---|
64 |
|
---|
65 | /* Confirm a successful initialization when it's the case */
|
---|
66 | autoInitSpan.setSucceeded();
|
---|
67 |
|
---|
68 | return S_OK;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
73 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
74 | */
|
---|
75 | void Guest::uninit()
|
---|
76 | {
|
---|
77 | LogFlowThisFunc (("\n"));
|
---|
78 |
|
---|
79 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
80 | AutoUninitSpan autoUninitSpan (this);
|
---|
81 | if (autoUninitSpan.uninitDone())
|
---|
82 | return;
|
---|
83 |
|
---|
84 | unconst (mParent).setNull();
|
---|
85 | }
|
---|
86 |
|
---|
87 | // IGuest properties
|
---|
88 | /////////////////////////////////////////////////////////////////////////////
|
---|
89 |
|
---|
90 | STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
|
---|
91 | {
|
---|
92 | if (!aOSTypeId)
|
---|
93 | return E_POINTER;
|
---|
94 |
|
---|
95 | AutoCaller autoCaller (this);
|
---|
96 | CheckComRCReturnRC (autoCaller.rc());
|
---|
97 |
|
---|
98 | AutoReaderLock alock (this);
|
---|
99 |
|
---|
100 | // redirect the call to IMachine if no additions are installed
|
---|
101 | if (mData.mAdditionsVersion.isNull())
|
---|
102 | return mParent->machine()->COMGETTER(OSTypeId) (aOSTypeId);
|
---|
103 |
|
---|
104 | mData.mOSTypeId.cloneTo (aOSTypeId);
|
---|
105 |
|
---|
106 | return S_OK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
|
---|
110 | {
|
---|
111 | if (!aAdditionsActive)
|
---|
112 | return E_POINTER;
|
---|
113 |
|
---|
114 | AutoCaller autoCaller (this);
|
---|
115 | CheckComRCReturnRC (autoCaller.rc());
|
---|
116 |
|
---|
117 | AutoReaderLock alock (this);
|
---|
118 |
|
---|
119 | *aAdditionsActive = mData.mAdditionsActive;
|
---|
120 |
|
---|
121 | return S_OK;
|
---|
122 | }
|
---|
123 |
|
---|
124 | STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
|
---|
125 | {
|
---|
126 | if (!aAdditionsVersion)
|
---|
127 | return E_POINTER;
|
---|
128 |
|
---|
129 | AutoCaller autoCaller (this);
|
---|
130 | CheckComRCReturnRC (autoCaller.rc());
|
---|
131 |
|
---|
132 | AutoReaderLock alock (this);
|
---|
133 |
|
---|
134 | mData.mAdditionsVersion.cloneTo (aAdditionsVersion);
|
---|
135 |
|
---|
136 | return S_OK;
|
---|
137 | }
|
---|
138 |
|
---|
139 | STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
|
---|
140 | {
|
---|
141 | if (!aSupportsSeamless)
|
---|
142 | return E_POINTER;
|
---|
143 |
|
---|
144 | AutoCaller autoCaller (this);
|
---|
145 | CheckComRCReturnRC (autoCaller.rc());
|
---|
146 |
|
---|
147 | AutoReaderLock alock (this);
|
---|
148 |
|
---|
149 | *aSupportsSeamless = mData.mSupportsSeamless;
|
---|
150 |
|
---|
151 | return S_OK;
|
---|
152 | }
|
---|
153 |
|
---|
154 | STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
|
---|
155 | INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
|
---|
156 | {
|
---|
157 | if (!aUserName || !aPassword || !aDomain)
|
---|
158 | return E_INVALIDARG;
|
---|
159 |
|
---|
160 | AutoCaller autoCaller (this);
|
---|
161 | CheckComRCReturnRC (autoCaller.rc());
|
---|
162 |
|
---|
163 | /* forward the information to the VMM device */
|
---|
164 | VMMDev *vmmDev = mParent->getVMMDev();
|
---|
165 | if (vmmDev)
|
---|
166 | {
|
---|
167 | uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
|
---|
168 | if (!aAllowInteractiveLogon)
|
---|
169 | u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
|
---|
170 |
|
---|
171 | vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
|
---|
172 | Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
|
---|
173 | Utf8Str(aDomain).raw(), u32Flags);
|
---|
174 | return S_OK;
|
---|
175 | }
|
---|
176 |
|
---|
177 | return setError (E_FAIL,
|
---|
178 | tr ("VMM device is not available (is the VM running?)"));
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | // public methods only for internal purposes
|
---|
183 | /////////////////////////////////////////////////////////////////////////////
|
---|
184 |
|
---|
185 | void Guest::setAdditionsVersion (Bstr aVersion)
|
---|
186 | {
|
---|
187 | AssertReturnVoid (!aVersion.isEmpty());
|
---|
188 |
|
---|
189 | AutoCaller autoCaller (this);
|
---|
190 | AssertComRCReturnVoid (autoCaller.rc());
|
---|
191 |
|
---|
192 | AutoLock alock (this);
|
---|
193 |
|
---|
194 | mData.mAdditionsVersion = aVersion;
|
---|
195 | /* this implies that Additions are active */
|
---|
196 | mData.mAdditionsActive = TRUE;
|
---|
197 | }
|
---|
198 |
|
---|
199 | void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
|
---|
200 | {
|
---|
201 | AutoCaller autoCaller (this);
|
---|
202 | AssertComRCReturnVoid (autoCaller.rc());
|
---|
203 |
|
---|
204 | AutoLock alock (this);
|
---|
205 |
|
---|
206 | mData.mSupportsSeamless = aSupportsSeamless;
|
---|
207 | }
|
---|