VirtualBox

Changeset 73825 in vbox for trunk/src/VBox/Main/src-all


Ignore:
Timestamp:
Aug 22, 2018 12:51:23 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124516
Message:

Main/ExtPack: Add extpack helper interface for creating and updating IProgress objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp

    r73716 r73825  
    143143    /** Set if we've made the pfnVirtualBoxReady or pfnConsoleReady call. */
    144144    bool                fMadeReadyCall;
     145#ifndef VBOX_COM_INPROC
     146    /** Pointer to the VirtualBox object so we can create a progress object. */
     147    VirtualBox         *pVirtualBox;
     148#endif
    145149
    146150    RTMEMEF_NEW_AND_DELETE_OPERATORS();
     
    720724 *
    721725 * @returns COM status code.
     726 * @param   a_pVirtualBox   The VirtualBox object.
    722727 * @param   a_enmContext    The context we're in.
    723728 * @param   a_pszName       The name of the extension pack.  This is also the
     
    726731 * @param   a_pszDir        The extension pack directory name.
    727732 */
    728 HRESULT ExtPack::initWithDir(VBOXEXTPACKCTX a_enmContext, const char *a_pszName, const char *a_pszDir)
     733HRESULT ExtPack::initWithDir(VirtualBox *a_pVirtualBox, VBOXEXTPACKCTX a_enmContext, const char *a_pszName, const char *a_pszDir)
    729734{
    730735    AutoInitSpan autoInitSpan(this);
     
    744749        /* pfnLoadVDPlugin      = */ ExtPack::i_hlpLoadVDPlugin,
    745750        /* pfnUnloadVDPlugin    = */ ExtPack::i_hlpUnloadVDPlugin,
     751        /* pfnCreateProgress    = */ ExtPack::i_hlpCreateProgress,
     752        /* pfnGetCanceledProgress = */ ExtPack::i_hlpGetCanceledProgress,
     753        /* pfnUpdateProgress    = */ ExtPack::i_hlpUpdateProgress,
     754        /* pfnNextOperationProgress = */ ExtPack::i_hlpNextOperationProgress,
     755        /* pfnCompleteProgress  = */ ExtPack::i_hlpCompleteProgress,
    746756        /* pfnReserved1         = */ ExtPack::i_hlpReservedN,
    747757        /* pfnReserved2         = */ ExtPack::i_hlpReservedN,
     
    774784    m->enmContext                   = a_enmContext;
    775785    m->fMadeReadyCall               = false;
     786#ifndef VBOX_COM_INPROC
     787    m->pVirtualBox                  = a_pVirtualBox;
     788#else
     789    RT_NOREF(a_pVirtualBox);
     790#endif
    776791
    777792    /*
     
    17231738}
    17241739
     1740/*static*/ DECLCALLBACK(uint32_t)
     1741ExtPack::i_hlpCreateProgress(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IUnknown) *pInitiator,
     1742                             const char *pcszDescription, uint32_t cOperations,
     1743                             uint32_t uTotalOperationsWeight, const char *pcszFirstOperationDescription,
     1744                             uint32_t uFirstOperationWeight, VBOXEXTPACK_IF_CS(IProgress) **ppProgressOut)
     1745{
     1746    /*
     1747     * Validate the input and get our bearings.
     1748     */
     1749    AssertPtrReturn(pcszDescription, E_INVALIDARG);
     1750    AssertReturn(cOperations >= 1, E_INVALIDARG);
     1751    AssertReturn(uTotalOperationsWeight >= 1, E_INVALIDARG);
     1752    AssertPtrReturn(pcszFirstOperationDescription, E_INVALIDARG);
     1753    AssertReturn(uFirstOperationWeight >= 1, E_INVALIDARG);
     1754    AssertPtrReturn(ppProgressOut, E_INVALIDARG);
     1755
     1756    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
     1757    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
     1758#ifndef VBOX_COM_INPROC
     1759    ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
     1760#endif
     1761
     1762    ComObjPtr<Progress> pProgress;
     1763    HRESULT hrc = pProgress.createObject();
     1764    if (FAILED(hrc))
     1765        return hrc;
     1766    hrc = pProgress->init(
     1767#ifndef VBOX_COM_INPROC
     1768                          m->pVirtualBox,
     1769#endif
     1770                          pInitiator, pcszDescription, TRUE /* aCancelable */,
     1771                          cOperations, uTotalOperationsWeight,
     1772                          pcszFirstOperationDescription, uFirstOperationWeight);
     1773    if (FAILED(hrc))
     1774        return hrc;
     1775
     1776    return pProgress.queryInterfaceTo(ppProgressOut);
     1777}
     1778
     1779/*static*/ DECLCALLBACK(uint32_t)
     1780ExtPack::i_hlpGetCanceledProgress(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IProgress) *pProgress,
     1781                                  bool *pfCanceled)
     1782{
     1783    /*
     1784     * Validate the input and get our bearings.
     1785     */
     1786    AssertPtrReturn(pProgress, E_INVALIDARG);
     1787    AssertPtrReturn(pfCanceled, E_INVALIDARG);
     1788
     1789    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
     1790    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
     1791
     1792    BOOL fCanceled = FALSE;
     1793    HRESULT hrc = pProgress->GetCanceled(&fCanceled);
     1794    *pfCanceled  = !!fCanceled;
     1795    return hrc;
     1796}
     1797
     1798/*static*/ DECLCALLBACK(uint32_t)
     1799ExtPack::i_hlpUpdateProgress(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IProgress) *pProgress,
     1800                             uint32_t uPercent)
     1801{
     1802    /*
     1803     * Validate the input and get our bearings.
     1804     */
     1805    AssertPtrReturn(pProgress, E_INVALIDARG);
     1806    AssertReturn(uPercent <= 100, E_INVALIDARG);
     1807
     1808    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
     1809    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
     1810
     1811    return pProgress->SetCurrentOperationProgress(uPercent);
     1812}
     1813
     1814/*static*/ DECLCALLBACK(uint32_t)
     1815ExtPack::i_hlpNextOperationProgress(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IProgress) *pProgress,
     1816                                    const char *pcszNextOperationDescription,
     1817                                    uint32_t uNextOperationWeight)
     1818{
     1819    /*
     1820     * Validate the input and get our bearings.
     1821     */
     1822    AssertPtrReturn(pProgress, E_INVALIDARG);
     1823    AssertPtrReturn(pcszNextOperationDescription, E_INVALIDARG);
     1824    AssertReturn(uNextOperationWeight >= 1, E_INVALIDARG);
     1825
     1826    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
     1827    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
     1828
     1829    return pProgress->SetNextOperation(Bstr(pcszNextOperationDescription).raw(), uNextOperationWeight);
     1830}
     1831
     1832/*static*/ DECLCALLBACK(uint32_t)
     1833ExtPack::i_hlpCompleteProgress(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IProgress) *pProgress,
     1834                               uint32_t uResultCode)
     1835{
     1836    /*
     1837     * Validate the input and get our bearings.
     1838     */
     1839    AssertPtrReturn(pProgress, E_INVALIDARG);
     1840
     1841    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
     1842    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
     1843
     1844    Progress *pProgressInt = static_cast<Progress *>(pProgress);
     1845    return pProgressInt->i_notifyComplete(uResultCode);
     1846}
     1847
    17251848/*static*/ DECLCALLBACK(int)
    17261849ExtPack::i_hlpReservedN(PCVBOXEXTPACKHLP pHlp)
     
    20052128                        HRESULT hrc2 = NewExtPack.createObject();
    20062129                        if (SUCCEEDED(hrc2))
    2007                             hrc2 = NewExtPack->initWithDir(a_enmContext, pstrName->c_str(), szExtPackDir);
     2130                            hrc2 = NewExtPack->initWithDir(a_pVirtualBox, a_enmContext, pstrName->c_str(), szExtPackDir);
    20082131                        delete pstrName;
    20092132                        if (SUCCEEDED(hrc2))
     
    25902713            hrc = ptrNewExtPack.createObject();
    25912714            if (SUCCEEDED(hrc))
    2592                 hrc = ptrNewExtPack->initWithDir(m->enmContext, a_pszName, szDir);
     2715                hrc = ptrNewExtPack->initWithDir(m->pVirtualBox, m->enmContext, a_pszName, szDir);
    25932716            if (SUCCEEDED(hrc))
    25942717            {
Note: See TracChangeset for help on using the changeset viewer.

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