VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/AdditionsFacilityImpl.cpp@ 79051

Last change on this file since 79051 was 79051, checked in by vboxsync, 6 years ago

Main/AdditionsFacilityImpl: i_getName() shouldn't return a 'Utf8Str' object (copy) but 'const char *'. Can skip locking when accessing mType as it is static for the lifetime of the object. Some cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: AdditionsFacilityImpl.cpp 79051 2019-06-08 22:43:14Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2014-2019 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.215389.xyz. 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#define LOG_GROUP LOG_GROUP_MAIN_ADDITIONSFACILITY
20#include "LoggingNew.h"
21
22#include "AdditionsFacilityImpl.h"
23#include "Global.h"
24
25#include "AutoCaller.h"
26
27
28/**
29 * @note We assume that unknown is always the first entry!
30 */
31/* static */
32const AdditionsFacility::FacilityInfo AdditionsFacility::s_aFacilityInfo[8] =
33{
34 { "Unknown", AdditionsFacilityType_None, AdditionsFacilityClass_None },
35 { "VirtualBox Base Driver", AdditionsFacilityType_VBoxGuestDriver, AdditionsFacilityClass_Driver },
36 { "Auto Logon", AdditionsFacilityType_AutoLogon, AdditionsFacilityClass_Feature },
37 { "VirtualBox System Service", AdditionsFacilityType_VBoxService, AdditionsFacilityClass_Service },
38 { "VirtualBox Desktop Integration", AdditionsFacilityType_VBoxTrayClient, AdditionsFacilityClass_Program },
39 { "Seamless Mode", AdditionsFacilityType_Seamless, AdditionsFacilityClass_Feature },
40 { "Graphics Mode", AdditionsFacilityType_Graphics, AdditionsFacilityClass_Feature },
41 { "Guest Monitor Attach", AdditionsFacilityType_MonitorAttach, AdditionsFacilityClass_Feature },
42};
43
44// constructor / destructor
45/////////////////////////////////////////////////////////////////////////////
46
47DEFINE_EMPTY_CTOR_DTOR(AdditionsFacility)
48
49HRESULT AdditionsFacility::FinalConstruct()
50{
51 LogFlowThisFunc(("\n"));
52 return BaseFinalConstruct();
53}
54
55void AdditionsFacility::FinalRelease()
56{
57 LogFlowThisFuncEnter();
58 uninit();
59 BaseFinalRelease();
60 LogFlowThisFuncLeave();
61}
62
63// public initializer/uninitializer for internal purposes only
64/////////////////////////////////////////////////////////////////////////////
65
66HRESULT AdditionsFacility::init(Guest *a_pParent, AdditionsFacilityType_T a_enmFacility, AdditionsFacilityStatus_T a_enmStatus,
67 uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
68{
69 RT_NOREF(a_pParent);
70 LogFlowThisFunc(("a_pParent=%p\n", a_pParent));
71
72 /* Enclose the state transition NotReady->InInit->Ready. */
73 AutoInitSpan autoInitSpan(this);
74 AssertReturn(autoInitSpan.isOk(), E_FAIL);
75
76 FacilityState state;
77 state.mStatus = a_enmStatus;
78 state.mTimestamp = *a_pTimeSpecTS;
79 NOREF(a_fFlags);
80
81 Assert(mData.mStates.size() == 0);
82 mData.mStates.push_back(state);
83 mData.mType = a_enmFacility;
84 /** @todo mClass is not initialized here. */
85 NOREF(a_fFlags);
86
87 /* Confirm a successful initialization when it's the case. */
88 autoInitSpan.setSucceeded();
89
90 return S_OK;
91}
92
93/**
94 * Uninitializes the instance.
95 * Called from FinalRelease().
96 */
97void AdditionsFacility::uninit()
98{
99 LogFlowThisFunc(("\n"));
100
101 /* Enclose the state transition Ready->InUninit->NotReady. */
102 AutoUninitSpan autoUninitSpan(this);
103 if (autoUninitSpan.uninitDone())
104 return;
105
106 mData.mStates.clear();
107}
108
109HRESULT AdditionsFacility::getClassType(AdditionsFacilityClass_T *aClassType)
110{
111 LogFlowThisFuncEnter();
112
113 /* mType is static, so no need to lock anything. */
114 *aClassType = AdditionsFacility::i_typeToInfo(mData.mType).mClass;
115 return S_OK;
116}
117
118HRESULT AdditionsFacility::getName(com::Utf8Str &aName)
119{
120 LogFlowThisFuncEnter();
121
122 /* mType is static, so no need to lock anything. */
123 int vrc = aName.assignNoThrow(AdditionsFacility::i_typeToInfo(mData.mType).mName);
124 return RT_SUCCESS(vrc) ? S_OK : E_OUTOFMEMORY;
125}
126
127HRESULT AdditionsFacility::getLastUpdated(LONG64 *aLastUpdated)
128{
129 LogFlowThisFuncEnter();
130
131 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
132
133 *aLastUpdated = i_getLastUpdated();
134
135 return S_OK;
136}
137
138HRESULT AdditionsFacility::getStatus(AdditionsFacilityStatus_T *aStatus)
139{
140 LogFlowThisFuncEnter();
141
142 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
143
144 *aStatus = i_getStatus();
145
146 return S_OK;
147}
148
149HRESULT AdditionsFacility::getType(AdditionsFacilityType_T *aType)
150{
151 LogFlowThisFuncEnter();
152
153 /* mType is static, so no need to lock anything. */
154 *aType = mData.mType;
155 return S_OK;
156}
157
158/*static*/ 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#if 0 /* unused */
169
170AdditionsFacilityType_T AdditionsFacility::i_getType() const
171{
172 return mData.mType;
173}
174
175AdditionsFacilityClass_T AdditionsFacility::i_getClass() const
176{
177 return AdditionsFacility::i_typeToInfo(mData.mType).mClass;
178}
179
180const char *AdditionsFacility::i_getName() const
181{
182 return AdditionsFacility::i_typeToInfo(mData.mType).mName;
183}
184
185#endif
186
187LONG64 AdditionsFacility::i_getLastUpdated() const
188{
189 if (mData.mStates.size())
190 return RTTimeSpecGetMilli(&mData.mStates.front().mTimestamp);
191
192 AssertMsgFailed(("Unknown timestamp of facility!\n"));
193 return 0; /* Should never happen! */
194}
195
196AdditionsFacilityStatus_T AdditionsFacility::i_getStatus() const
197{
198 if (mData.mStates.size())
199 return mData.mStates.back().mStatus;
200
201 AssertMsgFailed(("Unknown status of facility!\n"));
202 return AdditionsFacilityStatus_Unknown; /* Should never happen! */
203}
204
205/**
206 * Method used by IGuest::facilityUpdate to make updates.
207 *
208 * @returns change indicator.
209 */
210bool AdditionsFacility::i_update(AdditionsFacilityStatus_T a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
211{
212 bool const fChanged = mData.mStates.size() == 0
213 || mData.mStates.back().mStatus != a_enmStatus;
214
215 FacilityState state;
216 state.mStatus = a_enmStatus;
217 state.mTimestamp = *a_pTimeSpecTS;
218 NOREF(a_fFlags);
219
220 mData.mStates.push_back(state);
221 if (mData.mStates.size() > 10) /* Only keep the last 10 states. */
222 mData.mStates.erase(mData.mStates.begin());
223
224 return fChanged;
225}
226
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette