VirtualBox

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

Last change on this file since 29576 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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