VirtualBox

Ignore:
Timestamp:
Jan 19, 2011 7:10:49 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69546
Message:

Main. QT/FE: fix long standing COM issue

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/COMDefs.cpp

    r35524 r35638  
    2222#if !defined (VBOX_WITH_XPCOM)
    2323
     24
    2425#else /* !defined (VBOX_WITH_XPCOM) */
    2526
     
    8788 *  Initializes COM/XPCOM.
    8889 */
    89 HRESULT COMBase::InitializeCOM()
     90HRESULT COMBase::InitializeCOM(bool fGui)
    9091{
    9192    LogFlowFuncEnter();
    9293
    93     /* Note: On Win32, Qt somehow calls CoInitialize[Ex]() during creation of
    94      * the QApplication instance (didn't explore deeply why it does so) with
    95      * different flags which is incompatible with our multithreaded
    96      * apartment. com::Initialize() will properly care of this situation. */
    97 
    98     HRESULT rc = com::Initialize();
     94    HRESULT rc = com::Initialize(fGui);
    9995
    10096#if defined (VBOX_WITH_XPCOM)
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/COMDefs.h

    r34740 r35638  
    203203public:
    204204
    205     static HRESULT InitializeCOM();
     205    static HRESULT InitializeCOM(bool fGui);
    206206    static HRESULT CleanupCOM();
    207207
     
    355355
    356356    /* no arbitrary instance creations */
    357     COMBase() : mRC (S_OK) {};
     357    COMBase() : mRC (S_OK) {}
    358358
    359359#if defined (VBOX_WITH_XPCOM)
     
    633633    // constructors & destructor
    634634
    635     CInterface() : mIface (NULL) {}
    636 
    637     CInterface (const CInterface &that) : B (that), mIface (that.mIface)
    638     {
    639         addref (mIface);
    640     }
    641 
    642     CInterface (I *aIface) : mIface (aIface) { addref (mIface); }
    643 
    644     virtual ~CInterface() { release (mIface); }
     635    CInterface()
     636    {
     637        clear();
     638    }
     639
     640    CInterface (const CInterface &that) : B (that)
     641    {   
     642        clear();
     643        mIface = that.mIface;
     644        addref(ptr());
     645    }
     646
     647    CInterface (I *aIface)
     648    {
     649        clear();
     650        setPtr (aIface);
     651        addref (aIface);
     652    }
     653
     654    virtual ~CInterface()
     655    {
     656        detach();
     657#ifdef DEBUG
     658        mDead = true;
     659#endif
     660    }
    645661
    646662    // utility methods
    647 
    648663    void createInstance (const CLSID &aClsId)
    649664    {
    650         AssertMsg (!mIface, ("Instance is already non-NULL\n"));
    651         if (!mIface)
    652         {
     665        AssertMsg (ptr() == NULL, ("Instance is already non-NULL\n"));
     666        if (ptr() == NULL)
     667        {
     668            I* pObj = NULL;
    653669#if !defined (VBOX_WITH_XPCOM)
    654 
    655670            B::mRC = CoCreateInstance (aClsId, NULL, CLSCTX_ALL,
    656                                        _ATL_IIDOF (I), (void **) &mIface);
    657 
    658 #else /* !defined (VBOX_WITH_XPCOM) */
    659 
     671                                       _ATL_IIDOF (I), (void **) &pObj);
     672#else
    660673            nsCOMPtr <nsIComponentManager> manager;
    661674            B::mRC = NS_GetComponentManager (getter_AddRefs (manager));
    662675            if (SUCCEEDED (B::mRC))
    663676                B::mRC = manager->CreateInstance (aClsId, nsnull, NS_GET_IID (I),
    664                                                   (void **) &mIface);
    665 
    666 #endif /* !defined (VBOX_WITH_XPCOM) */
    667 
     677                                                  (void **) &pObj);
     678#endif
     679             
     680            if (SUCCEEDED (B::mRC))
     681               setPtr(pObj);
     682            else
     683               setPtr(NULL);
     684           
    668685            /* fetch error info, but don't assert if it's missing -- many other
    669686             * reasons can lead to an error (w/o providing error info), not only
    670687             * the instance initialization code (that should always provide it) */
    671688            B::fetchErrorInfo (NULL, NULL);
    672         }
     689         }
    673690    }
    674691
     
    680697    void attach (OI *aIface)
    681698    {
     699#ifdef DEBUG
     700        Assert(!mDead);
     701#endif
    682702        /* be aware of self assignment */
     703        I* amIface = ptr();
    683704        addref (aIface);
    684         release (mIface);
     705        release (amIface);
    685706        if (aIface)
    686707        {
    687             mIface = NULL;
    688             B::mRC = aIface->QueryInterface (COM_IIDOF (I), (void **) &mIface);
     708            amIface = NULL;
     709            B::mRC = aIface->QueryInterface (COM_IIDOF (I), (void **) &amIface);
    689710            release (aIface);
     711            setPtr(amIface);
    690712        }
    691713        else
    692714        {
    693             mIface = NULL;
     715            setPtr(NULL);
    694716            B::mRC = S_OK;
    695717        }
     
    699721    void attach (I *aIface)
    700722    {
     723#ifdef DEBUG
     724        Assert(!mDead);
     725#endif
    701726        /* be aware of self assignment */
    702727        addref (aIface);
    703         release (mIface);
    704         mIface = aIface;
     728        release (ptr());
     729        setPtr(aIface);
    705730        B::mRC = S_OK;
    706731    };
    707732
    708733    /** Detaches from the underlying interface pointer. */
    709     void detach() { release (mIface); mIface = NULL; }
     734    void detach()
     735    {
     736#ifdef DEBUG
     737       Assert(!mDead);
     738#endif
     739       release (ptr());
     740       setPtr(NULL);
     741    }
    710742
    711743    /** Returns @c true if not attached to any interface pointer. */
    712     bool isNull() const { return mIface == NULL; }
     744    bool isNull() const
     745    {
     746#ifdef DEBUG
     747       Assert(!mDead);
     748#endif
     749       return mIface == NULL;
     750    }
    713751
    714752    /**
     
    733771    CInterface &operator= (const CInterface &that)
    734772    {
    735         attach (that.mIface);
     773        attach (that.ptr());
    736774        B::operator= (that);
    737775        return *this;
     
    748786     * else but in generated wrappers and for debugging. You've been warned.
    749787     */
    750     I *raw() const { return mIface; }
    751 
    752     bool operator== (const CInterface &that) const { return mIface == that.mIface; }
    753     bool operator!= (const CInterface &that) const { return mIface != that.mIface; }
    754 
    755 /**
    756  * @todo: rethink if we'll ever need 'protected' back, removed to allow mIface access in rather
    757  *        nontrivial inheritance situations, see 'friend wrappers' code in COMWrappers.xsl
    758  */
    759 //protected:
    760 
    761     mutable I *mIface;
     788    I *raw() const
     789    {
     790       return ptr();
     791    }
     792
     793    bool operator== (const CInterface &that) const { return ptr() == that.ptr(); }
     794    bool operator!= (const CInterface &that) const { return ptr() != that.ptr(); }
     795
     796    I* ptr() const
     797    {
     798#ifdef DEBUG
     799      Assert(!mDead);
     800#endif
     801
     802      return   mIface;
     803    }
     804
     805    void setPtr(I* aObj) const
     806    {
     807#ifdef DEBUG
     808      Assert(!mDead);
     809#endif
     810      mIface = aObj;
     811    }
     812
     813private:
     814#ifdef DEBUG
     815    bool          mDead;
     816#endif
     817    mutable I *   mIface;
     818
     819    void clear()
     820    {
     821       mIface = NULL;       
     822#ifdef DEBUG
     823       mDead = false;
     824#endif
     825    }
    762826};
    763827
     
    776840    explicit CUnknown (const CInterface <OI, OB> &that)
    777841    {
    778         attach (that.mIface);
     842        attach (that.ptr());
    779843        if (SUCCEEDED (mRC))
    780844        {
     
    802866    CUnknown &operator= (const CInterface <OI, OB> &that)
    803867    {
    804         attach (that.mIface);
     868        attach (that.ptr());
    805869        if (SUCCEEDED (mRC))
    806870        {
     
    833897        return *this;
    834898    }
    835 
    836     /* @internal Used in generated wrappers. Never use directly. */
    837     IUnknown *&rawRef() { return mIface; };
    838899};
    839900
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/COMWrappers.xsl

    r34783 r35638  
    951951        <xsl:text>&#x0A;{&#x0A;</xsl:text>
    952952        <!-- iface assertion -->
    953         <xsl:text>    AssertReturnVoid(mIface);&#x0A;</xsl:text>
     953        <xsl:text>    AssertReturnVoid(ptr());&#x0A;</xsl:text>
    954954        <!-- method call -->
    955955        <xsl:call-template name="composeMethodCall">
     
    990990        <xsl:text>;&#x0A;</xsl:text>
    991991        <!-- iface assertion -->
    992         <xsl:text>    AssertReturn(mIface, a</xsl:text>
     992        <xsl:text>    AssertReturn(ptr(), a</xsl:text>
    993993        <xsl:call-template name="capitalize">
    994994          <xsl:with-param name="str" select="$return/@name"/>
     
    10971097  </xsl:choose>
    10981098  <!-- start the call -->
    1099   <xsl:text>    mRC = mIface-></xsl:text>
     1099  <xsl:text>    mRC = ptr()-></xsl:text>
    11001100  <xsl:choose>
    11011101    <!-- attribute method call -->
     
    11371137  </xsl:choose>
    11381138  <xsl:text>);&#x0A;</xsl:text>
     1139
     1140  <xsl:text>#ifdef RT_OS_WINDOWS&#x0A;</xsl:text>
     1141  <xsl:text>    Assert(mRC != RPC_E_WRONG_THREAD);&#x0A;</xsl:text>
     1142  <xsl:text>#endif;&#x0A;</xsl:text>
     1143
    11391144  <!-- apply 'post-call' hooks -->
    11401145  <xsl:choose>
     
    12011206      <xsl:if test="$supports='strict' or $supports='yes'">
    12021207        <xsl:text>    if (RT_UNLIKELY(mRC != S_OK))&#x0A;    {&#x0A;</xsl:text>
    1203         <xsl:text>        fetchErrorInfo(mIface, &amp;COM_IIDOF(Base::Iface));&#x0A;</xsl:text>
     1208        <xsl:text>        fetchErrorInfo(ptr(), &amp;COM_IIDOF(Base::Iface));&#x0A;</xsl:text>
    12041209        <xsl:if test="$supports='strict'">
    12051210          <xsl:text>        AssertMsg(errInfo.isFullAvailable(), </xsl:text>
     
    12941299            <xsl:with-param name="str" select="@name"/>
    12951300          </xsl:call-template>
    1296           <xsl:choose>
    1297             <xsl:when test="@type='$unknown'">
    1298               <xsl:text>.raw()</xsl:text>
    1299             </xsl:when>
    1300             <xsl:otherwise>
    1301               <xsl:text>.mIface</xsl:text>
    1302             </xsl:otherwise>
    1303           </xsl:choose>
     1301          <xsl:text>.ptr()</xsl:text>
    13041302        </xsl:when>
    13051303        <xsl:when test="$isOut">
    1306           <xsl:text>&amp;a</xsl:text>
    1307           <xsl:call-template name="capitalize">
    1308             <xsl:with-param name="str" select="@name"/>
    1309           </xsl:call-template>
    1310           <xsl:choose>
    1311             <xsl:when test="@type='$unknown'">
    1312               <xsl:text>.rawRef()</xsl:text>
    1313             </xsl:when>
    1314             <xsl:otherwise>
    1315               <xsl:text>.mIface</xsl:text>
    1316             </xsl:otherwise>
    1317           </xsl:choose>
     1304          <xsl:value-of select="concat('&amp;', @name, 'Ptr')"/>
    13181305        </xsl:when>
    13191306      </xsl:choose>
     
    17831770  )"/>
    17841771
     1772  <xsl:variable name="is_out" select="(
     1773      (name()='attribute' and not($isSetter)) or
     1774      (name()='param' and (@dir='out' or @dir='return'))
     1775   )"/>
     1776
    17851777  <xsl:choose>
    17861778    <xsl:when test="$when='pre-call'">
     
    18381830          </xsl:if>
    18391831        </xsl:when>
     1832        <xsl:when test="$is_out and ($is_iface or (@type='$unknown'))">
     1833          <xsl:text>    </xsl:text>
     1834          <xsl:choose>
     1835            <xsl:when test="@type='$unknown'">
     1836              <xsl:text>IUnknown</xsl:text>
     1837              </xsl:when>
     1838             <xsl:otherwise>
     1839                <xsl:value-of select="@type"/>
     1840             </xsl:otherwise>
     1841           </xsl:choose>
     1842           <xsl:value-of select="concat('* ',@name,'Ptr = NULL;&#10;')"/>
     1843        </xsl:when>
    18401844      </xsl:choose>
    18411845    </xsl:when>
     
    18431847      <xsl:choose>
    18441848        <xsl:when test="@safearray='yes'">
    1845           <xsl:if test="(name()='attribute' and not($isSetter)) or
    1846                         (name()='param' and (@dir='out' or @dir='return'))">
     1849          <xsl:if test="$is_out">
    18471850            <!-- convert SafeArray to QVector -->
    18481851            <xsl:choose>
     
    18641867          </xsl:if>
    18651868        </xsl:when>
     1869        <xsl:when test="$is_out and ($is_iface or (@type='$unknown'))">
     1870            <xsl:text>    a</xsl:text>
     1871            <xsl:call-template name="capitalize">
     1872              <xsl:with-param name="str" select="@name"/>
     1873            </xsl:call-template>
     1874           <xsl:value-of select="concat('.setPtr(',@name,'Ptr);&#10;')"/>
     1875        </xsl:when>
    18661876      </xsl:choose>
    18671877    </xsl:when>
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r35634 r35638  
    23902390        {
    23912391            LogFlow (("MediaEnumThread started.\n"));
    2392             COMBase::InitializeCOM();
     2392            COMBase::InitializeCOM(false);
    23932393
    23942394            CVirtualBox mVBox = vboxGlobal().virtualBox();
     
    47654765#endif
    47664766
    4767 #ifdef Q_WS_WIN
    4768     /* COM for the main thread is initialized in main() */
    4769 #else
    4770     HRESULT rc = COMBase::InitializeCOM();
     4767    HRESULT rc = COMBase::InitializeCOM(true);
    47714768    if (FAILED (rc))
    47724769    {
     
    47744771        return;
    47754772    }
    4776 #endif
    47774773
    47784774    mVBox.createInstance (CLSID_VirtualBox);
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r35636 r35638  
    290290    ShutUpAppKit();
    291291# endif
    292 
    293 #ifdef Q_WS_WIN
    294     /* Initialize COM early, before QApplication calls OleInitialize(), to
    295      * make sure we enter the multi threaded apartment instead of a single
    296      * threaded one. Note that this will make some non-threadsafe system
    297      * services that use OLE and require STA (such as Drag&Drop) not work
    298      * anymore, however it's still better because otherwise VBox will not work
    299      * on some Windows XP systems at all since it requires MTA (we cannot
    300      * leave STA by calling CoUninitialize() and re-enter MTA on those systems
    301      * for some unknown reason), see also src/VBox/Main/glue/initterm.cpp. */
    302     /// @todo find a proper solution that satisfies both OLE and VBox
    303     HRESULT hrc = COMBase::InitializeCOM();
    304 #endif
    305292
    306293    for (int i=0; i<argc; i++)
     
    464451        do
    465452        {
    466 #ifdef Q_WS_WIN
    467             /* Check for the COM error after we've initialized Qt */
    468             if (FAILED (hrc))
    469             {
    470                 vboxProblem().cannotInitCOM (hrc);
    471                 break;
    472             }
    473 #endif
    474 
    475453            if (!vboxGlobal().isValid())
    476454                break;
     
    555533    }
    556534
    557 #ifdef Q_WS_WIN
    558     /* See COMBase::initializeCOM() above */
    559     if (SUCCEEDED (hrc))
    560         COMBase::CleanupCOM();
    561 #endif
    562 
    563535    LogFlowFunc (("rc=%d\n", rc));
    564536    LogFlowFuncLeave();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.cpp

    r35613 r35638  
    6767    QImage scaledImage;
    6868
     69
    6970    /* If scaled-factor is set and current image is NOT null: */
    7071    if (m_scaledSize.isValid() && !m_img.isNull())
     
    9394    QPainter painter(m_pMachineView->viewport());
    9495
     96   
    9597    if ((ulong)r.width() < m_width * 2 / 3)
    9698    {
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