VirtualBox

Ignore:
Timestamp:
Apr 12, 2013 12:01:02 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84995
Message:

Main: Code generator for (xp)com API implementations, including logging and parameter conversion, so far only used by MediumFormat. Next try, needed significant tweaks to work with xpcom (safearray handling fixes in the parameter conversion helpers), different STL implementation (which doesn't support declaring template type parameters as const), missing build dependencies (which didn't show on the dual core system used for writing the code), and finally the duplicate XPCOM classinfo and AddRef/Release/QueryInterface method definitions needed to be removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MediumFormatImpl.cpp

    r45497 r45518  
    22/** @file
    33 *
    4  * VirtualBox COM class implementation
     4 * MediumFormat COM class implementation
    55 */
    66
     
    7676            DeviceType_T devType;
    7777
    78             unconst(m.llFileExtensions).push_back(papExtension->pszExtension);
     78            unconst(m.maFileExtensions).push_back(papExtension->pszExtension);
    7979
    8080            switch(papExtension->enmType)
     
    9494            }
    9595
    96             unconst(m.llDeviceTypes).push_back(devType);
     96            unconst(m.maDeviceTypes).push_back(devType);
    9797            ++papExtension;
    9898        }
     
    157157                                    flags,
    158158                                    defaultValue };
    159             unconst(m.llProperties).push_back(prop);
     159            unconst(m.maProperties).push_back(prop);
    160160            ++pa;
    161161        }
     
    181181        return;
    182182
    183     unconst(m.llProperties).clear();
    184     unconst(m.llFileExtensions).clear();
    185     unconst(m.llDeviceTypes).clear();
     183    unconst(m.maProperties).clear();
     184    unconst(m.maFileExtensions).clear();
     185    unconst(m.maDeviceTypes).clear();
    186186    unconst(m.capabilities) = (MediumFormatCapabilities_T)0;
    187187    unconst(m.strName).setNull();
     
    192192/////////////////////////////////////////////////////////////////////////////
    193193
    194 STDMETHODIMP MediumFormat::COMGETTER(Id)(BSTR *aId)
    195 {
    196     CheckComArgOutPointerValid(aId);
    197 
    198     AutoCaller autoCaller(this);
    199     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    200 
    201     /* this is const, no need to lock */
    202     m.strId.cloneTo(aId);
    203 
    204     return S_OK;
    205 }
    206 
    207 STDMETHODIMP MediumFormat::COMGETTER(Name)(BSTR *aName)
    208 {
    209     CheckComArgOutPointerValid(aName);
    210 
    211     AutoCaller autoCaller(this);
    212     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    213 
    214     /* this is const, no need to lock */
    215     m.strName.cloneTo(aName);
    216 
    217     return S_OK;
    218 }
    219 
    220 STDMETHODIMP MediumFormat::COMGETTER(Capabilities)(ComSafeArrayOut(MediumFormatCapabilities_T, aCaps))
    221 {
    222     CheckComArgOutSafeArrayPointerValid(aCaps);
    223 
    224     AutoCaller autoCaller(this);
    225     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    226 
    227     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    228 
    229     SafeArray<MediumFormatCapabilities_T> capabilities(sizeof(MediumFormatCapabilities_T)*8);
    230 
    231     for (ULONG i = 0; i < capabilities.size(); ++i)
    232     {
    233         ULONG temp = m.capabilities;
    234         temp &= 1<<i;
    235         capabilities [i] = (MediumFormatCapabilities_T)temp;
    236     }
    237 
    238     capabilities.detachTo(ComSafeArrayOutArg(aCaps));
    239 
    240     return S_OK;
    241 }
    242 
    243 STDMETHODIMP MediumFormat::DescribeFileExtensions(ComSafeArrayOut(BSTR, aFileExtensions),
    244                                                   ComSafeArrayOut(DeviceType_T, aDeviceTypes))
    245 {
    246     CheckComArgOutSafeArrayPointerValid(aFileExtensions);
    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> fileExtentions(m.llFileExtensions.size());
    253     int i = 0;
    254     for (StrList::const_iterator it = m.llFileExtensions.begin();
    255          it != m.llFileExtensions.end();
    256          ++it, ++i)
    257         (*it).cloneTo(&fileExtentions[i]);
    258     fileExtentions.detachTo(ComSafeArrayOutArg(aFileExtensions));
    259 
    260     com::SafeArray<DeviceType_T> deviceTypes(m.llDeviceTypes.size());
    261     i = 0;
    262     for (DeviceTypeList::const_iterator it = m.llDeviceTypes.begin();
    263          it != m.llDeviceTypes.end();
    264          ++it, ++i)
    265         deviceTypes[i] = (*it);
    266     deviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
    267 
    268     return S_OK;
    269 }
    270 
    271 STDMETHODIMP MediumFormat::DescribeProperties(ComSafeArrayOut(BSTR, aNames),
    272                                               ComSafeArrayOut(BSTR, aDescriptions),
    273                                               ComSafeArrayOut(DataType_T, aTypes),
    274                                               ComSafeArrayOut(ULONG, aFlags),
    275                                               ComSafeArrayOut(BSTR, aDefaults))
    276 {
    277     CheckComArgOutSafeArrayPointerValid(aNames);
    278     CheckComArgOutSafeArrayPointerValid(aDescriptions);
    279     CheckComArgOutSafeArrayPointerValid(aTypes);
    280     CheckComArgOutSafeArrayPointerValid(aFlags);
    281     CheckComArgOutSafeArrayPointerValid(aDefaults);
    282 
    283     AutoCaller autoCaller(this);
    284     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    285 
    286     /* this is const, no need to lock */
    287     size_t c = m.llProperties.size();
    288     com::SafeArray<BSTR>        propertyNames(c);
    289     com::SafeArray<BSTR>        propertyDescriptions(c);
    290     com::SafeArray<DataType_T>  propertyTypes(c);
    291     com::SafeArray<ULONG>       propertyFlags(c);
    292     com::SafeArray<BSTR>        propertyDefaults(c);
    293 
    294     int i = 0;
    295     for (PropertyList::const_iterator it = m.llProperties.begin();
    296          it != m.llProperties.end();
    297          ++it, ++i)
    298     {
    299         const Property &prop = (*it);
    300         prop.strName.cloneTo(&propertyNames[i]);
    301         prop.strDescription.cloneTo(&propertyDescriptions[i]);
    302         propertyTypes[i] = prop.type;
    303         propertyFlags[i] = prop.flags;
    304         prop.strDefaultValue.cloneTo(&propertyDefaults[i]);
    305     }
    306 
    307     propertyNames.detachTo(ComSafeArrayOutArg(aNames));
    308     propertyDescriptions.detachTo(ComSafeArrayOutArg(aDescriptions));
    309     propertyTypes.detachTo(ComSafeArrayOutArg(aTypes));
    310     propertyFlags.detachTo(ComSafeArrayOutArg(aFlags));
    311     propertyDefaults.detachTo(ComSafeArrayOutArg(aDefaults));
     194HRESULT MediumFormat::getId(com::Utf8Str &aId)
     195{
     196    /* this is const, no need to lock */
     197    aId = m.strId;
     198
     199    return S_OK;
     200}
     201
     202HRESULT MediumFormat::getName(com::Utf8Str &aName)
     203{
     204    /* this is const, no need to lock */
     205    aName = m.strName;
     206
     207    return S_OK;
     208}
     209
     210HRESULT MediumFormat::getCapabilities(std::vector<MediumFormatCapabilities_T> &aCapabilities)
     211{
     212    /* m.capabilities is const, no need to lock */
     213
     214    aCapabilities.resize(sizeof(MediumFormatCapabilities_T) * 8);
     215    size_t cCapabilities = 0;
     216    for (size_t i = 0; i < aCapabilities.size(); i++)
     217    {
     218        uint64_t tmp = m.capabilities;
     219        tmp &= 1ULL << i;
     220        if (tmp)
     221            aCapabilities[cCapabilities] = (MediumFormatCapabilities_T)tmp;
     222    }
     223    aCapabilities.resize(RT_MIN(cCapabilities, 1));
    312224
    313225    return S_OK;
     
    317229/////////////////////////////////////////////////////////////////////////////
    318230
     231HRESULT MediumFormat::describeFileExtensions(std::vector<com::Utf8Str> &aExtensions,
     232                                             std::vector<DeviceType_T> &aTypes)
     233{
     234    /* this is const, no need to lock */
     235    aExtensions = m.maFileExtensions;
     236    aTypes = m.maDeviceTypes;
     237
     238    return S_OK;
     239}
     240
     241HRESULT MediumFormat::describeProperties(std::vector<com::Utf8Str> &aNames,
     242                                         std::vector<com::Utf8Str> &aDescriptions,
     243                                         std::vector<DataType_T> &aTypes,
     244                                         std::vector<ULONG> &aFlags,
     245                                         std::vector<com::Utf8Str> &aDefaults)
     246{
     247    /* this is const, no need to lock */
     248    size_t c = m.maProperties.size();
     249    aNames.resize(c);
     250    aDescriptions.resize(c);
     251    aTypes.resize(c);
     252    aFlags.resize(c);
     253    aDefaults.resize(c);
     254    for (size_t i = 0; i < c; i++)
     255    {
     256        const Property &prop = m.maProperties[i];
     257        aNames[i] = prop.strName;
     258        aDescriptions[i] = prop.strDescription;
     259        aTypes[i] = prop.type;
     260        aFlags[i] = prop.flags;
     261        aDefaults[i] = prop.strDefaultValue;
     262    }
     263
     264    return S_OK;
     265}
     266
    319267// public methods only for internal purposes
    320268/////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette