VirtualBox

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

Last change on this file since 25776 was 25149, checked in by vboxsync, 15 years ago

Main: cleanup: remove all CheckComRC* macros (no functional change)

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