VirtualBox

source: vbox/trunk/src/VBox/Main/GuestImpl.cpp@ 2397

Last change on this file since 2397 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include "GuestImpl.h"
23#include "ConsoleImpl.h"
24#include "VMMDev.h"
25
26#include "Logging.h"
27
28#include <VBox/VBoxDev.h>
29
30// defines
31/////////////////////////////////////////////////////////////////////////////
32
33// constructor / destructor
34/////////////////////////////////////////////////////////////////////////////
35
36HRESULT Guest::FinalConstruct()
37{
38 return S_OK;
39}
40
41void Guest::FinalRelease()
42{
43 if (isReady())
44 uninit ();
45}
46
47// public methods only for internal purposes
48/////////////////////////////////////////////////////////////////////////////
49
50/**
51 * Initializes the guest object.
52 */
53HRESULT Guest::init (Console *aParent)
54{
55 LogFlowMember (("Guest::init (%p)\n", aParent));
56
57 ComAssertRet (aParent, E_INVALIDARG);
58
59 AutoLock alock (this);
60 ComAssertRet (!isReady(), E_UNEXPECTED);
61
62 mParent = aParent;
63
64 mData.allocate();
65 // mData.mAdditionsActive is FALSE
66
67 setReady (true);
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 */
75void Guest::uninit()
76{
77 LogFlowMember (("Guest::uninit()\n"));
78
79 AutoLock alock (this);
80 AssertReturn (isReady(), (void) 0);
81
82 mData.free();
83
84 mParent.setNull();
85
86 setReady (false);
87}
88
89// IGuest properties
90/////////////////////////////////////////////////////////////////////////////
91
92/**
93 * Returns the assigned guest OS type
94 *
95 * @returns COM status code
96 * @param guestOSType address of result variable
97 */
98STDMETHODIMP Guest::COMGETTER(OSType) (IGuestOSType **aOSType)
99{
100 if (!aOSType)
101 return E_POINTER;
102
103 AutoLock alock (this);
104 CHECK_READY();
105
106 // redirect the call to IMachine if no additions are installed
107 if (mData->mAdditionsVersion.isNull())
108 return mParent->machine()->COMGETTER(OSType) (aOSType);
109
110 mData->mGuestOSType.queryInterfaceTo (aOSType);
111 return S_OK;
112}
113
114/**
115 * Returns whether the Guest Additions are currently active.
116 *
117 * @returns COM status code
118 * @param active address of result variable
119 */
120STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
121{
122 if (!aAdditionsActive)
123 return E_POINTER;
124
125 AutoLock alock (this);
126 CHECK_READY();
127
128 *aAdditionsActive = mData->mAdditionsActive;
129 return S_OK;
130}
131
132/**
133 * Returns the reported Guest Additions version. Empty
134 * string if they are not installed.
135 *
136 * @returns COM status code
137 * @param version address of result variable
138 */
139STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
140{
141 if (!aAdditionsVersion)
142 return E_POINTER;
143
144 AutoLock alock (this);
145 CHECK_READY();
146
147 mData->mAdditionsVersion.cloneTo (aAdditionsVersion);
148 return S_OK;
149}
150
151/**
152 * Set guest logon credentials. They can be retrieved by the
153 * guest Additions. It's up to the guest what it does with them.
154 * Note that this has been placed here to make it transient
155 * information.
156 */
157STDMETHODIMP Guest::SetCredentials(INPTR BSTR aUserName, INPTR BSTR aPassword,
158 INPTR BSTR aDomain, BOOL aAllowInteractiveLogon)
159{
160 if (!aUserName || !aPassword || !aDomain)
161 return E_INVALIDARG;
162
163 AutoLock alock(this);
164 CHECK_READY();
165
166 /* forward the information to the VMM device */
167 VMMDev *vmmDev = mParent->getVMMDev();
168 if (vmmDev)
169 {
170 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
171 if (!aAllowInteractiveLogon)
172 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
173
174 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
175 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
176 Utf8Str(aDomain).raw(), u32Flags);
177 return S_OK;
178 }
179 return setError(E_FAIL, tr("VMM device not available, VM not running"));
180}
181
182
183// public methods only for internal purposes
184/////////////////////////////////////////////////////////////////////////////
185
186void Guest::setAdditionsVersion(Bstr version)
187{
188 if (!version)
189 return;
190 AutoLock alock(this);
191 mData->mAdditionsVersion = version;
192 // this implies that Additions are active
193 mData->mAdditionsActive = true;
194}
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