defs.h revision a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fc
/** @file
* MS COM / XPCOM Abstraction Layer:
* Common definitions
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___VBox_com_defs_h
#define ___VBox_com_defs_h
/*
* the macros that are optional in C++.
*/
#if !defined (VBOX_WITH_XPCOM)
#if defined (RT_OS_WINDOWS)
// Windows COM
/////////////////////////////////////////////////////////////////////////////
#include <objbase.h>
#ifndef VBOX_COM_NO_ATL
#include <atlbase.h>
#endif
#define NS_DECL_ISUPPORTS
#define NS_IMPL_ISUPPORTS1_CI(a, b)
/* these are XPCOM only, one for every interface implemented */
#define NS_DECL_ISUPPORTS
#define NS_DECL_IVIRTUALBOX
#define NS_DECL_IMACHINECOLLECTION
#define NS_DECL_IMACHINE
/* input pointer argument to method */
#define INPTR
/* makes the name of the getter interface function (n must be capitalized) */
/* makes the name of the setter interface function (n must be capitalized) */
/* a type for an input GUID parameter in the interface method declaration */
/* a type for an output GUID parameter in the interface method declaration */
#define GUIDPARAMOUT GUID*
/**
* Returns the const reference to the IID (i.e., |const GUID &|) of the given
* interface.
*
* @param i interface class
*/
#define COM_IIDOF(I) _ATL_IIDOF (I)
#else // defined (RT_OS_WINDOWS)
#error "VBOX_WITH_XPCOM is not defined!"
#endif // defined (RT_OS_WINDOWS)
#else // !defined (VBOX_WITH_XPCOM)
// XPCOM
/////////////////////////////////////////////////////////////////////////////
#if defined (RT_OS_OS2)
/* Make sure OS/2 Toolkit headers are pulled in to have
* them using #define. */
#define INCL_BASE
#define INCL_PM
#include <os2.h>
/* OS/2 Toolkit defines TRUE and FALSE */
#endif // defined (RT_OS_OS2)
#if defined (RT_OS_DARWIN)
/* CFBase.h defines these*/
#endif /* RT_OS_DARWIN */
#include <nsID.h>
#define ATL_NO_VTABLE
#define DECLARE_CLASSFACTORY(a)
#define DECLARE_CLASSFACTORY_SINGLETON(a)
#define DECLARE_REGISTRY_RESOURCEID(a)
#define DECLARE_NOT_AGGREGATABLE(a)
#define DECLARE_PROTECT_FINAL_CONSTRUCT(a)
#define BEGIN_COM_MAP(a)
#define COM_INTERFACE_ENTRY(a)
#define COM_INTERFACE_ENTRY2(a,b)
#define END_COM_MAP(a)
#define SUCCEEDED NS_SUCCEEDED
#define IUnknown nsISupports
/* makes the name of the getter interface function (n must be capitalized) */
/* makes the name of the setter interface function (n must be capitalized) */
/* a type to define a raw GUID variable (better to use the Guid class) */
/* a type for an input GUID parameter in the interface method declaration */
/* a type for an output GUID parameter in the interface method declaration */
#define GUIDPARAMOUT nsID **
/* CLSID and IID for compatibility with Win32 */
/* OLE error codes */
#define E_UNEXPECTED NS_ERROR_UNEXPECTED
#define E_NOTIMPL NS_ERROR_NOT_IMPLEMENTED
#define E_OUTOFMEMORY NS_ERROR_OUT_OF_MEMORY
#define E_INVALIDARG NS_ERROR_INVALID_ARG
#define E_NOINTERFACE NS_ERROR_NO_INTERFACE
#define E_POINTER NS_ERROR_NULL_POINTER
#define E_ABORT NS_ERROR_ABORT
#define E_FAIL NS_ERROR_FAILURE
/* Note: a better analog for E_ACCESSDENIED would probably be
* NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */
#define STDMETHOD(a) NS_IMETHOD a
#define STDMETHODIMP NS_IMETHODIMP
#define COM_IIDOF(I) NS_GET_IID (I)
/* two very simple ATL emulator classes to provide
* FinalConstruct()/FinalRelease() functionality on Linux */
{
void FinalRelease() {}
};
{
};
/* input pointer argument to method */
#define INPTR const
/* helper functions */
extern "C"
{
}
/**
* 'Constructor' for the component class.
* This constructor, as opposed to NS_GENERIC_FACTORY_CONSTRUCTOR,
* assumes that the component class is derived from the CComObjectRootEx<>
* template, so it calls FinalConstruct() right after object creation
* and ensures that FinalRelease() will be called right before destruction.
* The result from FinalConstruct() is returned to the caller.
*/
static NS_IMETHODIMP \
void **aResult) \
{ \
\
return rv; \
} \
\
rv = NS_ERROR_OUT_OF_MEMORY; \
return rv; \
} \
\
if (NS_SUCCEEDED(rv)) \
NS_RELEASE(inst); \
\
return rv; \
}
/**
* 'Constructor' that uses an existing getter function that gets a singleton.
* The getter function must have the following prototype:
* nsresult _GetterProc (_InstanceClass **inst)
* This constructor, as opposed to NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR,
* lets the getter function return a result code that is passed back to the
* caller that tries to instantiate the object.
* NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
*/
static NS_IMETHODIMP \
void **aResult) \
{ \
\
_InstanceClass * inst; \
\
return rv; \
} \
\
return rv; \
\
/* sanity check */ \
return NS_ERROR_OUT_OF_MEMORY; \
\
/* NS_ADDREF(inst); */ \
if (NS_SUCCEEDED(rv)) { \
} \
NS_RELEASE(inst); \
\
return rv; \
}
#endif // !defined (RT_OS_WINDOWS)
/**
* Declares a whar_t string literal from the argument.
* Necessary to overcome MSC / GCC differences.
* @param s expression to stringify
*/
#if defined (_MSC_VER)
# define WSTR_LITERAL(s) L#s
# define WSTR_LITERAL(s) L""#s
#else
# error "Unsupported compiler!"
#endif
#endif