~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/webservices/interfaceinfo/src/nsGenericInterfaceInfoSet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
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) 2002
 
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 the GNU General Public License Version 2 or later (the "GPL"), or
 
26
 * 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 NPL, 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 NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
/* The nsGenericInterfaceInfo/nsGenericInterfaceInfoSet implementations.*/
 
39
 
 
40
#include "iixprivate.h"
 
41
 
 
42
 
 
43
/***************************************************************************/
 
44
// implement nsGenericInterfaceInfoSet
 
45
 
 
46
#define ARENA_BLOCK_SIZE (1024 * 1)
 
47
 
 
48
NS_IMPL_THREADSAFE_ISUPPORTS3(nsGenericInterfaceInfoSet,
 
49
                              nsIInterfaceInfoManager,
 
50
                              nsIGenericInterfaceInfoSet,
 
51
                              nsISupportsWeakReference)
 
52
 
 
53
nsGenericInterfaceInfoSet::nsGenericInterfaceInfoSet()
 
54
{
 
55
    mArena = XPT_NewArena(ARENA_BLOCK_SIZE, sizeof(double),
 
56
                          "nsGenericInterfaceInfoSet Arena");
 
57
}
 
58
 
 
59
nsGenericInterfaceInfoSet::~nsGenericInterfaceInfoSet()
 
60
{
 
61
    PRInt32 count = mInterfaces.Count();
 
62
 
 
63
    for(PRInt32 i = 0; i < count; i++)
 
64
    {
 
65
        nsIInterfaceInfo* info = (nsIInterfaceInfo*) mInterfaces.ElementAt(i);
 
66
        if(CheckOwnedFlag(info))
 
67
            delete (nsGenericInterfaceInfo*) ClearOwnedFlag(info);
 
68
        else
 
69
            NS_RELEASE(info);
 
70
    }
 
71
 
 
72
    if(mArena)
 
73
        XPT_DestroyArena(mArena);
 
74
}
 
75
 
 
76
nsresult
 
77
nsGenericInterfaceInfoSet::IndexOfIID(const nsIID & aIID, PRUint16 *_retval)
 
78
{
 
79
    PRInt32 count = mInterfaces.Count();
 
80
 
 
81
    for(PRInt32 i = 0; i < count; i++)
 
82
    {
 
83
        nsIInterfaceInfo* info = (nsIInterfaceInfo*)
 
84
            ClearOwnedFlag(mInterfaces.ElementAt(i));
 
85
        const nsID* iid;
 
86
        nsresult rv = info->GetIIDShared(&iid);
 
87
        if(NS_FAILED(rv))
 
88
            return rv;
 
89
        if(iid->Equals(aIID))
 
90
        {
 
91
            *_retval = (PRUint16) i;
 
92
            return NS_OK;
 
93
        }
 
94
    }
 
95
    return NS_ERROR_NO_INTERFACE;
 
96
}
 
97
 
 
98
nsresult
 
99
nsGenericInterfaceInfoSet::IndexOfName(const char* aName, PRUint16 *_retval)
 
100
{
 
101
    PRInt32 count = mInterfaces.Count();
 
102
 
 
103
    for(PRInt32 i = 0; i < count; i++)
 
104
    {
 
105
        nsIInterfaceInfo* info = (nsIInterfaceInfo*)
 
106
            ClearOwnedFlag(mInterfaces.ElementAt(i));
 
107
        const char* name;
 
108
        nsresult rv = info->GetNameShared(&name);
 
109
        if(NS_FAILED(rv))
 
110
            return rv;
 
111
        if(!strcmp(name, aName))
 
112
        {
 
113
            *_retval = (PRUint16) i;
 
114
            return NS_OK;
 
115
        }
 
116
    }
 
117
    return NS_ERROR_NO_INTERFACE;
 
118
}
 
119
 
 
120
/************************************************/
 
121
// nsIGenericInterfaceInfoSet methods...
 
122
 
 
123
/* XPTParamDescriptorPtr allocateParamArray (in PRUint16 aCount); */
 
124
NS_IMETHODIMP
 
125
nsGenericInterfaceInfoSet::AllocateParamArray(PRUint16 aCount,
 
126
                                              XPTParamDescriptor * *_retval)
 
127
{
 
128
    *_retval = (XPTParamDescriptor*)
 
129
        XPT_MALLOC(GetArena(), sizeof(XPTParamDescriptor) * aCount);
 
130
    return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
131
}
 
132
 
 
133
/* XPTTypeDescriptorPtr allocateAdditionalType (out PRUint16 aIndex); */
 
134
NS_IMETHODIMP
 
135
nsGenericInterfaceInfoSet::AllocateAdditionalType(PRUint16 *aIndex,
 
136
                                                  XPTTypeDescriptor * *_retval)
 
137
{
 
138
    *_retval = (XPTTypeDescriptor*)
 
139
        XPT_MALLOC(GetArena(), sizeof(XPTTypeDescriptor));
 
140
    if(!*_retval || !mAdditionalTypes.AppendElement(*_retval))
 
141
        return NS_ERROR_OUT_OF_MEMORY;
 
142
    *aIndex = (PRUint16) mAdditionalTypes.Count()-1;
 
143
    return NS_OK;
 
144
}
 
145
 
 
146
/* PRUint16 createAndAppendInterface (in string aName, in nsIIDRef
 
147
   aIID, in PRUint16 aParent, in PRUint8 aFlags, out
 
148
   nsIGenericInterfaceInfo aInfo); */
 
149
NS_IMETHODIMP
 
150
nsGenericInterfaceInfoSet::CreateAndAppendInterface(const char *aName,
 
151
                                                    const nsIID & aIID,
 
152
                                                    PRUint16 aParent,
 
153
                                                    PRUint8 aFlags,
 
154
                                                    nsIGenericInterfaceInfo **aInfo,
 
155
                                                    PRUint16 *_retval)
 
156
{
 
157
    nsGenericInterfaceInfo* info =
 
158
        new nsGenericInterfaceInfo(this, aName, aIID,
 
159
                                   (aParent == (PRUint16) -1) ?
 
160
                                        nsnull : InfoAtNoAddRef(aParent),
 
161
                                   aFlags);
 
162
    if(!info || !mInterfaces.AppendElement(SetOwnedFlag(info)))
 
163
        return NS_ERROR_OUT_OF_MEMORY;
 
164
 
 
165
    *_retval = (PRUint16) mInterfaces.Count()-1;
 
166
    return CallQueryInterface(info, aInfo);
 
167
}
 
168
 
 
169
/* PRUint16 appendExternalInterface (in nsIInterfaceInfo aInfo); */
 
170
NS_IMETHODIMP
 
171
nsGenericInterfaceInfoSet::AppendExternalInterface(nsIInterfaceInfo *aInfo,
 
172
                                                   PRUint16 *_retval)
 
173
{
 
174
    if(!mInterfaces.AppendElement(aInfo))
 
175
        return NS_ERROR_OUT_OF_MEMORY;
 
176
 
 
177
    NS_ADDREF(aInfo);
 
178
    *_retval = (PRUint16) mInterfaces.Count()-1;
 
179
    return NS_OK;
 
180
}
 
181
 
 
182
/* PRUint16 indexOf (in nsIIDRef aIID); */
 
183
NS_IMETHODIMP
 
184
nsGenericInterfaceInfoSet::IndexOf(const nsIID & aIID, PRUint16 *_retval)
 
185
{
 
186
    return IndexOfIID(aIID, _retval);
 
187
}
 
188
 
 
189
/* PRUint16 indexOfByName (in string aName); */
 
190
NS_IMETHODIMP nsGenericInterfaceInfoSet::IndexOfByName(const char *aName,
 
191
                                                       PRUint16 *_retval)
 
192
{
 
193
    return IndexOfName(aName, _retval);
 
194
}
 
195
 
 
196
/* nsIInterfaceInfo interfaceInfoAt (in PRUint16 aIndex); */
 
197
NS_IMETHODIMP
 
198
nsGenericInterfaceInfoSet::InterfaceInfoAt(PRUint16 aIndex,
 
199
                                           nsIInterfaceInfo **_retval)
 
200
{
 
201
    NS_ASSERTION(aIndex < (PRUint16)mInterfaces.Count(), "bad index");
 
202
 
 
203
    *_retval = (nsIInterfaceInfo*)
 
204
        ClearOwnedFlag(mInterfaces.ElementAt(aIndex));
 
205
    NS_ADDREF(*_retval);
 
206
    return NS_OK;
 
207
}
 
208
 
 
209
/************************************************/
 
210
// nsIInterfaceInfoManager methods...
 
211
 
 
212
/* nsIInterfaceInfo getInfoForIID (in nsIIDPtr iid); */
 
213
NS_IMETHODIMP
 
214
nsGenericInterfaceInfoSet::GetInfoForIID(const nsIID * iid,
 
215
                                         nsIInterfaceInfo **_retval)
 
216
{
 
217
    PRUint16 index;
 
218
    nsresult rv = IndexOfIID(*iid, &index);
 
219
    if(NS_FAILED(rv))
 
220
        return rv;
 
221
    return InterfaceInfoAt(index, _retval);
 
222
}
 
223
 
 
224
/* nsIInterfaceInfo getInfoForName (in string name); */
 
225
NS_IMETHODIMP
 
226
nsGenericInterfaceInfoSet::GetInfoForName(const char *name,
 
227
                                          nsIInterfaceInfo **_retval)
 
228
{
 
229
    PRUint16 index;
 
230
    nsresult rv = IndexOfName(name, &index);
 
231
    if(NS_FAILED(rv))
 
232
        return rv;
 
233
    return InterfaceInfoAt(index, _retval);
 
234
}
 
235
 
 
236
/* nsIIDPtr getIIDForName (in string name); */
 
237
NS_IMETHODIMP
 
238
nsGenericInterfaceInfoSet::GetIIDForName(const char *name, nsIID **_retval)
 
239
{
 
240
    PRUint16 index;
 
241
    nsresult rv = IndexOfName(name, &index);
 
242
    if(NS_FAILED(rv))
 
243
        return rv;
 
244
 
 
245
    nsIInterfaceInfo* info = InfoAtNoAddRef(index);
 
246
    if(!info)
 
247
        return NS_ERROR_FAILURE;
 
248
 
 
249
    return info->GetInterfaceIID(_retval);
 
250
}
 
251
 
 
252
/* string getNameForIID (in nsIIDPtr iid); */
 
253
NS_IMETHODIMP
 
254
nsGenericInterfaceInfoSet::GetNameForIID(const nsIID * iid, char **_retval)
 
255
{
 
256
    PRUint16 index;
 
257
    nsresult rv = IndexOfIID(*iid, &index);
 
258
    if(NS_FAILED(rv))
 
259
        return rv;
 
260
 
 
261
    nsIInterfaceInfo* info = InfoAtNoAddRef(index);
 
262
    if(!info)
 
263
        return NS_ERROR_FAILURE;
 
264
 
 
265
    return info->GetName(_retval);
 
266
}
 
267
 
 
268
/* nsIEnumerator enumerateInterfaces (); */
 
269
NS_IMETHODIMP
 
270
nsGenericInterfaceInfoSet::EnumerateInterfaces(nsIEnumerator **_retval)
 
271
{
 
272
    return EnumerateInterfacesWhoseNamesStartWith(nsnull, _retval);
 
273
}
 
274
 
 
275
/* void autoRegisterInterfaces (); */
 
276
NS_IMETHODIMP
 
277
nsGenericInterfaceInfoSet::AutoRegisterInterfaces()
 
278
{
 
279
    // NOP
 
280
    return NS_OK;
 
281
}
 
282
 
 
283
/* nsIEnumerator enumerateInterfacesWhoseNamesStartWith (in string prefix); */
 
284
NS_IMETHODIMP
 
285
nsGenericInterfaceInfoSet::EnumerateInterfacesWhoseNamesStartWith(const char *prefix,
 
286
                                                                  nsIEnumerator **_retval)
 
287
{
 
288
    int count = (int) mInterfaces.Count();
 
289
    int len = prefix ? PL_strlen(prefix) : 0;
 
290
    const char* name;
 
291
 
 
292
    nsCOMPtr<nsISupportsArray> array;
 
293
    NS_NewISupportsArray(getter_AddRefs(array));
 
294
    if(!array)
 
295
        return NS_ERROR_OUT_OF_MEMORY;
 
296
 
 
297
    for(PRInt32 i = 0; i < count; i++)
 
298
    {
 
299
        nsIInterfaceInfo* info = InfoAtNoAddRef(i);
 
300
        if(!info)
 
301
            continue;
 
302
        if(!prefix ||
 
303
           (NS_SUCCEEDED(info->GetNameShared(&name)) &&
 
304
            name == PL_strnstr(name, prefix, len)))
 
305
        {
 
306
            if(!array->AppendElement(info))
 
307
                return NS_ERROR_OUT_OF_MEMORY;
 
308
        }
 
309
    }
 
310
 
 
311
    return array->Enumerate(_retval);
 
312
}
 
313
 
 
314
/***************************************************************************/
 
315
/***************************************************************************/
 
316
// implement nsGenericInterfaceInfo
 
317
 
 
318
NS_IMPL_QUERY_INTERFACE2(nsGenericInterfaceInfo,
 
319
                         nsIInterfaceInfo,
 
320
                         nsIGenericInterfaceInfo)
 
321
 
 
322
NS_IMETHODIMP_(nsrefcnt)
 
323
nsGenericInterfaceInfo::AddRef()
 
324
{
 
325
    return mSet->AddRef();
 
326
}
 
327
 
 
328
NS_IMETHODIMP_(nsrefcnt)
 
329
nsGenericInterfaceInfo::Release()
 
330
{
 
331
    return mSet->Release();
 
332
}
 
333
 
 
334
nsGenericInterfaceInfo::nsGenericInterfaceInfo(nsGenericInterfaceInfoSet* aSet,
 
335
                                               const char *aName,
 
336
                                               const nsIID & aIID,
 
337
                                               nsIInterfaceInfo* aParent,
 
338
                                               PRUint8 aFlags)
 
339
    : mName(nsnull),
 
340
      mIID(aIID),
 
341
      mSet(aSet),
 
342
      mParent(aParent),
 
343
      mFlags(aFlags)
 
344
{
 
345
    if(mParent)
 
346
    {
 
347
        mParent->GetMethodCount(&mMethodBaseIndex);
 
348
        mParent->GetConstantCount(&mConstantBaseIndex);
 
349
    }
 
350
    else
 
351
    {
 
352
        mMethodBaseIndex = mConstantBaseIndex = 0;
 
353
    }
 
354
 
 
355
    int len = PL_strlen(aName);
 
356
    mName = (char*) XPT_MALLOC(mSet->GetArena(), len+1);
 
357
    if(mName)
 
358
        memcpy(mName, aName, len);
 
359
}
 
360
 
 
361
/************************************************/
 
362
// nsIGenericInterfaceInfo methods...
 
363
 
 
364
/* PRUint16 appendMethod (in XPTMethodDescriptorPtr aMethod); */
 
365
NS_IMETHODIMP
 
366
nsGenericInterfaceInfo::AppendMethod(XPTMethodDescriptor * aMethod,
 
367
                                     PRUint16 *_retval)
 
368
{
 
369
    XPTMethodDescriptor* desc = (XPTMethodDescriptor*)
 
370
        XPT_MALLOC(mSet->GetArena(), sizeof(XPTMethodDescriptor));
 
371
    if(!desc)
 
372
        return NS_ERROR_OUT_OF_MEMORY;
 
373
 
 
374
    memcpy(desc, aMethod, sizeof(XPTMethodDescriptor));
 
375
 
 
376
    int len = PL_strlen(aMethod->name);
 
377
    desc->name = (char*) XPT_MALLOC(mSet->GetArena(), len+1);
 
378
    if(!desc->name)
 
379
        return NS_ERROR_OUT_OF_MEMORY;
 
380
 
 
381
    // XPT_MALLOC returns zeroed out memory, no need to copy the
 
382
    // terminating null character.
 
383
    memcpy(desc->name, aMethod->name, len);
 
384
 
 
385
    return mMethods.AppendElement(desc) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
386
}
 
