VirtualBox

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

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

Main: cleanup: get rid of VirtualBoxBaseProto, move AutoCaller*/*Span* classes out of VirtualBoxBaseProto class scope and into separate header; move CombinedProgress into separate header (it's only used by Console any more)

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

© 2023 Oracle
ContactPrivacy policyTerms of Use