LibreOffice Module cli_ure (master) 1
cli_data.cxx
Go to the documentation of this file.
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#if !defined WIN32_LEAN_AND_MEAN
21# define WIN32_LEAN_AND_MEAN
22#endif
23#include "windows.h"
24#include <ole2.h>
25
26#include <memory>
27
28#include "rtl/ustring.hxx"
29#include "rtl/ustrbuf.hxx"
30#include "uno/sequence2.h"
31#include "typelib/typedescription.hxx"
32#include "cli_proxy.h"
33#include "cli_base.h"
34#include "cli_bridge.h"
35
36#using <cli_uretypes.dll>
37
38#undef VOID
39
40namespace sri = System::Runtime::InteropServices;
41namespace sr = System::Reflection;
42namespace st = System::Text;
43namespace ucss = unoidl::com::sun::star;
44
45
46namespace cli_uno
47{
48System::String^ mapUnoPolymorphicName(System::String^ unoName);
49OUString mapCliTypeName(System::String^ typeName);
50System::String^ mapCliPolymorphicName(System::String^ unoName);
51System::String^ mapPolymorphicName(System::String^ unoName, bool bCliToUno);
52
53inline std::unique_ptr< rtl_mem > seq_allocate( sal_Int32 nElements, sal_Int32 nSize )
54{
55 std::unique_ptr< rtl_mem > seq(
57 uno_Sequence * p = (uno_Sequence *)seq.get();
58 p->nRefCount = 1;
59 p->nElements = nElements;
60 return seq;
61}
62
63System::Object^ Bridge::map_uno2cli(uno_Interface * pUnoI, typelib_InterfaceTypeDescription *pTD) const
64{
65 System::Object^ retVal= nullptr;
66 // get oid
67 rtl_uString * pOid = 0;
68 (*m_uno_env->getObjectIdentifier)( m_uno_env, &pOid, pUnoI );
69 OSL_ASSERT( 0 != pOid );
70 OUString oid(pOid, SAL_NO_ACQUIRE);
71
72 // see if the interface was already mapped
73 System::Type^ ifaceType= mapUnoType(reinterpret_cast<typelib_TypeDescription*>(pTD));
74 System::String^ sOid= mapUnoString(oid.pData);
75
76 System::Threading::Monitor::Enter( CliEnvHolder::g_cli_env );
77 try
78 {
79 retVal = CliEnvHolder::g_cli_env->getRegisteredInterface(sOid, ifaceType);
80 if (retVal)
81 {
82 // There is already a registered object. It can either be a proxy
83 // for the UNO object or a real cli object. In the first case we
84 // tell the proxy that it shall also represent the current UNO
85 // interface. If it already does that, then it does nothing
86 if (srr::RemotingServices::IsTransparentProxy(retVal))
87 {
88 UnoInterfaceProxy^ p = static_cast<UnoInterfaceProxy^>(
89 srr::RemotingServices::GetRealProxy(retVal));
90 p->addUnoInterface(pUnoI, pTD);
91 }
92 }
93 else
94 {
96 (Bridge *) this, pUnoI, pTD, oid );
97 }
98 }
99 __finally
100 {
101 System::Threading::Monitor::Exit( CliEnvHolder::g_cli_env );
102 }
103
104 return retVal;
105}
106
107uno_Interface* Bridge::map_cli2uno(System::Object^ cliObj, typelib_TypeDescription *pTD) const
108{
109 uno_Interface* retIface = NULL;
110 // get oid from dot net environment
111 System::String^ ds_oid = CliEnvHolder::g_cli_env->getObjectIdentifier( cliObj);
112 OUString ousOid = mapCliString(ds_oid);
113 // look if interface is already mapped
114 m_uno_env->getRegisteredInterface(m_uno_env, (void**) &retIface, ousOid.pData,
115 (typelib_InterfaceTypeDescription*) pTD);
116 if ( ! retIface)
117 {
118 System::Threading::Monitor::Enter(Cli_environment::typeid);
119 try
120 {
121 m_uno_env->getRegisteredInterface(m_uno_env, (void**) &retIface, ousOid.pData,
122 (typelib_InterfaceTypeDescription*) pTD);
123 if ( ! retIface)
124 {
125 retIface = CliProxy::create((Bridge*)this, cliObj, pTD, ousOid);
126 }
127 }
128 __finally
129 {
130 System::Threading::Monitor::Exit(Cli_environment::typeid);
131 }
132 }
133 return retIface;
134}
135
136inline System::Type^ loadCliType(rtl_uString * unoName)
137{
138 return loadCliType(mapUnoTypeName(unoName));
139}
140
141System::Type^ loadCliType(System::String ^ unoName)
142{
143 System::Type^ retVal= nullptr;
144 try
145 {
146 //If unoName denotes a polymorphic type, e.g com.sun.star.beans.Defaulted<System.Char>
147 //then we remove the type list, otherwise the type could not be loaded.
148 bool bIsPolymorphic = false;
149
150 System::String ^ loadName = unoName;
151 int index = unoName->IndexOf('<');
152 if (index != -1)
153 {
154 loadName = unoName->Substring(0, index);
155 bIsPolymorphic = true;
156 }
157 System::AppDomain^ currentDomain = System::AppDomain::CurrentDomain;
158 cli::array<sr::Assembly^>^ assems = currentDomain->GetAssemblies();
159 for (int i = 0; i < assems->Length; i++)
160 {
161 retVal = assems[i]->GetType(loadName, false);
162 if (retVal)
163 break;
164 }
165
166 if (retVal == nullptr)
167 {
168 System::String ^ msg = gcnew System::String("A type could not be loaded: ");
169 msg = System::String::Concat(msg, loadName);
171 }
172
173 if (bIsPolymorphic)
174 {
175 retVal = uno::PolymorphicType::GetType(retVal, unoName);
176 }
177 }
178 catch( System::Exception ^ e)
179 {
180 OUString ouMessage(mapCliString(e->Message));
181 throw BridgeRuntimeError(ouMessage);
182 }
183 return retVal;
184}
185
186System::Type^ mapUnoType(typelib_TypeDescription const * pTD)
187{
188 return mapUnoType(pTD->pWeakRef);
189}
190
191System::Type^ mapUnoType(typelib_TypeDescriptionReference const * pTD)
192{
193 System::Type ^ retVal = nullptr;
194 switch (pTD->eTypeClass)
195 {
196 case typelib_TypeClass_VOID:
197 retVal= void::typeid; break;
198 case typelib_TypeClass_CHAR:
199 retVal= System::Char::typeid; break;
200 case typelib_TypeClass_BOOLEAN:
201 retVal= System::Boolean::typeid; break;
202 case typelib_TypeClass_BYTE:
203 retVal= System::Byte::typeid; break;
204 case typelib_TypeClass_SHORT:
205 retVal= System::Int16::typeid; break;
206 case typelib_TypeClass_UNSIGNED_SHORT:
207 retVal= System::UInt16::typeid; break;
208 case typelib_TypeClass_LONG:
209 retVal= System::Int32::typeid; break;
210 case typelib_TypeClass_UNSIGNED_LONG:
211 retVal= System::UInt32::typeid; break;
212 case typelib_TypeClass_HYPER:
213 retVal= System::Int64::typeid; break;
214 case typelib_TypeClass_UNSIGNED_HYPER:
215 retVal= System::UInt64::typeid; break;
216 case typelib_TypeClass_FLOAT:
217 retVal= System::Single::typeid; break;
218 case typelib_TypeClass_DOUBLE:
219 retVal= System::Double::typeid; break;
220 case typelib_TypeClass_STRING:
221 retVal= System::String::typeid; break;
222 case typelib_TypeClass_TYPE:
223 retVal= System::Type::typeid; break;
224 case typelib_TypeClass_ANY:
225 retVal= uno::Any::typeid; break;
226 case typelib_TypeClass_ENUM:
227 case typelib_TypeClass_STRUCT:
228 case typelib_TypeClass_EXCEPTION:
229 retVal= loadCliType(pTD->pTypeName); break;
230 case typelib_TypeClass_INTERFACE:
231 {
232 //special handling for XInterface, since it does not exist in cli.
233 OUString usXInterface("com.sun.star.uno.XInterface");
234 if (usXInterface.equals(pTD->pTypeName))
235 retVal= System::Object::typeid;
236 else
237 retVal= loadCliType(pTD->pTypeName);
238 break;
239 }
240 case typelib_TypeClass_SEQUENCE:
241 {
242 css::uno::TypeDescription seqType(
243 const_cast<typelib_TypeDescriptionReference*>(pTD));
244 typelib_TypeDescriptionReference* pElementTDRef=
245 reinterpret_cast<typelib_IndirectTypeDescription*>(seqType.get())->pType;
246 switch (pElementTDRef->eTypeClass)
247 {
248 case typelib_TypeClass_CHAR:
249 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArChar)); break;
250 case typelib_TypeClass_BOOLEAN:
251 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArBoolean));
252 break;
253 case typelib_TypeClass_BYTE:
254 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArByte));
255 break;
256 case typelib_TypeClass_SHORT:
257 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArInt16));
258 break;
259 case typelib_TypeClass_UNSIGNED_SHORT:
260 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArUInt16));
261 break;
262 case typelib_TypeClass_LONG:
263 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArInt32));
264 break;
265 case typelib_TypeClass_UNSIGNED_LONG:
266 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArUInt32));
267 break;
268 case typelib_TypeClass_HYPER:
269 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArInt64));
270 break;
271 case typelib_TypeClass_UNSIGNED_HYPER:
272 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArUInt64));
273 break;
274 case typelib_TypeClass_FLOAT:
275 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArSingle));
276 break;
277 case typelib_TypeClass_DOUBLE:
278 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArDouble));
279 break;
280 case typelib_TypeClass_STRING:
281 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArString));
282 break;
283 case typelib_TypeClass_TYPE:
284 retVal= System::Type::GetType(const_cast<System::String^>(Constants::sArType));
285 break;
286 case typelib_TypeClass_ANY:
287 case typelib_TypeClass_ENUM:
288 case typelib_TypeClass_EXCEPTION:
289 case typelib_TypeClass_STRUCT:
290 case typelib_TypeClass_INTERFACE:
291 case typelib_TypeClass_SEQUENCE:
292 {
293 retVal= loadCliType(pTD->pTypeName);
294 break;
295 }
296 default:
297 //All cases should be handled by the case statements above
298 OSL_ASSERT(0);
299 break;
300 }
301 break;
302 }
303 default:
304 OSL_ASSERT(false);
305 break;
306 }
307 return retVal;
308}
309
312typelib_TypeDescriptionReference* mapCliType(System::Type^ cliType)
313{
314 typelib_TypeDescriptionReference* retVal= NULL;
315 if (cliType == nullptr)
316 {
318 typelib_TypeClass_VOID );
320 return retVal;
321 }
322 //check for Enum first,
323 //because otherwise case System::TypeCode::Int32 applies
324 if (cliType->IsEnum)
325 {
326 OUString usTypeName= mapCliTypeName(cliType->FullName);
327 css::uno::Type unoType(css::uno::TypeClass_ENUM, usTypeName);
328 retVal= unoType.getTypeLibType();
330 }
331 else
332 {
333 switch (System::Type::GetTypeCode(cliType))
334 {
335 case System::TypeCode::Boolean:
337 typelib_TypeClass_BOOLEAN );
339 break;
340 case System::TypeCode::Char:
342 typelib_TypeClass_CHAR );
344 break;
345 case System::TypeCode::Byte:
347 typelib_TypeClass_BYTE );
349 break;
350 case System::TypeCode::Int16:
352 typelib_TypeClass_SHORT );
354 break;
355 case System::TypeCode::Int32:
357 typelib_TypeClass_LONG );
359 break;
360 case System::TypeCode::Int64:
362 typelib_TypeClass_HYPER );
364 break;
365 case System::TypeCode::UInt16:
367 typelib_TypeClass_UNSIGNED_SHORT );
369 break;
370 case System::TypeCode::UInt32:
372 typelib_TypeClass_UNSIGNED_LONG );
374 break;
375 case System::TypeCode::UInt64:
377 typelib_TypeClass_UNSIGNED_HYPER );
379 break;
380 case System::TypeCode::Single:
382 typelib_TypeClass_FLOAT );
384 break;
385 case System::TypeCode::Double:
387 typelib_TypeClass_DOUBLE );
389 break;
390 case System::TypeCode::String:
392 typelib_TypeClass_STRING );
394 break;
395 default:
396 break;
397 }
398 }
399 if (retVal == NULL)
400 {
401 System::String^ cliTypeName= cliType->FullName;
402 // Void
403 if (const_cast<System::String^>(Constants::sVoid)->Equals(
404 cliTypeName))
405 {
407 typelib_TypeClass_VOID );
409 }
410 // Type
411 else if (const_cast<System::String^>(Constants::sType)->Equals(
412 cliTypeName))
413 {
415 typelib_TypeClass_TYPE );
417 }
418 // Any
419 else if (const_cast<System::String^>(Constants::sAny)->Equals(
420 cliTypeName))
421 {
423 typelib_TypeClass_ANY );
425 }
426 //struct, interfaces, sequences
427 else
428 {
429 OUString usTypeName;
430 uno::PolymorphicType ^ poly = dynamic_cast<uno::PolymorphicType^>(cliType);
431 if (poly != nullptr)
432 usTypeName = mapCliTypeName( poly->PolymorphicName);
433 else
434 usTypeName = mapCliTypeName(cliTypeName);
436 typelib_typedescription_getByName(&td, usTypeName.pData);
437 if (td)
438 {
439 retVal = td->pWeakRef;
442 }
443 }
444 }
445 if (retVal == NULL)
446 {
447 throw BridgeRuntimeError("[cli_uno bridge] mapCliType():could not map type: " + mapCliString(cliType->FullName));
448 }
449 return retVal;
450}
451
455System::String^ mapUnoTypeName(rtl_uString const * typeName)
456{
457 OUString usUnoName( const_cast< rtl_uString * >( typeName ) );
458 st::StringBuilder^ buf= gcnew st::StringBuilder();
459 //determine if the type is a sequence and its dimensions
460 int dims= 0;
461 if (usUnoName[0] == '[')
462 {
463 sal_Int32 index= 1;
464 while (true)
465 {
466 if (usUnoName[index++] == ']')
467 dims++;
468 if (usUnoName[index++] != '[')
469 break;
470 }
471 usUnoName = usUnoName.copy(index - 1);
472 }
473 System::String ^ sUnoName = mapUnoString(usUnoName.pData);
474 if (sUnoName->Equals(const_cast<System::String^>(Constants::usBool)))
475 buf->Append(const_cast<System::String^>(Constants::sBoolean));
476 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usChar)))
477 buf->Append(const_cast<System::String^>(Constants::sChar));
478 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usByte)))
479 buf->Append(const_cast<System::String^>(Constants::sByte));
480 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usShort)))
481 buf->Append(const_cast<System::String^>(Constants::sInt16));
482 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usUShort)))
483 buf->Append(const_cast<System::String^>(Constants::sUInt16));
484 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usLong)))
485 buf->Append(const_cast<System::String^>(Constants::sInt32));
486 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usULong)))
487 buf->Append(const_cast<System::String^>(Constants::sUInt32));
488 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usHyper)))
489 buf->Append(const_cast<System::String^>(Constants::sInt64));
490 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usUHyper)))
491 buf->Append(const_cast<System::String^>(Constants::sUInt64));
492 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usFloat)))
493 buf->Append(const_cast<System::String^>(Constants::sSingle));
494 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usDouble)))
495 buf->Append(const_cast<System::String^>(Constants::sDouble));
496 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usString)))
497 buf->Append(const_cast<System::String^>(Constants::sString));
498 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usVoid)))
499 buf->Append(const_cast<System::String^>(Constants::sVoid));
500 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usType)))
501 buf->Append(const_cast<System::String^>(Constants::sType));
502 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usXInterface)))
503 buf->Append(const_cast<System::String^>(Constants::sObject));
504 else if (sUnoName->Equals(const_cast<System::String^>(Constants::usAny)))
505 {
506 buf->Append(const_cast<System::String^>(Constants::sAny));
507 }
508 else
509 {
510 //put "unoidl." at the beginning
511 buf->Append(const_cast<System::String^>(Constants::sUnoidl));
512 //for polymorphic struct types remove the brackets, e.g mystruct<bool> -> mystruct
513 System::String ^ sName = mapUnoPolymorphicName(sUnoName);
514 buf->Append(sName);
515 }
516 // append []
517 for (;dims--;)
518 buf->Append(const_cast<System::String^>(Constants::sBrackets));
519
520 return buf->ToString();
521}
522
530inline System::String^ mapUnoPolymorphicName(System::String^ unoName)
531{
532 return mapPolymorphicName(unoName, false);
533}
534
542inline System::String^ mapCliPolymorphicName(System::String^ unoName)
543{
544 return mapPolymorphicName(unoName, true);
545}
546
547System::String^ mapPolymorphicName(System::String^ unoName, bool bCliToUno)
548{
549 int index = unoName->IndexOf('<');
550 if (index == -1)
551 return unoName;
552
553 System::Text::StringBuilder ^ builder = gcnew System::Text::StringBuilder(256);
554 builder->Append(unoName->Substring(0, index +1 ));
555
556 //Find the first occurrence of ','
557 //If the parameter is a polymorphic struct then we need to ignore everything
558 //between the brackets because it can also contain commas
559 //get the type list within < and >
560 int endIndex = unoName->Length - 1;
561 index++;
562 int cur = index;
563 int countParams = 0;
564 while (cur <= endIndex)
565 {
566 System::Char c = unoName[cur];
567 if (c == ',' || c == '>')
568 {
569 //insert a comma if needed
570 if (countParams != 0)
571 builder->Append(",");
572 countParams++;
573 System::String ^ sParam = unoName->Substring(index, cur - index);
574 //skip the comma
575 cur++;
576 //the index to the beginning of the next param
577 index = cur;
578 if (bCliToUno)
579 {
580 builder->Append(mapCliTypeName(sParam).getStr());
581 }
582 else
583 {
584 OUString s = mapCliString(sParam);
585 builder->Append(mapUnoTypeName(s.pData));
586 }
587 }
588 else if (c == '<')
589 {
590 cur++;
591 //continue until the matching '>'
592 int numNested = 0;
593 for (;;cur++)
594 {
595 System::Char curChar = unoName[cur];
596 if (curChar == '<')
597 {
598 numNested ++;
599 }
600 else if (curChar == '>')
601 {
602 if (numNested > 0)
603 numNested--;
604 else
605 break;
606 }
607 }
608 }
609 cur++;
610 }
611
612 builder->Append((System::Char) '>');
613 return builder->ToString();
614}
615
616OUString mapCliTypeName(System::String^ typeName)
617{
618 int dims= 0;
619 // Array? determine the "rank" (number of "[]")
620 // move from the rightmost end to the left, for example
621 // unoidl.PolymorphicStruct<System.Char[]>[]
622 // has only a "dimension" of 1
623 int cur = typeName->Length - 1;
624 bool bRightBracket = false;
625 while (cur >= 0)
626 {
627 System::Char c = typeName[cur];
628 if (c == ']')
629 {
630 bRightBracket = true;
631 }
632 else if (c == '[')
633 {
634 if (!bRightBracket)
635 throw BridgeRuntimeError(
636 "Typename is wrong. No matching brackets for sequence. Name is: " +
638 bRightBracket = false;
639 dims ++;
640 }
641 else
642 {
643 if (bRightBracket)
644 throw BridgeRuntimeError(
645 "Typename is wrong. No matching brackets for sequence. Name is: " +
647 break;
648 }
649 cur--;
650 }
651
652 if (bRightBracket || cur < 0)
653 throw BridgeRuntimeError(
654 "Typename is wrong. " +
656
657 typeName = typeName->Substring(0, cur + 1);
658
659 System::Text::StringBuilder ^ buf = gcnew System::Text::StringBuilder(512);
660
661 //Put the "[]" at the beginning of the uno type name
662 for (;dims--;)
663 buf->Append(const_cast<System::String^>(Constants::usBrackets));
664
665 if (typeName->Equals(const_cast<System::String^>(Constants::sBoolean)))
666 buf->Append(const_cast<System::String^>(Constants::usBool));
667 else if (typeName->Equals(const_cast<System::String^>(Constants::sChar)))
668 buf->Append(const_cast<System::String^>(Constants::usChar));
669 else if (typeName->Equals(const_cast<System::String^>(Constants::sByte)))
670 buf->Append(const_cast<System::String^>(Constants::usByte));
671 else if (typeName->Equals(const_cast<System::String^>(Constants::sInt16)))
672 buf->Append(const_cast<System::String^>(Constants::usShort));
673 else if (typeName->Equals(const_cast<System::String^>(Constants::sUInt16)))
674 buf->Append(const_cast<System::String^>(Constants::usUShort));
675 else if (typeName->Equals(const_cast<System::String^>(Constants::sInt32)))
676 buf->Append(const_cast<System::String^>(Constants::usLong));
677 else if (typeName->Equals(const_cast<System::String^>(Constants::sUInt32)))
678 buf->Append(const_cast<System::String^>(Constants::usULong));
679 else if (typeName->Equals(const_cast<System::String^>(Constants::sInt64)))
680 buf->Append(const_cast<System::String^>(Constants::usHyper));
681 else if (typeName->Equals(const_cast<System::String^>(Constants::sUInt64)))
682 buf->Append(const_cast<System::String^>(Constants::usUHyper));
683 else if (typeName->Equals(const_cast<System::String^>(Constants::sSingle)))
684 buf->Append(const_cast<System::String^>(Constants::usFloat));
685 else if (typeName->Equals(const_cast<System::String^>(Constants::sDouble)))
686 buf->Append(const_cast<System::String^>(Constants::usDouble));
687 else if (typeName->Equals(const_cast<System::String^>(Constants::sString)))
688 buf->Append(const_cast<System::String^>(Constants::usString));
689 else if (typeName->Equals(const_cast<System::String^>(Constants::sVoid)))
690 buf->Append(const_cast<System::String^>(Constants::usVoid));
691 else if (typeName->Equals(const_cast<System::String^>(Constants::sType)))
692 buf->Append(const_cast<System::String^>(Constants::usType));
693 else if (typeName->Equals(const_cast<System::String^>(Constants::sObject)))
694 buf->Append(const_cast<System::String^>(Constants::usXInterface));
695 else if (typeName->Equals(const_cast<System::String^>(Constants::sAny)))
696 buf->Append(const_cast<System::String^>(Constants::usAny));
697 else
698 {
699 System::String ^ sName = mapCliPolymorphicName(typeName);
700 int i= sName->IndexOf(L'.');
701 buf->Append(sName->Substring(i + 1));
702 }
703 return mapCliString(buf->ToString());
704}
705
709inline System::String^ mapUnoString( rtl_uString const * data)
710{
711 OSL_ASSERT(data);
712 return gcnew System::String((__wchar_t*) data->buffer, 0, data->length);
713}
714
715OUString mapCliString(System::String ^ data)
716{
717
718 if (data != nullptr)
719 {
720 static_assert(sizeof(wchar_t) == sizeof(sal_Unicode), "char mismatch");
721 pin_ptr<wchar_t const> pdata= PtrToStringChars(data);
722 return OUString(
723 reinterpret_cast<sal_Unicode const *>(pdata),
724 const_cast<System::String^>(data)->Length);
725 }
726 else
727 {
728 return OUString();
729 }
730}
731
732// ToDo convert cli types to expected types, e.g a long to a short where the uno type
733// is a sal_Int16. This could be necessary if a scripting language (typeless) is used
734// @param assign the uno_data has to be destructed (in/out args)
735void Bridge::map_to_uno(void * uno_data, System::Object^ cli_data,
736 typelib_TypeDescriptionReference * type,
737 bool assign) const
738{
739 try{
740 switch (type->eTypeClass)
741 {
742 case typelib_TypeClass_VOID:
743 break;
744 case typelib_TypeClass_CHAR:
745 {
746 System::Char aChar= *safe_cast<System::Char^>(cli_data);
747 *(sal_Unicode*) uno_data= aChar;
748 break;
749 }
750 case typelib_TypeClass_BOOLEAN:
751 {
752 System::Boolean aBool= *safe_cast<System::Boolean^>(cli_data);
753 *(sal_Bool*)uno_data= aBool == true ? sal_True : sal_False;
754 break;
755 }
756 case typelib_TypeClass_BYTE:
757 {
758 System::Byte aByte= *safe_cast<System::Byte^>(cli_data);
759 *(sal_Int8*) uno_data= aByte;
760 break;
761 }
762 case typelib_TypeClass_SHORT:
763 {
764 System::Int16 aShort= *safe_cast<System::Int16^>(cli_data);
765 *(sal_Int16*) uno_data= aShort;
766 break;
767 }
768 case typelib_TypeClass_UNSIGNED_SHORT:
769 {
770 System::UInt16 aUShort= *safe_cast<System::UInt16^>(cli_data);
771 *(sal_uInt16*) uno_data= aUShort;
772 break;
773 }
774 case typelib_TypeClass_LONG:
775 {
776 System::Int32 aLong= *safe_cast<System::Int32^>(cli_data);
777 *(sal_Int32*) uno_data= aLong;
778 break;
779 }
780 case typelib_TypeClass_UNSIGNED_LONG:
781 {
782 System::UInt32 aULong= *safe_cast<System::UInt32^>(cli_data);
783 *(sal_uInt32*) uno_data= aULong;
784 break;
785 }
786 case typelib_TypeClass_HYPER:
787 {
788 System::Int64 aHyper= *safe_cast<System::Int64^>(cli_data);
789 *(sal_Int64*) uno_data= aHyper;
790 break;
791 }
792 case typelib_TypeClass_UNSIGNED_HYPER:
793 {
794 System::UInt64 aLong= *safe_cast<System::UInt64^>(cli_data);
795 *(sal_uInt64*) uno_data= aLong;
796 break;
797 }
798 case typelib_TypeClass_FLOAT:
799 {
800 System::Single aFloat= *safe_cast<System::Single^>(cli_data);
801 *(float*) uno_data= aFloat;
802 break;
803 }
804 case typelib_TypeClass_DOUBLE:
805 {
806 System::Double aDouble= *safe_cast<System::Double^>(cli_data);
807 *(double*) uno_data= aDouble;
808 break;
809 }
810 case typelib_TypeClass_STRING:
811 {
812 if (assign && *(rtl_uString**) uno_data)
813 rtl_uString_release(*(rtl_uString**) uno_data);
814
815 *(rtl_uString **)uno_data = 0;
816 if (cli_data == nullptr)
817 {
818 rtl_uString_new((rtl_uString**) uno_data);
819 }
820 else
821 {
822 System::String ^s= safe_cast<System::String^>(cli_data);
823 pin_ptr<const wchar_t> pdata= PtrToStringChars(s);
824 rtl_uString_newFromStr_WithLength(
825 reinterpret_cast<rtl_uString **>(uno_data),
826 reinterpret_cast<sal_Unicode const *>(pdata), s->Length);
827 }
828 break;
829 }
830 case typelib_TypeClass_TYPE:
831 {
832 typelib_TypeDescriptionReference* td= mapCliType(safe_cast<System::Type^>(
833 cli_data));
834 if (assign)
835 {
837 *(typelib_TypeDescriptionReference **)uno_data );
838 }
839 *(typelib_TypeDescriptionReference **)uno_data = td;
840 break;
841 }
842 case typelib_TypeClass_ANY:
843 {
844 uno_Any * pAny = (uno_Any *)uno_data;
845 if (cli_data == nullptr) // null-ref or uninitialized any maps to empty any
846 {
847 if (assign)
848 uno_any_destruct( pAny, 0 );
849 uno_any_construct( pAny, 0, 0, 0 );
850 break;
851 }
852 uno::Any aAny= *safe_cast<uno::Any^>(cli_data);
853 css::uno::Type value_td( mapCliType(aAny.Type), SAL_NO_ACQUIRE);
854
855 if (assign)
856 uno_any_destruct( pAny, 0 );
857
858 try
859 {
860 switch (value_td.getTypeClass())
861 {
862 case css::uno::TypeClass_VOID:
863 pAny->pData = &pAny->pReserved;
864 break;
865 case css::uno::TypeClass_CHAR:
866 pAny->pData = &pAny->pReserved;
867 *(sal_Unicode*) &pAny->pReserved = *safe_cast<System::Char^>(aAny.Value);
868 break;
869 case css::uno::TypeClass_BOOLEAN:
870 pAny->pData = &pAny->pReserved;
871 *(sal_Bool *) &pAny->pReserved = *safe_cast<System::Boolean^>(aAny.Value);
872 break;
873 case css::uno::TypeClass_BYTE:
874 pAny->pData = &pAny->pReserved;
875 *(sal_Int8*) &pAny->pReserved = *safe_cast<System::Byte^>(aAny.Value);
876 break;
877 case css::uno::TypeClass_SHORT:
878 pAny->pData = &pAny->pReserved;
879 *(sal_Int16*) &pAny->pReserved = *safe_cast<System::Int16^>(aAny.Value);
880 break;
881 case css::uno::TypeClass_UNSIGNED_SHORT:
882 pAny->pData = &pAny->pReserved;
883 *(sal_uInt16*) &pAny->pReserved = *safe_cast<System::UInt16^>(aAny.Value);
884 break;
885 case css::uno::TypeClass_LONG:
886 pAny->pData = &pAny->pReserved;
887 *(sal_Int32*) &pAny->pReserved = *safe_cast<System::Int32^>(aAny.Value);
888 break;
889 case css::uno::TypeClass_UNSIGNED_LONG:
890 pAny->pData = &pAny->pReserved;
891 *(sal_uInt32*) &pAny->pReserved = *safe_cast<System::UInt32^>(aAny.Value);
892 break;
893 case css::uno::TypeClass_HYPER:
894 if (sizeof (sal_Int64) <= sizeof (void *))
895 {
896 pAny->pData = &pAny->pReserved;
897 *(sal_Int64*) &pAny->pReserved = *safe_cast<System::Int64^>(aAny.Value);
898 }
899 else
900 {
901 std::unique_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_Int64) ) );
902 *(sal_Int64 *) mem.get()= *safe_cast<System::Int64^>(aAny.Value);
903 pAny->pData = mem.release();
904 }
905 break;
906 case css::uno::TypeClass_UNSIGNED_HYPER:
907 if (sizeof (sal_uInt64) <= sizeof (void *))
908 {
909 pAny->pData = &pAny->pReserved;
910 *(sal_uInt64*) &pAny->pReserved = *safe_cast<System::UInt64^>(aAny.Value);
911 }
912 else
913 {
914 std::unique_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_uInt64) ) );
915 *(sal_uInt64 *) mem.get()= *safe_cast<System::UInt64^>(aAny.Value);
916 pAny->pData = mem.release();
917 }
918 break;
919 case css::uno::TypeClass_FLOAT:
920 if (sizeof (float) <= sizeof (void *))
921 {
922 pAny->pData = &pAny->pReserved;
923 *(float*) &pAny->pReserved = *safe_cast<System::Single^>(aAny.Value);
924 }
925 else
926 {
927 std::unique_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (float) ) );
928 *(float*) mem.get() = *safe_cast<System::Single^>(aAny.Value);
929 pAny->pData = mem.release();
930 }
931 break;
932 case css::uno::TypeClass_DOUBLE:
933 if (sizeof (double) <= sizeof (void *))
934 {
935 pAny->pData = &pAny->pReserved;
936 *(double*) &pAny->pReserved= *safe_cast<System::Double^>(aAny.Value);
937 }
938 else
939 {
940 std::unique_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (double) ) );
941 *(double*) mem.get()= *safe_cast<System::Double^>(aAny.Value);
942 pAny->pData= mem.release();
943 }
944 break;
945 case css::uno::TypeClass_STRING: // anies often contain strings; copy string directly
946 {
947 pAny->pData= &pAny->pReserved;
948 OUString _s = mapCliString(static_cast<System::String^>(aAny.Value));
949 pAny->pReserved= _s.pData;
950 rtl_uString_acquire(_s.pData);
951 break;
952 }
953 case css::uno::TypeClass_TYPE:
954 case css::uno::TypeClass_ENUM: //ToDo copy enum direct
955 case css::uno::TypeClass_SEQUENCE:
956 case css::uno::TypeClass_INTERFACE:
957 pAny->pData = &pAny->pReserved;
958 pAny->pReserved = 0;
960 &pAny->pReserved, aAny.Value, value_td.getTypeLibType(),
961 false /* no assign */);
962 break;
963 case css::uno::TypeClass_STRUCT:
964 case css::uno::TypeClass_EXCEPTION:
965 {
966 css::uno::Type anyType(value_td);
968 anyType.getDescription(&td);
969 std::unique_ptr< rtl_mem > mem(rtl_mem::allocate(td->nSize));
972 mem.get(), aAny.Value, value_td.getTypeLibType(),
973 false /* no assign */);
974 pAny->pData = mem.release();
975 break;
976 }
977 default:
978 {
979 throw BridgeRuntimeError("[map_to_uno():" + value_td.getTypeName() + "] unsupported value type of any!");
980 }
981 }
982 }
983 catch(System::InvalidCastException^ )
984 {
985// ToDo check this
986 if (assign)
987 uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
988 OUString str = "[map_to_uno():Any" + value_td.getTypeName() + "]The Any type " + value_td.getTypeName() + " does not correspond to its value type: ";
989 if(aAny.Value != nullptr)
990 {
991 css::uno::Type td(mapCliType(aAny.Value->GetType()), SAL_NO_ACQUIRE);
992 str += td.getTypeName();
993 }
994 if (assign)
995 uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
996 throw BridgeRuntimeError(str);
997 }
998 catch (BridgeRuntimeError& )
999 {
1000 if (assign)
1001 uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
1002 throw;
1003 }
1004 catch (...)
1005 {
1006 if (assign)
1007 uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
1008 throw;
1009 }
1010
1011 pAny->pType = value_td.getTypeLibType();
1013 break;
1014 }
1015 case typelib_TypeClass_ENUM:
1016 {
1017 // InvalidCastException is caught at the end of this method
1018 System::Int32 aEnum= System::Convert::ToInt32((cli_data));
1019 *(sal_Int32*) uno_data = aEnum;
1020 break;
1021 }
1022 case typelib_TypeClass_STRUCT:
1023 case typelib_TypeClass_EXCEPTION:
1024 {
1025 css::uno::TypeDescription td(type);
1026 typelib_CompoundTypeDescription * comp_td =
1027 (typelib_CompoundTypeDescription*) td.get();
1028
1029 typelib_StructTypeDescription * struct_td = NULL;
1030 if (type->eTypeClass == typelib_TypeClass_STRUCT)
1031 struct_td = (typelib_StructTypeDescription*) td.get();
1032
1033 if ( ! ((typelib_TypeDescription*) comp_td)->bComplete)
1034 ::typelib_typedescription_complete(
1035 (typelib_TypeDescription**) & comp_td );
1036
1037 sal_Int32 nMembers = comp_td->nMembers;
1038 boolean bException= false;
1039 System::Type^ cliType = nullptr;
1040 if (cli_data)
1041 cliType = cli_data->GetType();
1042
1043 if (0 != comp_td->pBaseTypeDescription)
1044 {
1045 map_to_uno(
1046 uno_data, cli_data,
1047 ((typelib_TypeDescription *)comp_td->pBaseTypeDescription)->pWeakRef,
1048 assign);
1049 }
1050 sal_Int32 nPos = 0;
1051 try
1052 {
1053 OUString usUnoException("com.sun.star.uno.Exception");
1054 for (; nPos < nMembers; ++nPos)
1055 {
1056 typelib_TypeDescriptionReference * member_type= comp_td->ppTypeRefs[nPos];
1057 System::Object^ val= nullptr;
1058 if (cli_data != nullptr)
1059 {
1060 sr::FieldInfo^ aField= cliType->GetField(
1061 mapUnoString(comp_td->ppMemberNames[nPos]));
1062 // special case for Exception.Message property
1063 // The com.sun.star.uno.Exception.Message field is mapped to the
1064 // System.Exception property. Type.GetField("Message") returns null
1065 if ( ! aField && usUnoException.equals(td.get()->pTypeName))
1066 {// get Exception.Message property
1067 OUString usMessageMember("Message");
1068 if (usMessageMember.equals(comp_td->ppMemberNames[nPos]))
1069 {
1070 sr::PropertyInfo^ pi= cliType->GetProperty(
1071 mapUnoString(comp_td->ppMemberNames[nPos]));
1072 val= pi->GetValue(cli_data, nullptr);
1073 }
1074 else
1075 {
1076 throw BridgeRuntimeError("[map_to_uno(): Member: " + OUString::unacquired(&comp_td->ppMemberNames[nPos]));
1077 }
1078 }
1079 else
1080 {
1081 val= aField->GetValue(cli_data);
1082 }
1083 }
1084 void * p = (char *) uno_data + comp_td->pMemberOffsets[ nPos ];
1085 //When using polymorphic structs then the parameterized members can be null.
1086 //Then we set a default value.
1087 bool bDefault = (struct_td != NULL
1088 && struct_td->pParameterizedTypes != NULL
1089 && struct_td->pParameterizedTypes[nPos] == sal_True
1090 && val == nullptr)
1091 || cli_data == nullptr;
1092 switch (member_type->eTypeClass)
1093 {
1094 case typelib_TypeClass_CHAR:
1095 if (bDefault)
1096 *(sal_Unicode*) p = 0;
1097 else
1098 *(sal_Unicode*) p = *safe_cast<System::Char^>(val);
1099 break;
1100 case typelib_TypeClass_BOOLEAN:
1101 if (bDefault)
1102 *(sal_Bool*) p = sal_False;
1103 else
1104 *(sal_Bool*) p = *safe_cast<System::Boolean^>(val);
1105 break;
1106 case typelib_TypeClass_BYTE:
1107 if (bDefault)
1108 *(sal_Int8*) p = 0;
1109 else
1110 *(sal_Int8*) p = *safe_cast<System::Byte^>(val);
1111 break;
1112 case typelib_TypeClass_SHORT:
1113 if (bDefault)
1114 *(sal_Int16*) p = 0;
1115 else
1116 *(sal_Int16*) p = *safe_cast<System::Int16^>(val);
1117 break;
1118 case typelib_TypeClass_UNSIGNED_SHORT:
1119 if (bDefault)
1120 *(sal_uInt16*) p = 0;
1121 else
1122 *(sal_uInt16*) p = *safe_cast<System::UInt16^>(val);
1123 break;
1124 case typelib_TypeClass_LONG:
1125 if (bDefault)
1126 *(sal_Int32*) p = 0;
1127 else
1128 *(sal_Int32*) p = *safe_cast<System::Int32^>(val);
1129 break;
1130 case typelib_TypeClass_UNSIGNED_LONG:
1131 if (bDefault)
1132 *(sal_uInt32*) p = 0;
1133 else
1134 *(sal_uInt32*) p = *safe_cast<System::UInt32^>(val);
1135 break;
1136 case typelib_TypeClass_HYPER:
1137 if (bDefault)
1138 *(sal_Int64*) p = 0;
1139 else
1140 *(sal_Int64*) p = *safe_cast<System::Int64^>(val);
1141 break;
1142 case typelib_TypeClass_UNSIGNED_HYPER:
1143 if (bDefault)
1144 *(sal_uInt64*) p = 0;
1145 else
1146 *(sal_uInt64*) p= *safe_cast<System::UInt64^>(val);
1147 break;
1148 case typelib_TypeClass_FLOAT:
1149 if (bDefault)
1150 *(float*) p = 0.;
1151 else
1152 *(float*) p = *safe_cast<System::Single^>(val);
1153 break;
1154 case typelib_TypeClass_DOUBLE:
1155 if (bDefault)
1156 *(double*) p = 0.;
1157 else
1158 *(double*) p = *safe_cast<System::Double^>(val);
1159 break;
1160 default:
1161 { // ToDo enum, should be converted here
1162 map_to_uno(p, val, member_type, assign);
1163 break;
1164 }
1165 }
1166 }
1167 }
1168 catch (BridgeRuntimeError& e)
1169 {
1170 bException= true;
1171 OUString str = "[map_to_uno():";
1172 if (cliType)
1173 {
1174 str += mapCliString(cliType->FullName) + "." + OUString::unacquired(&comp_td->ppMemberNames[nPos]) + " ";
1175 }
1176 str += e.m_message;
1177 throw BridgeRuntimeError(str);
1178 }
1179 catch (System::InvalidCastException^ )
1180 {
1181 bException= true;
1182 OUString str = "[map_to_uno():";
1183 if (cliType)
1184 {
1185 str += mapCliString(cliType->FullName) + "." + OUString::unacquired(&comp_td->ppMemberNames[nPos]);
1186 }
1187 str += "] Value has not the required type.";
1188 throw BridgeRuntimeError(str);
1189 }
1190 catch (...)
1191 {
1192 OSL_ASSERT(0);
1193 bException= true;
1194 throw;
1195 }
1196 __finally
1197 {
1198 if (bException && !assign) // if assign then caller cleans up
1199 {
1200 // cleanup the members which we have converted so far
1201 for ( sal_Int32 nCleanup = 0; nCleanup < nPos; ++nCleanup )
1202 {
1204 uno_data, comp_td->ppTypeRefs[ nCleanup ], 0 );
1205 }
1206 if (0 != comp_td->pBaseTypeDescription)
1207 {
1209 uno_data, (typelib_TypeDescription *)comp_td->pBaseTypeDescription, 0 );
1210 }
1211 }
1212 }
1213 break;
1214 }
1215 case typelib_TypeClass_SEQUENCE:
1216 {
1217 TypeDescr td( type );
1218 typelib_TypeDescriptionReference * element_type =
1219 ((typelib_IndirectTypeDescription *)td.get())->pType;
1220
1221 std::unique_ptr< rtl_mem > seq;
1222
1223 System::Array^ ar = nullptr;
1224 if (cli_data != nullptr)
1225 {
1226 ar = safe_cast<System::Array^>(cli_data);
1227 sal_Int32 nElements = ar->GetLength(0);
1228
1229 try
1230 {
1231 switch (element_type->eTypeClass)
1232 {
1233 case typelib_TypeClass_CHAR:
1234 seq = seq_allocate(nElements, sizeof (sal_Unicode));
1235 sri::Marshal::Copy(safe_cast<cli::array<System::Char>^>(cli_data), 0,
1236 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1237 break;
1238 case typelib_TypeClass_BOOLEAN:
1239 seq = seq_allocate(nElements, sizeof (sal_Bool));
1240 sri::Marshal::Copy(safe_cast<cli::array<System::Char>^>(cli_data), 0,
1241 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1242 break;
1243 case typelib_TypeClass_BYTE:
1244 seq = seq_allocate( nElements, sizeof (sal_Int8) );
1245 sri::Marshal::Copy(safe_cast<cli::array<System::Byte>^>(cli_data), 0,
1246 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1247 break;
1248 case typelib_TypeClass_SHORT:
1249 seq = seq_allocate(nElements, sizeof (sal_Int16));
1250 sri::Marshal::Copy(safe_cast<cli::array<System::Int16>^>(cli_data), 0,
1251 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1252 break;
1253 case typelib_TypeClass_UNSIGNED_SHORT:
1254 seq = seq_allocate( nElements, sizeof (sal_uInt16) );
1255 sri::Marshal::Copy(dynamic_cast<cli::array<System::Int16>^>(
1256 safe_cast<cli::array<System::UInt16>^>(cli_data)), 0,
1257 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1258 break;
1259 case typelib_TypeClass_LONG:
1260 seq = seq_allocate(nElements, sizeof (sal_Int32));
1261 sri::Marshal::Copy(safe_cast<cli::array<System::Int32>^>(cli_data), 0,
1262 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1263 break;
1264 case typelib_TypeClass_UNSIGNED_LONG:
1265 seq = seq_allocate( nElements, sizeof (sal_uInt32) );
1266 sri::Marshal::Copy(dynamic_cast<cli::array<System::Int32>^>(
1267 safe_cast<cli::array<System::UInt32>^>(cli_data)), 0,
1268 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1269 break;
1270 case typelib_TypeClass_HYPER:
1271 seq = seq_allocate(nElements, sizeof (sal_Int64));
1272 sri::Marshal::Copy(safe_cast<cli::array<System::Int64>^>(cli_data), 0,
1273 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1274 break;
1275 case typelib_TypeClass_UNSIGNED_HYPER:
1276 seq = seq_allocate(nElements, sizeof (sal_uInt64));
1277 sri::Marshal::Copy(dynamic_cast<cli::array<System::Int64>^>(
1278 safe_cast<cli::array<System::UInt64>^>(cli_data)), 0,
1279 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1280 break;
1281 case typelib_TypeClass_FLOAT:
1282 seq = seq_allocate(nElements, sizeof (float));
1283 sri::Marshal::Copy(safe_cast<cli::array<System::Single>^>(cli_data), 0,
1284 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1285 break;
1286 case typelib_TypeClass_DOUBLE:
1287 seq = seq_allocate(nElements, sizeof (double));
1288 sri::Marshal::Copy(safe_cast<cli::array<System::Double>^>(cli_data), 0,
1289 IntPtr(& ((uno_Sequence*) seq.get())->elements), nElements);
1290 break;
1291 case typelib_TypeClass_STRING:
1292 {
1293 seq = seq_allocate(nElements, sizeof (rtl_uString*));
1294 cli::array<System::String^>^ arStr= safe_cast<cli::array<System::String^>^>(cli_data);
1295 for (int i= 0; i < nElements; i++)
1296 {
1297 pin_ptr<const wchar_t> pdata= PtrToStringChars(arStr[i]);
1298 rtl_uString** pStr= & ((rtl_uString**) &
1299 ((uno_Sequence*) seq.get())->elements)[i];
1300 *pStr= NULL;
1301 rtl_uString_newFromStr_WithLength(
1302 pStr,
1303 reinterpret_cast<sal_Unicode const *>(pdata),
1304 arStr[i]->Length);
1305 }
1306 break;
1307 }
1308 case typelib_TypeClass_ENUM:
1309 seq = seq_allocate(nElements, sizeof (sal_Int32));
1310 for (int i= 0; i < nElements; i++)
1311 {
1312 ((sal_Int32*) &((uno_Sequence*) seq.get())->elements)[i]=
1313 System::Convert::ToInt32(ar->GetValue(i));
1314 }
1315 break;
1316 case typelib_TypeClass_TYPE:
1317 case typelib_TypeClass_ANY:
1318 case typelib_TypeClass_STRUCT:
1319 case typelib_TypeClass_EXCEPTION:
1320 case typelib_TypeClass_SEQUENCE:
1321 case typelib_TypeClass_INTERFACE:
1322 {
1323 TypeDescr element_td( element_type );
1324 seq = seq_allocate( nElements, element_td.get()->nSize );
1325
1326 for (sal_Int32 nPos = 0; nPos < nElements; ++nPos)
1327 {
1328 try
1329 {
1330 void * p= ((uno_Sequence *) seq.get())->elements +
1331 (nPos * element_td.get()->nSize);
1332 System::Object^ elemData= safe_cast<System::Array^>(cli_data)->GetValue(System::Int32(nPos));
1333 map_to_uno(
1334 p, elemData, element_td.get()->pWeakRef,
1335 false /* no assign */);
1336 }
1337 catch (...)
1338 {
1339 // cleanup
1340 for ( sal_Int32 nCleanPos = 0; nCleanPos < nPos; ++nCleanPos )
1341 {
1342 void * p =
1343 ((uno_Sequence *)seq.get())->elements +
1344 (nCleanPos * element_td.get()->nSize);
1345 uno_destructData( p, element_td.get(), 0 );
1346 }
1347 throw;
1348 }
1349 }
1350 break;
1351 }
1352 default:
1353 {
1354 throw BridgeRuntimeError("[map_to_uno():" + OUString::unacquired( &type->pTypeName ) +
1355 "] unsupported sequence element type: " + OUString::unacquired( &element_type->pTypeName ));
1356 }
1357 }
1358 }
1359 catch (BridgeRuntimeError& e)
1360 {
1361 throw BridgeRuntimeError("[map_to_uno():" + OUString::unacquired( &type->pTypeName ) + "] conversion failed\n " + e.m_message);
1362 }
1363 catch (System::InvalidCastException^ )
1364 {
1365 // Ok, checked
1366 throw BridgeRuntimeError("[map_to_uno():" + OUString::unacquired( &type->pTypeName) +
1367 "] could not convert sequence element type: " + OUString::unacquired( &element_type->pTypeName ));
1368 }
1369 catch (...)
1370 {
1371 OSL_ASSERT(0);
1372 throw;
1373 }
1374 __finally
1375 {
1376 if (assign)
1377 uno_destructData( uno_data, td.get(), 0 );
1378 }
1379 }
1380 else
1381 {
1382 seq = seq_allocate(0, sizeof (sal_Int32));
1383 }
1384 *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release();
1385 break;
1386 }
1387 case typelib_TypeClass_INTERFACE:
1388 {
1389 if (assign)
1390 {
1391 uno_Interface * p = *(uno_Interface **)uno_data;
1392 if (0 != p)
1393 (*p->release)( p );
1394 }
1395 if (nullptr == cli_data) // null-ref
1396 {
1397 *(uno_Interface **)uno_data = 0;
1398 }
1399 else
1400 {
1401 TypeDescr td( type );
1402 uno_Interface * pUnoI = map_cli2uno(cli_data, td.get());
1403 *(uno_Interface **)uno_data = pUnoI;
1404 }
1405 break;
1406 }
1407 default:
1408 {
1409 //ToDo check
1410 throw BridgeRuntimeError("[map_to_uno():" + OUString::unacquired( &type->pTypeName ) + "] unsupported type!");
1411 }
1412 }
1413 }
1414 // BridgeRuntimeError are allowed to be thrown
1415 catch (System::InvalidCastException^ )
1416 {
1417 //ToDo check
1418 throw BridgeRuntimeError("[map_to_uno():" + OUString::unacquired( &type->pTypeName ) + "] could not convert type!");
1419 }
1420 catch (System::NullReferenceException ^ e)
1421 {
1422 throw BridgeRuntimeError("[map_to_uno()] Illegal null reference passed!\n" + mapCliString(e->StackTrace));
1423 }
1424 catch (BridgeRuntimeError& )
1425 {
1426 throw;
1427 }
1428 catch (...)
1429 {
1430 OSL_ASSERT(0);
1431 throw;
1432 }
1433}
1434
1449 System::Object^ *cli_data, void const * uno_data,
1450 typelib_TypeDescriptionReference * type, System::Type^ info,
1451 bool bDontCreateObj) const
1452{
1453 switch (type->eTypeClass)
1454 {
1455 case typelib_TypeClass_CHAR:
1456 *cli_data= *(__wchar_t const*)uno_data;
1457 break;
1458 case typelib_TypeClass_BOOLEAN:
1459 *cli_data = (*(bool const*)uno_data) == sal_True;
1460 break;
1461 case typelib_TypeClass_BYTE:
1462 *cli_data = *(unsigned char const*) uno_data;
1463 break;
1464 case typelib_TypeClass_SHORT:
1465 *cli_data= *(short const*) uno_data;
1466 break;
1467 case typelib_TypeClass_UNSIGNED_SHORT:
1468 *cli_data= *(unsigned short const*) uno_data;
1469 break;
1470 case typelib_TypeClass_LONG:
1471 *cli_data= *(int const*) uno_data;
1472 break;
1473 case typelib_TypeClass_UNSIGNED_LONG:
1474 *cli_data= *(unsigned int const*) uno_data;
1475 break;
1476 case typelib_TypeClass_HYPER:
1477 *cli_data= *(__int64 const*) uno_data;
1478 break;
1479 case typelib_TypeClass_UNSIGNED_HYPER:
1480 *cli_data= *(unsigned __int64 const*) uno_data;
1481 break;
1482 case typelib_TypeClass_FLOAT:
1483 *cli_data= *(float const*) uno_data;
1484 break;
1485 case typelib_TypeClass_DOUBLE:
1486 *cli_data= *(double const*) uno_data;
1487 break;
1488 case typelib_TypeClass_STRING:
1489 {
1490 rtl_uString const* sVal= NULL;
1491 sVal= *(rtl_uString* const*) uno_data;
1492 *cli_data= gcnew System::String((__wchar_t*) sVal->buffer,0, sVal->length);
1493 break;
1494 }
1495 case typelib_TypeClass_TYPE:
1496 {
1497 *cli_data= mapUnoType( *(typelib_TypeDescriptionReference * const *)uno_data );
1498 break;
1499 }
1500 case typelib_TypeClass_ANY:
1501 {
1502 uno_Any const * pAny = (uno_Any const *)uno_data;
1503 if (typelib_TypeClass_VOID != pAny->pType->eTypeClass)
1504 {
1505 System::Object^ objCli= nullptr;
1506 map_to_cli(
1507 &objCli, pAny->pData, pAny->pType, nullptr,
1508 false);
1509
1510 uno::Any anyVal(mapUnoType(pAny->pType), objCli);
1511 *cli_data= anyVal;
1512 }
1513 else
1514 { // void any
1515 *cli_data= uno::Any::VOID;
1516 }
1517 break;
1518 }
1519 case typelib_TypeClass_ENUM:
1520 {
1521 if (info != nullptr)
1522 {
1523 OSL_ASSERT(info->IsByRef);
1524 info= info->GetElementType();
1525 *cli_data= System::Enum::ToObject(info, *(System::Int32*) uno_data);
1526 }
1527 else
1528 *cli_data= System::Enum::ToObject(
1529 mapUnoType(type), *(System::Int32*) uno_data);
1530 break;
1531 }
1532 case typelib_TypeClass_STRUCT:
1533 case typelib_TypeClass_EXCEPTION:
1534 {
1535 TypeDescr td( type );
1536 typelib_CompoundTypeDescription * comp_td =
1537 (typelib_CompoundTypeDescription *) td.get();
1538 if ( ! ((typelib_TypeDescription*) comp_td)->bComplete)
1539 ::typelib_typedescription_complete(
1540 (typelib_TypeDescription**) & comp_td );
1541
1542
1543 //create the type
1544 System::Type^ cliType= loadCliType(td.get()->pTypeName);
1545 //detect if we recursively convert inherited structures
1546 //If this point is reached because of a recursive call during covering a
1547 //struct then we must not create a new object rather we use the one in
1548 // cli_data argument.
1549 System::Object^ cliObj;
1550 if (bDontCreateObj)
1551 cliObj = *cli_data; // recursive call
1552 else
1553 {
1554 //Special handling for Exception conversion. We must call constructor System::Exception
1555 //to pass the message string
1556 if (ucss::uno::Exception::typeid->IsAssignableFrom(cliType))
1557 {
1558 //We need to get the Message field. Therefore we must obtain the offset from
1559 //the typedescription. The base interface of all exceptions is
1560 //com::sun::star::uno::Exception which contains the message
1561 typelib_CompoundTypeDescription* pCTD = comp_td;
1562 while (pCTD->pBaseTypeDescription)
1563 pCTD = pCTD->pBaseTypeDescription;
1564 int nPos = -1;
1565
1566 OUString usMessageMember("Message");
1567 for (int i = 0; i < pCTD->nMembers; i ++)
1568 {
1569 if (usMessageMember.equals(pCTD->ppMemberNames[i]))
1570 {
1571 nPos = i;
1572 break;
1573 }
1574 }
1575 OSL_ASSERT (nPos != -1);
1576 int offset = pCTD->pMemberOffsets[nPos];
1577 //With the offset within the exception we can get the message string
1578 System::String^ sMessage = mapUnoString(*(rtl_uString**)
1579 ((char*) uno_data + offset));
1580 //We need to find a constructor for the exception that takes the message string
1581 //We assume that the first argument is the message string
1582 cli::array<sr::ConstructorInfo^>^ arCtorInfo = cliType->GetConstructors();
1583 sr::ConstructorInfo^ ctorInfo = nullptr;
1584 int numCtors = arCtorInfo->Length;
1585 //Constructor must at least have 2 params for the base
1586 //unoidl.com.sun.star.uno.Exception (String, Object);
1587 cli::array<sr::ParameterInfo^>^ arParamInfo;
1588 for (int i = 0; i < numCtors; i++)
1589 {
1590 arParamInfo = arCtorInfo[i]->GetParameters();
1591 if (arParamInfo->Length < 2)
1592 continue;
1593 ctorInfo = arCtorInfo[i];
1594 break;
1595 }
1596 OSL_ASSERT(arParamInfo[0]->ParameterType->Equals(System::String::typeid)
1597 && arParamInfo[1]->ParameterType->Equals(System::Object::typeid)
1598 && arParamInfo[0]->Position == 0
1599 && arParamInfo[1]->Position == 1);
1600 //Prepare parameters for constructor
1601 int numArgs = arParamInfo->Length;
1602 cli::array<System::Object^>^ args = gcnew cli::array<System::Object^>(numArgs);
1603 //only initialize the first argument with the message
1604 args[0] = sMessage;
1605 cliObj = ctorInfo->Invoke(args);
1606 }
1607 else
1608 cliObj = System::Activator::CreateInstance(cliType);
1609 }
1610 sal_Int32 * pMemberOffsets = comp_td->pMemberOffsets;
1611
1612 if (comp_td->pBaseTypeDescription)
1613 {
1614 //convert inherited struct
1615 //cliObj is passed inout (args in_param, out_param are true), hence the passed
1616 // cliObj is used by the callee instead of a newly created struct
1617 map_to_cli(
1618 &cliObj, uno_data,
1619 ((typelib_TypeDescription *)comp_td->pBaseTypeDescription)->pWeakRef, nullptr,
1620 true);
1621 }
1622 OUString usUnoException("com.sun.star.uno.Exception");
1623 for (sal_Int32 nPos = comp_td->nMembers; nPos--; )
1624 {
1625 typelib_TypeDescriptionReference * member_type = comp_td->ppTypeRefs[ nPos ];
1626 System::String^ sMemberName= mapUnoString(comp_td->ppMemberNames[nPos]);
1627 sr::FieldInfo^ aField= cliType->GetField(sMemberName);
1628 // special case for Exception.Message. The field has already been
1629 // set while constructing cli object
1630 if ( ! aField && usUnoException.equals(td.get()->pTypeName))
1631 {
1632 continue;
1633 }
1634 void const * p = (char const *)uno_data + pMemberOffsets[ nPos ];
1635 switch (member_type->eTypeClass)
1636 {
1637 case typelib_TypeClass_CHAR:
1638 aField->SetValue(cliObj, *(System::Char*) p);
1639 break;
1640 case typelib_TypeClass_BOOLEAN:
1641 aField->SetValue(cliObj, *(System::Boolean*) p);
1642 break;
1643 case typelib_TypeClass_BYTE:
1644 aField->SetValue(cliObj, *(System::Byte*) p);
1645 break;
1646 case typelib_TypeClass_SHORT:
1647 aField->SetValue(cliObj, *(System::Int16*) p);
1648 break;
1649 case typelib_TypeClass_UNSIGNED_SHORT:
1650 aField->SetValue(cliObj, *(System::UInt16*) p);
1651 break;
1652 case typelib_TypeClass_LONG:
1653 aField->SetValue(cliObj, *(System::Int32*) p);
1654 break;
1655 case typelib_TypeClass_UNSIGNED_LONG:
1656 aField->SetValue(cliObj, *(System::UInt32*) p);
1657 break;
1658 case typelib_TypeClass_HYPER:
1659 aField->SetValue(cliObj, *(System::Int64*) p);
1660 break;
1661 case typelib_TypeClass_UNSIGNED_HYPER:
1662 aField->SetValue(cliObj, *(System::UInt64*) p);
1663 break;
1664 case typelib_TypeClass_FLOAT:
1665 aField->SetValue(cliObj, *(System::Single*) p);
1666 break;
1667 case typelib_TypeClass_DOUBLE:
1668 aField->SetValue(cliObj, *(System::Double*) p);
1669 break;
1670 default:
1671 {
1672 System::Object^ cli_val;
1673 map_to_cli(
1674 &cli_val, p, member_type, nullptr,
1675 false);
1676 aField->SetValue(cliObj, cli_val);
1677 break;
1678 }
1679 }
1680 }
1681 *cli_data= cliObj;
1682 break;
1683 }
1684 case typelib_TypeClass_SEQUENCE:
1685 {
1686 sal_Int32 nElements;
1687 uno_Sequence const * seq = 0;
1688 seq = *(uno_Sequence * const *)uno_data;
1689 nElements = seq->nElements;
1690
1691 TypeDescr td( type );
1692 typelib_TypeDescriptionReference * element_type =
1693 ((typelib_IndirectTypeDescription *)td.get())->pType;
1694
1695 switch (element_type->eTypeClass)
1696 {
1697 case typelib_TypeClass_CHAR:
1698 {
1699 cli::array<System::Char>^ arChar= gcnew cli::array<System::Char>(nElements);
1700 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arChar, 0, nElements);
1701 *cli_data= arChar;
1702 break;
1703 }
1704 case typelib_TypeClass_BOOLEAN:
1705 {
1706 cli::array<System::Byte>^ arBool= gcnew cli::array<System::Byte>(nElements);
1707 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arBool, 0, nElements);
1708 *cli_data= dynamic_cast<cli::array<System::Boolean>^>(arBool);
1709 break;
1710 }
1711 case typelib_TypeClass_BYTE:
1712 {
1713 cli::array<System::Byte>^ arByte= gcnew cli::array<System::Byte>(nElements);
1714 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arByte, 0, nElements);
1715 *cli_data= arByte;
1716 break;
1717 }
1718 case typelib_TypeClass_SHORT:
1719 {
1720 cli::array<System::Int16>^ arShort= gcnew cli::array<System::Int16>(nElements);
1721 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arShort, 0, nElements);
1722 *cli_data= arShort;
1723 break;
1724 }
1725 case typelib_TypeClass_UNSIGNED_SHORT:
1726 {
1727 cli::array<System::UInt16>^ arUInt16= gcnew cli::array<System::UInt16>(nElements);
1728 sri::Marshal::Copy( IntPtr((void*) &seq->elements), dynamic_cast<cli::array<System::Int16>^>(arUInt16),
1729 0, nElements);
1730 *cli_data= arUInt16;
1731 break;
1732 }
1733 case typelib_TypeClass_LONG:
1734 {
1735 cli::array<System::Int32>^ arInt32= gcnew cli::array<System::Int32>(nElements);
1736 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arInt32, 0, nElements);
1737 *cli_data= arInt32;
1738 break;
1739 }
1740 case typelib_TypeClass_UNSIGNED_LONG:
1741 {
1742 cli::array<System::UInt32>^ arUInt32= gcnew cli::array<System::UInt32>(nElements);
1743 sri::Marshal::Copy( IntPtr((void*) &seq->elements), dynamic_cast<cli::array<System::Int32>^>(arUInt32),
1744 0, nElements);
1745 *cli_data= arUInt32;
1746 break;
1747 }
1748 case typelib_TypeClass_HYPER:
1749 {
1750 cli::array<System::Int64>^ arInt64= gcnew cli::array<System::Int64>(nElements);
1751 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arInt64, 0, nElements);
1752 *cli_data= arInt64;
1753 break;
1754 }
1755 //FIXME: Marshal::Copy of UInt64?
1756 case typelib_TypeClass_UNSIGNED_HYPER:
1757 {
1758 cli::array<System::IntPtr>^ arUInt64= gcnew cli::array<System::IntPtr>(nElements);
1759 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arUInt64, 0, nElements);
1760 *cli_data= dynamic_cast<cli::array<System::UInt64>^>(arUInt64);
1761 break;
1762 }
1763 case typelib_TypeClass_FLOAT:
1764 {
1765 cli::array<System::Single>^ arSingle= gcnew cli::array<System::Single>(nElements);
1766 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arSingle, 0, nElements);
1767 *cli_data= arSingle;
1768 break;
1769 }
1770 case typelib_TypeClass_DOUBLE:
1771 {
1772 cli::array<System::Double>^ arDouble= gcnew cli::array<System::Double>(nElements);
1773 sri::Marshal::Copy( IntPtr((void*) &seq->elements), arDouble, 0, nElements);
1774 *cli_data= arDouble;
1775 break;
1776 }
1777 case typelib_TypeClass_STRING:
1778 {
1779 cli::array<System::String^>^ arString= gcnew cli::array<System::String^>(nElements);
1780 for (int i= 0; i < nElements; i++)
1781 {
1782 rtl_uString *aStr= ((rtl_uString**)(&seq->elements))[i];
1783 arString[i]= gcnew System::String( (__wchar_t *) &aStr->buffer, 0, aStr->length);
1784 }
1785 *cli_data= arString;
1786 break;
1787 }
1788 case typelib_TypeClass_TYPE:
1789 {
1790 cli::array<System::Type^>^ arType= gcnew cli::array<System::Type^>(nElements);
1791 for (int i= 0; i < nElements; i++)
1792 {
1793 arType[i]=
1794 mapUnoType( ((typelib_TypeDescriptionReference**) seq->elements)[i]);
1795 }
1796 *cli_data= arType;
1797 break;
1798 }
1799 case typelib_TypeClass_ANY:
1800 {
1801 cli::array<uno::Any>^ arCli= gcnew cli::array<uno::Any>(nElements);
1802 uno_Any const * p = (uno_Any const *)seq->elements;
1803 for (sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1804 {
1805 System::Object^ cli_obj = nullptr;
1806 map_to_cli(
1807 &cli_obj, &p[ nPos ], element_type, nullptr, false);
1808 arCli[nPos]= *safe_cast<uno::Any^>(cli_obj);
1809 }
1810 *cli_data= arCli;
1811 break;
1812 }
1813 case typelib_TypeClass_ENUM:
1814 {
1815 //get the Enum type
1816 System::Type^ enumType= nullptr;
1817 if (info != nullptr)
1818 {
1819 //info is EnumType[]&, remove &
1820 OSL_ASSERT(info->IsByRef);
1821 enumType = info->GetElementType();
1822 //enumType is EnumType[], remove []
1823 enumType = enumType->GetElementType();
1824 }
1825 else
1826 enumType= mapUnoType(element_type);
1827
1828 System::Array^ arEnum = System::Array::CreateInstance(
1829 enumType, nElements);
1830 for (int i= 0; i < nElements; i++)
1831 {
1832 arEnum->SetValue(System::Enum::ToObject(enumType,
1833 System::Int32(((sal_Int32*) seq->elements)[i])), i);
1834 }
1835 *cli_data = arEnum;
1836 break;
1837 }
1838 case typelib_TypeClass_STRUCT:
1839 case typelib_TypeClass_EXCEPTION:
1840 {
1841 TypeDescr element_td( element_type );
1842 System::Array^ ar= System::Array::CreateInstance(
1843 mapUnoType(element_type),nElements);
1844 if (0 < nElements)
1845 {
1846 // ToDo check this
1847 char * p = (char *) &seq->elements;
1848 sal_Int32 nSize = element_td.get()->nSize;
1849 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1850 {
1851 System::Object^ val;
1852 map_to_cli(
1853 &val, p + (nSize * nPos), element_type, nullptr, false);
1854 ar->SetValue(val, System::Int32(nPos));
1855 }
1856 }
1857 *cli_data = ar;
1858 break;
1859 }
1860// ToDo, verify
1861 case typelib_TypeClass_SEQUENCE:
1862 {
1863 System::Array ^ar= System::Array::CreateInstance(
1864 mapUnoType(element_type), nElements);
1865 if (0 < nElements)
1866 {
1867 TypeDescr element_td( element_type );
1868 uno_Sequence ** elements = (uno_Sequence**) seq->elements;
1869 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1870 {
1871 System::Object^ val;
1872 map_to_cli(
1873 &val, &elements[nPos], element_type, nullptr, false);
1874 ar->SetValue(val, System::Int32(nPos));
1875 }
1876 }
1877 *cli_data = ar;
1878 break;
1879 }
1880 case typelib_TypeClass_INTERFACE:
1881 {
1882 TypeDescr element_td( element_type );
1883 System::Type ^ ifaceType= mapUnoType(element_type);
1884 System::Array^ ar= System::Array::CreateInstance(ifaceType, nElements);
1885
1886 char * p = (char *)seq->elements;
1887 sal_Int32 nSize = element_td.get()->nSize;
1888 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1889 {
1890 System::Object^ val;
1891 map_to_cli(
1892 &val, p + (nSize * nPos), element_type, nullptr, false);
1893
1894 ar->SetValue(val, System::Int32(nPos));
1895 }
1896 *cli_data= ar;
1897 break;
1898 }
1899 default:
1900 {
1901 throw BridgeRuntimeError("[map_to_cli():" + OUString::unacquired( &type->pTypeName ) +
1902 "] unsupported element type: " + OUString::unacquired( &element_type->pTypeName ));
1903 }
1904 }
1905 break;
1906 }
1907 case typelib_TypeClass_INTERFACE:
1908 {
1909 uno_Interface * pUnoI = *(uno_Interface * const *)uno_data;
1910 if (0 != pUnoI)
1911 {
1912 TypeDescr td( type );
1913 *cli_data= map_uno2cli( pUnoI, reinterpret_cast<
1914 typelib_InterfaceTypeDescription*>(td.get())) ;
1915 }
1916 else
1917 *cli_data= nullptr;
1918 break;
1919 }
1920 default:
1921 {
1922 //ToDo check this exception. The String is probably crippled
1923 throw BridgeRuntimeError("[map_to_cli():" + OUString::unacquired( &type->pTypeName ) + "] unsupported type!");
1924 }
1925 } //switch
1926} // method
1927} // namespace
1928
1929/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SAL_CALL uno_any_construct(uno_Any *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Object getRegisteredInterface(System::String ^ oid, System::Type ^ type)
Retrieves an interface identified by its object id and type from this environment.
static System::String getObjectIdentifier(Object ^ obj)
Generates a worldwide unique object identifier (oid) for the given object.
typelib_TypeDescription * get() const
Definition: cli_base.h:151
static System::Object create(Bridge *bridge, uno_Interface *pUnoI, typelib_InterfaceTypeDescription *pTd, const OUString &oid)
Creates a proxy and registers it on the dot NET side.
Definition: cli_proxy.cxx:150
represents a polymorphic type.
static PolymorphicType GetType(Type type, string name)
provides a unique instance of this class.
sal_Int32 nElements
void SAL_CALL uno_type_destructData(void *pValue, typelib_TypeDescriptionReference *pType, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
OUString sName
void * p
sal_uInt16 nPos
return NULL
aStr
struct _typelib_TypeDescription typelib_TypeDescription
struct _uno_Any uno_Any
System::String mapPolymorphicName(System::String^ unoName, bool bCliToUno)
Definition: cli_data.cxx:547
System::Type loadCliType(System::String ^ typeName)
Definition: cli_data.cxx:141
System::String mapUnoPolymorphicName(System::String^ unoName)
For example, there is a uno type com.sun.star.Foo<char, long>.
Definition: cli_data.cxx:530
std::unique_ptr< rtl_mem > seq_allocate(sal_Int32 nElements, sal_Int32 nSize)
Definition: cli_data.cxx:53
OUString mapCliString(System::String ^ data)
Definition: cli_data.cxx:715
OUString mapCliTypeName(System::String^ typeName)
Definition: cli_data.cxx:616
System::String mapUnoTypeName(rtl_uString const *typeName)
Otherwise a leading "unoidl." is removed.
Definition: cli_data.cxx:455
System::Type mapUnoType(typelib_TypeDescription const *pTD)
Definition: cli_data.cxx:186
System::String mapCliPolymorphicName(System::String^ unoName)
For example, there is a type name such as com.sun.star.Foo<System.Char, System.Int32>.
Definition: cli_data.cxx:542
System::String mapUnoString(rtl_uString const *data)
Maps uno types to dot net types.
Definition: cli_data.cxx:709
typelib_TypeDescriptionReference * mapCliType(System::Type^ cliType)
Returns an acquired td.
Definition: cli_data.cxx:312
def assign(rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny)
int i
index
Length
args
OUString typeName
OUString sMessage
typelib_TypeDescriptionReference **SAL_CALL typelib_static_type_getByTypeClass(typelib_TypeClass eTypeClass) SAL_THROW_EXTERN_C()
An instance of Bridge represents exactly one mapping therefore either m_cli2uno or m_uno2cli is valid...
Definition: cli_bridge.h:58
System::Object map_uno2cli(uno_Interface *pUnoI, typelib_InterfaceTypeDescription *pTD) const
Definition: cli_data.cxx:63
void map_to_uno(void *uno_data, System::Object^ cli_data, typelib_TypeDescriptionReference *type, bool assign) const
Definition: cli_data.cxx:735
uno_ExtEnvironment * m_uno_env
Definition: cli_bridge.h:60
uno_Interface * map_cli2uno(System::Object^ cliI, typelib_TypeDescription *pTD) const
Definition: cli_data.cxx:107
void map_to_cli(System::Object^ *cli_data, void const *uno_data, typelib_TypeDescriptionReference *type, System::Type^ info, bool bDontCreateObj) const
Definition: cli_data.cxx:1448
static Cli_environment g_cli_env
Definition: cli_bridge.h:50
static uno_Interface * create(Bridge const *bridge, System::Object^ cliI, typelib_TypeDescription const *TD, OUString const &usOid)
Definition: cli_proxy.cxx:825
static System::String sArUInt32
Definition: cli_base.h:75
static System::String usHyper
Definition: cli_base.h:99
static System::String sChar
Definition: cli_base.h:58
static System::String sDouble
Definition: cli_base.h:68
static System::String sArByte
Definition: cli_base.h:71
static System::String sArType
Definition: cli_base.h:81
static System::String sArInt64
Definition: cli_base.h:76
static System::String usShort
Definition: cli_base.h:95
static System::String usBrackets
Definition: cli_base.h:91
static System::String sArUInt16
Definition: cli_base.h:73
static System::String usXInterface
Definition: cli_base.h:87
static System::String sType
Definition: cli_base.h:52
static System::String sInt32
Definition: cli_base.h:62
static System::String sInt64
Definition: cli_base.h:64
static System::String sArString
Definition: cli_base.h:78
static System::String usVoid
Definition: cli_base.h:88
static System::String usULong
Definition: cli_base.h:98
static System::String usUHyper
Definition: cli_base.h:100
static System::String sArDouble
Definition: cli_base.h:80
static System::String usLong
Definition: cli_base.h:97
static System::String usDouble
Definition: cli_base.h:103
static System::String sUInt16
Definition: cli_base.h:61
static System::String sAny
Definition: cli_base.h:55
static System::String sUnoidl
Definition: cli_base.h:53
static System::String sSingle
Definition: cli_base.h:67
static System::String sString
Definition: cli_base.h:66
static System::String sArInt16
Definition: cli_base.h:72
static System::String usType
Definition: cli_base.h:89
static System::String sArSingle
Definition: cli_base.h:79
static System::String usByte
Definition: cli_base.h:93
static System::String sArBoolean
Definition: cli_base.h:69
static System::String usBool
Definition: cli_base.h:92
static System::String sArUInt64
Definition: cli_base.h:77
static System::String sBoolean
Definition: cli_base.h:57
static System::String usUShort
Definition: cli_base.h:96
static System::String sUInt64
Definition: cli_base.h:65
static System::String sBrackets
Definition: cli_base.h:83
static System::String sObject
Definition: cli_base.h:51
static System::String usString
Definition: cli_base.h:101
static System::String usChar
Definition: cli_base.h:94
static System::String sVoid
Definition: cli_base.h:54
static System::String usAny
Definition: cli_base.h:90
static System::String sArInt32
Definition: cli_base.h:74
static System::String sInt16
Definition: cli_base.h:60
static System::String sByte
Definition: cli_base.h:59
static System::String sUInt32
Definition: cli_base.h:63
static System::String usFloat
Definition: cli_base.h:102
static System::String sArChar
Definition: cli_base.h:70
static std::unique_ptr< rtl_mem > allocate(std::size_t bytes)
Definition: cli_base.h:130
void SAL_CALL typelib_typedescriptionreference_acquire(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_release(typelib_TypeDescription *pTD) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_getByName(typelib_TypeDescription **ppRet, rtl_uString *pName) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_release(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
#define sal_True
#define sal_False
unsigned char sal_Bool
#define SAL_SEQUENCE_HEADER_SIZE
sal_uInt16 sal_Unicode
signed char sal_Int8
ResultType type