VirtualBox

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

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

Merged dmik/s2 branch (r25959:26751) to the trunk.

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