20#if !defined WIN32_LEAN_AND_MEAN
21# define WIN32_LEAN_AND_MEAN
28#include "rtl/ustring.hxx"
29#include "rtl/ustrbuf.hxx"
30#include "uno/sequence2.h"
31#include "typelib/typedescription.hxx"
36#using <cli_uretypes.dll>
40namespace sri = System::Runtime::InteropServices;
41namespace sr = System::Reflection;
42namespace st = System::Text;
43namespace ucss = unoidl::com::sun::star;
53inline std::unique_ptr< rtl_mem >
seq_allocate( sal_Int32 nElements, sal_Int32 nSize )
55 std::unique_ptr< rtl_mem > seq(
57 uno_Sequence *
p = (uno_Sequence *)seq.get();
63System::Object^
Bridge::map_uno2cli(uno_Interface * pUnoI, typelib_InterfaceTypeDescription *pTD)
const
65 System::Object^ retVal=
nullptr;
67 rtl_uString * pOid = 0;
69 OSL_ASSERT( 0 != pOid );
70 OUString oid(pOid, SAL_NO_ACQUIRE);
86 if (srr::RemotingServices::IsTransparentProxy(retVal))
89 srr::RemotingServices::GetRealProxy(retVal));
90 p->addUnoInterface(pUnoI, pTD);
96 (
Bridge *)
this, pUnoI, pTD, oid );
109 uno_Interface* retIface =
NULL;
115 (typelib_InterfaceTypeDescription*) pTD);
118 System::Threading::Monitor::Enter(Cli_environment::typeid);
122 (typelib_InterfaceTypeDescription*) pTD);
130 System::Threading::Monitor::Exit(Cli_environment::typeid);
143 System::Type^ retVal=
nullptr;
148 bool bIsPolymorphic =
false;
150 System::String ^ loadName = unoName;
151 int index = unoName->IndexOf(
'<');
154 loadName = unoName->Substring(0,
index);
155 bIsPolymorphic =
true;
157 System::AppDomain^ currentDomain = System::AppDomain::CurrentDomain;
158 cli::array<sr::Assembly^>^ assems = currentDomain->GetAssemblies();
159 for (
int i = 0;
i < assems->Length;
i++)
161 retVal = assems[
i]->GetType(loadName,
false);
166 if (retVal ==
nullptr)
168 System::String ^ msg = gcnew System::String(
"A type could not be loaded: ");
169 msg = System::String::Concat(msg, loadName);
178 catch( System::Exception ^ e)
191System::Type^
mapUnoType(typelib_TypeDescriptionReference
const * pTD)
193 System::Type ^ retVal =
nullptr;
194 switch (pTD->eTypeClass)
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:
230 case typelib_TypeClass_INTERFACE:
233 OUString usXInterface(
"com.sun.star.uno.XInterface");
234 if (usXInterface.equals(pTD->pTypeName))
235 retVal= System::Object::typeid;
240 case typelib_TypeClass_SEQUENCE:
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)
248 case typelib_TypeClass_CHAR:
249 retVal= System::Type::GetType(
const_cast<System::String^
>(
Constants::sArChar));
break;
250 case typelib_TypeClass_BOOLEAN:
253 case typelib_TypeClass_BYTE:
256 case typelib_TypeClass_SHORT:
259 case typelib_TypeClass_UNSIGNED_SHORT:
262 case typelib_TypeClass_LONG:
265 case typelib_TypeClass_UNSIGNED_LONG:
268 case typelib_TypeClass_HYPER:
271 case typelib_TypeClass_UNSIGNED_HYPER:
274 case typelib_TypeClass_FLOAT:
277 case typelib_TypeClass_DOUBLE:
280 case typelib_TypeClass_STRING:
283 case typelib_TypeClass_TYPE:
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:
312typelib_TypeDescriptionReference*
mapCliType(System::Type^ cliType)
314 typelib_TypeDescriptionReference* retVal=
NULL;
315 if (cliType ==
nullptr)
318 typelib_TypeClass_VOID );
327 css::uno::Type unoType(css::uno::TypeClass_ENUM, usTypeName);
328 retVal= unoType.getTypeLibType();
333 switch (System::Type::GetTypeCode(cliType))
335 case System::TypeCode::Boolean:
337 typelib_TypeClass_BOOLEAN );
340 case System::TypeCode::Char:
342 typelib_TypeClass_CHAR );
345 case System::TypeCode::Byte:
347 typelib_TypeClass_BYTE );
350 case System::TypeCode::Int16:
352 typelib_TypeClass_SHORT );
355 case System::TypeCode::Int32:
357 typelib_TypeClass_LONG );
360 case System::TypeCode::Int64:
362 typelib_TypeClass_HYPER );
365 case System::TypeCode::UInt16:
367 typelib_TypeClass_UNSIGNED_SHORT );
370 case System::TypeCode::UInt32:
372 typelib_TypeClass_UNSIGNED_LONG );
375 case System::TypeCode::UInt64:
377 typelib_TypeClass_UNSIGNED_HYPER );
380 case System::TypeCode::Single:
382 typelib_TypeClass_FLOAT );
385 case System::TypeCode::Double:
387 typelib_TypeClass_DOUBLE );
390 case System::TypeCode::String:
392 typelib_TypeClass_STRING );
401 System::String^ cliTypeName= cliType->FullName;
407 typelib_TypeClass_VOID );
415 typelib_TypeClass_TYPE );
423 typelib_TypeClass_ANY );
439 retVal = td->pWeakRef;
457 OUString usUnoName(
const_cast< rtl_uString *
>(
typeName ) );
458 st::StringBuilder^ buf= gcnew st::StringBuilder();
461 if (usUnoName[0] ==
'[')
466 if (usUnoName[
index++] ==
']')
468 if (usUnoName[
index++] !=
'[')
471 usUnoName = usUnoName.copy(
index - 1);
473 System::String ^ sUnoName =
mapUnoString(usUnoName.pData);
520 return buf->ToString();
549 int index = unoName->IndexOf(
'<');
553 System::Text::StringBuilder ^ builder = gcnew System::Text::StringBuilder(256);
554 builder->Append(unoName->Substring(0,
index +1 ));
560 int endIndex = unoName->Length - 1;
564 while (cur <= endIndex)
566 System::Char c = unoName[cur];
567 if (c ==
',' || c ==
'>')
570 if (countParams != 0)
571 builder->Append(
",");
573 System::String ^ sParam = unoName->Substring(
index, cur -
index);
595 System::Char curChar = unoName[cur];
600 else if (curChar ==
'>')
612 builder->Append((System::Char)
'>');
613 return builder->ToString();
624 bool bRightBracket =
false;
630 bRightBracket =
true;
636 "Typename is wrong. No matching brackets for sequence. Name is: " +
638 bRightBracket =
false;
645 "Typename is wrong. No matching brackets for sequence. Name is: " +
652 if (bRightBracket || cur < 0)
654 "Typename is wrong. " +
659 System::Text::StringBuilder ^ buf = gcnew System::Text::StringBuilder(512);
700 int i=
sName->IndexOf(L
'.');
701 buf->Append(
sName->Substring(
i + 1));
712 return gcnew System::String((__wchar_t*) data->buffer, 0, data->length);
720 static_assert(
sizeof(wchar_t) ==
sizeof(
sal_Unicode),
"char mismatch");
721 pin_ptr<wchar_t const> pdata= PtrToStringChars(data);
724 const_cast<System::String^
>(data)->
Length);
736 typelib_TypeDescriptionReference * type,
740 switch (
type->eTypeClass)
742 case typelib_TypeClass_VOID:
744 case typelib_TypeClass_CHAR:
746 System::Char aChar= *safe_cast<System::Char^>(cli_data);
750 case typelib_TypeClass_BOOLEAN:
752 System::Boolean aBool= *safe_cast<System::Boolean^>(cli_data);
756 case typelib_TypeClass_BYTE:
758 System::Byte aByte= *safe_cast<System::Byte^>(cli_data);
762 case typelib_TypeClass_SHORT:
764 System::Int16 aShort= *safe_cast<System::Int16^>(cli_data);
765 *(sal_Int16*) uno_data= aShort;
768 case typelib_TypeClass_UNSIGNED_SHORT:
770 System::UInt16 aUShort= *safe_cast<System::UInt16^>(cli_data);
771 *(sal_uInt16*) uno_data= aUShort;
774 case typelib_TypeClass_LONG:
776 System::Int32 aLong= *safe_cast<System::Int32^>(cli_data);
777 *(sal_Int32*) uno_data= aLong;
780 case typelib_TypeClass_UNSIGNED_LONG:
782 System::UInt32 aULong= *safe_cast<System::UInt32^>(cli_data);
783 *(sal_uInt32*) uno_data= aULong;
786 case typelib_TypeClass_HYPER:
788 System::Int64 aHyper= *safe_cast<System::Int64^>(cli_data);
789 *(sal_Int64*) uno_data= aHyper;
792 case typelib_TypeClass_UNSIGNED_HYPER:
794 System::UInt64 aLong= *safe_cast<System::UInt64^>(cli_data);
795 *(sal_uInt64*) uno_data= aLong;
798 case typelib_TypeClass_FLOAT:
800 System::Single aFloat= *safe_cast<System::Single^>(cli_data);
801 *(
float*) uno_data= aFloat;
804 case typelib_TypeClass_DOUBLE:
806 System::Double aDouble= *safe_cast<System::Double^>(cli_data);
807 *(
double*) uno_data= aDouble;
810 case typelib_TypeClass_STRING:
812 if (
assign && *(rtl_uString**) uno_data)
813 rtl_uString_release(*(rtl_uString**) uno_data);
815 *(rtl_uString **)uno_data = 0;
816 if (cli_data ==
nullptr)
818 rtl_uString_new((rtl_uString**) uno_data);
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);
830 case typelib_TypeClass_TYPE:
832 typelib_TypeDescriptionReference* td=
mapCliType(safe_cast<System::Type^>(
837 *(typelib_TypeDescriptionReference **)uno_data );
839 *(typelib_TypeDescriptionReference **)uno_data = td;
842 case typelib_TypeClass_ANY:
845 if (cli_data ==
nullptr)
852 uno::Any aAny= *safe_cast<uno::Any^>(cli_data);
853 css::uno::Type value_td(
mapCliType(aAny.Type), SAL_NO_ACQUIRE);
860 switch (value_td.getTypeClass())
862 case css::uno::TypeClass_VOID:
863 pAny->pData = &pAny->pReserved;
865 case css::uno::TypeClass_CHAR:
866 pAny->pData = &pAny->pReserved;
867 *(
sal_Unicode*) &pAny->pReserved = *safe_cast<System::Char^>(aAny.Value);
869 case css::uno::TypeClass_BOOLEAN:
870 pAny->pData = &pAny->pReserved;
871 *(
sal_Bool *) &pAny->pReserved = *safe_cast<System::Boolean^>(aAny.Value);
873 case css::uno::TypeClass_BYTE:
874 pAny->pData = &pAny->pReserved;
875 *(
sal_Int8*) &pAny->pReserved = *safe_cast<System::Byte^>(aAny.Value);
877 case css::uno::TypeClass_SHORT:
878 pAny->pData = &pAny->pReserved;
879 *(sal_Int16*) &pAny->pReserved = *safe_cast<System::Int16^>(aAny.Value);
881 case css::uno::TypeClass_UNSIGNED_SHORT:
882 pAny->pData = &pAny->pReserved;
883 *(sal_uInt16*) &pAny->pReserved = *safe_cast<System::UInt16^>(aAny.Value);
885 case css::uno::TypeClass_LONG:
886 pAny->pData = &pAny->pReserved;
887 *(sal_Int32*) &pAny->pReserved = *safe_cast<System::Int32^>(aAny.Value);
889 case css::uno::TypeClass_UNSIGNED_LONG:
890 pAny->pData = &pAny->pReserved;
891 *(sal_uInt32*) &pAny->pReserved = *safe_cast<System::UInt32^>(aAny.Value);
893 case css::uno::TypeClass_HYPER:
894 if (
sizeof (sal_Int64) <=
sizeof (
void *))
896 pAny->pData = &pAny->pReserved;
897 *(sal_Int64*) &pAny->pReserved = *safe_cast<System::Int64^>(aAny.Value);
902 *(sal_Int64 *) mem.get()= *safe_cast<System::Int64^>(aAny.Value);
903 pAny->pData = mem.release();
906 case css::uno::TypeClass_UNSIGNED_HYPER:
907 if (
sizeof (sal_uInt64) <=
sizeof (
void *))
909 pAny->pData = &pAny->pReserved;
910 *(sal_uInt64*) &pAny->pReserved = *safe_cast<System::UInt64^>(aAny.Value);
915 *(sal_uInt64 *) mem.get()= *safe_cast<System::UInt64^>(aAny.Value);
916 pAny->pData = mem.release();
919 case css::uno::TypeClass_FLOAT:
920 if (
sizeof (
float) <=
sizeof (
void *))
922 pAny->pData = &pAny->pReserved;
923 *(
float*) &pAny->pReserved = *safe_cast<System::Single^>(aAny.Value);
928 *(
float*) mem.get() = *safe_cast<System::Single^>(aAny.Value);
929 pAny->pData = mem.release();
932 case css::uno::TypeClass_DOUBLE:
933 if (
sizeof (
double) <=
sizeof (
void *))
935 pAny->pData = &pAny->pReserved;
936 *(
double*) &pAny->pReserved= *safe_cast<System::Double^>(aAny.Value);
941 *(
double*) mem.get()= *safe_cast<System::Double^>(aAny.Value);
942 pAny->pData= mem.release();
945 case css::uno::TypeClass_STRING:
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);
953 case css::uno::TypeClass_TYPE:
954 case css::uno::TypeClass_ENUM:
955 case css::uno::TypeClass_SEQUENCE:
956 case css::uno::TypeClass_INTERFACE:
957 pAny->pData = &pAny->pReserved;
960 &pAny->pReserved, aAny.Value, value_td.getTypeLibType(),
963 case css::uno::TypeClass_STRUCT:
964 case css::uno::TypeClass_EXCEPTION:
966 css::uno::Type anyType(value_td);
968 anyType.getDescription(&td);
972 mem.get(), aAny.Value, value_td.getTypeLibType(),
974 pAny->pData = mem.release();
979 throw BridgeRuntimeError(
"[map_to_uno():" + value_td.getTypeName() +
"] unsupported value type of any!");
983 catch(System::InvalidCastException^ )
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)
991 css::uno::Type td(
mapCliType(aAny.Value->GetType()), SAL_NO_ACQUIRE);
992 str += td.getTypeName();
1011 pAny->pType = value_td.getTypeLibType();
1015 case typelib_TypeClass_ENUM:
1018 System::Int32 aEnum= System::Convert::ToInt32((cli_data));
1019 *(sal_Int32*) uno_data = aEnum;
1022 case typelib_TypeClass_STRUCT:
1023 case typelib_TypeClass_EXCEPTION:
1025 css::uno::TypeDescription td(
type);
1026 typelib_CompoundTypeDescription * comp_td =
1027 (typelib_CompoundTypeDescription*) td.get();
1029 typelib_StructTypeDescription * struct_td =
NULL;
1030 if (
type->eTypeClass == typelib_TypeClass_STRUCT)
1031 struct_td = (typelib_StructTypeDescription*) td.get();
1034 ::typelib_typedescription_complete(
1037 sal_Int32 nMembers = comp_td->nMembers;
1038 boolean bException=
false;
1039 System::Type^ cliType =
nullptr;
1041 cliType = cli_data->GetType();
1043 if (0 != comp_td->pBaseTypeDescription)
1053 OUString usUnoException(
"com.sun.star.uno.Exception");
1056 typelib_TypeDescriptionReference * member_type= comp_td->ppTypeRefs[
nPos];
1057 System::Object^ val=
nullptr;
1058 if (cli_data !=
nullptr)
1060 sr::FieldInfo^ aField= cliType->GetField(
1065 if ( ! aField && usUnoException.equals(td.get()->pTypeName))
1067 OUString usMessageMember(
"Message");
1068 if (usMessageMember.equals(comp_td->ppMemberNames[
nPos]))
1070 sr::PropertyInfo^ pi= cliType->GetProperty(
1072 val= pi->GetValue(cli_data,
nullptr);
1076 throw BridgeRuntimeError(
"[map_to_uno(): Member: " + OUString::unacquired(&comp_td->ppMemberNames[
nPos]));
1081 val= aField->GetValue(cli_data);
1084 void *
p = (
char *) uno_data + comp_td->pMemberOffsets[
nPos ];
1087 bool bDefault = (struct_td !=
NULL
1088 && struct_td->pParameterizedTypes !=
NULL
1091 || cli_data ==
nullptr;
1092 switch (member_type->eTypeClass)
1094 case typelib_TypeClass_CHAR:
1100 case typelib_TypeClass_BOOLEAN:
1104 *(
sal_Bool*)
p = *safe_cast<System::Boolean^>(val);
1106 case typelib_TypeClass_BYTE:
1110 *(
sal_Int8*)
p = *safe_cast<System::Byte^>(val);
1112 case typelib_TypeClass_SHORT:
1114 *(sal_Int16*)
p = 0;
1116 *(sal_Int16*)
p = *safe_cast<System::Int16^>(val);
1118 case typelib_TypeClass_UNSIGNED_SHORT:
1120 *(sal_uInt16*)
p = 0;
1122 *(sal_uInt16*)
p = *safe_cast<System::UInt16^>(val);
1124 case typelib_TypeClass_LONG:
1126 *(sal_Int32*)
p = 0;
1128 *(sal_Int32*)
p = *safe_cast<System::Int32^>(val);
1130 case typelib_TypeClass_UNSIGNED_LONG:
1132 *(sal_uInt32*)
p = 0;
1134 *(sal_uInt32*)
p = *safe_cast<System::UInt32^>(val);
1136 case typelib_TypeClass_HYPER:
1138 *(sal_Int64*)
p = 0;
1140 *(sal_Int64*)
p = *safe_cast<System::Int64^>(val);
1142 case typelib_TypeClass_UNSIGNED_HYPER:
1144 *(sal_uInt64*)
p = 0;
1146 *(sal_uInt64*)
p= *safe_cast<System::UInt64^>(val);
1148 case typelib_TypeClass_FLOAT:
1152 *(
float*)
p = *safe_cast<System::Single^>(val);
1154 case typelib_TypeClass_DOUBLE:
1158 *(
double*)
p = *safe_cast<System::Double^>(val);
1171 OUString str =
"[map_to_uno():";
1174 str +=
mapCliString(cliType->FullName) +
"." + OUString::unacquired(&comp_td->ppMemberNames[
nPos]) +
" ";
1179 catch (System::InvalidCastException^ )
1182 OUString str =
"[map_to_uno():";
1185 str +=
mapCliString(cliType->FullName) +
"." + OUString::unacquired(&comp_td->ppMemberNames[
nPos]);
1187 str +=
"] Value has not the required type.";
1198 if (bException && !
assign)
1201 for ( sal_Int32 nCleanup = 0; nCleanup <
nPos; ++nCleanup )
1204 uno_data, comp_td->ppTypeRefs[ nCleanup ], 0 );
1206 if (0 != comp_td->pBaseTypeDescription)
1215 case typelib_TypeClass_SEQUENCE:
1218 typelib_TypeDescriptionReference * element_type =
1219 ((typelib_IndirectTypeDescription *)td.
get())->pType;
1221 std::unique_ptr< rtl_mem > seq;
1223 System::Array^ ar =
nullptr;
1224 if (cli_data !=
nullptr)
1226 ar = safe_cast<System::Array^>(cli_data);
1231 switch (element_type->eTypeClass)
1233 case typelib_TypeClass_CHAR:
1235 sri::Marshal::Copy(safe_cast<cli::array<System::Char>^>(cli_data), 0,
1236 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1238 case typelib_TypeClass_BOOLEAN:
1240 sri::Marshal::Copy(safe_cast<cli::array<System::Char>^>(cli_data), 0,
1241 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1243 case typelib_TypeClass_BYTE:
1245 sri::Marshal::Copy(safe_cast<cli::array<System::Byte>^>(cli_data), 0,
1246 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1248 case typelib_TypeClass_SHORT:
1250 sri::Marshal::Copy(safe_cast<cli::array<System::Int16>^>(cli_data), 0,
1251 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1253 case typelib_TypeClass_UNSIGNED_SHORT:
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);
1259 case typelib_TypeClass_LONG:
1261 sri::Marshal::Copy(safe_cast<cli::array<System::Int32>^>(cli_data), 0,
1262 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1264 case typelib_TypeClass_UNSIGNED_LONG:
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);
1270 case typelib_TypeClass_HYPER:
1272 sri::Marshal::Copy(safe_cast<cli::array<System::Int64>^>(cli_data), 0,
1273 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1275 case typelib_TypeClass_UNSIGNED_HYPER:
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);
1281 case typelib_TypeClass_FLOAT:
1283 sri::Marshal::Copy(safe_cast<cli::array<System::Single>^>(cli_data), 0,
1284 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1286 case typelib_TypeClass_DOUBLE:
1288 sri::Marshal::Copy(safe_cast<cli::array<System::Double>^>(cli_data), 0,
1289 IntPtr(& ((uno_Sequence*) seq.get())->elements),
nElements);
1291 case typelib_TypeClass_STRING:
1294 cli::array<System::String^>^ arStr= safe_cast<cli::array<System::String^>^>(cli_data);
1297 pin_ptr<const wchar_t> pdata= PtrToStringChars(arStr[
i]);
1298 rtl_uString** pStr= & ((rtl_uString**) &
1299 ((uno_Sequence*) seq.get())->elements)[
i];
1301 rtl_uString_newFromStr_WithLength(
1308 case typelib_TypeClass_ENUM:
1312 ((sal_Int32*) &((uno_Sequence*) seq.get())->elements)[
i]=
1313 System::Convert::ToInt32(ar->GetValue(
i));
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:
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));
1334 p, elemData, element_td.
get()->pWeakRef,
1340 for ( sal_Int32 nCleanPos = 0; nCleanPos <
nPos; ++nCleanPos )
1343 ((uno_Sequence *)seq.get())->elements +
1344 (nCleanPos * element_td.
get()->nSize);
1355 "] unsupported sequence element type: " + OUString::unacquired( &element_type->pTypeName ));
1363 catch (System::InvalidCastException^ )
1367 "] could not convert sequence element type: " + OUString::unacquired( &element_type->pTypeName ));
1384 *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release();
1387 case typelib_TypeClass_INTERFACE:
1391 uno_Interface *
p = *(uno_Interface **)uno_data;
1395 if (
nullptr == cli_data)
1397 *(uno_Interface **)uno_data = 0;
1403 *(uno_Interface **)uno_data = pUnoI;
1410 throw BridgeRuntimeError(
"[map_to_uno():" + OUString::unacquired( &
type->pTypeName ) +
"] unsupported type!");
1415 catch (System::InvalidCastException^ )
1418 throw BridgeRuntimeError(
"[map_to_uno():" + OUString::unacquired( &
type->pTypeName ) +
"] could not convert type!");
1420 catch (System::NullReferenceException ^ e)
1449 System::Object^ *cli_data,
void const * uno_data,
1450 typelib_TypeDescriptionReference * type, System::Type^ info,
1451 bool bDontCreateObj)
const
1453 switch (
type->eTypeClass)
1455 case typelib_TypeClass_CHAR:
1456 *cli_data= *(__wchar_t
const*)uno_data;
1458 case typelib_TypeClass_BOOLEAN:
1459 *cli_data = (*(
bool const*)uno_data) ==
sal_True;
1461 case typelib_TypeClass_BYTE:
1462 *cli_data = *(
unsigned char const*) uno_data;
1464 case typelib_TypeClass_SHORT:
1465 *cli_data= *(
short const*) uno_data;
1467 case typelib_TypeClass_UNSIGNED_SHORT:
1468 *cli_data= *(
unsigned short const*) uno_data;
1470 case typelib_TypeClass_LONG:
1471 *cli_data= *(
int const*) uno_data;
1473 case typelib_TypeClass_UNSIGNED_LONG:
1474 *cli_data= *(
unsigned int const*) uno_data;
1476 case typelib_TypeClass_HYPER:
1477 *cli_data= *(__int64
const*) uno_data;
1479 case typelib_TypeClass_UNSIGNED_HYPER:
1480 *cli_data= *(
unsigned __int64
const*) uno_data;
1482 case typelib_TypeClass_FLOAT:
1483 *cli_data= *(
float const*) uno_data;
1485 case typelib_TypeClass_DOUBLE:
1486 *cli_data= *(
double const*) uno_data;
1488 case typelib_TypeClass_STRING:
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);
1495 case typelib_TypeClass_TYPE:
1497 *cli_data=
mapUnoType( *(typelib_TypeDescriptionReference *
const *)uno_data );
1500 case typelib_TypeClass_ANY:
1503 if (typelib_TypeClass_VOID != pAny->pType->eTypeClass)
1505 System::Object^ objCli=
nullptr;
1507 &objCli, pAny->pData, pAny->pType,
nullptr,
1515 *cli_data= uno::Any::VOID;
1519 case typelib_TypeClass_ENUM:
1521 if (info !=
nullptr)
1523 OSL_ASSERT(info->IsByRef);
1524 info= info->GetElementType();
1525 *cli_data= System::Enum::ToObject(info, *(System::Int32*) uno_data);
1528 *cli_data= System::Enum::ToObject(
1532 case typelib_TypeClass_STRUCT:
1533 case typelib_TypeClass_EXCEPTION:
1536 typelib_CompoundTypeDescription * comp_td =
1537 (typelib_CompoundTypeDescription *) td.
get();
1539 ::typelib_typedescription_complete(
1549 System::Object^ cliObj;
1556 if (ucss::uno::Exception::typeid->IsAssignableFrom(cliType))
1561 typelib_CompoundTypeDescription* pCTD = comp_td;
1562 while (pCTD->pBaseTypeDescription)
1563 pCTD = pCTD->pBaseTypeDescription;
1566 OUString usMessageMember(
"Message");
1567 for (
int i = 0;
i < pCTD->nMembers;
i ++)
1569 if (usMessageMember.equals(pCTD->ppMemberNames[
i]))
1575 OSL_ASSERT (
nPos != -1);
1576 int offset = pCTD->pMemberOffsets[
nPos];
1579 ((
char*) uno_data + offset));
1582 cli::array<sr::ConstructorInfo^>^ arCtorInfo = cliType->GetConstructors();
1583 sr::ConstructorInfo^ ctorInfo =
nullptr;
1584 int numCtors = arCtorInfo->Length;
1587 cli::array<sr::ParameterInfo^>^ arParamInfo;
1588 for (
int i = 0;
i < numCtors;
i++)
1590 arParamInfo = arCtorInfo[
i]->GetParameters();
1591 if (arParamInfo->Length < 2)
1593 ctorInfo = arCtorInfo[
i];
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);
1601 int numArgs = arParamInfo->Length;
1602 cli::array<System::Object^>^
args = gcnew cli::array<System::Object^>(numArgs);
1605 cliObj = ctorInfo->Invoke(
args);
1608 cliObj = System::Activator::CreateInstance(cliType);
1610 sal_Int32 * pMemberOffsets = comp_td->pMemberOffsets;
1612 if (comp_td->pBaseTypeDescription)
1622 OUString usUnoException(
"com.sun.star.uno.Exception");
1623 for (sal_Int32
nPos = comp_td->nMembers;
nPos--; )
1625 typelib_TypeDescriptionReference * member_type = comp_td->ppTypeRefs[
nPos ];
1627 sr::FieldInfo^ aField= cliType->GetField(sMemberName);
1630 if ( ! aField && usUnoException.equals(td.
get()->pTypeName))
1634 void const *
p = (
char const *)uno_data + pMemberOffsets[
nPos ];
1635 switch (member_type->eTypeClass)
1637 case typelib_TypeClass_CHAR:
1638 aField->SetValue(cliObj, *(System::Char*)
p);
1640 case typelib_TypeClass_BOOLEAN:
1641 aField->SetValue(cliObj, *(System::Boolean*)
p);
1643 case typelib_TypeClass_BYTE:
1644 aField->SetValue(cliObj, *(System::Byte*)
p);
1646 case typelib_TypeClass_SHORT:
1647 aField->SetValue(cliObj, *(System::Int16*)
p);
1649 case typelib_TypeClass_UNSIGNED_SHORT:
1650 aField->SetValue(cliObj, *(System::UInt16*)
p);
1652 case typelib_TypeClass_LONG:
1653 aField->SetValue(cliObj, *(System::Int32*)
p);
1655 case typelib_TypeClass_UNSIGNED_LONG:
1656 aField->SetValue(cliObj, *(System::UInt32*)
p);
1658 case typelib_TypeClass_HYPER:
1659 aField->SetValue(cliObj, *(System::Int64*)
p);
1661 case typelib_TypeClass_UNSIGNED_HYPER:
1662 aField->SetValue(cliObj, *(System::UInt64*)
p);
1664 case typelib_TypeClass_FLOAT:
1665 aField->SetValue(cliObj, *(System::Single*)
p);
1667 case typelib_TypeClass_DOUBLE:
1668 aField->SetValue(cliObj, *(System::Double*)
p);
1672 System::Object^ cli_val;
1674 &cli_val,
p, member_type,
nullptr,
1676 aField->SetValue(cliObj, cli_val);
1684 case typelib_TypeClass_SEQUENCE:
1687 uno_Sequence
const * seq = 0;
1688 seq = *(uno_Sequence *
const *)uno_data;
1692 typelib_TypeDescriptionReference * element_type =
1693 ((typelib_IndirectTypeDescription *)td.
get())->pType;
1695 switch (element_type->eTypeClass)
1697 case typelib_TypeClass_CHAR:
1699 cli::array<System::Char>^ arChar= gcnew cli::array<System::Char>(
nElements);
1700 sri::Marshal::Copy( IntPtr((
void*) &seq->elements), arChar, 0,
nElements);
1704 case typelib_TypeClass_BOOLEAN:
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);
1711 case typelib_TypeClass_BYTE:
1713 cli::array<System::Byte>^ arByte= gcnew cli::array<System::Byte>(
nElements);
1714 sri::Marshal::Copy( IntPtr((
void*) &seq->elements), arByte, 0,
nElements);
1718 case typelib_TypeClass_SHORT:
1720 cli::array<System::Int16>^ arShort= gcnew cli::array<System::Int16>(
nElements);
1721 sri::Marshal::Copy( IntPtr((
void*) &seq->elements), arShort, 0,
nElements);
1725 case typelib_TypeClass_UNSIGNED_SHORT:
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),
1730 *cli_data= arUInt16;
1733 case typelib_TypeClass_LONG:
1735 cli::array<System::Int32>^ arInt32= gcnew cli::array<System::Int32>(
nElements);
1736 sri::Marshal::Copy( IntPtr((
void*) &seq->elements), arInt32, 0,
nElements);
1740 case typelib_TypeClass_UNSIGNED_LONG:
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),
1745 *cli_data= arUInt32;
1748 case typelib_TypeClass_HYPER:
1750 cli::array<System::Int64>^ arInt64= gcnew cli::array<System::Int64>(
nElements);
1751 sri::Marshal::Copy( IntPtr((
void*) &seq->elements), arInt64, 0,
nElements);
1756 case typelib_TypeClass_UNSIGNED_HYPER:
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);
1763 case typelib_TypeClass_FLOAT:
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;
1770 case typelib_TypeClass_DOUBLE:
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;
1777 case typelib_TypeClass_STRING:
1779 cli::array<System::String^>^ arString= gcnew cli::array<System::String^>(
nElements);
1782 rtl_uString *
aStr= ((rtl_uString**)(&seq->elements))[
i];
1783 arString[
i]= gcnew System::String( (__wchar_t *) &
aStr->buffer, 0,
aStr->length);
1785 *cli_data= arString;
1788 case typelib_TypeClass_TYPE:
1790 cli::array<System::Type^>^ arType= gcnew cli::array<System::Type^>(
nElements);
1794 mapUnoType( ((typelib_TypeDescriptionReference**) seq->elements)[
i]);
1799 case typelib_TypeClass_ANY:
1801 cli::array<uno::Any>^ arCli= gcnew cli::array<uno::Any>(
nElements);
1805 System::Object^ cli_obj =
nullptr;
1807 &cli_obj, &
p[
nPos ], element_type,
nullptr,
false);
1808 arCli[
nPos]= *safe_cast<uno::Any^>(cli_obj);
1813 case typelib_TypeClass_ENUM:
1816 System::Type^ enumType=
nullptr;
1817 if (info !=
nullptr)
1820 OSL_ASSERT(info->IsByRef);
1821 enumType = info->GetElementType();
1823 enumType = enumType->GetElementType();
1828 System::Array^ arEnum = System::Array::CreateInstance(
1832 arEnum->SetValue(System::Enum::ToObject(enumType,
1833 System::Int32(((sal_Int32*) seq->elements)[
i])),
i);
1838 case typelib_TypeClass_STRUCT:
1839 case typelib_TypeClass_EXCEPTION:
1842 System::Array^ ar= System::Array::CreateInstance(
1847 char *
p = (
char *) &seq->elements;
1848 sal_Int32 nSize = element_td.
get()->nSize;
1851 System::Object^ val;
1853 &val,
p + (nSize *
nPos), element_type,
nullptr,
false);
1854 ar->SetValue(val, System::Int32(
nPos));
1861 case typelib_TypeClass_SEQUENCE:
1863 System::Array ^ar= System::Array::CreateInstance(
1868 uno_Sequence ** elements = (uno_Sequence**) seq->elements;
1871 System::Object^ val;
1873 &val, &elements[
nPos], element_type,
nullptr,
false);
1874 ar->SetValue(val, System::Int32(
nPos));
1880 case typelib_TypeClass_INTERFACE:
1883 System::Type ^ ifaceType=
mapUnoType(element_type);
1884 System::Array^ ar= System::Array::CreateInstance(ifaceType,
nElements);
1886 char *
p = (
char *)seq->elements;
1887 sal_Int32 nSize = element_td.
get()->nSize;
1890 System::Object^ val;
1892 &val,
p + (nSize *
nPos), element_type,
nullptr,
false);
1894 ar->SetValue(val, System::Int32(
nPos));
1902 "] unsupported element type: " + OUString::unacquired( &element_type->pTypeName ));
1907 case typelib_TypeClass_INTERFACE:
1909 uno_Interface * pUnoI = *(uno_Interface *
const *)uno_data;
1914 typelib_InterfaceTypeDescription*
>(td.
get())) ;
1923 throw BridgeRuntimeError(
"[map_to_cli():" + OUString::unacquired( &
type->pTypeName ) +
"] unsupported type!");
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
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.
represents a polymorphic type.
static PolymorphicType GetType(Type type, string name)
provides a unique instance of this class.
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()
struct _typelib_TypeDescription typelib_TypeDescription
System::String mapPolymorphicName(System::String^ unoName, bool bCliToUno)
System::Type loadCliType(System::String ^ typeName)
System::String mapUnoPolymorphicName(System::String^ unoName)
For example, there is a uno type com.sun.star.Foo<char, long>.
std::unique_ptr< rtl_mem > seq_allocate(sal_Int32 nElements, sal_Int32 nSize)
OUString mapCliString(System::String ^ data)
OUString mapCliTypeName(System::String^ typeName)
System::String mapUnoTypeName(rtl_uString const *typeName)
Otherwise a leading "unoidl." is removed.
System::Type mapUnoType(typelib_TypeDescription const *pTD)
System::String mapCliPolymorphicName(System::String^ unoName)
For example, there is a type name such as com.sun.star.Foo<System.Char, System.Int32>.
System::String mapUnoString(rtl_uString const *data)
Maps uno types to dot net types.
typelib_TypeDescriptionReference * mapCliType(System::Type^ cliType)
Returns an acquired td.
def assign(rData, bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, eEnum, rStr, xTest, rAny)
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...
System::Object map_uno2cli(uno_Interface *pUnoI, typelib_InterfaceTypeDescription *pTD) const
void map_to_uno(void *uno_data, System::Object^ cli_data, typelib_TypeDescriptionReference *type, bool assign) const
uno_ExtEnvironment * m_uno_env
uno_Interface * map_cli2uno(System::Object^ cliI, typelib_TypeDescription *pTD) const
void map_to_cli(System::Object^ *cli_data, void const *uno_data, typelib_TypeDescriptionReference *type, System::Type^ info, bool bDontCreateObj) const
static Cli_environment g_cli_env
static uno_Interface * create(Bridge const *bridge, System::Object^ cliI, typelib_TypeDescription const *TD, OUString const &usOid)
static System::String sArUInt32
static System::String usHyper
static System::String sChar
static System::String sDouble
static System::String sArByte
static System::String sArType
static System::String sArInt64
static System::String usShort
static System::String usBrackets
static System::String sArUInt16
static System::String usXInterface
static System::String sType
static System::String sInt32
static System::String sInt64
static System::String sArString
static System::String usVoid
static System::String usULong
static System::String usUHyper
static System::String sArDouble
static System::String usLong
static System::String usDouble
static System::String sUInt16
static System::String sAny
static System::String sUnoidl
static System::String sSingle
static System::String sString
static System::String sArInt16
static System::String usType
static System::String sArSingle
static System::String usByte
static System::String sArBoolean
static System::String usBool
static System::String sArUInt64
static System::String sBoolean
static System::String usUShort
static System::String sUInt64
static System::String sBrackets
static System::String sObject
static System::String usString
static System::String usChar
static System::String sVoid
static System::String usAny
static System::String sArInt32
static System::String sInt16
static System::String sByte
static System::String sUInt32
static System::String usFloat
static System::String sArChar
static std::unique_ptr< rtl_mem > allocate(std::size_t bytes)
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_SEQUENCE_HEADER_SIZE