defs.h revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/** @file
*
* MS COM / XPCOM Abstraction Layer:
* Common definitions
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#ifndef __VBox_com_defs_h__
#define __VBox_com_defs_h__
#if defined (__WIN__)
// 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 (__WIN__)
// XPCOM
/////////////////////////////////////////////////////////////////////////////
#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
#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 (__WIN__)
/**
* 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 // __VBox_com_defs_h__