1 | /* $Id: HardDiskFormatImpl.cpp 14780 2008-11-28 14:36:22Z 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 |
|
---|
32 | DEFINE_EMPTY_CTOR_DTOR (HardDiskFormat)
|
---|
33 |
|
---|
34 | HRESULT HardDiskFormat::FinalConstruct()
|
---|
35 | {
|
---|
36 | return S_OK;
|
---|
37 | }
|
---|
38 |
|
---|
39 | void 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 | */
|
---|
52 | HRESULT 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->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 | */
|
---|
154 | void 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 |
|
---|
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 | // IHardDiskFormat properties
|
---|
171 | /////////////////////////////////////////////////////////////////////////////
|
---|
172 |
|
---|
173 | STDMETHODIMP HardDiskFormat::COMGETTER(Id)(BSTR *aId)
|
---|
174 | {
|
---|
175 | if (!aId)
|
---|
176 | return E_POINTER;
|
---|
177 |
|
---|
178 | AutoCaller autoCaller (this);
|
---|
179 | CheckComRCReturnRC (autoCaller.rc());
|
---|
180 |
|
---|
181 | /* this is const, no need to lock */
|
---|
182 | m.id.cloneTo (aId);
|
---|
183 |
|
---|
184 | return S_OK;
|
---|
185 | }
|
---|
186 |
|
---|
187 | STDMETHODIMP HardDiskFormat::COMGETTER(Name)(BSTR *aName)
|
---|
188 | {
|
---|
189 | if (!aName)
|
---|
190 | return E_POINTER;
|
---|
191 |
|
---|
192 | AutoCaller autoCaller (this);
|
---|
193 | CheckComRCReturnRC (autoCaller.rc());
|
---|
194 |
|
---|
195 | /* this is const, no need to lock */
|
---|
196 | m.name.cloneTo (aName);
|
---|
197 |
|
---|
198 | return S_OK;
|
---|
199 | }
|
---|
200 |
|
---|
201 | STDMETHODIMP HardDiskFormat::
|
---|
202 | COMGETTER(FileExtensions)(ComSafeArrayOut (BSTR, aFileExtensions))
|
---|
203 | {
|
---|
204 | if (ComSafeArrayOutIsNull (aFileExtensions))
|
---|
205 | return E_POINTER;
|
---|
206 |
|
---|
207 | AutoCaller autoCaller (this);
|
---|
208 | CheckComRCReturnRC (autoCaller.rc());
|
---|
209 |
|
---|
210 | /* this is const, no need to lock */
|
---|
211 | com::SafeArray <BSTR> fileExtentions (m.fileExtensions.size());
|
---|
212 | int i = 0;
|
---|
213 | for (BstrList::const_iterator it = m.fileExtensions.begin();
|
---|
214 | it != m.fileExtensions.end(); ++ it, ++ i)
|
---|
215 | (*it).cloneTo (&fileExtentions [i]);
|
---|
216 | fileExtentions.detachTo (ComSafeArrayOutArg (aFileExtensions));
|
---|
217 |
|
---|
218 | return S_OK;
|
---|
219 | }
|
---|
220 |
|
---|
221 | STDMETHODIMP HardDiskFormat::COMGETTER(Capabilities)(ULONG *aCaps)
|
---|
222 | {
|
---|
223 | if (!aCaps)
|
---|
224 | return E_POINTER;
|
---|
225 |
|
---|
226 | AutoCaller autoCaller (this);
|
---|
227 | CheckComRCReturnRC (autoCaller.rc());
|
---|
228 |
|
---|
229 | /* m.capabilities is const, no need to lock */
|
---|
230 |
|
---|
231 | /// @todo add COMGETTER(ExtendedCapabilities) when we reach the 32 bit
|
---|
232 | /// limit (or make the argument ULONG64 after checking that COM is capable
|
---|
233 | /// of defining enums (used to represent bit flags) that contain 64-bit
|
---|
234 | /// values)
|
---|
235 | ComAssertRet (m.capabilities == ((ULONG) m.capabilities), E_FAIL);
|
---|
236 |
|
---|
237 | *aCaps = (ULONG) m.capabilities;
|
---|
238 |
|
---|
239 | return S_OK;
|
---|
240 | }
|
---|
241 |
|
---|
242 | STDMETHODIMP HardDiskFormat::DescribeProperties(ComSafeArrayOut (BSTR, aNames),
|
---|
243 | ComSafeArrayOut (BSTR, aDescriptions),
|
---|
244 | ComSafeArrayOut (DataType_T, aTypes),
|
---|
245 | ComSafeArrayOut (ULONG, aFlags),
|
---|
246 | ComSafeArrayOut (BSTR, aDefaults))
|
---|
247 | {
|
---|
248 | if (ComSafeArrayOutIsNull (aNames) ||
|
---|
249 | ComSafeArrayOutIsNull (aDescriptions) ||
|
---|
250 | ComSafeArrayOutIsNull (aTypes) ||
|
---|
251 | ComSafeArrayOutIsNull (aFlags) ||
|
---|
252 | ComSafeArrayOutIsNull (aDefaults))
|
---|
253 | return E_POINTER;
|
---|
254 |
|
---|
255 | AutoCaller autoCaller (this);
|
---|
256 | CheckComRCReturnRC (autoCaller.rc());
|
---|
257 |
|
---|
258 | /* this is const, no need to lock */
|
---|
259 | com::SafeArray <BSTR> propertyNames (m.properties.size());
|
---|
260 | com::SafeArray <BSTR> propertyDescriptions (m.properties.size());
|
---|
261 | com::SafeArray <DataType_T> propertyTypes (m.properties.size());
|
---|
262 | com::SafeArray <ULONG> propertyFlags (m.properties.size());
|
---|
263 | com::SafeArray <BSTR> propertyDefaults (m.properties.size());
|
---|
264 |
|
---|
265 | int i = 0;
|
---|
266 | for (PropertyList::const_iterator it = m.properties.begin();
|
---|
267 | it != m.properties.end(); ++ it, ++ i)
|
---|
268 | {
|
---|
269 | const Property &prop = (*it);
|
---|
270 | prop.name.cloneTo (&propertyNames [i]);
|
---|
271 | prop.description.cloneTo (&propertyDescriptions [i]);
|
---|
272 | propertyTypes [i] = prop.type;
|
---|
273 | propertyFlags [i] = prop.flags;
|
---|
274 | prop.defaultValue.cloneTo (&propertyDefaults [i]);
|
---|
275 | }
|
---|
276 |
|
---|
277 | propertyNames.detachTo (ComSafeArrayOutArg (aNames));
|
---|
278 | propertyDescriptions.detachTo (ComSafeArrayOutArg (aDescriptions));
|
---|
279 | propertyTypes.detachTo (ComSafeArrayOutArg (aTypes));
|
---|
280 | propertyFlags.detachTo (ComSafeArrayOutArg (aFlags));
|
---|
281 | propertyDefaults.detachTo (ComSafeArrayOutArg (aDefaults));
|
---|
282 |
|
---|
283 | return S_OK;
|
---|
284 | }
|
---|
285 |
|
---|
286 | // IHardDiskFormat methods
|
---|
287 | /////////////////////////////////////////////////////////////////////////////
|
---|
288 |
|
---|
289 | // public methods only for internal purposes
|
---|
290 | /////////////////////////////////////////////////////////////////////////////
|
---|
291 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|