1 | /* $Id: AdditionsFacilityImpl.cpp 63259 2016-08-10 12:37:42Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBox COM class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2014-2016 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "AdditionsFacilityImpl.h"
|
---|
20 | #include "Global.h"
|
---|
21 |
|
---|
22 | #include "AutoCaller.h"
|
---|
23 | #include "Logging.h"
|
---|
24 |
|
---|
25 | /* static */
|
---|
26 | const AdditionsFacility::FacilityInfo AdditionsFacility::s_aFacilityInfo[8] =
|
---|
27 | {
|
---|
28 | /* NOTE: We assume that unknown is always the first entry! */
|
---|
29 | { "Unknown", AdditionsFacilityType_None, AdditionsFacilityClass_None },
|
---|
30 | { "VirtualBox Base Driver", AdditionsFacilityType_VBoxGuestDriver, AdditionsFacilityClass_Driver },
|
---|
31 | { "Auto Logon", AdditionsFacilityType_AutoLogon, AdditionsFacilityClass_Feature },
|
---|
32 | { "VirtualBox System Service", AdditionsFacilityType_VBoxService, AdditionsFacilityClass_Service },
|
---|
33 | { "VirtualBox Desktop Integration", AdditionsFacilityType_VBoxTrayClient, AdditionsFacilityClass_Program },
|
---|
34 | { "Seamless Mode", AdditionsFacilityType_Seamless, AdditionsFacilityClass_Feature },
|
---|
35 | { "Graphics Mode", AdditionsFacilityType_Graphics, AdditionsFacilityClass_Feature },
|
---|
36 | };
|
---|
37 |
|
---|
38 | // constructor / destructor
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 |
|
---|
41 | DEFINE_EMPTY_CTOR_DTOR(AdditionsFacility)
|
---|
42 |
|
---|
43 | HRESULT AdditionsFacility::FinalConstruct()
|
---|
44 | {
|
---|
45 | LogFlowThisFunc(("\n"));
|
---|
46 | return BaseFinalConstruct();
|
---|
47 | }
|
---|
48 |
|
---|
49 | void AdditionsFacility::FinalRelease()
|
---|
50 | {
|
---|
51 | LogFlowThisFuncEnter();
|
---|
52 | uninit();
|
---|
53 | BaseFinalRelease();
|
---|
54 | LogFlowThisFuncLeave();
|
---|
55 | }
|
---|
56 |
|
---|
57 | // public initializer/uninitializer for internal purposes only
|
---|
58 | /////////////////////////////////////////////////////////////////////////////
|
---|
59 |
|
---|
60 | HRESULT AdditionsFacility::init(Guest *a_pParent, AdditionsFacilityType_T a_enmFacility, AdditionsFacilityStatus_T a_enmStatus,
|
---|
61 | uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
|
---|
62 | {
|
---|
63 | RT_NOREF(a_pParent);
|
---|
64 | LogFlowThisFunc(("a_pParent=%p\n", a_pParent));
|
---|
65 |
|
---|
66 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
67 | AutoInitSpan autoInitSpan(this);
|
---|
68 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
69 |
|
---|
70 | FacilityState state;
|
---|
71 | state.mStatus = a_enmStatus;
|
---|
72 | state.mTimestamp = *a_pTimeSpecTS;
|
---|
73 | NOREF(a_fFlags);
|
---|
74 |
|
---|
75 | Assert(mData.mStates.size() == 0);
|
---|
76 | mData.mStates.push_back(state);
|
---|
77 | mData.mType = a_enmFacility;
|
---|
78 | /** @todo mClass is not initialized here. */
|
---|
79 | NOREF(a_fFlags);
|
---|
80 |
|
---|
81 | /* Confirm a successful initialization when it's the case. */
|
---|
82 | autoInitSpan.setSucceeded();
|
---|
83 |
|
---|
84 | return S_OK;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Uninitializes the instance.
|
---|
89 | * Called from FinalRelease().
|
---|
90 | */
|
---|
91 | void AdditionsFacility::uninit()
|
---|
92 | {
|
---|
93 | LogFlowThisFunc(("\n"));
|
---|
94 |
|
---|
95 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
96 | AutoUninitSpan autoUninitSpan(this);
|
---|
97 | if (autoUninitSpan.uninitDone())
|
---|
98 | return;
|
---|
99 |
|
---|
100 | mData.mStates.clear();
|
---|
101 | }
|
---|
102 |
|
---|
103 | HRESULT AdditionsFacility::getClassType(AdditionsFacilityClass_T *aClassType)
|
---|
104 | {
|
---|
105 | LogFlowThisFuncEnter();
|
---|
106 |
|
---|
107 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
108 |
|
---|
109 | *aClassType = i_getClass();
|
---|
110 |
|
---|
111 | return S_OK;
|
---|
112 | }
|
---|
113 |
|
---|
114 | HRESULT AdditionsFacility::getName(com::Utf8Str &aName)
|
---|
115 | {
|
---|
116 | LogFlowThisFuncEnter();
|
---|
117 |
|
---|
118 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
119 |
|
---|
120 | aName = i_getName();
|
---|
121 |
|
---|
122 | return S_OK;
|
---|
123 | }
|
---|
124 |
|
---|
125 | HRESULT AdditionsFacility::getLastUpdated(LONG64 *aLastUpdated)
|
---|
126 | {
|
---|
127 | LogFlowThisFuncEnter();
|
---|
128 |
|
---|
129 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
130 |
|
---|
131 | *aLastUpdated = i_getLastUpdated();
|
---|
132 |
|
---|
133 | return S_OK;
|
---|
134 | }
|
---|
135 |
|
---|
136 | HRESULT AdditionsFacility::getStatus(AdditionsFacilityStatus_T *aStatus)
|
---|
137 | {
|
---|
138 | LogFlowThisFuncEnter();
|
---|
139 |
|
---|
140 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
141 |
|
---|
142 | *aStatus = i_getStatus();
|
---|
143 |
|
---|
144 | return S_OK;
|
---|
145 | }
|
---|
146 |
|
---|
147 | HRESULT AdditionsFacility::getType(AdditionsFacilityType_T *aType)
|
---|
148 | {
|
---|
149 | LogFlowThisFuncEnter();
|
---|
150 |
|
---|
151 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
152 |
|
---|
153 | *aType = i_getType();
|
---|
154 |
|
---|
155 | return S_OK;
|
---|
156 | }
|
---|
157 |
|
---|
158 | const AdditionsFacility::FacilityInfo &AdditionsFacility::i_typeToInfo(AdditionsFacilityType_T aType)
|
---|
159 | {
|
---|
160 | for (size_t i = 0; i < RT_ELEMENTS(s_aFacilityInfo); ++i)
|
---|
161 | {
|
---|
162 | if (s_aFacilityInfo[i].mType == aType)
|
---|
163 | return s_aFacilityInfo[i];
|
---|
164 | }
|
---|
165 | return s_aFacilityInfo[0]; /* Return unknown type. */
|
---|
166 | }
|
---|
167 |
|
---|
168 | AdditionsFacilityClass_T AdditionsFacility::i_getClass() const
|
---|
169 | {
|
---|
170 | return AdditionsFacility::i_typeToInfo(mData.mType).mClass;
|
---|
171 | }
|
---|
172 |
|
---|
173 | com::Utf8Str AdditionsFacility::i_getName() const
|
---|
174 | {
|
---|
175 | return AdditionsFacility::i_typeToInfo(mData.mType).mName;
|
---|
176 | }
|
---|
177 |
|
---|
178 | LONG64 AdditionsFacility::i_getLastUpdated() const
|
---|
179 | {
|
---|
180 | if (mData.mStates.size())
|
---|
181 | return RTTimeSpecGetMilli(&mData.mStates.front().mTimestamp);
|
---|
182 |
|
---|
183 | AssertMsgFailed(("Unknown timestamp of facility!\n"));
|
---|
184 | return 0; /* Should never happen! */
|
---|
185 | }
|
---|
186 |
|
---|
187 | AdditionsFacilityStatus_T AdditionsFacility::i_getStatus() const
|
---|
188 | {
|
---|
189 | if (mData.mStates.size())
|
---|
190 | return mData.mStates.back().mStatus;
|
---|
191 |
|
---|
192 | AssertMsgFailed(("Unknown status of facility!\n"));
|
---|
193 | return AdditionsFacilityStatus_Unknown; /* Should never happen! */
|
---|
194 | }
|
---|
195 |
|
---|
196 | AdditionsFacilityType_T AdditionsFacility::i_getType() const
|
---|
197 | {
|
---|
198 | return mData.mType;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Method used by IGuest::facilityUpdate to make updates.
|
---|
203 | */
|
---|
204 | void AdditionsFacility::i_update(AdditionsFacilityStatus_T a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
|
---|
205 | {
|
---|
206 | FacilityState state;
|
---|
207 | state.mStatus = a_enmStatus;
|
---|
208 | state.mTimestamp = *a_pTimeSpecTS;
|
---|
209 | NOREF(a_fFlags);
|
---|
210 |
|
---|
211 | mData.mStates.push_back(state);
|
---|
212 | if (mData.mStates.size() > 10) /* Only keep the last 10 states. */
|
---|
213 | mData.mStates.erase(mData.mStates.begin());
|
---|
214 | }
|
---|
215 |
|
---|