summaryrefslogtreecommitdiffstats
path: root/src/libs/xpcom18a4/xpcom/reflect/xptcall/public/xptcall.h
blob: 153a047e2d54100a61b1c3f9bf24928629c500a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1999
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

/* Public declarations for xptcall. */

#ifndef xptcall_h___
#define xptcall_h___

#include "prtypes.h"
#include "nscore.h"
#include "nsISupports.h"
#include "xpt_struct.h"
#include "xptinfo.h"
#include "nsIInterfaceInfo.h"

#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
#define XPTC_InvokeByIndex VBoxNsxpXPTC_InvokeByIndex
#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */

/***************************************************************************/
/*
 * The linkage of XPTC API functions differs depending on whether the file is
 * used within the XPTC library or not.  Any source file within the XPTC
 * library should define EXPORT_XPTC_API whereas any client of the library
 * should not.
 */
#ifdef EXPORT_XPTC_API
#define XPTC_PUBLIC_API(t)    PR_IMPLEMENT(t)
#define XPTC_PUBLIC_DATA(t)   PR_IMPLEMENT_DATA(t)
#if defined(_WIN32)
#    define XPTC_EXPORT           __declspec(dllexport)
#elif defined(XP_OS2) && defined(__declspec)
#    define XPTC_EXPORT           __declspec(dllexport)
#elif defined(XP_OS2_VACPP)
#    define XPTC_EXPORT           extern
#else
#  ifdef VBOX_HAVE_VISIBILITY_HIDDEN
#    define XPTC_EXPORT           __attribute__((visibility("default")))
#  else
#    define XPTC_EXPORT 
#  endif
#endif
#else
#if defined(_WIN32)
#    define XPTC_PUBLIC_API(t)    __declspec(dllimport) t
#    define XPTC_PUBLIC_DATA(t)   __declspec(dllimport) t
#    define XPTC_EXPORT           __declspec(dllimport)
#elif defined(XP_OS2) && defined(__declspec)
#    define XPTC_PUBLIC_API(t)    __declspec(dllimport) t
#    define XPTC_PUBLIC_DATA(t)   __declspec(dllimport) t
#    define XPTC_EXPORT           __declspec(dllimport)
#elif defined(XP_OS2_VACPP)
#    define XPTC_PUBLIC_API(t)    extern t
#    define XPTC_PUBLIC_DATA(t)   extern t
#    define XPTC_EXPORT           extern
#else
#    define XPTC_PUBLIC_API(t)    PR_IMPLEMENT(t)
#    define XPTC_PUBLIC_DATA(t)   t
#    define XPTC_EXPORT
#endif
#endif
#define XPTC_FRIEND_API(t)    XPTC_PUBLIC_API(t)
#define XPTC_FRIEND_DATA(t)   XPTC_PUBLIC_DATA(t)
/***************************************************************************/

struct nsXPTCMiniVariant
{
// No ctors or dtors so that we can use arrays of these on the stack
// with no penalty.
    union
    {
        PRInt8    i8;
        PRInt16   i16;
        PRInt32   i32;
        PRInt64   i64;
        PRUint8   u8;
        PRUint16  u16;
        PRUint32  u32;
        PRUint64  u64;
        float     f;
        double    d;
        PRBool    b;
        char      c;
        PRUnichar wc;
        void*     p;
    } val;
};

struct nsXPTCVariant : public nsXPTCMiniVariant
{
// No ctors or dtors so that we can use arrays of these on the stack
// with no penalty.

    // inherits 'val' here
    void*     ptr;
    nsXPTType type;
    PRUint8   flags;

    enum
    {
        // these are bitflags!
        PTR_IS_DATA    = 0x1,  // ptr points to 'real' data in val
        VAL_IS_ALLOCD  = 0x2,  // val.p holds alloc'd ptr that must be freed
        VAL_IS_IFACE   = 0x4,  // val.p holds interface ptr that must be released
        VAL_IS_ARRAY   = 0x8,  // val.p holds a pointer to an array needing cleanup
        VAL_IS_DOMSTR  = 0x10, // val.p holds a pointer to domstring needing cleanup
        VAL_IS_UTF8STR = 0x20, // val.p holds a pointer to utf8string needing cleanup
        VAL_IS_CSTR    = 0x40  // val.p holds a pointer to cstring needing cleanup        
    };

    /* VBox: Added to prevent -Wclass-memaccess warnings (nsXPTType has a constructor) in python/src/VariantUtils.cpp */
    nsXPTCVariant() : ptr(NULL), flags(0)
    {
        val.p = NULL;
        type.flags = 0; /* stupid nsXPTType constructor only do random bytes (documented) */
    }

    void ClearFlags()         {flags = 0;}
    void SetPtrIsData()       {flags |= PTR_IS_DATA;}
    void SetValIsAllocated()  {flags |= VAL_IS_ALLOCD;}
    void SetValIsInterface()  {flags |= VAL_IS_IFACE;}
    void SetValIsArray()      {flags |= VAL_IS_ARRAY;}
    void SetValIsDOMString()  {flags |= VAL_IS_DOMSTR;}
    void SetValIsUTF8String() {flags |= VAL_IS_UTF8STR;}
    void SetValIsCString()    {flags |= VAL_IS_CSTR;}    

