VirtualBox

source: vbox/trunk/src/VBox/Main/MediumFormatImpl.cpp@ 32531

Last change on this file since 32531 was 32531, checked in by vboxsync, 14 years ago

Main/Medium+MediumFormat+GuestOSType+SystemPropertiesImpl+Console+Global: consistently use bytes as size units, forgotten const value in API, MaxVDISize method renamed to InfoVDSize, STDMETHOD macro usage fixes, whitespace cleanup

Frontends/VirtualBox+VBoxManage+VBoxShell: adapt to changed disk size units

Main/StorageControllerImpl: check the storage controller instance limit to avoid creating unusable VM configs, simplify unnecessarily complex code for querying the controller properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: MediumFormatImpl.cpp 32531 2010-09-15 17:04:48Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "MediumFormatImpl.h"
21#include "AutoCaller.h"
22#include "Logging.h"
23
24#include <VBox/VBoxHDD.h>
25
26#include <iprt/cpp/utils.h>
27
28// constructor / destructor
29/////////////////////////////////////////////////////////////////////////////
30
31DEFINE_EMPTY_CTOR_DTOR(MediumFormat)
32
33HRESULT MediumFormat::FinalConstruct()
34{
35 return S_OK;
36}
37
38void MediumFormat::FinalRelease()
39{
40 uninit();
41}
42
43// public initializer/uninitializer for internal purposes only
44/////////////////////////////////////////////////////////////////////////////
45
46/**
47 * Initializes the hard disk format object.
48 *
49 * @param aVDInfo Pointer to a backend info object.
50 */
51HRESULT MediumFormat::init(const VDBACKENDINFO *aVDInfo)
52{
53 LogFlowThisFunc(("aVDInfo=%p\n", aVDInfo));
54
55 ComAssertRet(aVDInfo, E_INVALIDARG);
56
57 /* Enclose the state transition NotReady->InInit->Ready */
58 AutoInitSpan autoInitSpan(this);
59 AssertReturn(autoInitSpan.isOk(), E_FAIL);
60
61 /* The ID of the backend */
62 unconst(m.strId) = aVDInfo->pszBackend;
63 /* The Name of the backend */
64 /* Use id for now as long as VDBACKENDINFO hasn't any extra
65 * name/description field. */
66 unconst(m.strName) = aVDInfo->pszBackend;
67 /* The capabilities of the backend */
68 unconst(m.capabilities) = aVDInfo->uBackendCaps;
69 /* Save the supported file extensions in a list */
70 if (aVDInfo->papszFileExtensions)
71 {
72 const char *const *papsz = aVDInfo->papszFileExtensions;
73 while (*papsz != NULL)
74 {
75 unconst(m.llFileExtensions).push_back(*papsz);
76 ++papsz;
77 }
78 }
79 /* Save a list of configure properties */
80 if (aVDInfo->paConfigInfo)
81 {
82 PCVDCONFIGINFO pa = aVDInfo->paConfigInfo;
83 /* Walk through all available keys */
84 while (pa->pszKey != NULL)
85 {
86 Utf8Str defaultValue("");
87 DataType_T dt;
88 ULONG flags = static_cast <ULONG>(pa->uKeyFlags);
89 /* Check for the configure data type */
90 switch (pa->enmValueType)
91 {
92 case VDCFGVALUETYPE_INTEGER:
93 {
94 dt = DataType_Int32;
95 /* If there is a default value get them in the right format */
96 if (pa->pszDefaultValue)
97 defaultValue = pa->pszDefaultValue;
98 break;
99 }
100 case VDCFGVALUETYPE_BYTES:
101 {
102 dt = DataType_Int8;
103 /* If there is a default value get them in the right format */
104 if (pa->pszDefaultValue)
105 {
106 /* Copy the bytes over - treated simply as a string */
107 defaultValue = pa->pszDefaultValue;
108 flags |= DataFlags_Array;
109 }
110 break;
111 }
112 case VDCFGVALUETYPE_STRING:
113 {
114 dt = DataType_String;
115 /* If there is a default value get them in the right format */
116 if (pa->pszDefaultValue)
117 defaultValue = pa->pszDefaultValue;
118 break;
119 }
120
121 default:
122 AssertMsgFailed(("Invalid enm type %d!\n", pa->enmValueType));
123 return E_INVALIDARG;
124 }
125
126 /// @todo add extendedFlags to Property when we reach the 32 bit
127 /// limit (or make the argument ULONG64 after checking that COM is
128 /// capable of defining enums (used to represent bit flags) that
129 /// contain 64-bit values)
130 ComAssertRet(pa->uKeyFlags == ((ULONG)pa->uKeyFlags), E_FAIL);
131
132 /* Create one property structure */
133 const Property prop = { Utf8Str(pa->pszKey),
134 Utf8Str(""),
135 dt,
136 flags,
137 defaultValue };
138 unconst(m.llProperties).push_back(prop);
139 ++pa;
140 }
141 }
142
143 /* Confirm a successful initialization */
144 autoInitSpan.setSucceeded();
145
146 return S_OK;
147}
148
149/**
150 * Uninitializes the instance and sets the ready flag to FALSE.
151 * Called either from FinalRelease() or by the parent when it gets destroyed.
152 */
153void MediumFormat::uninit()
154{
155 LogFlowThisFunc(("\n"));
156
157 /* Enclose the state transition Ready->InUninit->NotReady */
158 AutoUninitSpan autoUninitSpan(this);
159 if (autoUninitSpan.uninitDone())
160 return;
161
162 unconst(m.llProperties).clear();
163 unconst(m.llFileExtensions).clear();
164 unconst(m.capabilities) = 0;
165 unconst(m.strName).setNull();
166 unconst(m.strId).setNull();
167}
168
169// IMediumFormat properties
170/////////////////////////////////////////////////////////////////////////////
171
172STDMETHODIMP MediumFormat::COMGETTER(Id)(BSTR *aId)
173{
174 CheckComArgOutPointerValid(aId);
175
176 AutoCaller autoCaller(this);
177 if (FAILED(autoCaller.rc())) return autoCaller.rc();
178
179 /* this is const, no need to lock */
180 m.strId.cloneTo(aId);
181
182 return S_OK;
183}
184
185STDMETHODIMP MediumFormat::COMGETTER(Name)(BSTR *aName)
186{
187 CheckComArgOutPointerValid(aName);
188
189 AutoCaller autoCaller(this);
190 if (FAILED(autoCaller.rc())) return autoCaller.rc();
191
192 /* this is const, no need to lock */
193 m.strName.cloneTo(aName);
194
195 return S_OK;
196}
197
198STDMETHODIMP MediumFormat::COMGETTER(FileExtensions)(ComSafeArrayOut(BSTR, aFileExtensions))
199{
200 if (ComSafeArrayOutIsNull(aFileExtensions))
201 return E_POINTER;
202
203 AutoCaller autoCaller(this);
204 if (FAILED(autoCaller.rc())) return autoCaller.rc();
205
206 /* this is const, no need to lock */
207 com::SafeArray<BSTR> fileExtentions(m.llFileExtensions.size());
208 int i = 0;
209 for (StrList::const_iterator it = m.llFileExtensions.begin();
210 it != m.llFileExtensions.end();
211 ++it, ++i)
212 (*it).cloneTo(&fileExtentions[i]);
213 fileExtentions.detachTo(ComSafeArrayOutArg(aFileExtensions));
214
215 return S_OK;
216}
217
218STDMETHODIMP MediumFormat::COMGETTER(Capabilities)(ULONG *aCaps)
219{
220 CheckComArgOutPointerValid(aCaps);
221
222 AutoCaller autoCaller(this);
223 if (FAILED(autoCaller.rc())) return autoCaller.rc();
224
225 /* m.capabilities is const, no need to lock */
226
227 /// @todo add COMGETTER(ExtendedCapabilities) when we reach the 32 bit
228 /// limit (or make the argument ULONG64 after checking that COM is capable
229 /// of defining enums (used to represent bit flags) that contain 64-bit
230 /// values)
231 ComAssertRet(m.capabilities == ((ULONG)m.capabilities), E_FAIL);
232
233 *aCaps = (ULONG) m.capabilities;
234
235 return S_OK;
236}
237
238STDMETHODIMP MediumFormat::DescribeProperties(ComSafeArrayOut(BSTR, aNames),
239 ComSafeArrayOut(BSTR, aDescriptions),
240 ComSafeArrayOut(DataType_T, aTypes),
241 ComSafeArrayOut(ULONG, aFlags),
242 ComSafeArrayOut(BSTR, aDefaults))
243{
244 CheckComArgSafeArrayNotNull(aNames);
245 CheckComArgSafeArrayNotNull(aDescriptions);
246 CheckComArgSafeArrayNotNull(aTypes);
247 CheckComArgSafeArrayNotNull(aFlags);
248 CheckComArgSafeArrayNotNull(aDefaults);
249
250 AutoCaller autoCaller(this);
251 if (FAILED(autoCaller.rc())) return autoCaller.rc();
252
253 /* this is const, no need to lock */
254 size_t c = m.llProperties.size();
255 com::SafeArray<BSTR> propertyNames(c);
256 com::SafeArray<BSTR> propertyDescriptions(c);
257 com::SafeArray<DataType_T> propertyTypes(c);
258 com::SafeArray<ULONG> propertyFlags(c);
259 com::SafeArray<BSTR> propertyDefaults(c);
260
261 int i = 0;
262 for (PropertyList::const_iterator it = m.llProperties.begin();
263 it != m.llProperties.end();
264 ++it, ++i)
265 {
266 const Property &prop = (*it);
267 prop.strName.cloneTo(&propertyNames[i]);
268 prop.strDescription.cloneTo(&propertyDescriptions[i]);
269 propertyTypes[i] = prop.type;
270 propertyFlags[i] = prop.flags;
271 prop.strDefaultValue.cloneTo(&propertyDefaults[i]);
272 }
273
274 propertyNames.detachTo(ComSafeArrayOutArg(aNames));
275 propertyDescriptions.detachTo(ComSafeArrayOutArg(aDescriptions));
276 propertyTypes.detachTo(ComSafeArrayOutArg(aTypes));
277 propertyFlags.detachTo(ComSafeArrayOutArg(aFlags));
278 propertyDefaults.detachTo(ComSafeArrayOutArg(aDefaults));
279
280 return S_OK;
281}
282
283// IMediumFormat methods
284/////////////////////////////////////////////////////////////////////////////
285
286// public methods only for internal purposes
287/////////////////////////////////////////////////////////////////////////////
288/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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