VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/public/xptcall.h@ 33388

Last change on this file since 33388 was 24637, checked in by vboxsync, 15 years ago

xpcom: prevent valgrind warning

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 KB
Line 
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/* Public declarations for xptcall. */
39
40#ifndef xptcall_h___
41#define xptcall_h___
42
43#include "prtypes.h"
44#include "nscore.h"
45#include "nsISupports.h"
46#include "xpt_struct.h"
47#include "xptinfo.h"
48#include "nsIInterfaceInfo.h"
49
50#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
51#define XPTC_InvokeByIndex VBoxNsxpXPTC_InvokeByIndex
52#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
53
54/***************************************************************************/
55/*
56 * The linkage of XPTC API functions differs depending on whether the file is
57 * used within the XPTC library or not. Any source file within the XPTC
58 * library should define EXPORT_XPTC_API whereas any client of the library
59 * should not.
60 */
61#ifdef EXPORT_XPTC_API
62#define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
63#define XPTC_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
64#if defined(_WIN32)
65# define XPTC_EXPORT __declspec(dllexport)
66#elif defined(XP_OS2) && defined(__declspec)
67# define XPTC_EXPORT __declspec(dllexport)
68#elif defined(XP_OS2_VACPP)
69# define XPTC_EXPORT extern
70#else
71# ifdef VBOX_HAVE_VISIBILITY_HIDDEN
72# define XPTC_EXPORT __attribute__((visibility("default")))
73# else
74# define XPTC_EXPORT
75# endif
76#endif
77#else
78#if defined(_WIN32)
79# define XPTC_PUBLIC_API(t) __declspec(dllimport) t
80# define XPTC_PUBLIC_DATA(t) __declspec(dllimport) t
81# define XPTC_EXPORT __declspec(dllimport)
82#elif defined(XP_OS2) && defined(__declspec)
83# define XPTC_PUBLIC_API(t) __declspec(dllimport) t
84# define XPTC_PUBLIC_DATA(t) __declspec(dllimport) t
85# define XPTC_EXPORT __declspec(dllimport)
86#elif defined(XP_OS2_VACPP)
87# define XPTC_PUBLIC_API(t) extern t
88# define XPTC_PUBLIC_DATA(t) extern t
89# define XPTC_EXPORT extern
90#else
91# define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
92# define XPTC_PUBLIC_DATA(t) t
93# define XPTC_EXPORT
94#endif
95#endif
96#define XPTC_FRIEND_API(t) XPTC_PUBLIC_API(t)
97#define XPTC_FRIEND_DATA(t) XPTC_PUBLIC_DATA(t)
98/***************************************************************************/
99
100struct nsXPTCMiniVariant
101{
102// No ctors or dtors so that we can use arrays of these on the stack
103// with no penalty.
104 union
105 {
106 PRInt8 i8;
107 PRInt16 i16;
108 PRInt32 i32;
109 PRInt64 i64;
110 PRUint8 u8;
111 PRUint16 u16;
112 PRUint32 u32;
113 PRUint64 u64;
114 float f;
115 double d;
116 PRBool b;
117 char c;
118 PRUnichar wc;
119 void* p;
120 } val;
121};
122
123struct nsXPTCVariant : public nsXPTCMiniVariant
124{
125// No ctors or dtors so that we can use arrays of these on the stack
126// with no penalty.
127
128 // inherits 'val' here
129 void* ptr;
130 nsXPTType type;
131 PRUint8 flags;
132
133 enum
134 {
135 // these are bitflags!
136 PTR_IS_DATA = 0x1, // ptr points to 'real' data in val
137 VAL_IS_ALLOCD = 0x2, // val.p holds alloc'd ptr that must be freed
138 VAL_IS_IFACE = 0x4, // val.p holds interface ptr that must be released
139 VAL_IS_ARRAY = 0x8, // val.p holds a pointer to an array needing cleanup
140 VAL_IS_DOMSTR = 0x10, // val.p holds a pointer to domstring needing cleanup
141 VAL_IS_UTF8STR = 0x20, // val.p holds a pointer to utf8string needing cleanup
142 VAL_IS_CSTR = 0x40 // val.p holds a pointer to cstring needing cleanup
143 };
144
145 void ClearFlags() {flags = 0;}
146 void SetPtrIsData() {flags |= PTR_IS_DATA;}
147 void SetValIsAllocated() {flags |= VAL_IS_ALLOCD;}
148 void SetValIsInterface() {flags |= VAL_IS_IFACE;}
149 void SetValIsArray() {flags |= VAL_IS_ARRAY;}
150 void SetValIsDOMString() {flags |= VAL_IS_DOMSTR;}
151 void SetValIsUTF8String() {flags |= VAL_IS_UTF8STR;}
152 void SetValIsCString() {flags |= VAL_IS_CSTR;}
153
154 PRBool IsPtrData() const {return 0 != (flags & PTR_IS_DATA);}
155 PRBool IsValAllocated() const {return 0 != (flags & VAL_IS_ALLOCD);}
156 PRBool IsValInterface() const {return 0 != (flags & VAL_IS_IFACE);}
157 PRBool IsValArray() const {return 0 != (flags & VAL_IS_ARRAY);}
158 PRBool IsValDOMString() const {return 0 != (flags & VAL_IS_DOMSTR);}
159 PRBool IsValUTF8String() const {return 0 != (flags & VAL_IS_UTF8STR);}
160 PRBool IsValCString() const {return 0 != (flags & VAL_IS_CSTR);}
161#ifdef VBOX
162 PRBool MustFreeVal() const {return 0 != (flags & ( VAL_IS_ALLOCD
163 | VAL_IS_IFACE
164 | VAL_IS_DOMSTR
165 | VAL_IS_UTF8STR
166 | VAL_IS_CSTR)); }
167#endif
168
169 void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, PRUint8 f)
170 {
171 type = t;
172 flags = f;
173
174 if(f & PTR_IS_DATA)
175 {
176 ptr = mv.val.p;
177 val.p = nsnull;
178 }
179 else
180 {
181 ptr = nsnull;
182 switch(t.TagPart()) {
183 case nsXPTType::T_I8: val.i8 = mv.val.i8; break;
184 case nsXPTType::T_I16: val.i16 = mv.val.i16; break;
185 case nsXPTType::T_I32: val.i32 = mv.val.i32; break;
186 case nsXPTType::T_I64: val.i64 = mv.val.i64; break;
187 case nsXPTType::T_U8: val.u8 = mv.val.u8; break;
188 case nsXPTType::T_U16: val.u16 = mv.val.u16; break;
189 case nsXPTType::T_U32: val.u32 = mv.val.u32; break;
190 case nsXPTType::T_U64: val.u64 = mv.val.u64; break;
191 case nsXPTType::T_FLOAT: val.f = mv.val.f; break;
192 case nsXPTType::T_DOUBLE: val.d = mv.val.d; break;
193 case nsXPTType::T_BOOL: val.b = mv.val.b; break;
194 case nsXPTType::T_CHAR: val.c = mv.val.c; break;
195 case nsXPTType::T_WCHAR: val.wc = mv.val.wc; break;
196 case nsXPTType::T_VOID: /* fall through */
197 case nsXPTType::T_IID: /* fall through */
198 case nsXPTType::T_DOMSTRING: /* fall through */
199 case nsXPTType::T_CHAR_STR: /* fall through */
200 case nsXPTType::T_WCHAR_STR: /* fall through */
201 case nsXPTType::T_INTERFACE: /* fall through */
202 case nsXPTType::T_INTERFACE_IS: /* fall through */
203 case nsXPTType::T_ARRAY: /* fall through */
204 case nsXPTType::T_PSTRING_SIZE_IS: /* fall through */
205 case nsXPTType::T_PWSTRING_SIZE_IS: /* fall through */
206 case nsXPTType::T_UTF8STRING: /* fall through */
207 case nsXPTType::T_CSTRING: /* fall through */
208 default: val.p = mv.val.p; break;
209 }
210 }
211 }
212};
213
214/***************************************************************************/
215
216#undef IMETHOD_VISIBILITY
217#define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
218
219class XPTC_EXPORT nsXPTCStubBase : public nsISupports
220{
221public:
222 // We are going to implement this to force the compiler to generate a
223 // vtbl for this class. Since this is overridden in the inheriting class
224 // we expect it to never be called.
225 // *This is needed by the Irix implementation.*
226 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
227
228 // Include generated vtbl stub declarations.
229 // These are virtual and *also* implemented by this class..
230#include "xptcstubsdecl.inc"
231
232 // The following methods must be provided by inheritor of this class.
233
234 // return a refcounted pointer to the InterfaceInfo for this object
235 // NOTE: on some platforms this MUST not fail or we crash!
236 NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
237
238 // call this method and return result
239 NS_IMETHOD CallMethod(PRUint16 methodIndex,
240 const nsXPTMethodInfo* info,
241 nsXPTCMiniVariant* params) = 0;
242};
243
244#undef IMETHOD_VISIBILITY
245#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
246
247PR_BEGIN_EXTERN_C
248
249XPTC_PUBLIC_API(nsresult)
250XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
251 PRUint32 paramCount, nsXPTCVariant* params);
252
253// Used to force linking of these obj for the static library into the dll
254extern void xptc_dummy();
255extern void xptc_dummy2();
256
257PR_END_EXTERN_C
258
259#endif /* xptcall_h___ */
Note: See TracBrowser for help on using the repository browser.

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