387
 
 
388
/* PRUint16 appendConst (in XPTConstDescriptorPtr aConst); */
 
389
NS_IMETHODIMP
 
390
nsGenericInterfaceInfo::AppendConst(XPTConstDescriptor * aConst,
 
391
                                    PRUint16 *_retval)
 
392
{
 
393
    NS_ASSERTION(aConst->type.prefix.flags == TD_INT16  ||
 
394
                 aConst->type.prefix.flags == TD_UINT16 ||
 
395
                 aConst->type.prefix.flags == TD_INT32  ||
 
396
                 aConst->type.prefix.flags == TD_UINT32,
 
397
                 "unsupported const type");
 
398
 
 
399
    XPTConstDescriptor* desc = (XPTConstDescriptor*)
 
400
        XPT_MALLOC(mSet->GetArena(), sizeof(XPTConstDescriptor));
 
401
    if(!desc)
 
402
        return NS_ERROR_OUT_OF_MEMORY;
 
403
 
 
404
    memcpy(desc, aConst, sizeof(XPTConstDescriptor));
 
405
 
 
406
    int len = PL_strlen(aConst->name);
 
407
    desc->name = (char*) XPT_MALLOC(mSet->GetArena(), len+1);
 
408
    if(!desc->name)
 
409
        return NS_ERROR_OUT_OF_MEMORY;
 
410
 
 
411
    // XPT_MALLOC returns zeroed out memory, no need to copy the
 
412
    // terminating null character.
 
413
    memcpy(desc->name, aConst->name, len);
 
414
 
 
415
    return mConstants.AppendElement(desc) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
416
}
 
417
 
 
418
/************************************************/
 
419
// nsIInterfaceInfo methods...
 
420
 
 
421
/* readonly attribute string name; */
 
422
NS_IMETHODIMP
 
423
nsGenericInterfaceInfo::GetName(char * *aName)
 
424
{
 
425
    *aName = (char*) nsMemory::Clone(mName, PL_strlen(mName)+1);
 
426
    return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
427
}
 
428
 
 
429
/* readonly attribute nsIIDPtr InterfaceIID; */
 
430
NS_IMETHODIMP
 
431
nsGenericInterfaceInfo::GetInterfaceIID(nsIID * *aIID)
 
432
{
 
433
    *aIID = (nsIID*) nsMemory::Clone(&mIID, sizeof(nsIID));
 
434
    return *aIID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
435
}
 
436
 
 
437
/* PRBool isScriptable (); */
 
438
NS_IMETHODIMP
 
439
nsGenericInterfaceInfo::IsScriptable(PRBool *_retval)
 
440
{
 
441
    *_retval = XPT_ID_IS_SCRIPTABLE(mFlags) != 0;
 
442
    return NS_OK;
 
443
}
 
444
 
 
445
/* readonly attribute nsIInterfaceInfo parent; */
 
446
NS_IMETHODIMP
 
447
nsGenericInterfaceInfo::GetParent(nsIInterfaceInfo * *aParent)
 
448
{
 
449
    *aParent = mParent;
 
450
    NS_IF_ADDREF(*aParent);
 
451
    return NS_OK;
 
452
}
 
453
 
 
454
/* readonly attribute PRUint16 methodCount; */
 
455
NS_IMETHODIMP
 
456
nsGenericInterfaceInfo::GetMethodCount(PRUint16 *aMethodCount)
 
457
{
 
458
    *aMethodCount = mMethodBaseIndex + (PRUint16) mMethods.Count();
 
459
    return NS_OK;
 
460
}
 
461
 
 
462
/* readonly attribute PRUint16 constantCount; */
 
463
NS_IMETHODIMP
 
464
nsGenericInterfaceInfo::GetConstantCount(PRUint16 *aConstantCount)
 
465
{
 
466
    *aConstantCount = mConstantBaseIndex + (PRUint16) mConstants.Count();
 
467
    return NS_OK;
 
468
}
 
469
 
 
470
/* void getMethodInfo (in PRUint16 index, [shared, retval] out
 
471
   nsXPTMethodInfoPtr info); */
 
472
NS_IMETHODIMP
 
473
nsGenericInterfaceInfo::GetMethodInfo(PRUint16 index,
 
474
                                      const nsXPTMethodInfo * *info)
 
475
{
 
476
    if(index < mMethodBaseIndex)
 
477
        return mParent->GetMethodInfo(index, info);
 
478
    *info = (const nsXPTMethodInfo *) mMethods.ElementAt(index-mMethodBaseIndex);
 
479
    return NS_OK;
 
480
}
 
481
 
 
482
/* void getMethodInfoForName (in string methodName, out PRUint16
 
483
   index, [shared, retval] out nsXPTMethodInfoPtr info); */
 
484
NS_IMETHODIMP
 
485
nsGenericInterfaceInfo::GetMethodInfoForName(const char *methodName,
 
486
                                             PRUint16 *index,
 
487
                                             const nsXPTMethodInfo * *info)
 
488
{
 
489
    PRUint16 count = mMethodBaseIndex + (PRUint16) mMethods.Count();
 
490
    for(PRUint16 i = 0; i < count; i++)
 
491
    {
 
492
        const nsXPTMethodInfo* current;
 
493
        nsresult rv = GetMethodInfo(i, &current);
 
494
        if(NS_FAILED(rv))
 
495
            return rv;
 
496
 
 
497
        if(!PL_strcmp(methodName, current->GetName()))
 
498
        {
 
499
            *index = i;
 
500
            *info = current;
 
501
            return NS_OK;
 
502
        }
 
503
    }
 
504
    *index = 0;
 
505
    *info = 0;
 
506
    return NS_ERROR_INVALID_ARG;
 
507
}
 
508
 
 
509
/* void getConstant (in PRUint16 index, [shared, retval] out
 
510
   nsXPTConstantPtr constant); */
 
511
NS_IMETHODIMP
 
512
nsGenericInterfaceInfo::GetConstant(PRUint16 index,
 
513
                                    const nsXPTConstant * *constant)
 
514
{
 
515
    if(index < mConstantBaseIndex)
 
516
        return mParent->GetConstant(index, constant);
 
517
    *constant = (const nsXPTConstant *)
 
518
        mConstants.ElementAt(index-mConstantBaseIndex);
 
519
    return NS_OK;
 
520
}
 
521
 
 
522
/* nsIInterfaceInfo getInfoForParam (in PRUint16 methodIndex, [const]
 
523
   in nsXPTParamInfoPtr param); */
 
524
NS_IMETHODIMP
 
525
nsGenericInterfaceInfo::GetInfoForParam(PRUint16 methodIndex,
 
526
                                        const nsXPTParamInfo * param,
 
527
                                        nsIInterfaceInfo **_retval)
 
528
{
 
529
    if(methodIndex < mMethodBaseIndex)
 
530
        return mParent->GetInfoForParam(methodIndex, param, _retval);
 
531
 
 
532
    const XPTTypeDescriptor* td = GetPossiblyNestedType(param);
 
533
    NS_ASSERTION(XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE,
 
534
                 "not an interface");
 
535
 
 
536
    return mSet->InterfaceInfoAt(td->type.iface, _retval);
 
537
}
 
538
 
 
539
/* nsIIDPtr getIIDForParam (in PRUint16 methodIndex, [const] in
 
540
   nsXPTParamInfoPtr param); */
 
541
NS_IMETHODIMP
 
542
nsGenericInterfaceInfo::GetIIDForParam(PRUint16 methodIndex,
 
543
                                       const nsXPTParamInfo * param,
 
544
                                       nsIID * *_retval)
 
