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