VirtualBox

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

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

InnoTek -> innotek: all the headers and comments.

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