545
{
 
546
    if(methodIndex < mMethodBaseIndex)
 
547
        return mParent->GetIIDForParam(methodIndex, param, _retval);
 
548
 
 
549
    const XPTTypeDescriptor* td = GetPossiblyNestedType(param);
 
550
    NS_ASSERTION(XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE,
 
551
                 "not an interface");
 
552
 
 
553
    nsIInterfaceInfo* info = mSet->InfoAtNoAddRef(td->type.iface);
 
554
    if(!info)
 
555
        return NS_ERROR_FAILURE;
 
556
 
 
557
    return info->GetInterfaceIID(_retval);
 
558
}
 
559
 
 
560
/* nsXPTType getTypeForParam (in PRUint16 methodIndex, [const] in
 
561
   nsXPTParamInfoPtr param, in PRUint16 dimension); */
 
562
NS_IMETHODIMP
 
563
nsGenericInterfaceInfo::GetTypeForParam(PRUint16 methodIndex,
 
564
                                        const nsXPTParamInfo * param,
 
565
                                        PRUint16 dimension, nsXPTType *_retval)
 
566
{
 
567
    if(methodIndex < mMethodBaseIndex)
 
568
        return mParent->GetTypeForParam(methodIndex, param, dimension,
 
569
                                        _retval);
 
570
 
 
571
    const XPTTypeDescriptor *td =
 
572
        dimension ? GetTypeInArray(param, dimension) : &param->type;
 
573
 
 
574
    *_retval = nsXPTType(td->prefix);
 
575
    return NS_OK;
 
576
}
 
577
 
 
578
/* PRUint8 getSizeIsArgNumberForParam (in PRUint16 methodIndex,
 
579
   [const] in nsXPTParamInfoPtr param, in PRUint16 dimension); */
 
580
NS_IMETHODIMP
 
581
nsGenericInterfaceInfo::GetSizeIsArgNumberForParam(PRUint16 methodIndex,
 
582
                                                   const nsXPTParamInfo *param,
 
583
                                                   PRUint16 dimension,
 
584
                                                   PRUint8 *_retval)
 
585
{
 
586
    if(methodIndex < mMethodBaseIndex)
 
587
        return mParent->GetSizeIsArgNumberForParam(methodIndex, param,
 
588
                                                   dimension, _retval);
 
589
 
 
590
    const XPTTypeDescriptor *td =
 
591
        dimension ? GetTypeInArray(param, dimension) : &param->type;
 
592
 
 
593
    *_retval = td->argnum;
 
594
    return NS_OK;
 
595
}
 
596
 
 
597
/* PRUint8 getLengthIsArgNumberForParam (in PRUint16 methodIndex,
 
598
   [const] in nsXPTParamInfoPtr param, in PRUint16 dimension); */
 
599
NS_IMETHODIMP
 
600
nsGenericInterfaceInfo::GetLengthIsArgNumberForParam(PRUint16 methodIndex,
 
601
                                                     const nsXPTParamInfo *param,
 
602
                                                     PRUint16 dimension,
 
603
                                                     PRUint8 *_retval)
 
604
{
 
605
    if(methodIndex < mMethodBaseIndex)
 
606
        return mParent->GetLengthIsArgNumberForParam(methodIndex, param,
 
607
                                                     dimension, _retval);
 
608
 
 
609
    const XPTTypeDescriptor *td =
 
610
        dimension ? GetTypeInArray(param, dimension) : &param->type;
 
611
 
 
612
    *_retval = td->argnum2;
 
613
    return NS_OK;
 
614
}
 
615
 
 
616
/* PRUint8 getInterfaceIsArgNumberForParam (in PRUint16 methodIndex,
 
617
   [const] in nsXPTParamInfoPtr param); */
 
618
NS_IMETHODIMP
 
619
nsGenericInterfaceInfo::GetInterfaceIsArgNumberForParam(PRUint16 methodIndex,
 
620
                                                        const nsXPTParamInfo *param,
 
621
                                                        PRUint8 *_retval)
 
