VirtualBox

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

Last change on this file since 93622 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: AdditionsFacilityImpl.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Additions facility class.
4 */
5
6/*
7 * Copyright (C) 2014-2022 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#define LOG_GROUP LOG_GROUP_MAIN_ADDITIONSFACILITY
19#include "LoggingNew.h"
20
21#include "AdditionsFacilityImpl.h"
22#include "Global.h"
23
24#include "AutoCaller.h"
25
26
27/**
28 * @note We ASSUME that unknown is the first entry!
29 */
30/* static */
31const AdditionsFacility::FacilityInfo AdditionsFacility::s_aFacilityInfo[8] =
32{
33 { "Unknown", AdditionsFacilityType_None, AdditionsFacilityClass_None },
34 { "VirtualBox Base Driver", AdditionsFacilityType_VBoxGuestDriver, AdditionsFacilityClass_Driver },
35 { "Auto Logon", AdditionsFacilityType_AutoLogon, AdditionsFacilityClass_Feature },
36 { "VirtualBox System Service", AdditionsFacilityType_VBoxService, AdditionsFacilityClass_Service },
37 { "VirtualBox Desktop Integration", AdditionsFacilityType_VBoxTrayClient, AdditionsFacilityClass_Program },
38 { "Seamless Mode", AdditionsFacilityType_Seamless, AdditionsFacilityClass_Feature },
39 { "Graphics Mode", AdditionsFacilityType_Graphics, AdditionsFacilityClass_Feature },
40 { "Guest Monitor Attach", AdditionsFacilityType_MonitorAttach, AdditionsFacilityClass_Feature },
41};
42
43// constructor / destructor
44/////////////////////////////////////////////////////////////////////////////
45
46DEFINE_EMPTY_CTOR_DTOR(AdditionsFacility)
47
48HRESULT AdditionsFacility::FinalConstruct()
49{
50 LogFlowThisFunc(("\n"));
51 return BaseFinalConstruct();
52}
53
54void AdditionsFacility::FinalRelease()
55{
56 LogFlowThisFuncEnter();
57 uninit();
58 BaseFinalRelease();
59 LogFlowThisFuncLeave();
60}
61
62// public initializer/uninitializer for internal purposes only
63/////////////////////////////////////////////////////////////////////////////
64
65HRESULT AdditionsFacility::init(Guest *a_pParent, AdditionsFacilityType_T a_enmFacility, AdditionsFacilityStatus_T a_enmStatus,
66 uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
67{
68 RT_NOREF(a_pParent); /** @todo r=bird: For locking perhaps? */
69 LogFlowThisFunc(("a_pParent=%p\n", a_pParent));
70
71 /* Enclose the state transition NotReady->InInit->Ready. */
72 AutoInitSpan autoInitSpan(this);
73 AssertReturn(autoInitSpan.isOk(), E_FAIL);
74
75 /* Initialize the data: */
76 mData.mType = a_enmFacility;
77 mData.mStatus = a_enmStatus;
78 mData.mTimestamp = *a_pTimeSpecTS;
79 mData.mfFlags = a_fFlags;
80 mData.midxInfo = 0;
81 for (size_t i = 0; i < RT_ELEMENTS(s_aFacilityInfo); ++i)
82 if (s_aFacilityInfo[i].mType == a_enmFacility)
83 {
84 mData.midxInfo = i;
85 break;
86 }
87
88 /* Confirm a successful initialization when it's the case. */
89 autoInitSpan.setSucceeded();
90
91 return S_OK;
92}
93
94/**
95 * Uninitializes the instance.
96 *
97 * Called from FinalRelease().
98 */
99void AdditionsFacility::uninit()
100{
101 LogFlowThisFunc(("\n"));
102
103 /* Enclose the state transition Ready->InUninit->NotReady. */
104 AutoUninitSpan autoUninitSpan(this);
105 if (autoUninitSpan.uninitDone())
106 return;
107}
108
109HRESULT AdditionsFacility::getClassType(AdditionsFacilityClass_T *aClassType)
110{
111 LogFlowThisFuncEnter();
112
113 /* midxInfo is static, so no need to lock anything. */
114 size_t idxInfo = mData.midxInfo;
115 AssertStmt(idxInfo < RT_ELEMENTS(s_aFacilityInfo), idxInfo = 0);
116 *aClassType = s_aFacilityInfo[idxInfo].mClass;
117 return S_OK;
118}
119
120HRESULT AdditionsFacility::getName(com::Utf8Str &aName)
121{
122 LogFlowThisFuncEnter();
123
124 /* midxInfo is static, so no need to lock anything. */
125 size_t idxInfo = mData.midxInfo;
126 AssertStmt(idxInfo < RT_ELEMENTS(s_aFacilityInfo), idxInfo = 0);
127 int vrc = aName.assignNoThrow(s_aFacilityInfo[idxInfo].mName);
128 return RT_SUCCESS(vrc) ? S_OK : E_OUTOFMEMORY;
129}
130
131HRESULT AdditionsFacility::getLastUpdated(LONG64 *aLastUpdated)
132{
133 LogFlowThisFuncEnter();
134
135 /** @todo r=bird: Should take parent (Guest) lock here, see i_update(). */
136 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
137 *aLastUpdated = RTTimeSpecGetMilli(&mData.mTimestamp);
138 return S_OK;
139}
140
141HRESULT AdditionsFacility::getStatus(AdditionsFacilityStatus_T *aStatus)
142{
143 LogFlowThisFuncEnter();
144
145 /** @todo r=bird: Should take parent (Guest) lock here, see i_update(). */
146 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
147 *aStatus = mData.mStatus;
148 return S_OK;
149}
150
151HRESULT AdditionsFacility::getType(AdditionsFacilityType_T *aType)
152{
153 LogFlowThisFuncEnter();
154
155 /* mType is static, so no need to lock anything. */
156 *aType = mData.mType;
157 return S_OK;
158}
159
160#if 0 /* unused */
161
162AdditionsFacilityType_T AdditionsFacility::i_getType() const
163{
164 return mData.mType;
165}
166
167AdditionsFacilityClass_T AdditionsFacility::i_getClass() const
168{
169 size_t idxInfo = mData.midxInfo;
170 AssertStmt(idxInfo < RT_ELEMENTS(s_aFacilityInfo), idxInfo = 0);
171 return s_aFacilityInfo[idxInfo].mClass;
172}
173
174const char *AdditionsFacility::i_getName() const
175{
176 size_t idxInfo = mData.midxInfo;
177 AssertStmt(idxInfo < RT_ELEMENTS(s_aFacilityInfo), idxInfo = 0);
178 return s_aFacilityInfo[idxInfo].mName;
179}
180
181#endif /* unused */
182
183/**
184 * @note Caller should read lock the Guest object.
185 */
186LONG64 AdditionsFacility::i_getLastUpdated() const
187{
188 return RTTimeSpecGetMilli(&mData.mTimestamp);
189}
190
191/**
192 * @note Caller should read lock the Guest object.
193 */
194AdditionsFacilityStatus_T AdditionsFacility::i_getStatus() const
195{
196 return mData.mStatus;
197}
198
199/**
200 * Method used by IGuest::facilityUpdate to make updates.
201 *
202 * @returns change indicator.
203 *
204 * @todo r=bird: Locking here isn't quite sane. While updating is serialized
205 * by the caller holding down the Guest object lock, this code doesn't
206 * serialize with this object. So, the read locking done in the getter
207 * methods is utterly pointless. OTOH, the getter methods only get
208 * single values, so there isn't really much to be worried about here,
209 * especially with 32-bit hosts no longer being supported.
210 */
211bool AdditionsFacility::i_update(AdditionsFacilityStatus_T a_enmStatus, uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
212{
213 bool const fChanged = mData.mStatus != a_enmStatus;
214
215 mData.mTimestamp = *a_pTimeSpecTS;
216 mData.mStatus = a_enmStatus;
217 mData.mfFlags = a_fFlags;
218
219 return fChanged;
220}
221
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