VirtualBox

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

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

Main: Made it build on OS/2.

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