622
{
 
623
    if(methodIndex < mMethodBaseIndex)
 
624
        return mParent->GetInterfaceIsArgNumberForParam(methodIndex, param,
 
625
                                                        _retval);
 
626
 
 
627
    const XPTTypeDescriptor* td = GetPossiblyNestedType(param);
 
628
    NS_ASSERTION(XPT_TDP_TAG(td->prefix) == TD_INTERFACE_IS_TYPE,
 
629
                 "not an interface");
 
630
 
 
631
    *_retval = td->argnum;
 
632
    return NS_OK;
 
633
}
 
634
 
 
635
/* PRBool isIID (in nsIIDPtr IID); */
 
636
NS_IMETHODIMP
 
637
nsGenericInterfaceInfo::IsIID(const nsIID * IID, PRBool *_retval)
 
638
{
 
639
    *_retval = mIID.Equals(*IID);
 
640
    return NS_OK;
 
641
}
 
642
 
 
643
/* void getNameShared ([shared, retval] out string name); */
 
644
NS_IMETHODIMP
 
645
nsGenericInterfaceInfo::GetNameShared(const char **name)
 
646
{
 
647
    *name = mName;
 
648
    return NS_OK;
 
649
}
 
650
 
 
651
/* void getIIDShared ([shared, retval] out nsIIDPtrShared iid); */
 
652
NS_IMETHODIMP
 
653
nsGenericInterfaceInfo::GetIIDShared(const nsIID * *iid)
 
654
{
 
655
    *iid = &mIID;
 
656
    return NS_OK;
 
657
}
 
658
 
 
659
/* PRBool isFunction (); */
 
660
NS_IMETHODIMP
 
661
nsGenericInterfaceInfo::IsFunction(PRBool *_retval)
 
662
{
 
663
    *_retval = XPT_ID_IS_FUNCTION(mFlags) != 0;
 
664
    return NS_OK;
 
665
}
 
666
 
 
667
/* PRBool hasAncestor (in nsIIDPtr iid); */
 
668
NS_IMETHODIMP
 
669
nsGenericInterfaceInfo::HasAncestor(const nsIID * iid, PRBool *_retval)
 
670
{
 
671
    *_retval = PR_FALSE;
 
672
 
 
673
    nsCOMPtr<nsIInterfaceInfo> current =
 
674
        NS_STATIC_CAST(nsIInterfaceInfo*, this);
 
675
    while(current)
 
676
    {
 
677
        PRBool same;
 
678
        if(NS_SUCCEEDED(current->IsIID(iid, &same)) && same)
 
679
        {
 
680
            *_retval = PR_TRUE;
 
681
            break;
 
682
        }
 
683
        nsCOMPtr<nsIInterfaceInfo> temp(current);
 
684
        temp->GetParent(getter_AddRefs(current));
 
685
    }
 
686
    return NS_OK;
 
687
}
 
688
 
 
689
/* [notxpcom] nsresult getIIDForParamNoAlloc (in PRUint16 methodIndex,
 
690
   [const] in nsXPTParamInfoPtr param, out nsIID iid); */
 
691
NS_IMETHODIMP_(nsresult)
 
692
nsGenericInterfaceInfo::GetIIDForParamNoAlloc(PRUint16 methodIndex,
 
693
                                              const nsXPTParamInfo * param,
 
694
                                              nsIID *iid)
 
695
{
 
696
    if(methodIndex < mMethodBaseIndex)
 
697
        return mParent->GetIIDForParamNoAlloc(methodIndex, param, iid);
 
698
 
 
699
    const XPTTypeDescriptor* td = GetPossiblyNestedType(param);
 
700
    NS_ASSERTION(XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE,
 
701
                 "not an interface");
 
702
 
 
703
    nsIInterfaceInfo* info = mSet->InfoAtNoAddRef(td->type.iface);
 
704
    if(!info)
 
705
        return NS_ERROR_FAILURE;
 
706
 
 
707
    const nsIID* iidp;
 
708
    nsresult rv = info->GetIIDShared(&iidp);
 
709
    if(NS_FAILED(rv))
 
710
        return rv;
 
711
 
 
712
    *iid = *iidp;
 
713
    return NS_OK;
 
714
}