VirtualBox

source: vbox/trunk/src/VBox/Main/HardDiskFormatImpl.cpp@ 16560

Last change on this file since 16560 was 15649, checked in by vboxsync, 15 years ago

#3285: Improve error handling API to include unique error numbers
Document

  • IHardDiskFormat::describeProperties
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.3 KB
RevLine 
[13673]1/* $Id: HardDiskFormatImpl.cpp 15649 2008-12-18 12:37:11Z vboxsync $ */
[13580]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 "HardDiskFormatImpl.h"
25#include "Logging.h"
26
27#include <VBox/VBoxHDD-new.h>
28
29// constructor / destructor
30/////////////////////////////////////////////////////////////////////////////
31
32DEFINE_EMPTY_CTOR_DTOR (HardDiskFormat)
33
34HRESULT HardDiskFormat::FinalConstruct()
35{
36 return S_OK;
37}
38
39void HardDiskFormat::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 */
[13673]52HRESULT HardDiskFormat::init (const VDBACKENDINFO *aVDInfo)
[13580]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);
[14579]60 AssertReturn (autoInitSpan.isOk(), E_FAIL);
[13580]61
62 /* The ID of the backend */
[14225]63 unconst (m.id) = aVDInfo->pszBackend;
[13673]64 /* The Name of the backend */
65 /* Use id for now as long as VDBACKENDINFO hasn't any extra
66 * name/description field. */
[14225]67 unconst (m.name) = aVDInfo->pszBackend;
[13580]68 /* The capabilities of the backend */
[14225]69 unconst (m.capabilities) = aVDInfo->uBackendCaps;
[13580]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 {
[14225]76 unconst (m.fileExtensions).push_back (*papsz);
[13580]77 ++ papsz;
78 }
79 }
[13844]80 /* Save a list of configure properties */
[13673]81 if (aVDInfo->paConfigInfo)
82 {
83 PCVDCONFIGINFO pa = aVDInfo->paConfigInfo;
[13844]84 /* Walk through all available keys */
[13673]85 while (pa->pszKey != NULL)
86 {
[13950]87 Utf8Str defaultValue ("");
[13844]88 DataType_T dt;
[14009]89 ULONG flags = static_cast <ULONG> (pa->uKeyFlags);
[13844]90 /* Check for the configure data type */
91 switch (pa->enmValueType)
92 {
93 case VDCFGVALUETYPE_INTEGER:
[13950]94 {
95 dt = DataType_Int32;
96 /* If there is a default value get them in the right format */
[14780]97 if (pa->pszDefaultValue)
98 defaultValue = pa->pszDefaultValue;
[13950]99 break;
100 }
[13844]101 case VDCFGVALUETYPE_BYTES:
[13950]102 {
103 dt = DataType_Int8;
104 /* If there is a default value get them in the right format */
[14780]105 if (pa->pszDefaultValue)
[13844]106 {
[14780]107 /* Copy the bytes over - treated simply as a string */
108 defaultValue = pa->pszDefaultValue;
[14009]109 flags |= DataFlags_Array;
[13844]110 }
[13950]111 break;
112 }
[13844]113 case VDCFGVALUETYPE_STRING:
[13950]114 {
115 dt = DataType_String;
116 /* If there is a default value get them in the right format */
[14780]117 if (pa->pszDefaultValue)
118 defaultValue = pa->pszDefaultValue;
[13950]119 break;
120 }
[14561]121
122 default:
123 AssertMsgFailed(("Invalid enm type %d!\n", pa->enmValueType));
124 return E_INVALIDARG;
[13844]125 }
[13950]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
[13844]133 /* Create one property structure */
134 const Property prop = { Utf8Str (pa->pszKey),
135 Utf8Str (""),
136 dt,
[14009]137 flags,
[13950]138 defaultValue };
[14225]139 unconst (m.properties).push_back (prop);
[13673]140 ++ pa;
141 }
142 }
[13580]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 HardDiskFormat::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
[14225]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();
[13580]168}
169
170// IHardDiskFormat properties
171/////////////////////////////////////////////////////////////////////////////
172
173STDMETHODIMP HardDiskFormat::COMGETTER(Id)(BSTR *aId)
174{
[14972]175 CheckComArgOutPointerValid(aId);
[13580]176
177 AutoCaller autoCaller (this);
178 CheckComRCReturnRC (autoCaller.rc());
179
[13673]180 /* this is const, no need to lock */
[14225]181 m.id.cloneTo (aId);
[13580]182
183 return S_OK;
184}
185
[13673]186STDMETHODIMP HardDiskFormat::COMGETTER(Name)(BSTR *aName)
[13580]187{
[14972]188 CheckComArgOutPointerValid(aName);
[13580]189
190 AutoCaller autoCaller (this);
191 CheckComRCReturnRC (autoCaller.rc());
192
[13673]193 /* this is const, no need to lock */
[14225]194 m.name.cloneTo (aName);
[13580]195
196 return S_OK;
197}
198
[13673]199STDMETHODIMP HardDiskFormat::
200COMGETTER(FileExtensions)(ComSafeArrayOut (BSTR, aFileExtensions))
[13580]201{
[13673]202 if (ComSafeArrayOutIsNull (aFileExtensions))
[13580]203 return E_POINTER;
204
205 AutoCaller autoCaller (this);
206 CheckComRCReturnRC (autoCaller.rc());
207
[13673]208 /* this is const, no need to lock */
[14225]209 com::SafeArray <BSTR> fileExtentions (m.fileExtensions.size());
[13673]210 int i = 0;
[14225]211 for (BstrList::const_iterator it = m.fileExtensions.begin();
212 it != m.fileExtensions.end(); ++ it, ++ i)
[13673]213 (*it).cloneTo (&fileExtentions [i]);
214 fileExtentions.detachTo (ComSafeArrayOutArg (aFileExtensions));
[13580]215
216 return S_OK;
217}
218
[13673]219STDMETHODIMP HardDiskFormat::COMGETTER(Capabilities)(ULONG *aCaps)
[13580]220{
[14972]221 CheckComArgOutPointerValid(aCaps);
[13580]222
223 AutoCaller autoCaller (this);
224 CheckComRCReturnRC (autoCaller.rc());
225
[14225]226 /* m.capabilities is const, no need to lock */
[13580]227
[13728]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)
[14225]232 ComAssertRet (m.capabilities == ((ULONG) m.capabilities), E_FAIL);
[13728]233
[14225]234 *aCaps = (ULONG) m.capabilities;
[13728]235
[13580]236 return S_OK;
237}
238
[13844]239STDMETHODIMP HardDiskFormat::DescribeProperties(ComSafeArrayOut (BSTR, aNames),
240 ComSafeArrayOut (BSTR, aDescriptions),
[13956]241 ComSafeArrayOut (DataType_T, aTypes),
[13844]242 ComSafeArrayOut (ULONG, aFlags),
243 ComSafeArrayOut (BSTR, aDefaults))
[13580]244{
[15649]245 CheckComArgSafeArrayNotNull(aNames);
246 CheckComArgSafeArrayNotNull(aDescriptions);
247 CheckComArgSafeArrayNotNull(aTypes);
248 CheckComArgSafeArrayNotNull(aFlags);
249 CheckComArgSafeArrayNotNull(aDefaults);
[13580]250
251 AutoCaller autoCaller (this);
252 CheckComRCReturnRC (autoCaller.rc());
253
[13673]254 /* this is const, no need to lock */
[14225]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());
[13950]260
[13673]261 int i = 0;
[14225]262 for (PropertyList::const_iterator it = m.properties.begin();
263 it != m.properties.end(); ++ it, ++ i)
[13844]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;
[13950]270 prop.defaultValue.cloneTo (&propertyDefaults [i]);
[13844]271 }
[13950]272
[13844]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));
[13580]278
279 return S_OK;
280}
281
282// IHardDiskFormat methods
283/////////////////////////////////////////////////////////////////////////////
284
285// public methods only for internal purposes
286/////////////////////////////////////////////////////////////////////////////
[14772]287/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use