VirtualBox

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

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