VirtualBox

Changeset 34086 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Nov 15, 2010 5:45:50 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67776
Message:

Main: Pass more IVirtualBox pointers to the extension pack. VRDE registration hook, VirtualBoxReady hook.

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r34048 r34086  
    532532#ifdef VBOX_WITH_EXTPACK
    533533    unconst(mptrExtPackManager).createObject();
    534     rc = mptrExtPackManager->init(NULL, false); /* Drop zone handling is VBoxSVC only. */
     534    rc = mptrExtPackManager->init(NULL, NULL, false); /* Drop zone handling is VBoxSVC only. */
    535535    AssertComRCReturnRC(rc);
    536536#endif
  • trunk/src/VBox/Main/ExtPackManagerImpl.cpp

    r34074 r34086  
    4242#include "AutoCaller.h"
    4343#include "Global.h"
     44#include "SystemPropertiesImpl.h"
     45#include "VirtualBoxImpl.h"
    4446
    4547
     
    9799    /** The extension pack registration structure. */
    98100    PCVBOXEXTPACKREG    pReg;
     101    /** Pointer to the VirtualBox object (for VRDE registration). */
     102    VirtualBox         *pVirtualBox;
    99103};
    100104
     
    117121    /** The list of installed extension packs. */
    118122    ExtPackList llInstalledExtPacks;
     123    /** Pointer to the VirtualBox object, our parent. */
     124    VirtualBox *pVirtualBox;
    119125};
    120126
     
    139145 *
    140146 * @returns COM status code.
     147 * @param   a_pVirtualBox   Pointer to the VirtualBox object (grandparent).
    141148 * @param   a_pszName       The name of the extension pack.  This is also the
    142149 *                          name of the subdirector under @a a_pszParentDir
     
    144151 * @param   a_pszParentDir  The parent directory.
    145152 */
    146 HRESULT ExtPack::init(const char *a_pszName, const char *a_pszParentDir)
     153HRESULT ExtPack::init(VirtualBox *a_pVirtualBox, const char *a_pszName, const char *a_pszParentDir)
    147154{
    148155    AutoInitSpan autoInitSpan(this);
     
    158165        /* pfnFindModule        = */ ExtPack::hlpFindModule,
    159166        /* pfnGetFilePath       = */ ExtPack::hlpGetFilePath,
     167        /* pfnRegisterVrde      = */ ExtPack::hlpRegisterVrde,
    160168        /* u32EndMarker         = */ VBOXEXTPACKHLP_VERSION
    161169    };
     
    183191    m->pThis                        = this;
    184192    m->pReg                         = NULL;
     193    m->pVirtualBox                  = a_pVirtualBox;
    185194
    186195    /*
     
    229238/**
    230239 * Calls the installed hook.
     240 *
     241 * @param   a_pVirtualBox       The VirtualBox interface.
    231242 * @remarks Caller holds the extension manager lock.
    232243 */
    233 void    ExtPack::callInstalledHook(void)
     244void    ExtPack::callInstalledHook(IVirtualBox *a_pVirtualBox)
    234245{
    235246    if (   m->hMainMod != NIL_RTLDRMOD
    236247        && m->pReg->pfnInstalled)
    237         m->pReg->pfnInstalled(m->pReg);
     248        m->pReg->pfnInstalled(m->pReg, a_pVirtualBox);
    238249}
    239250
     
    242253 *
    243254 * @returns S_OK or COM error status with error information.
     255 * @param   a_pVirtualBox       The VirtualBox interface.
    244256 * @param   a_fForcedRemoval    When set, we'll ignore complaints from the
    245257 *                              uninstall hook.
    246258 * @remarks The caller holds the manager's write lock.
    247259 */
    248 HRESULT ExtPack::callUninstallHookAndClose(bool a_fForcedRemoval)
     260HRESULT ExtPack::callUninstallHookAndClose(IVirtualBox *a_pVirtualBox, bool a_fForcedRemoval)
    249261{
    250262    HRESULT hrc = S_OK;
     
    252264    if (m->hMainMod != NIL_RTLDRMOD)
    253265    {
    254         if (m->pReg->pfnUninstall)
    255         {
    256             int vrc = m->pReg->pfnUninstall(m->pReg);
     266        if (m->pReg->pfnUninstall && !a_fForcedRemoval)
     267        {
     268            int vrc = m->pReg->pfnUninstall(m->pReg, a_pVirtualBox);
    257269            if (RT_FAILURE(vrc))
    258270            {
     
    274286
    275287/**
     288 * Calls the pfnVirtualBoxReady hook.
     289 *
     290 * @param   a_pVirtualBox       The VirtualBox interface.
     291 * @remarks Caller holds the extension manager lock.
     292 */
     293void ExtPack::callVirtualBoxReadyHook(IVirtualBox *a_pVirtualBox)
     294{
     295    if (   m->hMainMod != NIL_RTLDRMOD
     296        && m->pReg->pfnVirtualBoxReady)
     297        m->pReg->pfnVirtualBoxReady(m->pReg, a_pVirtualBox);
     298}
     299
     300/**
    276301 * Calls the pfnVMCreate hook.
    277302 *
     303 * @param   a_pVirtualBox       The VirtualBox interface.
    278304 * @param   a_pMachine          The machine interface of the new VM.
    279305 * @remarks Caller holds the extension manager lock.
    280306 */
    281 void ExtPack::callVmCreatedHook(IMachine *a_pMachine)
     307void ExtPack::callVmCreatedHook(IVirtualBox *a_pVirtualBox, IMachine *a_pMachine)
    282308{
    283309    if (   m->hMainMod != NIL_RTLDRMOD
    284310        && m->pReg->pfnVMCreated)
    285         m->pReg->pfnVMCreated(m->pReg, a_pMachine);
     311        m->pReg->pfnVMCreated(m->pReg, a_pVirtualBox, a_pMachine);
    286312}
    287313
     
    530556                && m->pReg->u32EndMarker == VBOXEXTPACKREG_VERSION)
    531557            {
    532                 if (   (!m->pReg->pfnInstalled      || RT_VALID_PTR(m->pReg->pfnInstalled))
    533                     && (!m->pReg->pfnUninstall      || RT_VALID_PTR(m->pReg->pfnUninstall))
    534                     && (!m->pReg->pfnUnload         || RT_VALID_PTR(m->pReg->pfnUnload))
    535                     && (!m->pReg->pfnVMCreated      || RT_VALID_PTR(m->pReg->pfnVMCreated))
    536                     && (!m->pReg->pfnVMConfigureVMM || RT_VALID_PTR(m->pReg->pfnVMConfigureVMM))
    537                     && (!m->pReg->pfnVMPowerOn      || RT_VALID_PTR(m->pReg->pfnVMPowerOn))
    538                     && (!m->pReg->pfnVMPowerOff     || RT_VALID_PTR(m->pReg->pfnVMPowerOff))
    539                     && (!m->pReg->pfnQueryObject    || RT_VALID_PTR(m->pReg->pfnQueryObject))
     558                if (   (!m->pReg->pfnInstalled       || RT_VALID_PTR(m->pReg->pfnInstalled))
     559                    && (!m->pReg->pfnUninstall       || RT_VALID_PTR(m->pReg->pfnUninstall))
     560                    && (!m->pReg->pfnVirtualBoxReady || RT_VALID_PTR(m->pReg->pfnVirtualBoxReady))
     561                    && (!m->pReg->pfnUnload          || RT_VALID_PTR(m->pReg->pfnUnload))
     562                    && (!m->pReg->pfnVMCreated       || RT_VALID_PTR(m->pReg->pfnVMCreated))
     563                    && (!m->pReg->pfnVMConfigureVMM  || RT_VALID_PTR(m->pReg->pfnVMConfigureVMM))
     564                    && (!m->pReg->pfnVMPowerOn       || RT_VALID_PTR(m->pReg->pfnVMPowerOn))
     565                    && (!m->pReg->pfnVMPowerOff      || RT_VALID_PTR(m->pReg->pfnVMPowerOff))
     566                    && (!m->pReg->pfnQueryObject     || RT_VALID_PTR(m->pReg->pfnQueryObject))
    540567                    )
    541568                {
     
    760787}
    761788
     789/*static*/ DECLCALLBACK(int)
     790ExtPack::hlpRegisterVrde(PCVBOXEXTPACKHLP pHlp, const char *pszName, bool fSetDefault)
     791{
     792    /*
     793     * Validate the input and get our bearings.
     794     */
     795    AssertPtrReturn(pszName, VERR_INVALID_POINTER);
     796
     797    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
     798    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
     799    ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
     800    AssertPtrReturn(m, VERR_INVALID_POINTER);
     801    ExtPack *pThis = m->pThis;
     802    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
     803    AssertPtrReturn(pThis->m->pVirtualBox, VERR_WRONG_ORDER);
     804
     805    /*
     806     * Find the given module and register it (will succeed if it's already
     807     * registered).
     808     */
     809/** @todo Might consider redoing this VRDERegistration interface to be an aspect of the extension
     810 * pack manager instead of IVirtualBox.  That would make sure we won't have any broke paths and stuff later on. */
     811    int vrc = VERR_MODULE_NOT_FOUND;
     812#if 0 /** @todo causing lock order asserts. Should execute the above todo I think. */
     813    Utf8Str strFound;
     814    if (pThis->findModule(pszName, NULL, &strFound, NULL, NULL))
     815    {
     816        Bstr bstrFound(strFound);
     817        HRESULT hrc = pThis->m->pVirtualBox->VRDERegisterLibrary(bstrFound.raw());
     818        if (SUCCEEDED(hrc) && fSetDefault)
     819        {
     820            /*
     821             * Is there a default already?
     822             */
     823            SystemProperties *pSysProps = pThis->m->pVirtualBox->getSystemProperties();
     824            Bstr bstrDefaultLib;
     825            hrc = pSysProps->COMGETTER(DefaultVRDELibrary)(bstrDefaultLib.asOutParam());
     826            if (SUCCEEDED(hrc) && bstrDefaultLib.isEmpty())
     827            {
     828                bstrDefaultLib = strFound;
     829                hrc = pSysProps->COMSETTER(DefaultVRDELibrary)(bstrDefaultLib.raw());
     830            }
     831        }
     832        vrc = Global::vboxStatusCodeFromCOM(hrc);
     833    }
     834#endif
     835    return vrc;
     836}
     837
    762838
    763839
     
    896972 *
    897973 * @returns COM status code.
     974 * @param   a_pVirtualBox           Pointer to the VirtualBox object.
    898975 * @param   a_pszDropZoneDir        The path to the drop zone directory.
    899976 * @param   a_fCheckDropZone        Whether to check the drop zone for new
     
    901978 *                                  and then only when wanted.
    902979 */
    903 HRESULT ExtPackManager::init(const char *a_pszDropZoneDir, bool a_fCheckDropZone)
     980HRESULT ExtPackManager::init(VirtualBox *a_pVirtualBox, const char *a_pszDropZoneDir, bool a_fCheckDropZone)
    904981{
    905982    AutoInitSpan autoInitSpan(this);
     
    9281005    m->strCertificatDirPath = szCertificatDir;
    9291006    m->strDropZoneDir       = a_pszDropZoneDir;
     1007    m->pVirtualBox          = a_pVirtualBox;
    9301008
    9311009    /*
     
    9621040                HRESULT hrc2 = NewExtPack.createObject();
    9631041                if (SUCCEEDED(hrc2))
    964                     hrc2 = NewExtPack->init(Entry.szName, szBaseDir);
     1042                    hrc2 = NewExtPack->init(m->pVirtualBox, Entry.szName, szBaseDir);
    9651043                if (SUCCEEDED(hrc2))
    9661044                    m->llInstalledExtPacks.push_back(NewExtPack);
     
    11101188                                {
    11111189                                    LogRel(("ExtPackManager: Successfully installed extension pack '%s'.\n", pStrName->c_str()));
    1112                                     pExtPack->callInstalledHook();
     1190                                    pExtPack->callInstalledHook(m->pVirtualBox);
    11131191                                }
    11141192                            }
     
    11761254                 * Call the uninstall hook and unload the main dll.
    11771255                 */
    1178                 hrc = pExtPack->callUninstallHookAndClose(a_fForcedRemoval != FALSE);
     1256                hrc = pExtPack->callUninstallHookAndClose(m->pVirtualBox, a_fForcedRemoval != FALSE);
    11791257                if (SUCCEEDED(hrc))
    11801258                {
     
    15741652            hrc = NewExtPack.createObject();
    15751653            if (SUCCEEDED(hrc))
    1576                 hrc = NewExtPack->init(a_pszName, m->strBaseDir.c_str());
     1654                hrc = NewExtPack->init(m->pVirtualBox, a_pszName, m->strBaseDir.c_str());
    15771655            if (SUCCEEDED(hrc))
    15781656            {
     
    16911769
    16921770/**
    1693  * Calls the pfnVMCreated hook for all working extension packs.
    1694  *
    1695  * @param   a_pMachine          The machine interface of the new VM.
    1696  */
    1697 void ExtPackManager::callAllVmCreatedHooks(IMachine *a_pMachine)
     1771 * Calls the pfnVirtualBoxReady hook for all working extension packs.
     1772 */
     1773void ExtPackManager::callAllVirtualBoxReadyHooks(void)
    16981774{
    16991775    AutoCaller autoCaller(this);
     
    17061782         it != m->llInstalledExtPacks.end();
    17071783         it++)
    1708         (*it)->callVmCreatedHook(a_pMachine);
     1784        (*it)->callVirtualBoxReadyHook(m->pVirtualBox);
     1785}
     1786
     1787/**
     1788 * Calls the pfnVMCreated hook for all working extension packs.
     1789 *
     1790 * @param   a_pMachine          The machine interface of the new VM.
     1791 */
     1792void ExtPackManager::callAllVmCreatedHooks(IMachine *a_pMachine)
     1793{
     1794    AutoCaller autoCaller(this);
     1795    HRESULT hrc = autoCaller.rc();
     1796    if (FAILED(hrc))
     1797        return;
     1798    AutoReadLock autoLock(this COMMA_LOCKVAL_SRC_POS);
     1799
     1800    for (ExtPackList::iterator it = m->llInstalledExtPacks.begin();
     1801         it != m->llInstalledExtPacks.end();
     1802         it++)
     1803        (*it)->callVmCreatedHook(m->pVirtualBox, a_pMachine);
    17091804}
    17101805
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r33952 r34086  
    504504        if (SUCCEEDED(rc))
    505505            /** @todo Define drop zone location. */
    506             rc = m->ptrExtPackManager->init(NULL /*a_pszDropZoneDir*/, false /*a_fCheckDropZone*/);
     506            rc = m->ptrExtPackManager->init(this, NULL /*a_pszDropZoneDir*/, false /*a_fCheckDropZone*/);
    507507        if (FAILED(rc))
    508508            throw rc;
     
    570570    if (SUCCEEDED(rc))
    571571        autoInitSpan.setSucceeded();
     572
     573#ifdef VBOX_WITH_EXTPACK
     574    /* Let the extension packs have a go at things. */
     575    if (SUCCEEDED(rc))
     576        m->ptrExtPackManager->callAllVirtualBoxReadyHooks();
     577#endif
    572578
    573579    LogFlowThisFunc(("rc=%08X\n", rc));
  • trunk/src/VBox/Main/include/ExtPackManagerImpl.h

    r34073 r34086  
    4848    HRESULT     FinalConstruct();
    4949    void        FinalRelease();
    50     HRESULT     init(const char *a_pszName, const char *a_pszParentDir);
     50    HRESULT     init(VirtualBox *a_pVirtualBox, const char *a_pszName, const char *a_pszParentDir);
    5151    void        uninit();
    5252    /** @}  */
     
    6666    /** @name Internal interfaces used by ExtPackManager.
    6767     * @{ */
    68     void        callInstalledHook(void);
    69     HRESULT     callUninstallHookAndClose(bool a_fForcedRemoval);
    70     void        callVmCreatedHook(IMachine *a_pMachine);
     68    void        callInstalledHook(IVirtualBox *a_pVirtualBox);
     69    HRESULT     callUninstallHookAndClose(IVirtualBox *a_pVirtualBox, bool a_fForcedRemoval);
     70    void        callVirtualBoxReadyHook(IVirtualBox *a_pVirtualBox);
     71    void        callVmCreatedHook(IVirtualBox *a_pVirtualBox, IMachine *a_pMachine);
    7172    int         callVmConfigureVmmHook(IConsole *a_pConsole, PVM a_pVM);
    7273    int         callVmPowerOnHook(IConsole *a_pConsole, PVM a_pVM);
     
    8990                                              char *pszFound, size_t cbFound, bool *pfNative);
    9091    static DECLCALLBACK(int)    hlpGetFilePath(PCVBOXEXTPACKHLP pHlp, const char *pszFilename, char *pszPath, size_t cbPath);
     92    static DECLCALLBACK(int)    hlpRegisterVrde(PCVBOXEXTPACKHLP pHlp, const char *pszName, bool fSetDefault);
    9193    /** @}  */
    9294
     
    121123    HRESULT     FinalConstruct();
    122124    void        FinalRelease();
    123     HRESULT     init(const char *a_pszDropZonePath, bool a_fCheckDropZone);
     125    HRESULT     init(VirtualBox *a_pVirtualBox, const char *a_pszDropZonePath, bool a_fCheckDropZone);
    124126    void        uninit();
    125127    /** @}  */
     
    138140     * @{ */
    139141    void        processDropZone(void);
     142    void        callAllVirtualBoxReadyHooks(void);
    140143    void        callAllVmCreatedHooks(IMachine *a_pMachine);
    141144    int         callAllVmConfigureVmmHooks(IConsole *a_pConsole, PVM a_pVM);
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