/src/libreoffice/cppu/source/uno/data.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include <sal/log.hxx> |
22 | | #include <uno/data.h> |
23 | | |
24 | | #include "constr.hxx" |
25 | | #include "destr.hxx" |
26 | | #include "copy.hxx" |
27 | | #include "assign.hxx" |
28 | | #include "eq.hxx" |
29 | | |
30 | | using namespace ::cppu; |
31 | | |
32 | | namespace cppu |
33 | | { |
34 | | |
35 | | // Sequence<>() (default ctor) relies on this being static: |
36 | | uno_Sequence g_emptySeq = { 1, 0, { 0 } }; |
37 | | typelib_TypeDescriptionReference * g_pVoidType = nullptr; |
38 | | |
39 | | |
40 | | void * binuno_queryInterface( void * pUnoI, typelib_TypeDescriptionReference * pDestType ) |
41 | 0 | { |
42 | | // init queryInterface() td |
43 | 0 | static typelib_TypeDescription* g_pQITD = []() { |
44 | 0 | typelib_TypeDescriptionReference* type_XInterface |
45 | 0 | = *typelib_static_type_getByTypeClass(typelib_TypeClass_INTERFACE); |
46 | 0 | typelib_InterfaceTypeDescription* pTXInterfaceDescr = nullptr; |
47 | 0 | TYPELIB_DANGER_GET(reinterpret_cast<typelib_TypeDescription**>(&pTXInterfaceDescr), |
48 | 0 | type_XInterface); |
49 | 0 | assert(pTXInterfaceDescr->ppAllMembers); |
50 | 0 | typelib_TypeDescription* pQITD = nullptr; |
51 | 0 | typelib_typedescriptionreference_getDescription(&pQITD, |
52 | 0 | pTXInterfaceDescr->ppAllMembers[0]); |
53 | 0 | TYPELIB_DANGER_RELEASE(&pTXInterfaceDescr->aBase); |
54 | 0 | return pQITD; |
55 | 0 | }(); |
56 | |
|
57 | 0 | uno_Any aRet, aExc; |
58 | 0 | uno_Any * pExc = &aExc; |
59 | 0 | void * aArgs[ 1 ]; |
60 | 0 | aArgs[ 0 ] = &pDestType; |
61 | 0 | (*static_cast<uno_Interface *>(pUnoI)->pDispatcher)( |
62 | 0 | static_cast<uno_Interface *>(pUnoI), g_pQITD, &aRet, aArgs, &pExc ); |
63 | |
|
64 | 0 | uno_Interface * ret = nullptr; |
65 | 0 | if (nullptr == pExc) |
66 | 0 | { |
67 | 0 | typelib_TypeDescriptionReference * ret_type = aRet.pType; |
68 | 0 | switch (ret_type->eTypeClass) |
69 | 0 | { |
70 | 0 | case typelib_TypeClass_VOID: // common case |
71 | 0 | typelib_typedescriptionreference_release( ret_type ); |
72 | 0 | break; |
73 | 0 | case typelib_TypeClass_INTERFACE: |
74 | | // tweaky... avoiding acquire/ release pair |
75 | 0 | typelib_typedescriptionreference_release( ret_type ); |
76 | 0 | ret = static_cast<uno_Interface *>(aRet.pReserved); // serving acquired interface |
77 | 0 | break; |
78 | 0 | default: |
79 | 0 | _destructAny( &aRet, nullptr ); |
80 | 0 | break; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | else |
84 | 0 | { |
85 | 0 | SAL_WARN( |
86 | 0 | "cppu", |
87 | 0 | "exception occurred querying for interface " |
88 | 0 | << OUString(pDestType->pTypeName) << ": [" |
89 | 0 | << OUString(pExc->pType->pTypeName) << "] " |
90 | 0 | << *static_cast<OUString const *>(pExc->pData)); |
91 | | // Message is very first member |
92 | 0 | uno_any_destruct( pExc, nullptr ); |
93 | 0 | } |
94 | 0 | return ret; |
95 | 0 | } |
96 | | |
97 | | |
98 | | void defaultConstructStruct( |
99 | | void * pMem, |
100 | | typelib_CompoundTypeDescription * pCompType ) |
101 | 30.4M | { |
102 | 30.4M | _defaultConstructStruct( pMem, pCompType ); |
103 | 30.4M | } |
104 | | |
105 | | void copyConstructStruct( |
106 | | void * pDest, void * pSource, |
107 | | typelib_CompoundTypeDescription * pTypeDescr, |
108 | | uno_AcquireFunc acquire, uno_Mapping * mapping ) |
109 | 4.64M | { |
110 | 4.64M | _copyConstructStruct( pDest, pSource, pTypeDescr, acquire, mapping ); |
111 | 4.64M | } |
112 | | |
113 | | void destructStruct( |
114 | | void * pValue, |
115 | | typelib_CompoundTypeDescription * pTypeDescr, |
116 | | uno_ReleaseFunc release ) |
117 | 35.1M | { |
118 | 35.1M | _destructStruct( pValue, pTypeDescr, release ); |
119 | 35.1M | } |
120 | | |
121 | | bool equalStruct( |
122 | | void * pDest, void *pSource, |
123 | | typelib_CompoundTypeDescription * pTypeDescr, |
124 | | uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) |
125 | 20.5k | { |
126 | 20.5k | return _equalStruct( pDest, pSource, pTypeDescr, queryInterface, release ); |
127 | 20.5k | } |
128 | | |
129 | | bool assignStruct( |
130 | | void * pDest, void * pSource, |
131 | | typelib_CompoundTypeDescription * pTypeDescr, |
132 | | uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) |
133 | 251k | { |
134 | 251k | return _assignStruct( pDest, pSource, pTypeDescr, queryInterface, acquire, release ); |
135 | 251k | } |
136 | | |
137 | | |
138 | | uno_Sequence * copyConstructSequence( |
139 | | uno_Sequence * pSource, |
140 | | typelib_TypeDescriptionReference * pElementType, |
141 | | uno_AcquireFunc acquire, uno_Mapping * mapping ) |
142 | 6.34M | { |
143 | 6.34M | return icopyConstructSequence( pSource, pElementType, acquire, mapping ); |
144 | 6.34M | } |
145 | | |
146 | | |
147 | | void destructSequence( |
148 | | uno_Sequence * pSequence, |
149 | | typelib_TypeDescriptionReference * pType, |
150 | | typelib_TypeDescription * pTypeDescr, |
151 | | uno_ReleaseFunc release ) |
152 | 6.69M | { |
153 | 6.69M | idestructSequence( pSequence, pType, pTypeDescr, release ); |
154 | 6.69M | } |
155 | | |
156 | | |
157 | | bool equalSequence( |
158 | | uno_Sequence * pDest, uno_Sequence * pSource, |
159 | | typelib_TypeDescriptionReference * pElementType, |
160 | | uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) |
161 | 11.2k | { |
162 | 11.2k | return _equalSequence( pDest, pSource, pElementType, queryInterface, release ); |
163 | 11.2k | } |
164 | | |
165 | | } |
166 | | |
167 | | extern "C" |
168 | | { |
169 | | |
170 | | void SAL_CALL uno_type_constructData( |
171 | | void * pMem, typelib_TypeDescriptionReference * pType ) noexcept |
172 | 429M | { |
173 | 429M | _defaultConstructData( pMem, pType, nullptr ); |
174 | 429M | } |
175 | | |
176 | | void SAL_CALL uno_constructData( |
177 | | void * pMem, typelib_TypeDescription * pTypeDescr ) noexcept |
178 | 0 | { |
179 | 0 | _defaultConstructData( pMem, pTypeDescr->pWeakRef, pTypeDescr ); |
180 | 0 | } |
181 | | |
182 | | void SAL_CALL uno_type_destructData( |
183 | | void * pValue, typelib_TypeDescriptionReference * pType, |
184 | | uno_ReleaseFunc release ) noexcept |
185 | 891M | { |
186 | 891M | _destructData( pValue, pType, nullptr, release ); |
187 | 891M | } |
188 | | |
189 | | void SAL_CALL uno_destructData( |
190 | | void * pValue, |
191 | | typelib_TypeDescription * pTypeDescr, |
192 | | uno_ReleaseFunc release ) noexcept |
193 | 128k | { |
194 | 128k | _destructData( pValue, pTypeDescr->pWeakRef, pTypeDescr, release ); |
195 | 128k | } |
196 | | |
197 | | void SAL_CALL uno_type_copyData( |
198 | | void * pDest, void * pSource, |
199 | | typelib_TypeDescriptionReference * pType, |
200 | | uno_AcquireFunc acquire ) noexcept |
201 | 461M | { |
202 | 461M | _copyConstructData( pDest, pSource, pType, nullptr, acquire, nullptr ); |
203 | 461M | } |
204 | | |
205 | | void SAL_CALL uno_copyData( |
206 | | void * pDest, void * pSource, |
207 | | typelib_TypeDescription * pTypeDescr, |
208 | | uno_AcquireFunc acquire ) noexcept |
209 | 0 | { |
210 | 0 | _copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, acquire, nullptr ); |
211 | 0 | } |
212 | | |
213 | | void SAL_CALL uno_type_copyAndConvertData( |
214 | | void * pDest, void * pSource, |
215 | | typelib_TypeDescriptionReference * pType, |
216 | | uno_Mapping * mapping ) noexcept |
217 | 381k | { |
218 | 381k | _copyConstructData( pDest, pSource, pType, nullptr, nullptr, mapping ); |
219 | 381k | } |
220 | | |
221 | | void SAL_CALL uno_copyAndConvertData( |
222 | | void * pDest, void * pSource, |
223 | | typelib_TypeDescription * pTypeDescr, |
224 | | uno_Mapping * mapping ) noexcept |
225 | 64.1k | { |
226 | 64.1k | _copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, nullptr, mapping ); |
227 | 64.1k | } |
228 | | |
229 | | sal_Bool SAL_CALL uno_type_equalData( |
230 | | void * pVal1, typelib_TypeDescriptionReference * pVal1Type, |
231 | | void * pVal2, typelib_TypeDescriptionReference * pVal2Type, |
232 | | uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) noexcept |
233 | 7.90M | { |
234 | 7.90M | return _equalData( |
235 | 7.90M | pVal1, pVal1Type, nullptr, |
236 | 7.90M | pVal2, pVal2Type, |
237 | 7.90M | queryInterface, release ); |
238 | 7.90M | } |
239 | | |
240 | | sal_Bool SAL_CALL uno_equalData( |
241 | | void * pVal1, typelib_TypeDescription * pVal1TD, |
242 | | void * pVal2, typelib_TypeDescription * pVal2TD, |
243 | | uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) noexcept |
244 | 0 | { |
245 | 0 | return _equalData( |
246 | 0 | pVal1, pVal1TD->pWeakRef, pVal1TD, |
247 | 0 | pVal2, pVal2TD->pWeakRef, |
248 | 0 | queryInterface, release ); |
249 | 0 | } |
250 | | |
251 | | sal_Bool SAL_CALL uno_type_assignData( |
252 | | void * pDest, typelib_TypeDescriptionReference * pDestType, |
253 | | void * pSource, typelib_TypeDescriptionReference * pSourceType, |
254 | | uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) noexcept |
255 | 40.7M | { |
256 | 40.7M | return _assignData( |
257 | 40.7M | pDest, pDestType, nullptr, |
258 | 40.7M | pSource, pSourceType, nullptr, |
259 | 40.7M | queryInterface, acquire, release ); |
260 | 40.7M | } |
261 | | |
262 | | sal_Bool SAL_CALL uno_assignData( |
263 | | void * pDest, typelib_TypeDescription * pDestTD, |
264 | | void * pSource, typelib_TypeDescription * pSourceTD, |
265 | | uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) noexcept |
266 | 0 | { |
267 | 0 | return _assignData( |
268 | 0 | pDest, pDestTD->pWeakRef, pDestTD, |
269 | 0 | pSource, pSourceTD->pWeakRef, pSourceTD, |
270 | 0 | queryInterface, acquire, release ); |
271 | 0 | } |
272 | | |
273 | | sal_Bool SAL_CALL uno_type_isAssignableFromData( |
274 | | typelib_TypeDescriptionReference * pAssignable, |
275 | | void * pFrom, typelib_TypeDescriptionReference * pFromType, |
276 | | uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) noexcept |
277 | 181k | { |
278 | 181k | if (::typelib_typedescriptionreference_isAssignableFrom( pAssignable, pFromType )) |
279 | 153k | return true; |
280 | 27.1k | if (typelib_TypeClass_INTERFACE != pFromType->eTypeClass || |
281 | 22.4k | typelib_TypeClass_INTERFACE != pAssignable->eTypeClass) |
282 | 5.51k | { |
283 | 5.51k | return false; |
284 | 5.51k | } |
285 | | |
286 | | // query |
287 | 21.6k | if (nullptr == pFrom) |
288 | 0 | return false; |
289 | 21.6k | void * pInterface = *static_cast<void **>(pFrom); |
290 | 21.6k | if (nullptr == pInterface) |
291 | 0 | return false; |
292 | | |
293 | 21.6k | if (nullptr == queryInterface) |
294 | 0 | queryInterface = binuno_queryInterface; |
295 | 21.6k | void * p = (*queryInterface)( pInterface, pAssignable ); |
296 | 21.6k | _release( p, release ); |
297 | 21.6k | return (nullptr != p); |
298 | 21.6k | } |
299 | | |
300 | | } |
301 | | |
302 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |