VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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