    PRBool IsPtrData()       const  {return 0 != (flags & PTR_IS_DATA);}
    PRBool IsValAllocated()  const  {return 0 != (flags & VAL_IS_ALLOCD);}
    PRBool IsValInterface()  const  {return 0 != (flags & VAL_IS_IFACE);}
    PRBool IsValArray()      const  {return 0 != (flags & VAL_IS_ARRAY);}
    PRBool IsValDOMString()  const  {return 0 != (flags & VAL_IS_DOMSTR);}
    PRBool IsValUTF8String() const  {return 0 != (flags & VAL_IS_UTF8STR);}
    PRBool IsValCString()    const  {return 0 != (flags & VAL_IS_CSTR);}    
#ifdef VBOX
    PRBool MustFreeVal()     const  {return 0 != (flags & (  VAL_IS_ALLOCD
                                                           | VAL_IS_IFACE
                                                           | VAL_IS_DOMSTR
                                                           | VAL_IS_UTF8STR
                                                           | VAL_IS_CSTR)); }
#endif

    void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, PRUint8 f)
    {
        type = t;
        flags = f;

        if(f & PTR_IS_DATA)
        {
            ptr = mv.val.p;
            val.p = nsnull;
        }
        else
        {
            ptr = nsnull;
            switch(t.TagPart()) {
              case nsXPTType::T_I8:                val.i8  = mv.val.i8;  break;
              case nsXPTType::T_I16:               val.i16 = mv.val.i16; break;
              case nsXPTType::T_I32:               val.i32 = mv.val.i32; break;
              case nsXPTType::T_I64:               val.i64 = mv.val.i64; break;
              case nsXPTType::T_U8:                val.u8  = mv.val.u8;  break;
              case nsXPTType::T_U16:               val.u16 = mv.val.u16; break;
              case nsXPTType::T_U32:               val.u32 = mv.val.u32; break;
              case nsXPTType::T_U64:               val.u64 = mv.val.u64; break;
              case nsXPTType::T_FLOAT:             val.f   = mv.val.f;   break;
              case nsXPTType::T_DOUBLE:            val.d   = mv.val.d;   break;
              case nsXPTType::T_BOOL:              val.b   = mv.val.b;   break;
              case nsXPTType::T_CHAR:              val.c   = mv.val.c;   break;
              case nsXPTType::T_WCHAR:             val.wc  = mv.val.wc;  break;
              case nsXPTType::T_VOID:              /* fall through */
              case nsXPTType::T_IID:               /* fall through */
              case nsXPTType::T_DOMSTRING:         /* fall through */
              case nsXPTType::T_CHAR_STR:          /* fall through */
              case nsXPTType::T_WCHAR_STR:         /* fall through */
              case nsXPTType::T_INTERFACE:         /* fall through */
              case nsXPTType::T_INTERFACE_IS:      /* fall through */
              case nsXPTType::T_ARRAY:             /* fall through */
              case nsXPTType::T_PSTRING_SIZE_IS:   /* fall through */
              case nsXPTType::T_PWSTRING_SIZE_IS:  /* fall through */
              case nsXPTType::T_UTF8STRING:        /* fall through */
              case nsXPTType::T_CSTRING:           /* fall through */              
              default:                             val.p   = mv.val.p;   break;
            }
        }
    }
};

/***************************************************************************/

#undef  IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT

class XPTC_EXPORT nsXPTCStubBase : public nsISupports
{
public:
    // We are going to implement this to force the compiler to generate a 
    // vtbl for this class. Since this is overridden in the inheriting class
    // we expect it to never be called. 
    // *This is needed by the Irix implementation.*
    NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);

    // Implement dummy constructor, destructor to workaround Solaris gcc 4.8.2
    // linking issue (see @bugref{5838}).
    nsXPTCStubBase() {}
    ~nsXPTCStubBase() {}

    // Include generated vtbl stub declarations.
    // These are virtual and *also* implemented by this class..
#include "xptcstubsdecl.inc"

    // The following methods must be provided by inheritor of this class.

    // return a refcounted pointer to the InterfaceInfo for this object
    // NOTE: on some platforms this MUST not fail or we crash!
    NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;

    // call this method and return result
    NS_IMETHOD CallMethod(PRUint16 methodIndex,
                          const nsXPTMethodInfo* info,
                          nsXPTCMiniVariant* params) = 0;
};

#undef  IMETHOD_VISIBILITY
#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN

PR_BEGIN_EXTERN_C

XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
                   PRUint32 paramCount, nsXPTCVariant* params);

// Used to force linking of these obj for the static library into the dll
extern void xptc_dummy();
extern void xptc_dummy2();

PR_END_EXTERN_C

#endif /* xptcall_h___ */