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