1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski #ifndef PRIM_HXX
24*b1cdbd2cSJim Jagielski #define PRIM_HXX
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski #include "typelib/typedescription.h"
27*b1cdbd2cSJim Jagielski #ifndef _typelib_TypeClass_H_
28*b1cdbd2cSJim Jagielski #include "typelib/typeclass.h"
29*b1cdbd2cSJim Jagielski #endif
30*b1cdbd2cSJim Jagielski #include "uno/sequence2.h"
31*b1cdbd2cSJim Jagielski #include "uno/any2.h"
32*b1cdbd2cSJim Jagielski #include "uno/data.h"
33*b1cdbd2cSJim Jagielski #include "uno/mapping.h"
34*b1cdbd2cSJim Jagielski #include "uno/dispatcher.h"
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim Jagielski #ifndef _OSL_INTERLCK_H
37*b1cdbd2cSJim Jagielski #include "osl/interlck.h"
38*b1cdbd2cSJim Jagielski #endif
39*b1cdbd2cSJim Jagielski #include "osl/diagnose.h"
40*b1cdbd2cSJim Jagielski #ifndef _RTL_USTRING_HXX
41*b1cdbd2cSJim Jagielski #include "rtl/ustring.hxx"
42*b1cdbd2cSJim Jagielski #endif
43*b1cdbd2cSJim Jagielski #include "rtl/alloc.h"
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski #if OSL_DEBUG_LEVEL > 1
46*b1cdbd2cSJim Jagielski #include "rtl/ustrbuf.hxx"
47*b1cdbd2cSJim Jagielski #include "rtl/string.hxx"
48*b1cdbd2cSJim Jagielski #endif
49*b1cdbd2cSJim Jagielski
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski namespace cppu
52*b1cdbd2cSJim Jagielski {
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielski extern uno_Sequence g_emptySeq;
55*b1cdbd2cSJim Jagielski extern typelib_TypeDescriptionReference * g_pVoidType;
56*b1cdbd2cSJim Jagielski
57*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
_map(void * p,typelib_TypeDescriptionReference * pType,typelib_TypeDescription * pTypeDescr,uno_Mapping * mapping)58*b1cdbd2cSJim Jagielski inline void * _map(
59*b1cdbd2cSJim Jagielski void * p,
60*b1cdbd2cSJim Jagielski typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
61*b1cdbd2cSJim Jagielski uno_Mapping * mapping )
62*b1cdbd2cSJim Jagielski SAL_THROW( () )
63*b1cdbd2cSJim Jagielski {
64*b1cdbd2cSJim Jagielski void * pRet = 0;
65*b1cdbd2cSJim Jagielski if (p)
66*b1cdbd2cSJim Jagielski {
67*b1cdbd2cSJim Jagielski if (pTypeDescr)
68*b1cdbd2cSJim Jagielski {
69*b1cdbd2cSJim Jagielski (*mapping->mapInterface)(
70*b1cdbd2cSJim Jagielski mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr );
71*b1cdbd2cSJim Jagielski }
72*b1cdbd2cSJim Jagielski else
73*b1cdbd2cSJim Jagielski {
74*b1cdbd2cSJim Jagielski TYPELIB_DANGER_GET( &pTypeDescr, pType );
75*b1cdbd2cSJim Jagielski (*mapping->mapInterface)(
76*b1cdbd2cSJim Jagielski mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr );
77*b1cdbd2cSJim Jagielski TYPELIB_DANGER_RELEASE( pTypeDescr );
78*b1cdbd2cSJim Jagielski }
79*b1cdbd2cSJim Jagielski }
80*b1cdbd2cSJim Jagielski return pRet;
81*b1cdbd2cSJim Jagielski }
82*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
_acquire(void * p,uno_AcquireFunc acquire)83*b1cdbd2cSJim Jagielski inline void _acquire( void * p, uno_AcquireFunc acquire ) SAL_THROW( () )
84*b1cdbd2cSJim Jagielski {
85*b1cdbd2cSJim Jagielski if (p)
86*b1cdbd2cSJim Jagielski {
87*b1cdbd2cSJim Jagielski if (acquire)
88*b1cdbd2cSJim Jagielski {
89*b1cdbd2cSJim Jagielski (*acquire)( p );
90*b1cdbd2cSJim Jagielski }
91*b1cdbd2cSJim Jagielski else
92*b1cdbd2cSJim Jagielski {
93*b1cdbd2cSJim Jagielski (*((uno_Interface *)p)->acquire)( (uno_Interface *)p );
94*b1cdbd2cSJim Jagielski }
95*b1cdbd2cSJim Jagielski }
96*b1cdbd2cSJim Jagielski }
97*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
_release(void * p,uno_ReleaseFunc release)98*b1cdbd2cSJim Jagielski inline void _release( void * p, uno_ReleaseFunc release ) SAL_THROW( () )
99*b1cdbd2cSJim Jagielski {
100*b1cdbd2cSJim Jagielski if (p)
101*b1cdbd2cSJim Jagielski {
102*b1cdbd2cSJim Jagielski if (release)
103*b1cdbd2cSJim Jagielski {
104*b1cdbd2cSJim Jagielski (*release)( p );
105*b1cdbd2cSJim Jagielski }
106*b1cdbd2cSJim Jagielski else
107*b1cdbd2cSJim Jagielski {
108*b1cdbd2cSJim Jagielski (*((uno_Interface *)p)->release)( (uno_Interface *)p );
109*b1cdbd2cSJim Jagielski }
110*b1cdbd2cSJim Jagielski }
111*b1cdbd2cSJim Jagielski }
112*b1cdbd2cSJim Jagielski
113*b1cdbd2cSJim Jagielski //------------------------------------------------------------------------------
calcSeqMemSize(sal_Int32 nElementSize,sal_Int32 nElements)114*b1cdbd2cSJim Jagielski inline sal_uInt32 calcSeqMemSize(
115*b1cdbd2cSJim Jagielski sal_Int32 nElementSize, sal_Int32 nElements )
116*b1cdbd2cSJim Jagielski {
117*b1cdbd2cSJim Jagielski sal_uInt64 nSize =
118*b1cdbd2cSJim Jagielski (sal_uInt64) SAL_SEQUENCE_HEADER_SIZE +
119*b1cdbd2cSJim Jagielski ((sal_uInt64) nElementSize * (sal_uInt64) nElements);
120*b1cdbd2cSJim Jagielski if (nSize > 0xffffffffU)
121*b1cdbd2cSJim Jagielski return 0;
122*b1cdbd2cSJim Jagielski else
123*b1cdbd2cSJim Jagielski return (sal_uInt32) nSize;
124*b1cdbd2cSJim Jagielski }
125*b1cdbd2cSJim Jagielski
126*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
createEmptySequence()127*b1cdbd2cSJim Jagielski inline uno_Sequence * createEmptySequence() SAL_THROW( () )
128*b1cdbd2cSJim Jagielski {
129*b1cdbd2cSJim Jagielski ::osl_incrementInterlockedCount( &g_emptySeq.nRefCount );
130*b1cdbd2cSJim Jagielski return &g_emptySeq;
131*b1cdbd2cSJim Jagielski }
132*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
_getVoidType()133*b1cdbd2cSJim Jagielski inline typelib_TypeDescriptionReference * _getVoidType()
134*b1cdbd2cSJim Jagielski SAL_THROW( () )
135*b1cdbd2cSJim Jagielski {
136*b1cdbd2cSJim Jagielski if (! g_pVoidType)
137*b1cdbd2cSJim Jagielski {
138*b1cdbd2cSJim Jagielski g_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID );
139*b1cdbd2cSJim Jagielski }
140*b1cdbd2cSJim Jagielski ::typelib_typedescriptionreference_acquire( g_pVoidType );
141*b1cdbd2cSJim Jagielski return g_pVoidType;
142*b1cdbd2cSJim Jagielski }
143*b1cdbd2cSJim Jagielski
144*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
145*b1cdbd2cSJim Jagielski #if OSL_DEBUG_LEVEL > 0
146*b1cdbd2cSJim Jagielski #define CONSTRUCT_EMPTY_ANY( pAny ) \
147*b1cdbd2cSJim Jagielski (pAny)->pType = _getVoidType(); \
148*b1cdbd2cSJim Jagielski (pAny)->pData = (void *)0xdeadbeef;
149*b1cdbd2cSJim Jagielski #else
150*b1cdbd2cSJim Jagielski #define CONSTRUCT_EMPTY_ANY( pAny ) \
151*b1cdbd2cSJim Jagielski (pAny)->pType = _getVoidType(); \
152*b1cdbd2cSJim Jagielski (pAny)->pData = (pAny);
153*b1cdbd2cSJim Jagielski #endif
154*b1cdbd2cSJim Jagielski
155*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
156*b1cdbd2cSJim Jagielski #define TYPE_ACQUIRE( pType ) \
157*b1cdbd2cSJim Jagielski ::osl_incrementInterlockedCount( &(pType)->nRefCount );
158*b1cdbd2cSJim Jagielski
159*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
160*b1cdbd2cSJim Jagielski extern "C" void * binuno_queryInterface(
161*b1cdbd2cSJim Jagielski void * pUnoI, typelib_TypeDescriptionReference * pDestType );
162*b1cdbd2cSJim Jagielski
163*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
_unionGetSetType(void * pUnion,typelib_TypeDescription * pTD)164*b1cdbd2cSJim Jagielski inline typelib_TypeDescriptionReference * _unionGetSetType(
165*b1cdbd2cSJim Jagielski void * pUnion, typelib_TypeDescription * pTD )
166*b1cdbd2cSJim Jagielski SAL_THROW( () )
167*b1cdbd2cSJim Jagielski {
168*b1cdbd2cSJim Jagielski typelib_TypeDescriptionReference * pRet = 0;
169*b1cdbd2cSJim Jagielski sal_Int32 nPos;
170*b1cdbd2cSJim Jagielski
171*b1cdbd2cSJim Jagielski sal_Int64 * pDiscr = ((typelib_UnionTypeDescription *)pTD)->pDiscriminants;
172*b1cdbd2cSJim Jagielski sal_Int64 nDiscr = *(sal_Int64 *)pUnion;
173*b1cdbd2cSJim Jagielski for ( nPos = ((typelib_UnionTypeDescription *)pTD)->nMembers; nPos--; )
174*b1cdbd2cSJim Jagielski {
175*b1cdbd2cSJim Jagielski if (pDiscr[nPos] == nDiscr)
176*b1cdbd2cSJim Jagielski {
177*b1cdbd2cSJim Jagielski pRet = ((typelib_UnionTypeDescription *)pTD)->ppTypeRefs[nPos];
178*b1cdbd2cSJim Jagielski break;
179*b1cdbd2cSJim Jagielski }
180*b1cdbd2cSJim Jagielski }
181*b1cdbd2cSJim Jagielski if (nPos >= 0)
182*b1cdbd2cSJim Jagielski {
183*b1cdbd2cSJim Jagielski // default
184*b1cdbd2cSJim Jagielski pRet = ((typelib_UnionTypeDescription *)pTD)->pDefaultTypeRef;
185*b1cdbd2cSJim Jagielski }
186*b1cdbd2cSJim Jagielski typelib_typedescriptionreference_acquire( pRet );
187*b1cdbd2cSJim Jagielski return pRet;
188*b1cdbd2cSJim Jagielski }
189*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------------------------------------
_type_equals(typelib_TypeDescriptionReference * pType1,typelib_TypeDescriptionReference * pType2)190*b1cdbd2cSJim Jagielski inline sal_Bool _type_equals(
191*b1cdbd2cSJim Jagielski typelib_TypeDescriptionReference * pType1, typelib_TypeDescriptionReference * pType2 )
192*b1cdbd2cSJim Jagielski SAL_THROW( () )
193*b1cdbd2cSJim Jagielski {
194*b1cdbd2cSJim Jagielski return (pType1 == pType2 ||
195*b1cdbd2cSJim Jagielski (pType1->eTypeClass == pType2->eTypeClass &&
196*b1cdbd2cSJim Jagielski pType1->pTypeName->length == pType2->pTypeName->length &&
197*b1cdbd2cSJim Jagielski ::rtl_ustr_compare( pType1->pTypeName->buffer, pType2->pTypeName->buffer ) == 0));
198*b1cdbd2cSJim Jagielski }
199*b1cdbd2cSJim Jagielski
200*b1cdbd2cSJim Jagielski }
201*b1cdbd2cSJim Jagielski
202*b1cdbd2cSJim Jagielski #endif
203