VirtualBox

Ignore:
Timestamp:
Nov 17, 2017 9:41:44 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119127
Message:

Main: More SDS plan B sketching.

File:
1 edited

Legend:

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

    r69729 r69731  
    2727
    2828#include "VirtualBoxImpl.h"
     29#ifdef VBOX_WITH_SDS_PLAN_B
     30# include "VBoxSVCWrap.h"
     31#endif
    2932#include "Logging.h"
    3033
     
    139142
    140143#ifdef VBOX_WITH_SDS_PLAN_B
     144class VBoxSVC;
    141145
    142146/**
     
    150154    /** Tri state: 0=uninitialized or initializing; 1=success; -1=failure.
    151155     * This will be updated after both m_hrcCreate and m_pObj have been set. */
    152     volatile int32_t    m_iState;
     156    volatile int32_t       m_iState;
    153157    /** The result of the instantiation attempt. */
    154     HRESULT             m_hrcCreate;
     158    HRESULT                m_hrcCreate;
    155159    /** The IUnknown of the VirtualBox object/interface we're working with. */
    156     IUnknown           *m_pObj;
     160    IUnknown              *m_pObj;
     161    /** Pointer to the IVBoxSVC implementation that VBoxSDS works with. */
     162    ComObjPtr<VBoxSVC>     m_ptrVBoxSVC;
     163    /** The VBoxSDS interface. */
     164    ComPtr<IVirtualBoxSDS> m_ptrVirtualBoxSDS;
    157165
    158166public:
     
    172180    STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvObj);
    173181
    174     // IVBoxSVC
    175     STDMETHOD(GetVirtualBox)(IUnknown **ppOtherObj);
     182    /** Worker for VBoxSVC::getVirtualBox. */
     183    HRESULT i_getVirtualBox(ComPtr<IUnknown> &aResult);
    176184
    177185private:
     
    181189
    182190
     191/**
     192 * The VBoxSVC class is handed to VBoxSDS so it can call us back and ask for the
     193 * VirtualBox object when the next VBoxSVC for this user registers itself.
     194 */
     195class ATL_NO_VTABLE VBoxSVC : public VBoxSVCWrap
     196{
     197public:
     198    DECLARE_EMPTY_CTOR_DTOR(VBoxSVC)
     199
     200    HRESULT FinalConstruct()
     201    {
     202        return BaseFinalConstruct();
     203    }
     204
     205    void FinalRelease()
     206    {
     207        uninit();
     208        BaseFinalRelease();
     209    }
     210
     211    // public initializer/uninitializer for internal purposes only
     212    HRESULT init(VirtualBoxClassFactory *pFactory)
     213    {
     214        AutoInitSpan autoInitSpan(this);
     215        AssertReturn(autoInitSpan.isOk(), E_FAIL);
     216
     217        m_pFactory = pFactory;
     218
     219        autoInitSpan.setSucceeded();
     220        return S_OK;
     221    }
     222
     223    void uninit()
     224    {
     225        AutoUninitSpan autoUninitSpan(this);
     226        if (!autoUninitSpan.uninitDone())
     227            m_pFactory = NULL;
     228    }
     229
     230private:
     231    // Wrapped IVBoxSVC method.
     232    HRESULT getVirtualBox(ComPtr<IUnknown> &aResult)
     233    {
     234        if (m_pFactory)
     235            return m_pFactory->i_getVirtualBox(aResult);
     236        return E_FAIL;
     237    }
     238
     239public:
     240    /** Pointer to the factory. */
     241    VirtualBoxClassFactory *m_pFactory;
     242};
     243
     244DEFINE_EMPTY_CTOR_DTOR(VBoxSVC);
     245
     246
    183247HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox)
    184248{
     249    /*
     250     * Connect to VBoxSDS.
     251     */
     252    ComPtr<IVirtualBoxSDS> m_ptrVirtualBoxSDS;
     253    HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxSDS, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxSDS,
     254                                   (void **)m_ptrVirtualBoxSDS.asOutParam());
     255    if (SUCCEEDED(hrc))
     256    {
     257        /*
     258         * Create VBoxSVC object and hand that to VBoxSDS.
     259         */
     260        hrc = m_ptrVBoxSVC.createObject();
     261        if (SUCCEEDED(hrc))
     262        {
     263            hrc = m_ptrVBoxSVC->init(this);
     264            if (SUCCEEDED(hrc))
     265            {
     266                hrc = m_ptrVirtualBoxSDS->RegisterVBoxSVC(m_ptrVBoxSVC, GetCurrentProcessId(), ppOtherVirtualBox);
     267                if (SUCCEEDED(hrc))
     268                {
     269                    return hrc;
     270                }
     271            }
     272        }
     273    }
     274    m_ptrVirtualBoxSDS.setNull();
     275    m_ptrVBoxSVC.setNull();
    185276    *ppOtherVirtualBox = NULL;
    186     return S_OK;
     277    return hrc;
    187278}
    188279
     
    194285
    195286
    196 STDMETHODIMP VirtualBoxClassFactory::GetVirtualBox(IUnknown **ppUnkVirtualBox)
     287HRESULT VirtualBoxClassFactory::i_getVirtualBox(ComPtr<IUnknown> &aResult)
    197288{
    198289    IUnknown *pObj = m_pObj;
     
    201292        /** @todo Do we need to do something regarding server locking?  Hopefully COM
    202293         *        deals with that........... */
    203         pObj->AddRef();
    204         *ppUnkVirtualBox = pObj;
     294        aResult = pObj;
    205295        Log(("VirtualBoxClassFactory::GetVirtualBox: S_OK - %p\n", pObj));
    206296        return S_OK;
    207297    }
    208     *ppUnkVirtualBox = NULL;
     298    aResult.setNull();
    209299    Log(("VirtualBoxClassFactory::GetVirtualBox: E_FAIL\n"));
    210300    return E_FAIL;
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