COMDefs.h revision b9042bb7a5efd07d617a8a7d812b669d75682779
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* Various COM definitions and COM wrapper class declarations
*
* This header is used in conjunction with the header generated from
* XIDL expressed interface definitions to provide cross-platform Qt-based
* interface wrapper classes.
*/
/*
* 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 __COMDefs_h__
#define __COMDefs_h__
#include <qglobal.h>
#include <qstring.h>
#include <quuid.h>
/*
* common COM / XPCOM includes and defines
*/
#if defined(Q_OS_WIN32)
#include <objbase.h>
/* for _ATL_IIDOF */
#include <atldef.h>
/* these are XPCOM only */
#define NS_DECL_ISUPPORTS
#define IN_BSTRPARAM BSTR
#define IN_GUIDPARAM GUID
/* const reference to IID of the interface */
#define COM_IIDOF(I) _ATL_IIDOF (I)
#else
#include <nsMemory.h>
#include <nsIComponentManager.h>
#include <ipcIDConnectService.h>
#define STDMETHOD(a) NS_IMETHOD a
#define STDMETHODIMP NS_IMETHODIMP
#define SUCCEEDED NS_SUCCEEDED
/// @todo error code mappings
#define IUnknown nsISupports
#define IN_BSTRPARAM const BSTR
#define IN_GUIDPARAM const nsID &
/* const reference to IID of the interface */
#define COM_IIDOF(I) NS_GET_IID (I)
/* helper functions (defined in the Runtime3 library) */
extern "C" {
}
#endif
/* VirtualBox interfaces declarations */
#if defined(Q_OS_WIN32)
#include <VirtualBox.h>
#else
#include <VirtualBox_XPCOM.h>
#endif
#include "VBoxDefs.h"
/////////////////////////////////////////////////////////////////////////////
/** Represents extended error information */
{
: mIsNull (true)
, mIsBasicAvailable (false), mIsFullAvailable (false)
, mResultCode (S_OK) {}
/* the default copy ctor and assignment op are ok */
bool isBasicAvailable() const { return mIsBasicAvailable; }
bool isFullAvailable() const { return mIsFullAvailable; }
bool mIsNull : 1;
bool mIsBasicAvailable : 1;
bool mIsFullAvailable : 1;
};
/////////////////////////////////////////////////////////////////////////////
/**
* Base COM class the CInterface template and all wrapper classes are derived
* from. Provides common functionality for all COM wrappers.
*/
{
static HRESULT initializeCOM();
static HRESULT cleanupCOM();
/** Converts a GUID value to QUuid */
#if defined (Q_OS_WIN32)
}
#else
}
#endif
/**
* Returns the result code of the last interface method called
* by the wrapper instance or the result of CInterface::createInstance()
* operation.
*/
/**
* Returns error info set by the last unsuccessfully invoked interface
* method. Returned error info is useful only if CInterface::lastRC()
* represents a failure (i.e. CInterface::isOk() is false).
*/
/* no arbitrary instance creations */
#if !defined (Q_OS_WIN32)
static nsIComponentManager *componentManager;
static nsIEventQueue* eventQ;
static ipcIDConnectService *dconnectService;
static PRUint32 vboxServerID;
static XPCOMEventQSocketListener *socketListener;
#endif
/** Adapter to pass QString as input BSTR params */
{
~BSTRIn() {
if (bstr)
}
};
/** Adapter to pass QString as output BSTR params */
{
~BSTROut() {
if (bstr) {
}
}
};
/** Adapter to pass CEnums enums as output VirtualBox enum params (*_T) */
{
};
#if defined (Q_OS_WIN32)
/** Adapter to pass QUuid as input GUID params */
/** Adapter to pass QUuid as output GUID params */
{
}
~GUIDOut() {
);
}
};
#else
/** Adapter to pass QUuid as input GUID params */
}
/** Adapter to pass QUuid as output GUID params */
{
~GUIDOut() {
if (nsid) {
);
}
}
};
#endif
};
/////////////////////////////////////////////////////////////////////////////
/**
* Alternative base class for the CInterface template that adds
* the errorInfo() method for providing extended error info about
* unsuccessful invocation of the last called interface method.
*/
{
/**
* Returns error info set by the last unsuccessfully invoked interface
* method. Returned error info is useful only if CInterface::lastRC()
* represents a failure (i.e. CInterface::isOk() is false).
*/
/* no arbitrary instance creations */
COMBaseWithEI() : COMBase () {};
}
};
/////////////////////////////////////////////////////////////////////////////
/**
* Simple class that encapsulates the result code and COMErrorInfo.
*/
{
/** Queries the current result code and error info from the given component */
{
}
/** Queries the current result code and error info from the given component */
{
return *this;
}
};
/////////////////////////////////////////////////////////////////////////////
/**
* Wrapper template class for all interfaces.
*
* All interface methods named as they are in the original, i.e. starting
* with the capital letter. All utility non-interface methods are named
* starting with the small letter. Utility methods should be not normally
* called by the end-user client application.
*
* @param I interface class (i.e. IUnknown/nsISupports derivant)
* @param B base class, either COMBase (by default) or COMBaseWithEI
*/
{
typedef B Base;
typedef I Iface;
/* constructors & destructor */
}
/* utility methods */
if (!iface)
{
#if defined (Q_OS_WIN32)
_ATL_IIDOF (I), (void**) &iface);
#else
/* first, try to create an instance within the in-proc server
* (for compatibility with Win32) */
);
/* now try the out-of-proc server if it exists */
B::vboxServerID, clsid,
NS_GET_IID (I), (void**) &iface
);
}
#endif
/* fetch error info, but don't assert if it's missing -- many other
* reasons can lead to an error (w/o providing error info), not only
* the instance initialization code (that should always provide it) */
}
}
void attach (I *i) {
/* be aware of self (from COM point of view) assignment */
iface = i;
};
void attachUnknown (IUnknown *i) {
/* be aware of self (from COM point of view) assignment */
if (i)
#if defined (Q_OS_WIN32)
#else
#endif
};
/* utility operators */
return *this;
}
#ifdef VBOX_WITH_DEBUGGER_GUI
/** @todo bird: dmik, perhaps I missed something, but I didn't find anything equivalent
* to this. feel free to fix &/| remove this hack. */
I *getInterface() { return iface; }
#endif
};
/////////////////////////////////////////////////////////////////////////////
{
#if defined (Q_OS_WIN32)
#else
#endif
}
}
/* specialization for CUnknown */
}
/* be aware of self (from COM point of view) assignment */
#if defined (Q_OS_WIN32)
#else
#endif
}
return *this;
}
/* specialization for CUnknown */
return *this;
}
};
/* inlined CInterface methods that use CUnknown */
{
}
{
return *this;
}
/////////////////////////////////////////////////////////////////////////////
/* include the generated header containing concrete wrapper definitions */
#include "COMWrappers.h"
#endif // __COMDefs_h__