1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011 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 | #include "AdditionsFacilityImpl.h"
|
---|
19 | #include "Global.h"
|
---|
20 |
|
---|
21 | #include "AutoCaller.h"
|
---|
22 | #include "Logging.h"
|
---|
23 |
|
---|
24 | /* static */
|
---|
25 | const AdditionsFacility::FacilityInfo AdditionsFacility::sFacilityInfo[8] =
|
---|
26 | {
|
---|
27 | /* NOTE: We assume that unknown is always the first entry! */
|
---|
28 | { "Unknown", AdditionsFacilityType_None, AdditionsFacilityClass_None },
|
---|
29 | { "VirtualBox Base Driver", AdditionsFacilityType_VBoxGuestDriver, AdditionsFacilityClass_Driver },
|
---|
30 | { "VirtualBox System Service", AdditionsFacilityType_VBoxService, AdditionsFacilityClass_Service },
|
---|
31 | { "VirtualBox Desktop Integration", AdditionsFacilityType_VBoxTrayClient, AdditionsFacilityClass_Program },
|
---|
32 | { "Seamless Mode", AdditionsFacilityType_Seamless, AdditionsFacilityClass_Feature },
|
---|
33 | { "Graphics Mode", AdditionsFacilityType_Graphics, AdditionsFacilityClass_Feature },
|
---|
34 | };
|
---|
35 |
|
---|
36 | // constructor / destructor
|
---|
37 | /////////////////////////////////////////////////////////////////////////////
|
---|
38 |
|
---|
39 | DEFINE_EMPTY_CTOR_DTOR (AdditionsFacility)
|
---|
40 |
|
---|
41 | HRESULT AdditionsFacility::FinalConstruct()
|
---|
42 | {
|
---|
43 | LogFlowThisFunc(("\n"));
|
---|
44 | return BaseFinalConstruct();
|
---|
45 | }
|
---|
46 |
|
---|
47 | void AdditionsFacility::FinalRelease()
|
---|
48 | {
|
---|
49 | LogFlowThisFuncEnter();
|
---|
50 | uninit();
|
---|
51 | BaseFinalRelease();
|
---|
52 | LogFlowThisFuncLeave();
|
---|
53 | }
|
---|
54 |
|
---|
55 | // public initializer/uninitializer for internal purposes only
|
---|
56 | /////////////////////////////////////////////////////////////////////////////
|
---|
57 |
|
---|
58 | HRESULT AdditionsFacility::init(Guest *aParent, AdditionsFacilityType_T enmFacility, AdditionsFacilityStatus_T enmStatus)
|
---|
59 | {
|
---|
60 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
61 |
|
---|
62 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
63 | AutoInitSpan autoInitSpan(this);
|
---|
64 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
65 |
|
---|
66 | RTTimeNow (&mData.mLastUpdated);
|
---|
67 | mData.mStatus = enmStatus;
|
---|
68 | mData.mType = enmFacility;
|
---|
69 |
|
---|
70 | /* Confirm a successful initialization when it's the case. */
|
---|
71 | autoInitSpan.setSucceeded();
|
---|
72 |
|
---|
73 | return S_OK;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Uninitializes the instance.
|
---|
78 | * Called from FinalRelease().
|
---|
79 | */
|
---|
80 | void AdditionsFacility::uninit()
|
---|
81 | {
|
---|
82 | LogFlowThisFunc(("\n"));
|
---|
83 |
|
---|
84 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
85 | AutoUninitSpan autoUninitSpan(this);
|
---|
86 | if (autoUninitSpan.uninitDone())
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 | STDMETHODIMP AdditionsFacility::COMGETTER(ClassType)(AdditionsFacilityClass_T *aClass)
|
---|
91 | {
|
---|
92 | LogFlowThisFuncEnter();
|
---|
93 |
|
---|
94 | CheckComArgOutPointerValid(aClass);
|
---|
95 |
|
---|
96 | AutoCaller autoCaller(this);
|
---|
97 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
98 |
|
---|
99 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
100 |
|
---|
101 | *aClass = getClass();
|
---|
102 |
|
---|
103 | return S_OK;
|
---|
104 | }
|
---|
105 |
|
---|
106 | STDMETHODIMP AdditionsFacility::COMGETTER(Name)(BSTR *aName)
|
---|
107 | {
|
---|
108 | LogFlowThisFuncEnter();
|
---|
109 |
|
---|
110 | CheckComArgOutPointerValid(aName);
|
---|
111 |
|
---|
112 | AutoCaller autoCaller(this);
|
---|
113 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
114 |
|
---|
115 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
116 |
|
---|
117 | Bstr(getName()).cloneTo(aName);
|
---|
118 |
|
---|
119 | return S_OK;
|
---|
120 | }
|
---|
121 |
|
---|
122 | STDMETHODIMP AdditionsFacility::COMGETTER(LastUpdated)(LONG64 *aTimestamp)
|
---|
123 | {
|
---|
124 | LogFlowThisFuncEnter();
|
---|
125 |
|
---|
126 | CheckComArgOutPointerValid(aTimestamp);
|
---|
127 |
|
---|
128 | AutoCaller autoCaller(this);
|
---|
129 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
130 |
|
---|
131 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
132 |
|
---|
133 | *aTimestamp = getLastUpdated();
|
---|
134 |
|
---|
135 | return S_OK;
|
---|
136 | }
|
---|
137 |
|
---|
138 | STDMETHODIMP AdditionsFacility::COMGETTER(Status)(AdditionsFacilityStatus_T *aStatus)
|
---|
139 | {
|
---|
140 | LogFlowThisFuncEnter();
|
---|
141 |
|
---|
142 | CheckComArgOutPointerValid(aStatus);
|
---|
143 |
|
---|
144 | AutoCaller autoCaller(this);
|
---|
145 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
146 |
|
---|
147 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
148 |
|
---|
149 | *aStatus = getStatus();
|
---|
150 |
|
---|
151 | return S_OK;
|
---|
152 | }
|
---|
153 |
|
---|
154 | STDMETHODIMP AdditionsFacility::COMGETTER(Type)(AdditionsFacilityType_T *aType)
|
---|
155 | {
|
---|
156 | LogFlowThisFuncEnter();
|
---|
157 |
|
---|
158 | CheckComArgOutPointerValid(aType);
|
---|
159 |
|
---|
160 | AutoCaller autoCaller(this);
|
---|
161 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
162 |
|
---|
163 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
164 |
|
---|
165 | *aType = getType();
|
---|
166 |
|
---|
167 | return S_OK;
|
---|
168 | }
|
---|
169 |
|
---|
170 | const AdditionsFacility::FacilityInfo &AdditionsFacility::typeToInfo(AdditionsFacilityType_T aType)
|
---|
171 | {
|
---|
172 | for (size_t i = 0; i < RT_ELEMENTS(sFacilityInfo); ++i)
|
---|
173 | {
|
---|
174 | if (sFacilityInfo[i].mType == aType)
|
---|
175 | return sFacilityInfo[i];
|
---|
176 | }
|
---|
177 | return sFacilityInfo[0]; /* Return unknown type. */
|
---|
178 | }
|
---|
179 |
|
---|
180 | AdditionsFacilityClass_T AdditionsFacility::getClass() const
|
---|
181 | {
|
---|
182 | return AdditionsFacility::typeToInfo(mData.mType).mClass;
|
---|
183 | }
|
---|
184 |
|
---|
185 | Bstr AdditionsFacility::getName() const
|
---|
186 | {
|
---|
187 | return AdditionsFacility::typeToInfo(mData.mType).mName;
|
---|
188 | }
|
---|
189 |
|
---|
190 | LONG64 AdditionsFacility::getLastUpdated() const
|
---|
191 | {
|
---|
192 | return RTTimeSpecGetMilli(&mData.mLastUpdated);
|
---|
193 | }
|
---|
194 |
|
---|
195 | AdditionsFacilityStatus_T AdditionsFacility::getStatus() const
|
---|
196 | {
|
---|
197 | return mData.mStatus;
|
---|
198 | }
|
---|
199 |
|
---|
200 | AdditionsFacilityType_T AdditionsFacility::getType() const
|
---|
201 | {
|
---|
202 | return mData.mType;
|
---|
203 | }
|
---|
204 |
|
---|
205 | HRESULT AdditionsFacility::update(AdditionsFacilityStatus_T aStatus, RTTIMESPEC aTimestamp)
|
---|
206 | {
|
---|
207 | mData.mStatus = aStatus;
|
---|
208 | mData.mLastUpdated = aTimestamp;
|
---|
209 |
|
---|
210 | return S_OK;
|
---|
211 | }
|
---|
212 |
|
---|