VirtualBox

Changeset 71791 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 9, 2018 4:52:12 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Build and link GUI COM wrappers to VBoxGlobal library only.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r71784 r71791  
    280280        $(VBOX_GUI_INC_DIRS) \
    281281        $(VirtualBox_0_OUTDIR)/include \
     282        $(VBoxGlobal_0_OUTDIR)/include \
    282283        $(VBOX_GRAPHICS_INCS)
    283284
     
    288289VBoxGlobal_INCS = \
    289290        $(VBOX_GUI_INC_DIRS) \
    290         $(VirtualBox_0_OUTDIR)/include
     291        $(VBoxGlobal_0_OUTDIR)/include
    291292
    292293
     
    14291430
    14301431#
    1431 # Generate the COM wrappers.
    1432 #
    1433 includedep $(PATH_TARGET)/VirtualBoxComWrapperFiles.dep
    1434 VirtualBox_BLDDIRS       += $(VirtualBox_0_OUTDIR)/include
    1435 VirtualBox_INTERMEDIATES += $(VirtualBox_0_OUTDIR)/include/COMWrappers
    1436 VirtualBox_CLEAN         += $(wildcard $(VirtualBox_0_OUTDIR)/include/*) $(PATH_TARGET)/VirtualBoxComWrapperFiles.dep
    1437 
    1438 #
    1439 # VirtualBox - GUI Application.
    14401432# Build generated COM wrappers as part of app.
    14411433#
    1442 VirtualBox_SOURCES       += $(VirtualBox_0_OUTDIR)/include/COMWrappers.cpp
    1443 
    1444 #
    1445 # VirtualBox - GUI Global Shared Library.
    1446 # Build generated COM wrappers as part of app.
    1447 #
    1448 VBoxGlobal_SOURCES += $(VirtualBox_0_OUTDIR)/include/COMWrappers.cpp
    1449 
    1450 ## @todo kmk doesn't remake optional outputs when they are missing...
    1451 $$(VirtualBox_0_OUTDIR)/include/COMWrappers \
    1452 + $(PATH_TARGET)/VirtualBoxComWrapperFiles.dep \
    1453 +| $(if-expr defined(VirtualBox_VBOX_COMWRAPPERS) \
    1454 , $(VirtualBox_VBOX_COMWRAPPERS) \
    1455 , $$(VirtualBox_0_OUTDIR)/include/COMEnums.h \
    1456   $$(VirtualBox_0_OUTDIR)/include/COMWrappers.cpp \
    1457 ): \
     1434ifndef VBOX_GUI_WITH_SHARED_LIBRARY
     1435
     1436 #
     1437 # VirtualBox - GUI Application.
     1438 #
     1439 includedep $(PATH_TARGET)/VirtualBoxComWrapperFiles.dep
     1440 VirtualBox_BLDDIRS       += $(VirtualBox_0_OUTDIR)/include
     1441 VirtualBox_INTERMEDIATES += $(VirtualBox_0_OUTDIR)/include/COMWrappers
     1442 VirtualBox_SOURCES       += $(VirtualBox_0_OUTDIR)/include/COMWrappers.cpp
     1443 VirtualBox_CLEAN         += $(wildcard $(VirtualBox_0_OUTDIR)/include/*) $(PATH_TARGET)/VirtualBoxComWrapperFiles.dep
     1444
     1445 ## @todo kmk doesn't remake optional outputs when they are missing...
     1446 $$(VirtualBox_0_OUTDIR)/include/COMWrappers \
     1447 + $(PATH_TARGET)/VirtualBoxComWrapperFiles.dep \
     1448 +| $(if-expr defined(VirtualBox_VBOX_COMWRAPPERS) \
     1449 , $(VirtualBox_VBOX_COMWRAPPERS) \
     1450 , $$(VirtualBox_0_OUTDIR)/include/COMEnums.h \
     1451   $$(VirtualBox_0_OUTDIR)/include/COMWrappers.cpp \
     1452 ): \
    14581453                $(VBOX_XIDL_FILE) \
    14591454                $(VBOX_VIRTUALBOX_SRC)/src/globals/COMWrappers.xsl \
     
    14681463        $(APPEND) "$@"
    14691464
    1470 # alias for generating the COM Wrappers file.
    1471 testwrappers:: $$(VirtualBox_0_OUTDIR)/include/COMWrappers
     1465 # alias for generating the COM Wrappers file.
     1466 testwrappers:: $$(VirtualBox_0_OUTDIR)/include/COMWrappers
     1467
     1468else
     1469
     1470 #
     1471 # VirtualBox - GUI Global Shared Library.
     1472 #
     1473 includedep $(PATH_TARGET)/VboxGlobalComWrapperFiles.dep
     1474 VBoxGlobal_BLDDIRS       += $(VBoxGlobal_0_OUTDIR)/include
     1475 VBoxGlobal_INTERMEDIATES += $(VBoxGlobal_0_OUTDIR)/include/COMWrappers
     1476 VBoxGlobal_SOURCES       += $(VBoxGlobal_0_OUTDIR)/include/COMWrappers.cpp
     1477 VBoxGlobal_CLEAN         += $(wildcard $(VBoxGlobal_0_OUTDIR)/include/*) $(PATH_TARGET)/VboxGlobalComWrapperFiles.dep
     1478
     1479 ## @todo kmk doesn't remake optional outputs when they are missing...
     1480 $$(VBoxGlobal_0_OUTDIR)/include/COMWrappers \
     1481 + $(PATH_TARGET)/VBoxGlobalComWrapperFiles.dep \
     1482 +| $(if-expr defined(VBoxGlobal_VBOX_COMWRAPPERS) \
     1483 , $(VBoxGlobal_VBOX_COMWRAPPERS) \
     1484 , $$(VBoxGlobal_0_OUTDIR)/include/COMEnums.h \
     1485   $$(VBoxGlobal_0_OUTDIR)/include/COMWrappers.cpp \
     1486 ): \
     1487                $(VBOX_XIDL_FILE) \
     1488                $(VBOX_VIRTUALBOX_SRC)/src/globals/COMWrappers.xsl \
     1489                $(VBOX_FILESPLIT) \
     1490                | $$(dir $$@)
     1491        $(call MSG_GENERATE,VBoxGlobal,$<,$@)
     1492        $(QUIET)$(RM) -f -- "$@" "$(PATH_TARGET)/VBoxGlobalComWrapperFiles.dep"
     1493        $(QUIET)$(VBOX_XSLTPROC) -o $@ \
     1494                $(VBOX_VIRTUALBOX_SRC)/src/globals/COMWrappers.xsl $<
     1495        $(QUIET)$(VBOX_FILESPLIT) $@ $(VBoxGlobal_0_OUTDIR)/include \
     1496                $(PATH_TARGET)/VBoxGlobalComWrapperFiles.dep VBoxGlobal_VBOX_COMWRAPPERS
     1497        $(APPEND) "$@"
     1498
     1499 # alias for generating the COM Wrappers file.
     1500 testwrappers:: $$(VBoxGlobal_0_OUTDIR)/include/COMWrappers
     1501
     1502endif
    14721503
    14731504
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/COMDefs.h

    r71630 r71791  
    810810};
    811811
     812/**
     813 * Partial specialization for CInterface template class above for a case when B == COMBase.
     814 *
     815 * We had to add it because on exporting template to a library at least on Windows there is
     816 * an implicit instantiation of the createInstance() member (even if it's not used) which
     817 * in case of base template uses API present in COMBaseWithEI class only, not in COMBase.
     818 *
     819 * @param  I  Brings the interface class (i.e. derived from IUnknown/nsISupports).
     820 */
     821template <class I>
     822class CInterface<I, COMBase> : public COMBase
     823{
     824public:
     825
     826    typedef COMBase Base;
     827    typedef I       Iface;
     828
     829    // constructors & destructor
     830
     831    CInterface()
     832    {
     833        clear();
     834    }
     835
     836    CInterface(const CInterface &that) : COMBase(that)
     837    {
     838        clear();
     839        mIface = that.mIface;
     840        this->addref((IUnknown*)ptr());
     841    }
     842
     843    CInterface(I *pIface)
     844    {
     845        clear();
     846        setPtr(pIface);
     847        this->addref((IUnknown*)pIface);
     848    }
     849
     850    virtual ~CInterface()
     851    {
     852        detach();
     853#ifdef RT_STRICT
     854        mDead = true;
     855#endif
     856    }
     857
     858    // utility methods
     859
     860    void createInstance(const CLSID &clsId)
     861    {
     862        AssertMsg(ptr() == NULL, ("Instance is already non-NULL\n"));
     863        if (ptr() == NULL)
     864        {
     865            I* pObj = NULL;
     866#if !defined(VBOX_WITH_XPCOM)
     867            COMBase::mRC = CoCreateInstance(clsId, NULL, CLSCTX_ALL,
     868                                            COM_IIDOF(I), (void **)&pObj);
     869#else
     870            nsCOMPtr<nsIComponentManager> manager;
     871            COMBase::mRC = NS_GetComponentManager(getter_AddRefs(manager));
     872            if (SUCCEEDED(COMBase::mRC))
     873                COMBase::mRC = manager->CreateInstance(clsId, nsnull, NS_GET_IID(I),
     874                                                       (void **)&pObj);
     875#endif
     876
     877            if (SUCCEEDED(COMBase::mRC))
     878               setPtr(pObj);
     879            else
     880               setPtr(NULL);
     881         }
     882    }
     883
     884    /**
     885     * Attaches to the given foreign interface pointer by querying the own
     886     * interface on it. The operation may fail.
     887     */
     888    template <class OI>
     889    void attach(OI *pIface)
     890    {
     891        Assert(!mDead);
     892        /* Be aware of self assignment: */
     893        I *pmIface = ptr();
     894        this->addref((IUnknown*)pIface);
     895        this->release((IUnknown*)pmIface);
     896        if (pIface)
     897        {
     898            pmIface = NULL;
     899            COMBase::mRC = pIface->QueryInterface(COM_IIDOF(I), (void **)&pmIface);
     900            this->release((IUnknown*)pIface);
     901            setPtr(pmIface);
     902        }
     903        else
     904        {
     905            setPtr(NULL);
     906            COMBase::mRC = S_OK;
     907        }
     908    };
     909
     910    /** Specialization of attach() for our own interface I. Never fails. */
     911    void attach(I *pIface)
     912    {
     913        Assert(!mDead);
     914        /* Be aware of self assignment: */
     915        this->addref((IUnknown*)pIface);
     916        this->release((IUnknown*)ptr());
     917        setPtr(pIface);
     918        COMBase::mRC = S_OK;
     919    };
     920
     921    /** Detaches from the underlying interface pointer. */
     922    void detach()
     923    {
     924        Assert(!mDead);
     925        this->release((IUnknown*)ptr());
     926        setPtr(NULL);
     927    }
     928
     929    /** Returns @c true if not attached to any interface pointer. */
     930    bool isNull() const
     931    {
     932        Assert(!mDead);
     933        return mIface == NULL;
     934    }
     935
     936    /** Returns @c true if attached to an interface pointer. */
     937    bool isNotNull() const
     938    {
     939        Assert(!mDead);
     940        return mIface != NULL;
     941    }
     942
     943    /** Returns @c true if the result code represents success (with or without warnings). */
     944    bool isOk() const { return !isNull() && SUCCEEDED(COMBase::mRC); }
     945
     946    /** Returns @c true if the result code represents success with one or more warnings. */
     947    bool isWarning() const { return !isNull() && SUCCEEDED_WARNING(COMBase::mRC); }
     948
     949    /** Returns @c true if the result code represents success with no warnings. */
     950    bool isReallyOk() const { return !isNull() && COMBase::mRC == S_OK; }
     951
     952    // utility operators
     953
     954    CInterface &operator=(const CInterface &that)
     955    {
     956        attach(that.ptr());
     957        COMBase::operator=(that);
     958        return *this;
     959    }
     960
     961    CInterface &operator=(I *pIface)
     962    {
     963        attach(pIface);
     964        return *this;
     965    }
     966
     967    /**
     968     * Returns the raw interface pointer. Not intended to be used for anything
     969     * else but in generated wrappers and for debugging. You've been warned.
     970     */
     971    I *raw() const
     972    {
     973       return ptr();
     974    }
     975
     976    bool operator==(const CInterface &that) const { return ptr() == that.ptr(); }
     977    bool operator!=(const CInterface &that) const { return ptr() != that.ptr(); }
     978
     979    I *ptr() const
     980    {
     981        Assert(!mDead);
     982        return mIface;
     983    }
     984
     985    void setPtr(I* aObj) const
     986    {
     987        Assert(!mDead);
     988        mIface = aObj;
     989    }
     990
     991private:
     992
     993#ifdef RT_STRICT
     994    bool       mDead;
     995#endif
     996    mutable I *mIface;
     997
     998    void clear()
     999    {
     1000       mIface = NULL;
     1001#ifdef RT_STRICT
     1002       mDead = false;
     1003#endif
     1004    }
     1005};
     1006
    8121007/////////////////////////////////////////////////////////////////////////////
    8131008
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/COMWrappers.xsl

    r66274 r71791  
    256256    <xsl:text> * Generator : src/VBox/Frontends/VirtualBox/src/globals/COMWrappers.xsl&#x0A;</xsl:text>
    257257    <xsl:text> */&#x0A;&#x0A;</xsl:text>
    258     <xsl:text>/* VirtualBox interface declarations: */&#x0A;</xsl:text>
    259     <xsl:text>#ifndef VBOX_WITH_XPCOM&#x0A;</xsl:text>
    260     <xsl:text># include "VirtualBox.h"&#x0A;</xsl:text>
    261     <xsl:text>#else /* !VBOX_WITH_XPCOM */&#x0A;</xsl:text>
    262     <xsl:text># include "VirtualBox_XPCOM.h"&#x0A;</xsl:text>
    263     <xsl:text>#endif /* VBOX_WITH_XPCOM */&#x0A;&#x0A;</xsl:text>
    264258    <xsl:text>/* COM includes: */&#x0A;</xsl:text>
    265259    <xsl:text>#include "COMEnums.h"&#x0A;</xsl:text>
     
    303297    <xsl:text>_h__&#x0A;&#x0A;</xsl:text>
    304298    <xsl:text>/* GUI includes: */&#x0A;</xsl:text>
    305     <xsl:text>#include "COMDefs.h"&#x0A;&#x0A;</xsl:text>
     299    <xsl:text>#include "COMDefs.h"&#x0A;</xsl:text>
     300        <xsl:text>#include "UILibraryDefs.h"&#x0A;&#x0A;</xsl:text>
     301        <xsl:text>/* VirtualBox interface declarations: */&#x0A;</xsl:text>
     302    <xsl:text>#ifndef VBOX_WITH_XPCOM&#x0A;</xsl:text>
     303    <xsl:text># include "VirtualBox.h"&#x0A;</xsl:text>
     304    <xsl:text>#else /* !VBOX_WITH_XPCOM */&#x0A;</xsl:text>
     305    <xsl:text># include "VirtualBox_XPCOM.h"&#x0A;</xsl:text>
     306    <xsl:text>#endif /* VBOX_WITH_XPCOM */&#x0A;&#x0A;</xsl:text>
    306307
    307308    <!-- Forward declarations: -->
     
    322323    <!-- Interface wrapper declaration: -->
    323324    <xsl:text>/* Interface wrapper declaration: */&#x0A;</xsl:text>
    324     <xsl:text>class C</xsl:text>
     325    <xsl:text>class SHARED_LIBRARY_STUFF C</xsl:text>
    325326    <xsl:value-of select="substring(@name,2)"/>
    326327    <xsl:text> : public CInterface&lt;</xsl:text>
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