VirtualBox

Changeset 60765 in vbox for trunk/include


Ignore:
Timestamp:
Apr 29, 2016 2:26:58 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106960
Message:

API: stop using ATL and use a vastly smaller lookalike instead, plus a lot of cleanups

Location:
trunk/include/VBox/com
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/defs.h

    r60506 r60765  
    44
    55/*
    6  * Copyright (C) 2006-2015 Oracle Corporation
     6 * Copyright (C) 2006-2016 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    8282#include <objbase.h>
    8383#ifndef VBOX_COM_NO_ATL
    84 # define _ATL_FREE_THREADED
    85 
    86 # include <atlbase.h>
    87 #include <atlcom.h>
    88 #endif
     84
     85/* Do not use actual ATL, just provide a superficial lookalike ourselves. */
     86# include <VBox/com/microatl.h>
     87#endif /* VBOX_COM_NO_ATL */
    8988
    9089#define NS_DECL_ISUPPORTS
     
    126125#define IN_GUID GUID
    127126/** Output GUID argument of interface method declaration. */
    128 #define OUT_GUID GUID*
     127#define OUT_GUID GUID *
    129128
    130129/** Makes the name of the getter interface function (n must be capitalized). */
     
    250249 *  @param I    interface class
    251250 */
    252 #define COM_IIDOF(I) _ATL_IIDOF(I)
     251#define COM_IIDOF(I) __uuidof(I)
    253252
    254253/**
     
    280279
    281280#include <nsID.h>
     281
     282#ifndef VBOX_COM_NO_ATL
     283
     284namespace ATL
     285{
    282286
    283287#define ATL_NO_VTABLE
     
    292296#define END_COM_MAP() NS_DECL_ISUPPORTS
    293297#define COM_INTERFACE_ENTRY_AGGREGATE(a,b)
     298
     299/* A few very simple ATL emulator classes to provide
     300 * FinalConstruct()/FinalRelease() functionality with XPCOM. */
     301
     302class CComMultiThreadModel
     303{
     304};
     305
     306template <class DummyThreadModel> class CComObjectRootEx
     307{
     308public:
     309    HRESULT FinalConstruct()
     310    {
     311        return S_OK;
     312    }
     313    void FinalRelease()
     314    {
     315    }
     316};
     317
     318template <class DummyThreadModel> class CComObject
     319{
     320public:
     321    virtual ~CComObject() { this->FinalRelease(); }
     322};
     323
     324} /* namespace ATL */
     325
     326#endif /* !VBOX_COM_NO_ATL */
    294327
    295328#define HRESULT     nsresult
     
    394427#define COM_STRUCT_OR_CLASS(I) class I
    395428
    396 namespace ATL
    397 {
    398 
    399 /* A few very simple ATL emulator classes to provide
    400  * FinalConstruct()/FinalRelease() functionality on Linux. */
    401 
    402 class CComMultiThreadModel
    403 {
    404 };
    405 
    406 template <class Base> class CComObjectRootEx : public Base
    407 {
    408 public:
    409     HRESULT FinalConstruct() { return S_OK; }
    410     void FinalRelease() {}
    411 };
    412 
    413 template <class Base> class CComObject : public Base
    414 {
    415 public:
    416     virtual ~CComObject() { this->FinalRelease(); }
    417 };
    418 
    419 } /* namespace ATL */
    420 
    421 using namespace ATL;
    422 
    423429/* helper functions */
    424430extern "C"
    425431{
    426 BSTR SysAllocString(const OLECHAR* sz);
     432BSTR SysAllocString(const OLECHAR *sz);
    427433BSTR SysAllocStringByteLen(char *psz, unsigned int len);
    428434BSTR SysAllocStringLen(const OLECHAR *pch, unsigned int cch);
     
    434440}
    435441
     442#ifndef VBOX_COM_NO_ATL
     443
    436444/**
    437445 *  'Constructor' for the component class.
     
    455463    }                                                                         \
    456464                                                                              \
    457     CComObject <_InstanceClass> *inst = new CComObject <_InstanceClass>();    \
     465    CComObject<_InstanceClass> *inst = new CComObject<_InstanceClass>();      \
    458466    if (NULL == inst) {                                                       \
    459467        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
     
    486494    nsresult rv;                                                              \
    487495                                                                              \
    488     _InstanceClass * inst = NULL;       /* initialized to shut up gcc */      \
     496    _InstanceClass *inst = NULL;       /* initialized to shut up gcc */       \
    489497                                                                              \
    490498    *aResult = NULL;                                                          \
     
    510518    return rv;                                                                \
    511519}
     520
     521#endif /* !VBOX_COM_NO_ATL */
    512522
    513523#endif /* !defined(VBOX_WITH_XPCOM) */
     
    529539{
    530540
     541#ifndef VBOX_COM_NO_ATL
     542
    531543// use this macro to implement scriptable interfaces
    532544#ifdef RT_OS_WINDOWS
    533545#define VBOX_SCRIPTABLE_IMPL(iface)                                          \
    534     public IDispatchImpl<iface, &IID_##iface, &LIBID_VirtualBox,             \
    535                          kTypeLibraryMajorVersion, kTypeLibraryMinorVersion>
     546    public ATL::IDispatchImpl<iface, &IID_##iface, &LIBID_VirtualBox,        \
     547                              kTypeLibraryMajorVersion, kTypeLibraryMinorVersion>
    536548
    537549#define VBOX_SCRIPTABLE_DISPATCH_IMPL(iface)                                 \
    538     STDMETHOD(QueryInterface)(REFIID riid , void **ppObj)                    \
     550    STDMETHOD(QueryInterface)(REFIID riid, void **ppObj)                     \
    539551    {                                                                        \
    540552        if (riid == IID_##iface)                                             \
    541553        {                                                                    \
    542             *ppObj = (iface*)this;                                           \
     554            *ppObj = (iface *)this;                                          \
    543555            AddRef();                                                        \
    544556            return S_OK;                                                     \
     
    546558        if (riid == IID_IUnknown)                                            \
    547559        {                                                                    \
    548             *ppObj = (IUnknown*)this;                                        \
     560            *ppObj = (IUnknown *)this;                                       \
    549561            AddRef();                                                        \
    550562            return S_OK;                                                     \
     
    552564        if (riid == IID_IDispatch)                                           \
    553565        {                                                                    \
    554             *ppObj = (IDispatch*)this;                                       \
     566            *ppObj = (IDispatch *)this;                                      \
    555567            AddRef();                                                        \
    556568            return S_OK;                                                     \
     
    559571        return E_NOINTERFACE;                                                \
    560572    }
    561 
    562 
    563 #define VBOX_DEFAULT_INTERFACE_ENTRIES(iface)                                \
    564         COM_INTERFACE_ENTRY(ISupportErrorInfo)                               \
    565         COM_INTERFACE_ENTRY(iface)                                           \
    566         COM_INTERFACE_ENTRY2(IDispatch,iface)                                \
    567         COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
    568573#else
    569574#define VBOX_SCRIPTABLE_IMPL(iface)                     \
    570575    public iface
    571576#define VBOX_SCRIPTABLE_DISPATCH_IMPL(iface)
    572 #define VBOX_DEFAULT_INTERFACE_ENTRIES(iface)
    573577#endif
    574578
     579#endif /* !VBOX_COM_NO_ATL */
    575580
    576581} /* namespace com */
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