VirtualBox

Changeset 90879 in vbox for trunk


Ignore:
Timestamp:
Aug 25, 2021 12:20:08 PM (3 years ago)
Author:
vboxsync
Message:

Main: bugref:1909: Fixed listener unregistration and race of event delivering during com::Shutdown.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxClientImpl.h

    r90828 r90879  
    9999        ComPtr<IToken> m_pToken;
    100100        const ComObjPtr<EventSource> m_pEventSource;
     101        ComPtr<IEventSource> m_pVBoxEventSource;
     102        ComPtr<IEventListener> m_pVBoxEventListener;
    101103
    102104        RTTHREAD m_ThreadWatcher;
     
    118120    HRESULT i_reloadApiLanguage();
    119121    HRESULT i_registerEventListener();
     122    void    i_unregisterEventListener();
    120123#endif
    121124};
  • trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp

    r90849 r90879  
    5959
    6060
    61     HRESULT init(VirtualBoxClient *aClient)
    62     {
    63         mClient = aClient;
     61    HRESULT init(void *)
     62    {
     63        return S_OK;
     64    }
     65
     66    HRESULT init()
     67    {
    6468        return S_OK;
    6569    }
     
    8084            case VBoxEventType_OnLanguageChanged:
    8185            {
    82                 mClient->i_reloadApiLanguage();
     86                VirtualBoxTranslator *pTranslator = VirtualBoxTranslator::instance();
     87                if (pTranslator)
     88                {
     89                    ComPtr<ILanguageChangedEvent> pEvent = aEvent;
     90                    HRESULT rc = E_FAIL;
     91                    Assert(pEvent);
     92
     93                    com::Bstr bstrLanguageId;
     94                    rc = pEvent->COMGETTER(LanguageId)(bstrLanguageId.asOutParam());
     95                    AssertComRC(rc);
     96
     97                    com::Utf8Str strLanguageId(bstrLanguageId);
     98                    pTranslator->i_loadLanguage(strLanguageId.c_str());
     99                    pTranslator->release();
     100                }
    83101                break;
    84102            }
     
    90108        return S_OK;
    91109    }
    92 private:
    93     ComObjPtr<VirtualBoxClient>    mClient;
    94110};
    95111
    96 typedef ListenerImpl<VBoxEventListener, VirtualBoxClient*> VBoxEventListenerImpl;
    97 
    98 VBOX_LISTENER_DECLARE(VBoxEventListenerImpl)
     112typedef ListenerImpl<VBoxEventListener> VBoxEventListenerImpl;
     113
     114VBOX_LISTENER_DECLARE(VBoxTrEventListenerImpl)
    99115
    100116#endif /* VBOX_WITH_MAIN_NLS */
     
    527543    if (autoUninitSpan.uninitDone())
    528544        return;
     545
     546#ifdef VBOX_WITH_MAIN_NLS
     547    i_unregisterEventListener();
     548#endif
    529549
    530550    if (mData.m_ThreadWatcher != NIL_RTTHREAD)
     
    724744HRESULT VirtualBoxClient::i_registerEventListener()
    725745{
    726     ComPtr<IEventSource> pES;
    727     HRESULT rc = mData.m_pVirtualBox->COMGETTER(EventSource)(pES.asOutParam());
     746    HRESULT rc = mData.m_pVirtualBox->COMGETTER(EventSource)(mData.m_pVBoxEventSource.asOutParam());
    728747    if (SUCCEEDED(rc))
    729748    {
    730         ComObjPtr<VBoxEventListenerImpl> aVBoxListener;
    731         aVBoxListener.createObject();
    732         aVBoxListener->init(new VBoxEventListener(), this);
    733 //        mData.m_pVBoxListener = aVBoxListener;
     749        ComObjPtr<VBoxEventListenerImpl> pVBoxListener;
     750        pVBoxListener.createObject();
     751        pVBoxListener->init(new VBoxEventListener());
     752        mData.m_pVBoxEventListener = pVBoxListener;
    734753        com::SafeArray<VBoxEventType_T> eventTypes;
    735754        eventTypes.push_back(VBoxEventType_OnLanguageChanged);
    736         rc = pES->RegisterListener(aVBoxListener, ComSafeArrayAsInParam(eventTypes), true);
     755        rc = mData.m_pVBoxEventSource->RegisterListener(pVBoxListener, ComSafeArrayAsInParam(eventTypes), true);
    737756        if (FAILED(rc))
     757        {
    738758            rc = setError(rc, tr("Failed to register listener"));
     759            mData.m_pVBoxEventListener.setNull();
     760            mData.m_pVBoxEventSource.setNull();
     761        }
    739762    }
    740763    else
     
    743766}
    744767
     768void VirtualBoxClient::i_unregisterEventListener()
     769{
     770    if (mData.m_pVBoxEventListener.isNotNull())
     771    {
     772        if (mData.m_pVBoxEventSource.isNotNull())
     773            mData.m_pVBoxEventSource->UnregisterListener(mData.m_pVBoxEventListener);
     774        mData.m_pVBoxEventListener.setNull();
     775    }
     776    mData.m_pVBoxEventSource.setNull();
     777}
     778
    745779#endif /* VBOX_WITH_MAIN_NLS */
    746780
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