VirtualBox

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

Last change on this file since 26600 was 26561, checked in by vboxsync, 15 years ago

*: set svn:eol-style correctly.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1/* $Id: MediumFormatImpl.cpp 26561 2010-02-16 00:55:05Z 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::COMGETTER(FileExtensions)(ComSafeArrayOut(BSTR, aFileExtensions))
201{
202 if (ComSafeArrayOutIsNull(aFileExtensions))
203 return E_POINTER;
204
205 AutoCaller autoCaller(this);
206 if (FAILED(autoCaller.rc())) return autoCaller.rc();
207
208 /* this is const, no need to lock */
209 com::SafeArray<BSTR> fileExtentions(m.fileExtensions.size());
210 int i = 0;
211 for (BstrList::const_iterator it = m.fileExtensions.begin();
212 it != m.fileExtensions.end();
213 ++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();
265 ++it, ++i)
266 {
267 const Property &prop = (*it);
268 prop.name.cloneTo(&propertyNames[i]);
269 prop.description.cloneTo(&propertyDescriptions[i]);
270 propertyTypes[i] = prop.type;
271 propertyFlags[i] = prop.flags;
272 prop.defaultValue.cloneTo(&propertyDefaults[i]);
273 }
274
275 propertyNames.detachTo(ComSafeArrayOutArg(aNames));
276 propertyDescriptions.detachTo(ComSafeArrayOutArg(aDescriptions));
277 propertyTypes.detachTo(ComSafeArrayOutArg(aTypes));
278 propertyFlags.detachTo(ComSafeArrayOutArg(aFlags));
279 propertyDefaults.detachTo(ComSafeArrayOutArg(aDefaults));
280
281 return S_OK;
282}
283
284// IMediumFormat methods
285/////////////////////////////////////////////////////////////////////////////
286
287// public methods only for internal purposes
288/////////////////////////////////////////////////////////////////////////////
289/* 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