|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 /* Implement shared vtbl methods. */ |
|
8 |
|
9 #include "xptcprivate.h" |
|
10 #include "xptiprivate.h" |
|
11 |
|
12 nsresult ATTRIBUTE_USED |
|
13 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args) |
|
14 { |
|
15 #define PARAM_BUFFER_COUNT 16 |
|
16 |
|
17 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
|
18 nsXPTCMiniVariant* dispatchParams = nullptr; |
|
19 const nsXPTMethodInfo* info; |
|
20 uint8_t paramCount; |
|
21 uint8_t i; |
|
22 nsresult result = NS_ERROR_FAILURE; |
|
23 |
|
24 NS_ASSERTION(self,"no self"); |
|
25 |
|
26 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
|
27 NS_ASSERTION(info,"no interface info"); |
|
28 |
|
29 paramCount = info->GetParamCount(); |
|
30 |
|
31 // setup variant array pointer |
|
32 if(paramCount > PARAM_BUFFER_COUNT) |
|
33 dispatchParams = new nsXPTCMiniVariant[paramCount]; |
|
34 else |
|
35 dispatchParams = paramBuffer; |
|
36 NS_ASSERTION(dispatchParams,"no place for params"); |
|
37 |
|
38 uint32_t* ap = args; |
|
39 for(i = 0; i < paramCount; i++, ap++) |
|
40 { |
|
41 const nsXPTParamInfo& param = info->GetParam(i); |
|
42 const nsXPTType& type = param.GetType(); |
|
43 nsXPTCMiniVariant* dp = &dispatchParams[i]; |
|
44 |
|
45 if(param.IsOut() || !type.IsArithmetic()) |
|
46 { |
|
47 dp->val.p = (void*) *ap; |
|
48 continue; |
|
49 } |
|
50 // else |
|
51 dp->val.p = (void*) *ap; |
|
52 switch(type) |
|
53 { |
|
54 case nsXPTType::T_I64 : dp->val.i64 = *((int64_t*) ap); ap++; break; |
|
55 case nsXPTType::T_U64 : dp->val.u64 = *((uint64_t*)ap); ap++; break; |
|
56 case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break; |
|
57 } |
|
58 } |
|
59 |
|
60 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); |
|
61 |
|
62 if(dispatchParams != paramBuffer) |
|
63 delete [] dispatchParams; |
|
64 |
|
65 return result; |
|
66 } |
|
67 |
|
68 #define STUB_ENTRY(n) |
|
69 |
|
70 #define SENTINEL_ENTRY(n) \ |
|
71 nsresult nsXPTCStubBase::Sentinel##n() \ |
|
72 { \ |
|
73 NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
|
74 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
75 } |
|
76 |
|
77 #include "xptcstubsdef.inc" |