VirtualBox

source: vbox/trunk/include/VBox/com/defs.h@ 3638

Last change on this file since 3638 was 3638, checked in by vboxsync, 17 years ago

AMD64 -> RT_ARCH_AMD64; X86 -> RT_ARCH_X86; [OS] -> RT_OS_[OS].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer:
3 * Common definitions
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ___VBox_com_defs_h
23#define ___VBox_com_defs_h
24
25/*
26 * Include iprt/types.h now to make sure iprt get to stdint.h first,
27 * otherwise a system/xpcom header might beat us and we'll be without
28 * the macros that are optional in C++.
29 */
30#include <iprt/types.h>
31
32#if !defined (VBOX_WITH_XPCOM)
33
34#if defined (RT_OS_WINDOWS)
35
36// Windows COM
37/////////////////////////////////////////////////////////////////////////////
38
39#include <objbase.h>
40#ifndef VBOX_COM_NO_ATL
41#include <atlbase.h>
42#endif
43
44#define NS_DECL_ISUPPORTS
45#define NS_IMPL_ISUPPORTS1_CI(a, b)
46
47/* these are XPCOM only, one for every interface implemented */
48#define NS_DECL_ISUPPORTS
49#define NS_DECL_IVIRTUALBOX
50#define NS_DECL_IMACHINECOLLECTION
51#define NS_DECL_IMACHINE
52
53/* input pointer argument to method */
54#define INPTR
55
56/* makes the name of the getter interface function (n must be capitalized) */
57#define COMGETTER(n) get_##n
58/* makes the name of the setter interface function (n must be capitalized) */
59#define COMSETTER(n) put_##n
60
61/* a type for an input GUID parameter in the interface method declaration */
62#define GUIDPARAM GUID
63/* a type for an output GUID parameter in the interface method declaration */
64#define GUIDPARAMOUT GUID*
65
66/**
67 * Returns the const reference to the IID (i.e., |const GUID &|) of the given
68 * interface.
69 *
70 * @param i interface class
71 */
72#define COM_IIDOF(I) _ATL_IIDOF (I)
73
74#else // defined (RT_OS_WINDOWS)
75
76#error "VBOX_WITH_XPCOM is not defined!"
77
78#endif // defined (RT_OS_WINDOWS)
79
80#else // !defined (VBOX_WITH_XPCOM)
81
82// XPCOM
83/////////////////////////////////////////////////////////////////////////////
84
85#if defined (RT_OS_OS2)
86
87/* Make sure OS/2 Toolkit headers are pulled in to have
88 * BOOL/ULONG/etc. typedefs already defined in order to be able to redefine
89 * them using #define. */
90#define INCL_BASE
91#define INCL_PM
92#include <os2.h>
93
94/* OS/2 Toolkit defines TRUE and FALSE */
95#undef FALSE
96#undef TRUE
97
98#endif // defined (RT_OS_OS2)
99
100#if defined (RT_OS_DARWIN)
101 /* CFBase.h defines these*/
102# undef FALSE
103# undef TRUE
104#endif /* RT_OS_DARWIN */
105
106#include <nsID.h>
107
108#define ATL_NO_VTABLE
109#define DECLARE_CLASSFACTORY(a)
110#define DECLARE_CLASSFACTORY_SINGLETON(a)
111#define DECLARE_REGISTRY_RESOURCEID(a)
112#define DECLARE_NOT_AGGREGATABLE(a)
113#define DECLARE_PROTECT_FINAL_CONSTRUCT(a)
114#define BEGIN_COM_MAP(a)
115#define COM_INTERFACE_ENTRY(a)
116#define COM_INTERFACE_ENTRY2(a,b)
117#define END_COM_MAP(a)
118
119#define HRESULT nsresult
120#define SUCCEEDED NS_SUCCEEDED
121#define FAILED NS_FAILED
122#define NS_NULL nsnull
123
124#define IUnknown nsISupports
125
126#define BOOL PRBool
127#define BYTE PRUint8
128#define SHORT PRInt16
129#define USHORT PRUint16
130#define LONG PRInt32
131#define ULONG PRUint32
132#define LONG64 PRInt64
133#define ULONG64 PRUint64
134
135#define BSTR PRUnichar *
136#define LPBSTR BSTR *
137#define OLECHAR wchar_t
138
139#define FALSE PR_FALSE
140#define TRUE PR_TRUE
141
142/* makes the name of the getter interface function (n must be capitalized) */
143#define COMGETTER(n) Get##n
144/* makes the name of the setter interface function (n must be capitalized) */
145#define COMSETTER(n) Set##n
146
147/* a type to define a raw GUID variable (better to use the Guid class) */
148#define GUID nsID
149/* a type for an input GUID parameter in the interface method declaration */
150#define GUIDPARAM nsID &
151/* a type for an output GUID parameter in the interface method declaration */
152#define GUIDPARAMOUT nsID **
153
154/* CLSID and IID for compatibility with Win32 */
155typedef nsCID CLSID;
156typedef nsIID IID;
157
158/* OLE error codes */
159#define S_OK NS_OK
160#define E_UNEXPECTED NS_ERROR_UNEXPECTED
161#define E_NOTIMPL NS_ERROR_NOT_IMPLEMENTED
162#define E_OUTOFMEMORY NS_ERROR_OUT_OF_MEMORY
163#define E_INVALIDARG NS_ERROR_INVALID_ARG
164#define E_NOINTERFACE NS_ERROR_NO_INTERFACE
165#define E_POINTER NS_ERROR_NULL_POINTER
166#define E_ABORT NS_ERROR_ABORT
167#define E_FAIL NS_ERROR_FAILURE
168/* Note: a better analog for E_ACCESSDENIED would probably be
169 * NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */
170#define E_ACCESSDENIED ((nsresult) 0x80070005L)
171
172#define STDMETHOD(a) NS_IMETHOD a
173#define STDMETHODIMP NS_IMETHODIMP
174
175#define COM_IIDOF(I) NS_GET_IID (I)
176
177/* two very simple ATL emulator classes to provide
178 * FinalConstruct()/FinalRelease() functionality on Linux */
179
180class CComObjectRootEx
181{
182public:
183 HRESULT FinalConstruct() { return S_OK; }
184 void FinalRelease() {}
185};
186
187template <class Base> class CComObject : public Base
188{
189public:
190 virtual ~CComObject() { this->FinalRelease(); }
191};
192
193/* input pointer argument to method */
194#define INPTR const
195
196/* helper functions */
197extern "C"
198{
199BSTR SysAllocString (const OLECHAR* sz);
200BSTR SysAllocStringByteLen (char *psz, unsigned int len);
201BSTR SysAllocStringLen (const OLECHAR *pch, unsigned int cch);
202void SysFreeString (BSTR bstr);
203int SysReAllocString (BSTR *pbstr, const OLECHAR *psz);
204int SysReAllocStringLen (BSTR *pbstr, const OLECHAR *psz, unsigned int cch);
205unsigned int SysStringByteLen (BSTR bstr);
206unsigned int SysStringLen (BSTR bstr);
207}
208
209/**
210 * 'Constructor' for the component class.
211 * This constructor, as opposed to NS_GENERIC_FACTORY_CONSTRUCTOR,
212 * assumes that the component class is derived from the CComObjectRootEx<>
213 * template, so it calls FinalConstruct() right after object creation
214 * and ensures that FinalRelease() will be called right before destruction.
215 * The result from FinalConstruct() is returned to the caller.
216 */
217#define NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC(_InstanceClass) \
218static NS_IMETHODIMP \
219_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
220 void **aResult) \
221{ \
222 nsresult rv; \
223 \
224 *aResult = NULL; \
225 if (NULL != aOuter) { \
226 rv = NS_ERROR_NO_AGGREGATION; \
227 return rv; \
228 } \
229 \
230 CComObject <_InstanceClass> *inst = new CComObject <_InstanceClass>(); \
231 if (NULL == inst) { \
232 rv = NS_ERROR_OUT_OF_MEMORY; \
233 return rv; \
234 } \
235 \
236 NS_ADDREF(inst); /* protect FinalConstruct() */ \
237 rv = inst->FinalConstruct(); \
238 if (NS_SUCCEEDED(rv)) \
239 rv = inst->QueryInterface(aIID, aResult); \
240 NS_RELEASE(inst); \
241 \
242 return rv; \
243}
244
245/**
246 * 'Constructor' that uses an existing getter function that gets a singleton.
247 * The getter function must have the following prototype:
248 * nsresult _GetterProc (_InstanceClass **inst)
249 * This constructor, as opposed to NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR,
250 * lets the getter function return a result code that is passed back to the
251 * caller that tries to instantiate the object.
252 * NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
253 */
254#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC(_InstanceClass, _GetterProc) \
255static NS_IMETHODIMP \
256_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
257 void **aResult) \
258{ \
259 nsresult rv; \
260 \
261 _InstanceClass * inst; \
262 \
263 *aResult = NULL; \
264 if (NULL != aOuter) { \
265 rv = NS_ERROR_NO_AGGREGATION; \
266 return rv; \
267 } \
268 \
269 rv = _GetterProc(&inst); \
270 if (NS_FAILED(rv)) \
271 return rv; \
272 \
273 /* sanity check */ \
274 if (NULL == inst) \
275 return NS_ERROR_OUT_OF_MEMORY; \
276 \
277 /* NS_ADDREF(inst); */ \
278 if (NS_SUCCEEDED(rv)) { \
279 rv = inst->QueryInterface(aIID, aResult); \
280 } \
281 NS_RELEASE(inst); \
282 \
283 return rv; \
284}
285
286#endif // !defined (RT_OS_WINDOWS)
287
288/**
289 * Declares a whar_t string literal from the argument.
290 * Necessary to overcome MSC / GCC differences.
291 * @param s expression to stringify
292 */
293#if defined (_MSC_VER)
294# define WSTR_LITERAL(s) L#s
295#elif defined (__GNUC__)
296# define WSTR_LITERAL(s) L""#s
297#else
298# error "Unsupported compiler!"
299#endif
300
301#endif
302
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette