VirtualBox

Changeset 106880 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Nov 8, 2024 8:36:27 AM (2 months ago)
Author:
vboxsync
Message:

Added implementations of getTrackedObject and getTrackedObjectIds. Reshuffle lit bit init() and uninit() for the correct build.

File:
1 edited

Legend:

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

    r106077 r106880  
    109109#include "VBoxEvents.h"
    110110
     111#include "ObjectsTracker.h"
     112
    111113#include <QMTranslator.h>
    112114
     
    130132//
    131133////////////////////////////////////////////////////////////////////////////////
     134
     135extern TrackedObjectsCollector gTrackedObjectsCollector;
    132136
    133137// static
     
    265269typedef std::map<RTPROCESS, WatchedClientProcess *> WatchedClientProcessMap;
    266270#endif
    267 
    268271
    269272typedef ObjectsList<Medium> MediaOList;
     
    331334        , cRefsCrypto(0)
    332335        , pCryptoIf(NULL)
     336        , objectTrackerTask(NULL)
    333337    {
    334338#if defined(RT_OS_WINDOWS) && defined(VBOXSVC_WITH_CLIENT_WATCHER)
     
    468472    RTCRITSECT                          CritSectModCrypto;
    469473    /** @} */
     474
     475    /** The tracked object collector (better if it'll be a singleton) */
     476    ObjectTracker *objectTrackerTask;
    470477};
    471478
     
    561568
    562569    LogFlowThisFunc(("Version: %s, Package: %s, API Version: %s\n", sVersion.c_str(), sPackageType.c_str(), sAPIVersion.c_str()));
     570
     571    /* Try to start Object tracker thread as earlier as possible */
     572    {
     573        int vrc = 0;
     574        if(gTrackedObjectsCollector.init())
     575        {
     576            LogRel(("Starting the Object tracker thread\n"));
     577            try
     578            {
     579                m->objectTrackerTask = new ObjectTracker();
     580                if (!m->objectTrackerTask->init()) // some init procedure
     581                    vrc = E_FAIL;
     582                else
     583                    vrc = m->objectTrackerTask->createThread();
     584            }
     585            catch (...)
     586            {
     587                LogRel(("Exception during starting the Object tracker thread\n"));
     588                if (m->objectTrackerTask)
     589                {
     590                    delete m->objectTrackerTask;
     591                    m->objectTrackerTask = NULL;
     592                }
     593                vrc = E_FAIL;
     594            }
     595        }
     596
     597        if(RT_SUCCESS(vrc))
     598            LogRel(("Successfully started the Object tracker thread\n"));
     599        else
     600            LogRel(("Failed to start the Object tracker thread (%Rrc)\n", vrc));
     601    }
    563602
    564603    /* Important: DO NOT USE any kind of "early return" (except the single
     
    10751114    else
    10761115        m->allMachines.uninitAll();
     1116
    10771117    m->allFloppyImages.uninitAll();
    10781118    m->allDVDImages.uninitAll();
    10791119    m->allHardDisks.uninitAll();
    10801120    m->allDHCPServers.uninitAll();
    1081 
    1082     m->mapProgressOperations.clear();
    1083 
    10841121    m->allGuestOSTypes.uninitAll();
    10851122
     
    11301167
    11311168    RTCritSectDelete(&m->CritSectModCrypto);
     1169
     1170    m->mapProgressOperations.clear();
     1171    /*
     1172     * Call gTrackedObjectsCollector uninitialization before ExtPackManager uninitialization!!!
     1173     * Otherwise, this results in an error when releasing resources (in ComPtr::cleanup).
     1174     */
     1175    if (m->objectTrackerTask)
     1176    {
     1177        LogRel(("BACKEND: Terminating the object tracker...\n"));
     1178        m->objectTrackerTask->finish();//set the termination flag in the thread
     1179        delete m->objectTrackerTask;//waiting the thread termination is going in the m_objectTrackerTask destructor
     1180        gTrackedObjectsCollector.uninit();
     1181    }
    11321182
    11331183#ifdef VBOX_WITH_EXTPACK
     
    63896439}
    63906440
    6391 
    63926441HRESULT VirtualBox::findProgressById(const com::Guid &aId,
    63936442                                     ComPtr<IProgress> &aProgressObject)
     
    64106459}
    64116460
     6461HRESULT VirtualBox::getTrackedObject (const com::Utf8Str& aTrObjId,
     6462                                      ComPtr<IUnknown> &aPIface)
     6463{
     6464    TrackedObjectData trObjData;
     6465    HRESULT hrc = gTrackedObjectsCollector.getObj(aTrObjId, trObjData);
     6466    if (SUCCEEDED(hrc))
     6467        trObjData.getInterface().queryInterfaceTo(aPIface.asOutParam());
     6468
     6469    return hrc;
     6470}
     6471
     6472
     6473std::map <com::Utf8Str, com::Utf8Str> lMapInterfaceNameToIID = {
     6474    {"IProgress", Guid(IID_IProgress).toString()},
     6475    {"ISession", Guid(IID_ISession).toString()},
     6476    {"IMedium", Guid(IID_IMedium).toString()},
     6477    {"IMachine", Guid(IID_IMachine).toString()}
     6478};
     6479
     6480/**
     6481 * Get the tracked object Ids list by the interface name.
     6482 *
     6483 * @param aName  Interface name (like "IProgress", "ISession", "IMedium" etc)
     6484 * @param aObjIdsList  The list of Ids of the found objects
     6485 *
     6486 * @return The list of the found objects Ids
     6487 */
     6488HRESULT VirtualBox::getTrackedObjectIds (const com::Utf8Str& aName,
     6489                                         std::vector<com::Utf8Str> &aObjIdsList)
     6490{
     6491    HRESULT hrc = S_OK;
     6492
     6493    try
     6494    {
     6495        /* Check the supported tracked classes to avoid "out of range" exception */
     6496        if (lMapInterfaceNameToIID.count(aName))
     6497        {
     6498            hrc = gTrackedObjectsCollector.getObjIdsByClassIID(lMapInterfaceNameToIID.at(aName), aObjIdsList);
     6499            if (FAILED(hrc))
     6500                hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("No objects were found for the passed interface name '%s'."),
     6501                               aName.c_str());
     6502        }
     6503        else
     6504            hrc = setError(E_INVALIDARG, tr("The objects of the passed interface '%s' are not tracked at moment."), aName.c_str());
     6505    }
     6506    catch (...)
     6507    {
     6508            hrc = setError(E_FAIL, tr("The unknown exception in the VirtualBox::getTrackedObjectIds()."));
     6509    }
     6510
     6511    return hrc;
     6512}
    64126513
    64136514/**
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