VirtualBox

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

Last change on this file since 14683 was 14579, checked in by vboxsync, 16 years ago

Main: VirtualBoxBase::addCaller() now returns E_ACCESSDENIED. Also replaced E_UNEXPECTED with E_FAIL in all Assert* statements (for consistency).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1/* $Id: HardDiskFormatImpl.cpp 14579 2008-11-25 15:59:35Z 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 "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 */
52HRESULT HardDiskFormat::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->pDefaultValue)
98 defaultValue =
99 Utf8StrFmt ("%d", pa->pDefaultValue->Integer.u64);
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->pDefaultValue)
107 {
108 /* Copy the bytes over */
109 defaultValue.alloc (pa->pDefaultValue->Bytes.cb + 1);
110 memcpy (defaultValue.mutableRaw(), pa->pDefaultValue->Bytes.pv,
111 pa->pDefaultValue->Bytes.cb);
112 defaultValue.mutableRaw() [defaultValue.length()] = 0;
113 flags |= DataFlags_Array;
114 }
115 break;
116 }
117 case VDCFGVALUETYPE_STRING:
118 {
119 dt = DataType_String;
120 /* If there is a default value get them in the right format */
121 if (pa->pDefaultValue)
122 defaultValue = pa->pDefaultValue->String.psz;
123 break;
124 }
125
126 default:
127 AssertMsgFailed(("Invalid enm type %d!\n", pa->enmValueType));
128 return E_INVALIDARG;
129 }
130
131 /// @todo add extendedFlags to Property when we reach the 32 bit
132 /// limit (or make the argument ULONG64 after checking that COM is
133 /// capable of defining enums (used to represent bit flags) that
134 /// contain 64-bit values)
135 ComAssertRet (pa->uKeyFlags == ((ULONG) pa->uKeyFlags), E_FAIL);
136
137 /* Create one property structure */
138 const Property prop = { Utf8Str (pa->pszKey),
139 Utf8Str (""),
140 dt,
141 flags,
142 defaultValue };
143 unconst (m.properties).push_back (prop);
144 ++ pa;
145 }
146 }
147
148 /* Confirm a successful initialization */
149 autoInitSpan.setSucceeded();
150
151 return S_OK;
152}
153
154/**
155 * Uninitializes the instance and sets the ready flag to FALSE.
156 * Called either from FinalRelease() or by the parent when it gets destroyed.
157 */
158void HardDiskFormat::uninit()
159{
160 LogFlowThisFunc (("\n"));
161
162 /* Enclose the state transition Ready->InUninit->NotReady */
163 AutoUninitSpan autoUninitSpan (this);
164 if (autoUninitSpan.uninitDone())
165 return;
166
167 unconst (m.properties).clear();
168 unconst (m.fileExtensions).clear();
169 unconst (m.capabilities) = 0;
170 unconst (m.name).setNull();
171 unconst (m.id).setNull();
172}
173
174// IHardDiskFormat properties
175/////////////////////////////////////////////////////////////////////////////
176
177STDMETHODIMP HardDiskFormat::COMGETTER(Id)(BSTR *aId)
178{
179 if (!aId)
180 return E_POINTER;
181
182 AutoCaller autoCaller (this);
183 CheckComRCReturnRC (autoCaller.rc());
184
185 /* this is const, no need to lock */
186 m.id.cloneTo (aId);
187
188 return S_OK;
189}
190
191STDMETHODIMP HardDiskFormat::COMGETTER(Name)(BSTR *aName)
192{
193 if (!aName)
194 return E_POINTER;
195
196 AutoCaller autoCaller (this);
197 CheckComRCReturnRC (autoCaller.rc());
198
199 /* this is const, no need to lock */
200 m.name.cloneTo (aName);
201
202 return S_OK;
203}
204
205STDMETHODIMP HardDiskFormat::
206COMGETTER(FileExtensions)(ComSafeArrayOut (BSTR, aFileExtensions))
207{
208 if (ComSafeArrayOutIsNull (aFileExtensions))
209 return E_POINTER;
210
211 AutoCaller autoCaller (this);
212 CheckComRCReturnRC (autoCaller.rc());
213
214 /* this is const, no need to lock */
215 com::SafeArray <BSTR> fileExtentions (m.fileExtensions.size());
216 int i = 0;
217 for (BstrList::const_iterator it = m.fileExtensions.begin();
218 it != m.fileExtensions.end(); ++ it, ++ i)
219 (*it).cloneTo (&fileExtentions [i]);
220 fileExtentions.detachTo (ComSafeArrayOutArg (aFileExtensions));
221
222 return S_OK;
223}
224
225STDMETHODIMP HardDiskFormat::COMGETTER(Capabilities)(ULONG *aCaps)
226{
227 if (!aCaps)
228 return E_POINTER;
229
230 AutoCaller autoCaller (this);
231 CheckComRCReturnRC (autoCaller.rc());
232
233 /* m.capabilities is const, no need to lock */
234
235 /// @todo add COMGETTER(ExtendedCapabilities) when we reach the 32 bit
236 /// limit (or make the argument ULONG64 after checking that COM is capable
237 /// of defining enums (used to represent bit flags) that contain 64-bit
238 /// values)
239 ComAssertRet (m.capabilities == ((ULONG) m.capabilities), E_FAIL);
240
241 *aCaps = (ULONG) m.capabilities;
242
243 return S_OK;
244}
245
246STDMETHODIMP HardDiskFormat::DescribeProperties(ComSafeArrayOut (BSTR, aNames),
247 ComSafeArrayOut (BSTR, aDescriptions),
248 ComSafeArrayOut (DataType_T, aTypes),
249 ComSafeArrayOut (ULONG, aFlags),
250 ComSafeArrayOut (BSTR, aDefaults))
251{
252 if (ComSafeArrayOutIsNull (aNames) ||
253 ComSafeArrayOutIsNull (aDescriptions) ||
254 ComSafeArrayOutIsNull (aTypes) ||
255 ComSafeArrayOutIsNull (aFlags) ||
256 ComSafeArrayOutIsNull (aDefaults))
257 return E_POINTER;
258
259 AutoCaller autoCaller (this);
260 CheckComRCReturnRC (autoCaller.rc());
261
262 /* this is const, no need to lock */
263 com::SafeArray <BSTR> propertyNames (m.properties.size());
264 com::SafeArray <BSTR> propertyDescriptions (m.properties.size());
265 com::SafeArray <DataType_T> propertyTypes (m.properties.size());
266 com::SafeArray <ULONG> propertyFlags (m.properties.size());
267 com::SafeArray <BSTR> propertyDefaults (m.properties.size());
268
269 int i = 0;
270 for (PropertyList::const_iterator it = m.properties.begin();
271 it != m.properties.end(); ++ it, ++ i)
272 {
273 const Property &prop = (*it);
274 prop.name.cloneTo (&propertyNames [i]);
275 prop.description.cloneTo (&propertyDescriptions [i]);
276 propertyTypes [i] = prop.type;
277 propertyFlags [i] = prop.flags;
278 prop.defaultValue.cloneTo (&propertyDefaults [i]);
279 }
280
281 propertyNames.detachTo (ComSafeArrayOutArg (aNames));
282 propertyDescriptions.detachTo (ComSafeArrayOutArg (aDescriptions));
283 propertyTypes.detachTo (ComSafeArrayOutArg (aTypes));
284 propertyFlags.detachTo (ComSafeArrayOutArg (aFlags));
285 propertyDefaults.detachTo (ComSafeArrayOutArg (aDefaults));
286
287 return S_OK;
288}
289
290// IHardDiskFormat methods
291/////////////////////////////////////////////////////////////////////////////
292
293// public methods only for internal purposes
294/////////////////////////////////////////////////////////////////////////////
295
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