merge the formfield patch from ooo-build
[ooovba.git] / applied_patches / 0309-cli_ure-mono-bridge.diff
blob61a8157136953146072a2856ac711a36933478e3
1 --- cli_ure/prj/build.lst.old 2009-04-02 10:49:20.000000000 +0000
2 +++ cli_ure/prj/build.lst 2009-04-06 16:41:58.000000000 +0000
3 @@ -8,6 +8,7 @@ ure cli_ure\source\climaker nmake - w,v
4 ure cli_ure\unotypes nmake - w,vc7 ure_unotypes ure_source_version ure_source_source.w ure_source_climaker.w ure_inc NULL
5 ure cli_ure\source\ure nmake - w,vc7 ure_source_ure ure_source_version ure_source_source.w ure_unotypes.w ure_inc NULL
6 ure cli_ure\source\uno_bridge nmake - w,vc7 ure_source_uno_bridge ure_source_basetypes.w ure_unotypes.w ure_source_ure.w ure_inc NULL
7 +ure cli_ure\source\mono_bridge nmake - u ure_source_mono_bridge ure_unotypes ure_source_ure ure_inc NULL
8 ure cli_ure\source\native nmake - w,vc7 ure_source_native ure_source_version ure_source_source.w ure_source_ure.w ure_unotypes.w ure_source_uno_bridge.w ure_inc NULL
10 #ure cli_ure\util nmake - w,vc7 ure_util ure_source_ure.w ure_source_native.w NULL
11 --- cli_ure/source/mono_bridge/binaryuno.cs.old 1970-01-01 00:00:00.000000000 +0000
12 +++ cli_ure/source/mono_bridge/binaryuno.cs 2009-04-06 16:41:58.000000000 +0000
13 @@ -0,0 +1,192 @@
14 +/*************************************************************************
15 + *
16 + * $RCSfile: $
17 + *
18 + * $Revision: $
19 + *
20 + * last change: $Author: $ $Date: $
21 + *
22 + * The Contents of this file are made available subject to the terms of
23 + * either of the following licenses
24 + *
25 + * - GNU Lesser General Public License Version 2.1
26 + * - Sun Industry Standards Source License Version 1.1
27 + *
28 + * Sun Microsystems Inc., October, 2000
29 + *
30 + * GNU Lesser General Public License Version 2.1
31 + * =============================================
32 + * Copyright 2000 by Sun Microsystems, Inc.
33 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
34 + *
35 + * This library is free software; you can redistribute it and/or
36 + * modify it under the terms of the GNU Lesser General Public
37 + * License version 2.1, as published by the Free Software Foundation.
38 + *
39 + * This library is distributed in the hope that it will be useful,
40 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 + * Lesser General Public License for more details.
43 + *
44 + * You should have received a copy of the GNU Lesser General Public
45 + * License along with this library; if not, write to the Free Software
46 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
47 + * MA 02111-1307 USA
48 + *
49 + *
50 + * Sun Industry Standards Source License Version 1.1
51 + * =================================================
52 + * The contents of this file are subject to the Sun Industry Standards
53 + * Source License Version 1.1 (the "License"); You may not use this file
54 + * except in compliance with the License. You may obtain a copy of the
55 + * License at http://www.openoffice.org/license.html.
56 + *
57 + * Software provided under this License is provided on an "AS IS" basis,
58 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
59 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
60 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
61 + * See the License for the specific provisions governing your rights and
62 + * obligations concerning the Software.
63 + *
64 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
65 + *
66 + * Copyright: 2000 by Sun Microsystems, Inc.
67 + *
68 + * All Rights Reserved.
69 + *
70 + * Contributor(s): _______________________________________
71 + *
72 + *
73 + ************************************************************************/
75 +namespace uno.Binary {
77 +using System;
78 +using System.Runtime.InteropServices;
79 +using uno.Typelib;
80 +using uno.rtl;
82 +[ StructLayout(LayoutKind.Sequential) ]
83 +public unsafe struct Any
85 + /** type of value
86 + */
87 + public uno.Typelib.TypeDescriptionReference *pType;
89 + /** pointer to value; this may point to pReserved and thus the uno_Any is not anytime
90 + mem-copyable! You may have to correct the pData pointer to pReserved. Otherwise you need
91 + not, because the data is stored in heap space.
92 + */
93 + public void *pData;
94 + /** reserved space for storing value
95 + */
96 + public void *pReserved;
98 + [ DllImport("uno_cppu", EntryPoint="uno_any_construct") ]
99 + public static unsafe extern void Construct(/* Any */ void *dest,
100 + void *source,
101 + /* uno.Typelib.TypeDescriptionReference */ void *type,
102 + void *acquireFunction);
104 + [ DllImport("uno_cppu", EntryPoint="uno_any_destruct") ]
105 + public static unsafe extern void Destroy(/* Any */ void *value, void *releaseFunction);
108 +// FIXME wrap this nicely
109 +public struct Interface
111 + [ DllImport("cli_uno", EntryPoint="cli_uno_interface_acquire") ]
112 + public static extern void Acquire(IntPtr unoInterface);
114 + [ DllImport("cli_uno", EntryPoint="cli_uno_interface_release") ]
115 + public static extern void Release(IntPtr unoInterface);
117 + [ DllImport("cli_uno", EntryPoint="cli_uno_interface_dispatch") ]
118 + public static unsafe extern void Dispatch(IntPtr unoInterface,
119 + /* uno.Typelib.TypeDescription */ void *memberTD,
120 + void *result,
121 + void **args,
122 + uno.Binary.Any **exception);
125 +// FIXME and this
126 +public class Environment
128 + [ DllImport("cli_uno", EntryPoint="cli_uno_environment_getObjectIdentifier") ]
129 + public static unsafe extern void GetObjectIdentifier(IntPtr unoEnvironment,
130 + UString** oid,
131 + IntPtr unoInterface);
133 + [ DllImport("cli_uno", EntryPoint="cli_uno_environment_registerInterface") ]
134 + public static unsafe extern void RegisterInterface(
135 + IntPtr unoEnvironment,
136 + ref IntPtr ppInterface,
137 + /* UString */ void* oid,
138 + /* InterfaceTypeDescription */ void *td);
140 + [ DllImport("cli_uno", EntryPoint="cli_uno_environment_getRegisteredInterface") ]
141 + public static unsafe extern void GetRegisteredInterface(
142 + IntPtr unoEnvironment,
143 + ref IntPtr ppInterface,
144 + /* UString */ void* oid,
145 + /* InterfaceTypeDescription */ void *td);
148 +public struct Data
150 + [ DllImport("uno_cppu", EntryPoint="uno_type_destructData") ]
151 + public static unsafe extern void Destroy(void *data,
152 + /* uno.Typelib.TypeDescription */ void *td,
153 + // FIXME is this okay? release is a function pointer
154 + void *release);
157 +public unsafe struct SequencePtr
159 + int *sal_Sequence;
161 + // sal_Int32 nRefCount;
162 + // sal_Int32 nElements;
163 + // char elements[1];
165 + /** element count<br>
166 + */
167 + /** elements array<br>
168 + */
170 + /** reference count of sequence<br>
171 + */
172 + private unsafe int nRefCount
174 + get { return *(sal_Sequence); }
175 + set { *(sal_Sequence) = value; }
178 + public unsafe int nElements
180 + get { return *(sal_Sequence + 1); }
181 + set { *(sal_Sequence + 1) = value; }
184 + public unsafe IntPtr elementsPtr
186 + get { return new IntPtr((void *)(sal_Sequence + 2)); }
189 + private unsafe SequencePtr(void *mem)
191 + sal_Sequence = (int*)mem;
194 + private const int HEADER_SIZE = 8; // FIXME alignment
196 + public static SequencePtr Allocate(int length, int elementSize)
198 + void *rtlPtr = uno.rtl.Mem.Allocate(HEADER_SIZE + (length * elementSize));
199 + SequencePtr seqPtr = new SequencePtr(rtlPtr);
200 + seqPtr.nRefCount = 1;
201 + seqPtr.nElements = length;
202 + return seqPtr;
206 --- cli_ure/source/mono_bridge/bridge.cs.old 1970-01-01 00:00:00.000000000 +0000
207 +++ cli_ure/source/mono_bridge/bridge.cs 2009-04-06 16:41:58.000000000 +0000
208 @@ -0,0 +1,1873 @@
209 +/*************************************************************************
211 + * $RCSfile: $
213 + * $Revision: $
215 + * last change: $Author: $ $Date: $
217 + * The Contents of this file are made available subject to the terms of
218 + * either of the following licenses
220 + * - GNU Lesser General Public License Version 2.1
221 + * - Sun Industry Standards Source License Version 1.1
223 + * Sun Microsystems Inc., October, 2000
225 + * GNU Lesser General Public License Version 2.1
226 + * =============================================
227 + * Copyright 2000 by Sun Microsystems, Inc.
228 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
230 + * This library is free software; you can redistribute it and/or
231 + * modify it under the terms of the GNU Lesser General Public
232 + * License version 2.1, as published by the Free Software Foundation.
234 + * This library is distributed in the hope that it will be useful,
235 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
236 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
237 + * Lesser General Public License for more details.
239 + * You should have received a copy of the GNU Lesser General Public
240 + * License along with this library; if not, write to the Free Software
241 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
242 + * MA 02111-1307 USA
245 + * Sun Industry Standards Source License Version 1.1
246 + * =================================================
247 + * The contents of this file are subject to the Sun Industry Standards
248 + * Source License Version 1.1 (the "License"); You may not use this file
249 + * except in compliance with the License. You may obtain a copy of the
250 + * License at http://www.openoffice.org/license.html.
252 + * Software provided under this License is provided on an "AS IS" basis,
253 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
254 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
255 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
256 + * See the License for the specific provisions governing your rights and
257 + * obligations concerning the Software.
259 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
261 + * Copyright: 2000 by Sun Microsystems, Inc.
263 + * All Rights Reserved.
265 + * Contributor(s): _______________________________________
268 + ************************************************************************/
270 +namespace com.sun.star.bridges.mono_uno /* FIXME use some uno.foo namespace ? */
273 +using System;
274 +using System.Reflection;
275 +using System.Runtime.InteropServices;
276 +using System.Runtime.Remoting;
277 +using System.Text;
278 +using uno.Binary;
279 +using uno.rtl;
280 +using uno.Typelib;
282 +public unsafe class Bridge
284 + static IntPtr unoEnvironment;
285 + static cli_uno.Cli_environment managedEnvironment;
287 + Bridge(IntPtr unoEnv)
289 + unoEnvironment = unoEnv;
290 + managedEnvironment = new cli_uno.Cli_environment();
293 + public unsafe IntPtr MapManagedToUno(object managedData, TypeDescription *td)
295 + IntPtr result = new IntPtr(null);
297 + // get oid from managed environment
298 + string oid = cli_uno.Cli_environment.getObjectIdentifier(managedData);
300 + UString* unoOid = null;
301 + UString.NewFromString(&unoOid, oid);
302 + uno.Binary.Environment.GetRegisteredInterface(unoEnvironment,
303 + ref result,
304 + unoOid,
305 + (InterfaceTypeDescription *)td);
306 + if (result == IntPtr.Zero)
307 + lock (typeof(cli_uno.Cli_environment))
309 + uno.Binary.Environment.GetRegisteredInterface(unoEnvironment,
310 + ref result,
311 + unoOid,
312 + (InterfaceTypeDescription *)td);
313 + if (result == IntPtr.Zero)
314 + result = CreateManagedProxy(managedData, td, unoOid);
317 + UString.Release(unoOid);
319 + return result;
322 + public unsafe object MapUnoToManaged(IntPtr unoInterface, InterfaceTypeDescription *iTD)
324 + object result = null;
326 + UString* oidPtr = null;
327 + uno.Binary.Environment.GetObjectIdentifier(unoEnvironment, &oidPtr, unoInterface);
329 + // See if the interface was already mapped
330 + Type ifaceType = MapUnoType((TypeDescription *)iTD);
331 + string oid = UString.UStringToString(oidPtr);
332 + // the string is owned by unoEnvironment
333 + oidPtr = null;
335 + lock (managedEnvironment)
337 + result = managedEnvironment.getRegisteredInterface(oid, ifaceType);
338 + if (result != null)
340 + // There is already an registered object. It can either be a proxy
341 + // for the UNO object or a real cli object. In the first case we
342 + // tell the proxy that it shall also represent the current UNO
343 + // interface. If it already does that, then it does nothing
344 + if (RemotingServices.IsTransparentProxy(result))
346 + UnoInterfaceProxy p = (UnoInterfaceProxy)RemotingServices.GetRealProxy(result);
347 + p.AddUnoInterface(unoInterface, iTD);
350 + else
352 + result = UnoInterfaceProxy.Create(this, unoInterface, iTD, oid);
356 + return result;
359 + // FIXME convert cli types to expected types, e.g a long to a short where the uno type
360 + // is a sal_Int16. This could be necessary if a scripting language (typeless) is used
361 + // @param assign the uno_data has to be destructed (in/out args)
362 + unsafe void MapToUno(void *unoData, object managedData,
363 + // FIXME it's a TypeDescriptionReference
364 + TypeDescription *type, bool assign)
366 + // FIXME acquire the TypeDescription?
367 + // FIXME assert that all the type equivalences in the comments hold
368 + switch (type->eTypeClass)
370 + case TypeClass.VOID:
371 + break;
372 + case TypeClass.CHAR:
373 + *(ushort *)unoData = (char)managedData; // sal_Unicode = ushort
374 + break;
375 + case TypeClass.BOOLEAN:
376 + *(byte *)unoData = (bool)managedData ? (byte)1 : (byte)0; // sal_Bool = byte
377 + break;
378 + case TypeClass.BYTE:
379 + *(byte *)unoData = (byte)managedData; // sal_Int8 = byte
380 + break;
381 + case TypeClass.SHORT:
382 + *(short *)unoData = (short)managedData; // sal_Int16 = short
383 + break;
384 + case TypeClass.UNSIGNED_SHORT:
385 + *(ushort *)unoData = (ushort)managedData; // sal_uInt16 = ushort
386 + break;
387 + case TypeClass.LONG:
388 + *(int *)unoData = (int)managedData; // sal_Int32 = int
389 + break;
390 + case TypeClass.UNSIGNED_LONG:
391 + *(uint *)unoData = (uint)managedData; // sal_uInt32 = uint
392 + break;
393 + case TypeClass.HYPER:
394 + *(long *)unoData = (long)managedData; // sal_Int64 = long
395 + break;
396 + case TypeClass.UNSIGNED_HYPER:
397 + *(ulong *)unoData = (ulong)managedData; // sal_uInt64 = ulong
398 + break;
399 + case TypeClass.FLOAT:
400 + *(float *)unoData = (float)managedData; // C++ float = C# float
401 + break;
402 + case TypeClass.DOUBLE:
403 + *(double *)unoData = (double)managedData; // C++ double = C# double
404 + break;
405 + case TypeClass.STRING:
407 + if (assign && *(UString **)unoData != null)
408 + UString.Release(*(UString **)unoData);
410 + *(UString **)unoData = null;
411 + if (managedData == null)
413 + UString.New((UString **)unoData);
415 + else
417 + string s = (string)managedData;
418 + UString.NewFromString((UString **)unoData, s);
421 + break;
422 + case TypeClass.TYPE:
423 + if (assign)
424 + TypeDescriptionReference.Release(*(TypeDescriptionReference **)unoData);
426 + *(TypeDescriptionReference **)unoData = MapManagedType((Type)managedData);
427 + break;
428 + case TypeClass.ANY:
430 + uno.Binary.Any *binAny = (uno.Binary.Any *)unoData;
432 + if (assign)
433 + uno.Binary.Any.Destroy(binAny, null);
435 + if (managedData == null)
437 + uno.Binary.Any.Construct(binAny, null, null, null);
438 + break;
441 + uno.Any any = (uno.Any)managedData;
442 + TypeDescription *valueTD = (TypeDescription *)MapManagedType(any.Type);
444 + // if there's enough room in void *pReserved, store the value in the pointer
445 + binAny->pData = &binAny->pReserved; // this triggers a bug in mcs < 1.1.4
446 + switch (valueTD->eTypeClass)
448 + case TypeClass.VOID:
449 + break;
450 + case TypeClass.CHAR:
451 + *(ushort *)binAny->pData = (char)any.Value;
452 + break;
453 + case TypeClass.BOOLEAN:
454 + *(byte *)binAny->pData = (bool)any.Value ? (byte)1 : (byte)0;
455 + break;
456 + case TypeClass.BYTE:
457 + *(byte *)binAny->pData = (byte)any.Value;
458 + break;
459 + case TypeClass.SHORT:
460 + *(short *)binAny->pData = (short)any.Value;
461 + break;
462 + case TypeClass.UNSIGNED_SHORT:
463 + *(ushort *)binAny->pData = (ushort)any.Value;
464 + break;
465 + case TypeClass.LONG:
466 + *(int *)binAny->pData = (int)any.Value;
467 + break;
468 + case TypeClass.UNSIGNED_LONG:
469 + *(uint *)binAny->pData = (uint)any.Value;
470 + break;
471 + case TypeClass.HYPER:
472 + if (sizeof(long) > sizeof(void *))
473 + binAny->pData = uno.rtl.Mem.Allocate(sizeof(long));
475 + *(long *)binAny->pData = (long)any.Value;
476 + break;
477 + case TypeClass.UNSIGNED_HYPER:
478 + if (sizeof(ulong) > sizeof(void *))
479 + binAny->pData = uno.rtl.Mem.Allocate(sizeof(ulong));
481 + *(ulong *)binAny->pData = (ulong)any.Value;
482 + break;
483 + case TypeClass.FLOAT:
484 + if (sizeof(float) > sizeof(void *)) // FIXME can this happen?
485 + binAny->pData = uno.rtl.Mem.Allocate(sizeof(float));
487 + *(float *)binAny->pData = (float)any.Value;
488 + break;
489 + case TypeClass.DOUBLE:
490 + if (sizeof(double) > sizeof(void *))
491 + binAny->pData = uno.rtl.Mem.Allocate(sizeof(double));
493 + *(double *)binAny->pData = (double)any.Value;
494 + break;
495 + case TypeClass.STRING:
496 + // string anies are used so often, that we handle them
497 + // separately, to be a little faster than with an
498 + // extra MapToUno call
500 + // the Any was already destroyed, can't contain a
501 + // valid string that we could leak here.
502 + *(UString **)binAny->pData = null;
504 + if (managedData == null)
506 + UString.New((UString **)binAny->pData);
508 + else
510 + string s = (string)any.Value;
511 + UString.NewFromString((UString **)binAny->pData, s);
513 + // the string is owned by the Any
514 + break;
515 + case TypeClass.ENUM:
516 + *(int *) binAny->pData = System.Convert.ToInt32(any.Value);
517 + break;
518 + case TypeClass.TYPE:
519 + case TypeClass.SEQUENCE:
520 + case TypeClass.INTERFACE:
521 + binAny->pReserved = null;
522 + MapToUno(binAny->pData, any.Value, valueTD, false /* no assign */);
523 + break;
524 + case TypeClass.STRUCT:
525 + case TypeClass.EXCEPTION:
526 + binAny->pData = uno.rtl.Mem.Allocate(valueTD->nSize);
527 + MapToUno(binAny->pData, any.Value, valueTD, false /* no assign */);
528 + break;
529 + default:
530 + // FIXME
531 + throw new Exception();
533 + binAny->pType = (TypeDescriptionReference *)valueTD;
534 + TypeDescriptionReference.Acquire(binAny->pType);
536 + break;
537 + case TypeClass.ENUM:
538 + *(int *)unoData = System.Convert.ToInt32(managedData);
539 + break;
540 + case TypeClass.STRUCT:
541 + case TypeClass.EXCEPTION:
543 + TypeDescription *td = null; // FIXME leak
544 + TypeDescriptionReference.GetDescription(&td, (TypeDescriptionReference *)type);
545 + CompoundTypeDescription *compTD = (CompoundTypeDescription *)td;
546 + StructTypeDescription *structTD = null;
548 + if (type->eTypeClass == TypeClass.STRUCT)
549 + structTD = (StructTypeDescription *)type;
551 + if (((TypeDescription *)compTD)->bComplete == 0)
552 + TypeDescription.Complete((TypeDescription **)&compTD);
554 + int members = compTD->nMembers;
555 + Type managedType = null;
556 + if (managedData != null)
557 + managedType = managedData.GetType();
559 + if (compTD->pBaseTypeDescription != null)
560 + MapToUno(unoData, managedData,
561 + (TypeDescription *)((TypeDescription *)compTD->pBaseTypeDescription)->pWeakRef,
562 + assign);
564 + TypeDescriptionReference *memberType = null;
565 + for (int i = 0; i < members; ++i)
567 + memberType = compTD->ppTypeRefs[i];
569 + object val = null;
570 + if (managedData != null)
572 + string fieldName = UString.UStringToString(compTD->ppMemberNames[i]);
573 + FieldInfo fieldInfo = managedType.GetField(fieldName);
574 + // special case for Exception.Message property
575 + // The com.sun.star.uno.Exception.Message field is mapped to the
576 + // System.Exception property. Type.GetField("Message") returns null
577 + if (fieldInfo == null &&
578 + UString.UStringToString(type->pTypeName) == "com.sun.star.uno.Exception")
580 + // get ExceptionMessage property
581 + if (fieldName == "Message")
583 + PropertyInfo propInfo = managedType.GetProperty(fieldName);
584 + val = propInfo.GetValue(managedData, null);
585 + } // FIXME else throw exception
587 + else if (fieldInfo != null)
589 + val = fieldInfo.GetValue(managedData);
590 + } // FIXME else throw exception
593 + void *p = (byte *)unoData + compTD->pMemberOffsets[i];
594 + // When using polymorphic structs then the parameterized members can be null.
595 + // Then we set a default value.
596 + bool useDefault = ((structTD != null &&
597 + structTD->pParameterizedTypes != null &&
598 + structTD->pParameterizedTypes[i] == 1 &&
599 + val == null) ||
600 + managedData == null);
601 + switch (memberType->eTypeClass)
603 + case TypeClass.CHAR:
604 + if (useDefault)
605 + *(ushort *)p = 0;
606 + else
607 + *(ushort *)p = (char)val;
608 + break;
609 + case TypeClass.BOOLEAN:
610 + if (useDefault)
611 + *(byte *)p = (byte)0;
612 + else
613 + *(byte *)p = (bool)val ? (byte)1 : (byte)0;
614 + break;
615 + case TypeClass.BYTE:
616 + if (useDefault)
617 + *(byte *)p = (byte)0;
618 + else
619 + *(byte *)p = (byte)val;
620 + break;
621 + case TypeClass.SHORT:
622 + if (useDefault)
623 + *(short *)p = (short)0;
624 + else
625 + *(short *)p = (short)val;
626 + break;
627 + case TypeClass.UNSIGNED_SHORT:
628 + if (useDefault)
629 + *(ushort *)p = (ushort)0;
630 + else
631 + *(ushort *)p = (ushort)val;
632 + break;
633 + case TypeClass.LONG:
634 + if (useDefault)
635 + *(int *)p = 0;
636 + else
637 + *(int *)p = (int)val;
638 + break;
639 + case TypeClass.UNSIGNED_LONG:
640 + if (useDefault)
641 + *(uint *)p = (uint)0;
642 + else
643 + *(uint *)p = (uint)val;
644 + break;
645 + case TypeClass.HYPER:
646 + if (useDefault)
647 + *(long *)p = (long)0;
648 + else
649 + *(long *)p = (long)val;
650 + break;
651 + case TypeClass.UNSIGNED_HYPER:
652 + if (useDefault)
653 + *(ulong *)p = (ulong)0;
654 + else
655 + *(ulong *)p = (ulong)val;
656 + break;
657 + case TypeClass.FLOAT:
658 + if (useDefault)
659 + *(float *)p = 0.0F;
660 + else
661 + *(float *)p = (float)val;
662 + break;
663 + case TypeClass.DOUBLE:
664 + if (useDefault)
665 + *(double *)p = 0.0;
666 + else
667 + *(double *)p = (double)val;
668 + break;
669 + default:
670 + // FIXME enum should be converted here
671 + MapToUno(p, val, (TypeDescription *)memberType, assign);
672 + break;
673 + }
675 + // FIXME exception handling
677 + break;
678 + case TypeClass.SEQUENCE:
680 + TypeDescription *td = null; // FIXME
681 + TypeDescriptionReference.GetDescription(&td, (TypeDescriptionReference *)type);
682 + TypeDescriptionReference *elementType =
683 + ((IndirectTypeDescription *)td)->pType;
685 + SequencePtr seq = new SequencePtr();
687 + if (managedData != null)
689 + Array array = (Array)managedData;
690 + int length = array.GetLength(0);
692 + switch (elementType->eTypeClass)
694 + case TypeClass.CHAR:
695 + seq = SequencePtr.Allocate(length, sizeof(ushort));
696 + Marshal.Copy((char [])managedData, 0, seq.elementsPtr, length);
697 + break;
698 +/* case TypeClass.BOOLEAN:
699 + // FIXME bool vs. byte ???
700 + seq = SequencePtr.Allocate(length, sizeof(byte));
701 + Marshal.Copy((byte [])managedData, 0, seq.elementsPtr, length);
702 + break;*/
703 + case TypeClass.BYTE:
704 + seq = SequencePtr.Allocate(length, sizeof(byte));
705 + Marshal.Copy((byte [])managedData, 0, seq.elementsPtr, length);
706 + break;
707 + case TypeClass.SHORT:
708 + seq = SequencePtr.Allocate(length, sizeof(short));
709 + Marshal.Copy((short [])managedData, 0, seq.elementsPtr, length);
710 + break;
711 +/* case TypeClass.UNSIGNED_SHORT:
712 + seq = SequencePtr.Allocate(length, sizeof(ushort));
713 + Marshal.Copy((short [])managedData, 0, seq.elementsPtr, length);
714 + break; */
715 + case TypeClass.LONG:
716 + seq = SequencePtr.Allocate(length, sizeof(int));
717 + Marshal.Copy((int [])managedData, 0, seq.elementsPtr, length);
718 + break;
719 +/* case TypeClass.UNSIGNED_LONG:
720 + seq = SequencePtr.Allocate(length, sizeof(uint));
721 + Marshal.Copy((int [])managedData, 0, seq.elementsPtr, length);
722 + break; */
723 + case TypeClass.HYPER:
724 + seq = SequencePtr.Allocate(length, sizeof(long));
725 + Marshal.Copy((long [])managedData, 0, seq.elementsPtr, length);
726 + break;
727 +/* case TypeClass.UNSIGNED_HYPER:
728 + seq = SequencePtr.Allocate(length, sizeof(ulong));
729 + Marshal.Copy((long [])managedData, 0, seq.elementsPtr, length);
730 + break; */
731 + case TypeClass.FLOAT:
732 + seq = SequencePtr.Allocate(length, sizeof(float));
733 + Marshal.Copy((float [])managedData, 0, seq.elementsPtr, length);
734 + break;
735 + case TypeClass.DOUBLE:
736 + seq = SequencePtr.Allocate(length, sizeof(double));
737 + Marshal.Copy((double [])managedData, 0, seq.elementsPtr, length);
738 + break;
739 + case TypeClass.STRING:
741 + seq = SequencePtr.Allocate(length, sizeof(void *));
742 + string[] stringArray = (string [])managedData;
743 + for (int i = 0; i < length; ++i)
745 + UString** pStr = ((UString** )seq.elementsPtr) + i;
746 + *pStr = null;
747 + UString.NewFromString(pStr, stringArray[i]);
748 + // string ownership goes to callee
751 + break;
752 + case TypeClass.ENUM:
753 + seq = SequencePtr.Allocate(length, sizeof(int));
754 + for (int i = 0; i < length; ++i)
755 + ((int *)seq.elementsPtr)[i] =
756 + Convert.ToInt32(array.GetValue(i));
757 + break;
758 + case TypeClass.TYPE:
759 + case TypeClass.ANY:
760 + case TypeClass.STRUCT:
761 + case TypeClass.EXCEPTION:
762 + case TypeClass.SEQUENCE:
763 + case TypeClass.INTERFACE:
764 + // FIXME: surely we can do better for this lot [!] - sign problems ...
765 + case TypeClass.BOOLEAN:
766 + case TypeClass.UNSIGNED_SHORT:
767 + case TypeClass.UNSIGNED_LONG:
768 + case TypeClass.UNSIGNED_HYPER:
770 + seq = SequencePtr.Allocate(
771 + length, ((TypeDescription *)elementType)->nSize);
773 + for (int i = 0; i < length; ++i)
775 + void *p =
776 + (byte *)seq.elementsPtr +
777 + i * ((TypeDescription *)elementType)->nSize;
778 + object elementData = ((Array)managedData).GetValue(i);
779 + MapToUno(p, elementData,
780 + (TypeDescription *)((TypeDescription *)elementType)->pWeakRef,
781 + false /* no assign */);
783 + // FIXME exception handling
785 + break;
786 + default:
787 + break; // FIXME throw some exception
790 + else
792 + seq = SequencePtr.Allocate(0, sizeof(int));
794 + *(SequencePtr *)unoData = seq;
796 + break;
797 + case TypeClass.INTERFACE:
799 + if (assign && *(void **)unoData != null)
800 + uno.Binary.Interface.Release(new IntPtr(*(void **)unoData));
802 + if (managedData == null)
803 + *(void **)unoData = null;
804 + else
806 + TypeDescription *td = null; // FIXME leak
807 + TypeDescriptionReference.GetDescription(&td, (TypeDescriptionReference *)type);
808 + *(void **)unoData = MapManagedToUno(managedData, td).ToPointer();
810 + break;
812 + default:
813 + // FIXME throw some exception
814 + break;
818 + unsafe void MapToManaged(ref object managedData, void *unoData,
819 + TypeDescriptionReference *type, Type info, bool dontCreateObj)
821 + switch (type->eTypeClass)
823 + case TypeClass.CHAR:
824 + managedData = (char)*(ushort *)unoData;
825 + break;
826 + case TypeClass.BOOLEAN:
827 + managedData = (*(byte *)unoData != 0);
828 + break;
829 + case TypeClass.BYTE:
830 + managedData = *(byte *)unoData;
831 + break;
832 + case TypeClass.SHORT:
833 + managedData = *(short *)unoData;
834 + break;
835 + case TypeClass.UNSIGNED_SHORT:
836 + managedData = *(ushort *)unoData;
837 + break;
838 + case TypeClass.LONG:
839 + managedData = *(int *)unoData;
840 + break;
841 + case TypeClass.UNSIGNED_LONG:
842 + managedData = *(uint *)unoData;
843 + break;
844 + case TypeClass.HYPER:
845 + managedData = *(long *)unoData;
846 + break;
847 + case TypeClass.UNSIGNED_HYPER:
848 + managedData = *(ulong *)unoData;
849 + break;
850 + case TypeClass.FLOAT:
851 + managedData = *(float *)unoData;
852 + break;
853 + case TypeClass.DOUBLE:
854 + managedData = *(double *)unoData;
855 + break;
856 + case TypeClass.STRING:
857 + managedData = UString.UStringToString(*(UString **)unoData);
858 + break;
859 + case TypeClass.TYPE:
860 + managedData = MapUnoType(*(TypeDescriptionReference **)unoData);
861 + break;
862 + case TypeClass.ANY:
864 + uno.Binary.Any *binAny = (uno.Binary.Any *)unoData;
865 + if (binAny->pType->eTypeClass != TypeClass.VOID)
867 + object value = null;
868 + MapToManaged(ref value, binAny->pData, binAny->pType, null, false);
869 + managedData = new uno.Any(MapUnoType(binAny->pType), value);
871 + else
873 + managedData = uno.Any.VOID;
875 + break;
877 + case TypeClass.ENUM:
878 + if (info != null)
879 + managedData = Enum.ToObject(
880 + info.GetElementType(), *(int *)unoData);
881 + else
882 + managedData = Enum.ToObject(
883 + MapUnoType(type), *(int *)unoData);
884 + break;
885 + case TypeClass.STRUCT:
886 + case TypeClass.EXCEPTION:
888 + TypeDescription *td = null; // FIXME leak
889 + TypeDescriptionReference.GetDescription(&td, (TypeDescriptionReference *)type);
890 + CompoundTypeDescription *compTD = (CompoundTypeDescription *)td;
892 + if (((TypeDescription *)compTD)->bComplete == 0)
893 + TypeDescription.Complete((TypeDescription **)&compTD);
895 + // create the type
896 + Type managedType = LoadCliType(td->pTypeName);
898 + // detect if we recursivly convert inherited
899 + // structures. If this point is reached because of a
900 + // recursive call during converting a struct then we must
901 + // not create a new object rather we use the one in
902 + // cli_data argument.
903 + object managedObject;
904 + if (dontCreateObj)
905 + managedObject = managedData;
906 + else
908 + // Special handling for Exception conversion. We must
909 + // call constructor System::Exception to pass the
910 + // message string
911 + if (typeof(unoidl.com.sun.star.uno.Exception).IsAssignableFrom(managedType))
913 + // We need to get the Message field. Therefore we
914 + // must obtain the offset from the
915 + // typedescription. The base interface of all
916 + // exceptions is com::sun::star::uno::Exception
917 + // which contains the message
918 + CompoundTypeDescription *pCTD = compTD;
919 + while (pCTD->pBaseTypeDescription != null)
920 + pCTD = pCTD->pBaseTypeDescription;
922 + int pos = -1;
923 + for (int i = 0; i < pCTD->nMembers; ++i)
925 + if (UString.UStringToString(pCTD->ppMemberNames[i]) == "Message")
927 + pos = i;
928 + break;
932 + int offset = pCTD->pMemberOffsets[pos];
933 + // With the offset within the exception we can get
934 + // the message string
935 + string message = UString.UStringToString(
936 + (*(UString **)((byte *)unoData + offset)));
937 + // We need to find a constructor for the exception
938 + // that takes the message string. We assume that
939 + // the first argument is the message string
940 + ConstructorInfo[] ctorInfos = managedType.GetConstructors();
941 + ConstructorInfo ctorInfo = null;
942 + // Constructor must at least have 2 params for the base
943 + // unoidl.com.sun.star.uno.Exception (String, Object);
944 + int numArgs = -1;
945 + foreach (ConstructorInfo ci in ctorInfos)
947 + numArgs = ci.GetParameters().Length;
948 + if (numArgs < 2)
949 + continue;
950 + ctorInfo = ci;
951 + break;
954 + // Prepare parameters for constructor
955 + object[] args = new object[numArgs];
956 + // only initialize the first argument with the
957 + // message. All unoidl.<Foo Exception>s are
958 + // autogenerated, we know that this is safe.
959 + args[0] = message;
960 + managedObject = ctorInfo.Invoke(args);
962 + else
963 + managedObject = Activator.CreateInstance(managedType);
966 + TypeDescriptionReference **memberTypeRefs = compTD->ppTypeRefs;
967 + int *memberOffsets = compTD->pMemberOffsets;
969 + if (compTD->pBaseTypeDescription != null)
971 + // convert inherited struct
972 + // cliObj is passed inout (args in_param, out_param are true), hence the passed
973 + // cliObj is used by the callee instead of a newly created struct
974 + MapToManaged(ref managedObject, unoData,
975 + ((TypeDescription *)compTD->pBaseTypeDescription)->pWeakRef,
976 + null,
977 + true);
979 + for (int i = compTD->nMembers - 1; i >= 0; --i)
981 + TypeDescriptionReference *memberType = memberTypeRefs[i];
982 + string memberName = UString.UStringToString(compTD->ppMemberNames[i]);
983 + FieldInfo fieldInfo = managedType.GetField(memberName);
984 + // special case for Exception.Message. The field has already been
985 + // set while constructing cli object
986 + if (fieldInfo == null &&
987 + UString.UStringToString(type->pTypeName) == "com.sun.star.uno.Exception")
988 + continue;
990 + void *p = (byte *)unoData + memberOffsets[i];
991 + switch (memberType->eTypeClass)
993 + case TypeClass.CHAR:
994 + fieldInfo.SetValue(managedObject, (char)*(short *)p);
995 + break;
996 + case TypeClass.BOOLEAN:
997 + fieldInfo.SetValue(managedObject, (*(byte *)p) != 0);
998 + break;
999 + case TypeClass.BYTE:
1000 + fieldInfo.SetValue(managedObject, *(byte *)p);
1001 + break;
1002 + case TypeClass.SHORT:
1003 + fieldInfo.SetValue(managedObject, *(short *)p);
1004 + break;
1005 + case TypeClass.UNSIGNED_SHORT:
1006 + fieldInfo.SetValue(managedObject, *(ushort *)p);
1007 + break;
1008 + case TypeClass.LONG:
1009 + fieldInfo.SetValue(managedObject, *(int *)p);
1010 + break;
1011 + case TypeClass.UNSIGNED_LONG:
1012 + fieldInfo.SetValue(managedObject, *(uint *)p);
1013 + break;
1014 + case TypeClass.HYPER:
1015 + fieldInfo.SetValue(managedObject, *(long *)p);
1016 + break;
1017 + case TypeClass.UNSIGNED_HYPER:
1018 + fieldInfo.SetValue(managedObject, *(ulong *)p);
1019 + break;
1020 + case TypeClass.FLOAT:
1021 + fieldInfo.SetValue(managedObject, *(float *)p);
1022 + break;
1023 + case TypeClass.DOUBLE:
1024 + fieldInfo.SetValue(managedObject, *(double *)p);
1025 + break;
1026 + default:
1028 + object managedValue = null;
1029 + MapToManaged(ref managedValue, p, memberType, null, false);
1030 + fieldInfo.SetValue(managedObject, managedValue);
1031 + break;
1035 + managedData = managedObject;
1036 + break;
1038 + case TypeClass.SEQUENCE:
1040 + SequencePtr seq = *(SequencePtr *)unoData;
1041 + int length = seq.nElements;
1043 + TypeDescription *td = null; // FIXME leak
1044 + TypeDescriptionReference.GetDescription(&td, (TypeDescriptionReference *)type);
1045 + TypeDescriptionReference *elementType = ((IndirectTypeDescription *)td)->pType;
1047 + switch (elementType->eTypeClass)
1049 + case TypeClass.CHAR:
1051 + char[] array = new char[length];
1052 + Marshal.Copy(seq.elementsPtr, array, 0, length);
1053 + managedData = array;
1054 + break;
1056 + case TypeClass.BOOLEAN:
1058 + bool[] array = new bool[length];
1059 + byte *source = (byte *)seq.elementsPtr;
1060 + if (length > 0) fixed (bool *arrayPtr = array)
1062 + bool *dest = arrayPtr;
1063 + for (int i = 0; i < length; ++i)
1064 + *dest++ = (*source++ != 0);
1066 + managedData = array;
1067 + break;
1069 + case TypeClass.BYTE:
1071 + byte[] array = new byte[length];
1072 + byte *source = (byte *)seq.elementsPtr;
1073 + if (length > 0) fixed (byte *arrayPtr = array)
1075 + byte *dest = arrayPtr;
1076 + for (int i = 0; i < length; ++i)
1077 + *dest++ = *source++;
1079 + managedData = array;
1080 + break;
1082 + case TypeClass.SHORT:
1084 + short[] array = new short[length];
1085 + Marshal.Copy(seq.elementsPtr, array, 0, length);
1086 + managedData = array;
1087 + break;
1089 + case TypeClass.UNSIGNED_SHORT:
1091 + ushort[] array = new ushort[length];
1092 + ushort *source = (ushort *)seq.elementsPtr;
1093 + if (length > 0) fixed (ushort *arrayPtr = array)
1095 + ushort *dest = arrayPtr;
1096 + for (int i = 0; i < length; ++i)
1097 + *dest++ = *source++;
1099 + managedData = array;
1100 + break;
1102 + case TypeClass.LONG:
1104 + int[] array = new int[length];
1105 + Marshal.Copy(seq.elementsPtr, array, 0, length);
1106 + managedData = array;
1107 + break;
1109 + case TypeClass.UNSIGNED_LONG:
1111 + uint[] array = new uint[length];
1112 + uint *source = (uint *)seq.elementsPtr;
1113 + if (length > 0) fixed (uint *arrayPtr = array)
1115 + uint *dest = arrayPtr;
1116 + for (int i = 0; i < length; ++i)
1117 + *dest++ = *source++;
1119 + managedData = array;
1120 + break;
1122 + case TypeClass.HYPER:
1124 + long[] array = new long[length];
1125 + Marshal.Copy(seq.elementsPtr, array, 0, length);
1126 + managedData = array;
1127 + break;
1129 + case TypeClass.UNSIGNED_HYPER:
1131 + ulong[] array = new ulong[length];
1132 + ulong *source = (ulong *)seq.elementsPtr;
1133 + if (length > 0) fixed (ulong *arrayPtr = array)
1135 + ulong *dest = arrayPtr;
1136 + for (int i = 0; i < length; ++i)
1137 + *dest++ = *source++;
1139 + managedData = array;
1140 + break;
1142 + case TypeClass.FLOAT:
1144 + float[] array = new float[length];
1145 + Marshal.Copy(seq.elementsPtr, array, 0, length);
1146 + managedData = array;
1147 + break;
1149 + case TypeClass.DOUBLE:
1151 + double[] array = new double[length];
1152 + Marshal.Copy(seq.elementsPtr, array, 0, length);
1153 + managedData = array;
1154 + break;
1156 + case TypeClass.STRING:
1158 + string[] array = new string[length];
1159 + for (int i = 0; i < length; ++i)
1161 + UString *us = ((UString **)seq.elementsPtr)[i];
1162 + array[i] = UString.UStringToString(us);
1164 + managedData = array;
1165 + break;
1167 + case TypeClass.TYPE:
1169 + Type[] array = new Type[length];
1170 + for (int i = 0; i < length; ++i)
1171 + array[i] = MapUnoType(((TypeDescriptionReference **)
1172 + seq.elementsPtr)[i]);
1173 + managedData = array;
1174 + break;
1176 + case TypeClass.ANY:
1178 + uno.Any[] array = new uno.Any[length];
1179 + uno.Binary.Any *binAny = (uno.Binary.Any *)seq.elementsPtr;
1180 + for (int i = 0; i < length; ++i)
1182 + object any = new uno.Any();
1183 + MapToManaged(ref any, (void **)(binAny + i),
1184 + (TypeDescriptionReference *)elementType,
1185 + null, false);
1186 + array[i] = (uno.Any)any;
1188 + managedData = array;
1189 + break;
1191 + case TypeClass.ENUM:
1193 + Type enumType = null;
1194 + if (info != null)
1196 + enumType = info.GetElementType();
1197 + // enumType is EnumType[], get EnumType
1198 + enumType = enumType.GetElementType();
1200 + else
1201 + enumType = MapUnoType(elementType);
1203 + Array array = Array.CreateInstance(enumType, length);
1204 + for (int i = 0; i < length; ++i)
1206 + array.SetValue(Enum.ToObject(enumType,
1207 + ((int *)seq.elementsPtr)[i]),
1208 + i);
1210 + managedData = array;
1211 + break;
1213 + case TypeClass.STRUCT:
1214 + case TypeClass.EXCEPTION:
1216 + Array array = Array.CreateInstance(MapUnoType(elementType), length);
1217 + if (length > 0)
1219 + // FIXME check this
1220 + byte *p = (byte *)seq.elementsPtr;
1221 + int size = ((TypeDescription *)elementType)->nSize;
1222 + for (int i = 0; i < length; ++i)
1224 + object val = null;
1225 + MapToManaged(ref val, p + (size * i), elementType, null, false);
1226 + array.SetValue(val, i);
1229 + managedData = array;
1230 + break;
1232 + // FIXME verify (says cli_data.cxx)
1233 + case TypeClass.SEQUENCE:
1235 + Array array = Array.CreateInstance(
1236 + MapUnoType(elementType), length);
1237 + if (length > 0)
1239 + SequencePtr *elements = (SequencePtr *)seq.elementsPtr;
1240 + for (int i = 0; i < length; ++i)
1242 + object val = null;
1243 + MapToManaged(ref val, elements + i, elementType, null, false);
1244 + array.SetValue(val, i);
1247 + managedData = array;
1248 + break;
1250 + case TypeClass.INTERFACE:
1252 + Type ifaceType = MapUnoType(elementType);
1253 + Array array = Array.CreateInstance(ifaceType, length);
1255 + byte *p = (byte *)seq.elementsPtr;
1256 + int size = ((TypeDescription *)elementType)->nSize;
1257 + for (int i = 0; i < length; ++i)
1259 + object val = null;
1260 + MapToManaged(ref val, p + (size * i), elementType, null, false);
1261 + array.SetValue(val, i);
1263 + managedData = array;
1264 + break;
1266 + default:
1268 + // FIXME throw some exception
1269 + break;
1272 + break;
1274 + case TypeClass.INTERFACE:
1276 + IntPtr unoI = new IntPtr(*(void **)unoData);
1277 + if (unoI != IntPtr.Zero)
1279 + TypeDescription *td = null; // FIXME leak
1280 + TypeDescriptionReference.GetDescription(&td, type);
1281 + managedData = MapUnoToManaged(unoI, (InterfaceTypeDescription *)td);
1283 + else
1284 + managedData = null;
1285 + break;
1287 + default:
1289 + // FIXME throw some exception
1290 + break;
1295 + public static Type MapUnoType(TypeDescription *TD)
1297 + return MapUnoType(TD->pWeakRef);
1300 + public static Type MapUnoType(TypeDescriptionReference *TD)
1302 + Type result;
1304 + switch(TD->eTypeClass)
1306 + case TypeClass.VOID:
1307 + result = typeof(void);
1308 + break;
1309 + case TypeClass.CHAR:
1310 + result = typeof(char);
1311 + break;
1312 + case TypeClass.BOOLEAN:
1313 + result = typeof(bool);
1314 + break;
1315 + case TypeClass.BYTE:
1316 + result = typeof(byte);
1317 + break;
1318 + case TypeClass.SHORT:
1319 + result = typeof(short);
1320 + break;
1321 + case TypeClass.UNSIGNED_SHORT:
1322 + result = typeof(ushort);
1323 + break;
1324 + case TypeClass.LONG:
1325 + result = typeof(int);
1326 + break;
1327 + case TypeClass.UNSIGNED_LONG:
1328 + result = typeof(uint);
1329 + break;
1330 + case TypeClass.HYPER:
1331 + result = typeof(long);
1332 + break;
1333 + case TypeClass.UNSIGNED_HYPER:
1334 + result = typeof(ulong);
1335 + break;
1336 + case TypeClass.FLOAT:
1337 + result = typeof(float);
1338 + break;
1339 + case TypeClass.DOUBLE:
1340 + result = typeof(double);
1341 + break;
1342 + case TypeClass.STRING:
1343 + result = typeof(string);
1344 + break;
1345 + case TypeClass.TYPE:
1346 + result = typeof(Type);
1347 + break;
1348 + case TypeClass.ANY:
1349 + result = typeof(uno.Any);
1350 + break;
1351 + case TypeClass.ENUM:
1352 + case TypeClass.STRUCT:
1353 + case TypeClass.EXCEPTION:
1354 + result = LoadCliType(TD->pTypeName);
1355 + break;
1356 + case TypeClass.INTERFACE:
1357 + // special handling for XInterface, since it does not exist in cli.
1358 + if (UString.UStringToString(TD->pTypeName) == "com.sun.star.uno.XInterface")
1359 + result = typeof(object);
1360 + else
1361 + result = LoadCliType(TD->pTypeName);
1362 + break;
1363 + case TypeClass.SEQUENCE:
1365 + TypeDescription *seqType = null; // FIXME leak
1366 + TypeDescriptionReference.GetDescription(&seqType, TD);
1368 + // FIXME do something with TD here?
1369 + TypeDescriptionReference *elementTDRef =
1370 + ((IndirectTypeDescription *)seqType)->pType;
1372 + switch (elementTDRef->eTypeClass)
1374 + case TypeClass.CHAR:
1375 + result = Type.GetType("System.Char[]");
1376 + break;
1377 + case TypeClass.BOOLEAN:
1378 + result = Type.GetType("System.Boolean[]");
1379 + break;
1380 + case TypeClass.BYTE:
1381 + result = Type.GetType("System.Byte[]");
1382 + break;
1383 + case TypeClass.SHORT:
1384 + result = Type.GetType("System.Int16[]");
1385 + break;
1386 + case TypeClass.UNSIGNED_SHORT:
1387 + result = Type.GetType("System.UInt16[]");
1388 + break;
1389 + case TypeClass.LONG:
1390 + result = Type.GetType("System.Int32[]");
1391 + break;
1392 + case TypeClass.UNSIGNED_LONG:
1393 + result = Type.GetType("System.UInt32[]");
1394 + break;
1395 + case TypeClass.HYPER:
1396 + result = Type.GetType("System.Int64[]");
1397 + break;
1398 + case TypeClass.UNSIGNED_HYPER:
1399 + result = Type.GetType("System.UInt64[]");
1400 + break;
1401 + case TypeClass.FLOAT:
1402 + result = Type.GetType("System.Single[]");
1403 + break;
1404 + case TypeClass.DOUBLE:
1405 + result = Type.GetType("System.Double[]");
1406 + break;
1407 + case TypeClass.STRING:
1408 + result = Type.GetType("System.String[]");
1409 + break;
1410 + case TypeClass.TYPE:
1411 + result = Type.GetType("System.Type[]");
1412 + break;
1413 + case TypeClass.ANY:
1414 + case TypeClass.ENUM:
1415 + case TypeClass.EXCEPTION:
1416 + case TypeClass.STRUCT:
1417 + case TypeClass.INTERFACE:
1418 + case TypeClass.SEQUENCE:
1419 + result = LoadCliType(TD->pTypeName);
1420 + break;
1421 + default:
1422 + // FIXME can't happen
1423 + result = null;
1424 + break;
1426 + break;
1428 + default:
1429 + // FIXME can't happen
1430 + result = null;
1431 + break;
1433 + return result;
1436 + public static Type LoadCliType(UString* unoName)
1438 + return LoadCliType(MapUnoTypeName(UString.UStringToString(unoName)));
1441 + public static Type LoadCliType(string unoName)
1443 + Type result = null;
1444 + bool isPolymorphic = false;
1446 + string loadName = unoName;
1447 + int index = unoName.IndexOf('<');
1448 + if (index != -1)
1450 + loadName = unoName.Substring(0, index);
1451 + isPolymorphic = true;
1454 + result = Type.GetType(loadName + ",cli_uretypes");
1456 + if (result == null)
1457 + result = Type.GetType(loadName + ",cli_basetypes");
1459 + if (result == null)
1460 + result = Type.GetType(loadName, false);
1462 + if (result == null)
1464 + foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
1466 + result = a.GetType(loadName, false);
1467 + if (result != null)
1468 + break;
1472 + if (result == null)
1473 + // FIXME don't use generic Exception type
1474 + throw new Exception("A type could not be loaded: " + loadName);
1476 + if (isPolymorphic)
1477 + result = uno.PolymorphicType.GetType(result, unoName);
1479 + return result;
1482 + static TypeDescriptionReference *MapManagedType(Type managedType)
1484 + TypeDescriptionReference *result = null;
1485 + if (managedType == null)
1487 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.VOID);
1488 + TypeDescriptionReference.Acquire(result);
1489 + return result;
1492 + // check for Enum first,
1493 + // because otherwise case System.TypeCode.Int32 applies
1494 + if (managedType.IsEnum)
1496 + UString* unoTypeName = MapManagedTypeName(managedType.FullName);
1497 + TypeDescriptionReference.New(&result, TypeClass.ENUM, unoTypeName);
1498 + TypeDescriptionReference.Acquire(result);
1500 + else
1502 + switch (System.Type.GetTypeCode(managedType))
1504 + case System.TypeCode.Boolean:
1505 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.BOOLEAN);
1506 + TypeDescriptionReference.Acquire(result);
1507 + break;
1508 + case System.TypeCode.Char:
1509 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.CHAR);
1510 + TypeDescriptionReference.Acquire(result);
1511 + break;
1512 + case System.TypeCode.Byte:
1513 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.BYTE);
1514 + TypeDescriptionReference.Acquire(result);
1515 + break;
1516 + case System.TypeCode.Int16:
1517 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.SHORT);
1518 + TypeDescriptionReference.Acquire(result);
1519 + break;
1520 + case System.TypeCode.Int32:
1521 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.LONG);
1522 + TypeDescriptionReference.Acquire(result);
1523 + break;
1524 + case System.TypeCode.Int64:
1525 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.HYPER);
1526 + TypeDescriptionReference.Acquire(result);
1527 + break;
1528 + case System.TypeCode.UInt16:
1529 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.UNSIGNED_SHORT);
1530 + TypeDescriptionReference.Acquire(result);
1531 + break;
1532 + case System.TypeCode.UInt32:
1533 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.UNSIGNED_LONG);
1534 + TypeDescriptionReference.Acquire(result);
1535 + break;
1536 + case System.TypeCode.UInt64:
1537 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.UNSIGNED_HYPER);
1538 + TypeDescriptionReference.Acquire(result);
1539 + break;
1540 + case System.TypeCode.Single:
1541 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.FLOAT);
1542 + TypeDescriptionReference.Acquire(result);
1543 + break;
1544 + case System.TypeCode.Double:
1545 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.DOUBLE);
1546 + TypeDescriptionReference.Acquire(result);
1547 + break;
1548 + case System.TypeCode.String:
1549 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.STRING);
1550 + TypeDescriptionReference.Acquire(result);
1551 + break;
1555 + if (result == null)
1557 + string managedTypeName = managedType.FullName;
1558 + if (managedTypeName == "System.Void")
1560 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.VOID);
1561 + TypeDescriptionReference.Acquire(result);
1563 + else if (managedTypeName == "System.Type")
1565 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.TYPE);
1566 + TypeDescriptionReference.Acquire(result);
1568 + else if (managedTypeName == "uno.Any")
1570 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.ANY);
1571 + TypeDescriptionReference.Acquire(result);
1573 + else
1575 + UString* unoTypeName;
1577 + uno.PolymorphicType poly = managedType as uno.PolymorphicType;
1578 + if (poly != null)
1579 + unoTypeName = MapManagedTypeName(poly.PolymorphicName);
1580 + else
1581 + unoTypeName = MapManagedTypeName(managedTypeName);
1583 + TypeDescription *td = null;
1584 + TypeDescription.GetByName(&td, unoTypeName);
1585 + if (td != null)
1587 + result = td->pWeakRef;
1588 + TypeDescriptionReference.Acquire(result);
1589 + TypeDescription.Release(td);
1594 + if (result == null)
1596 + // FIXME - quite probably we should throw an exception here instead.
1597 + result = *TypeDescriptionReference.GetByTypeClass(TypeClass.VOID);
1598 + TypeDescriptionReference.Acquire(result);
1601 + return result;
1604 + static string MapUnoTypeName(string typeName)
1606 + StringBuilder buf = new StringBuilder();
1608 + // determine if the type is a sequence and its dimensions
1609 + int dims = 0;
1610 + if (typeName[0] == '[')
1612 + int index = 1;
1613 + while (true)
1615 + if (typeName[index++] == ']')
1616 + ++dims;
1617 + if (typeName[index++] != '[')
1618 + break;
1620 + typeName = typeName.Substring(index - 1);
1623 + switch (typeName)
1625 + case "boolean":
1626 + buf.Append("System.Boolean");
1627 + break;
1628 + case "char":
1629 + buf.Append("System.Char");
1630 + break;
1631 + case "byte":
1632 + buf.Append("System.Byte");
1633 + break;
1634 + case "short":
1635 + buf.Append("System.Int16");
1636 + break;
1637 + case "unsigned short":
1638 + buf.Append("System.UInt16");
1639 + break;
1640 + case "long":
1641 + buf.Append("System.Int32");
1642 + break;
1643 + case "unsigned long":
1644 + buf.Append("System.UInt32");
1645 + break;
1646 + case "hyper":
1647 + buf.Append("System.Int64");
1648 + break;
1649 + case "unsigned hyper":
1650 + buf.Append("System.UInt64");
1651 + break;
1652 + case "float":
1653 + buf.Append("System.Single");
1654 + break;
1655 + case "double":
1656 + buf.Append("System.Double");
1657 + break;
1658 + case "string":
1659 + buf.Append("System.String");
1660 + break;
1661 + case "void":
1662 + buf.Append("System.Void");
1663 + break;
1664 + case "type":
1665 + buf.Append("System.Type");
1666 + break;
1667 + case "com.sun.star.uno.XInterface":
1668 + buf.Append("System.Object");
1669 + break;
1670 + case "any":
1671 + buf.Append("uno.Any");
1672 + break;
1673 + default:
1674 + // put "unoidl." at the beginning
1675 + buf.Append("unoidl.");
1676 + // for polymorphic struct types remove the brackets, e.g. mystruct<bool> -> mystruct
1677 + buf.Append(MapUnoPolymorphicName(typeName));
1678 + break;
1681 + // append []
1682 + for ( ; dims > 0; --dims)
1683 + buf.Append("[]");
1685 + return buf.ToString();
1688 + /** For example, there is a uno type
1689 + com.sun.star.Foo<char, long>.
1690 + The values in the type list
1691 + are uno types and are replaced by cli types, such as System.Char,
1692 + System.Int32, etc.
1693 + */
1694 + static string MapUnoPolymorphicName(string unoName)
1696 + int startIndex = unoName.LastIndexOf('<');
1697 + if (startIndex == -1)
1698 + return unoName;
1700 + // get the type list within < and >
1701 + int endIndex = unoName.LastIndexOf('>');
1702 + string list = unoName.Substring(startIndex + 1, endIndex - startIndex - 1);
1704 + // parse the type list and replace the types with the corresponding CLI types
1705 + char[] delimiters = new char[] { ',' };
1706 + string[] unoTypes = list.Split(delimiters);
1708 + StringBuilder builder = new StringBuilder(unoName.Substring(0, startIndex + 1));
1710 + int typeCount = unoTypes.Length;
1711 + for (int i = 0; i < typeCount; ++i)
1712 + builder.Append(MapUnoTypeName(unoTypes[i]));
1714 + builder.Append('>');
1715 + return builder.ToString();
1718 + static UString* MapManagedTypeName(string typeName)
1720 + int dims = 0;
1721 + int index = 0;
1723 + if ((index = typeName.IndexOf("[]")) > 0)
1725 + dims = 1;
1727 + int curIndex = index;
1728 + while ((curIndex + 2) < typeName.Length &&
1729 + (curIndex = typeName.IndexOf("[]", curIndex + 2)) > 0)
1730 + ++dims;
1732 + // get the element name by removing the brackets
1733 + typeName = typeName.Substring(0, index);
1736 + StringBuilder buf = new StringBuilder(256);
1737 + for (; dims > 0; --dims)
1738 + buf.Append("[]");
1740 + switch (typeName)
1742 + case "System.Boolean":
1743 + buf.Append("boolean");
1744 + break;
1745 + case "System.Char":
1746 + buf.Append("char");
1747 + break;
1748 + case "System.Byte":
1749 + buf.Append("byte");
1750 + break;
1751 + case "System.Int16":
1752 + buf.Append("short");
1753 + break;
1754 + case "System.UInt16":
1755 + buf.Append("unsigned short");
1756 + break;
1757 + case "System.Int32":
1758 + buf.Append("long");
1759 + break;
1760 + case "System.UInt32":
1761 + buf.Append("unsigned long");
1762 + break;
1763 + case "System.Int64":
1764 + buf.Append("hyper");
1765 + break;
1766 + case "System.UInt64":
1767 + buf.Append("unsigned hyper");
1768 + break;
1769 + case "System.Single":
1770 + buf.Append("float");
1771 + break;
1772 + case "System.Double":
1773 + buf.Append("double");
1774 + break;
1775 + case "System.String":
1776 + buf.Append("string");
1777 + break;
1778 + case "System.Void":
1779 + buf.Append("void");
1780 + break;
1781 + case "System.Type":
1782 + buf.Append("type");
1783 + break;
1784 + case "System.Object":
1785 + buf.Append("com.sun.star.uno.XInterface");
1786 + break;
1787 + case "uno.Any":
1788 + buf.Append("any");
1789 + break;
1790 + default:
1792 + string name = MapManagedPolymorphicName(typeName);
1793 + int i = name.IndexOf('.');
1794 + buf.Append(name.Substring(i + 1));
1795 + break;
1799 + UString *rtl_uString = null;
1800 + UString.NewFromStringBuilder(&rtl_uString, buf);
1801 + return rtl_uString;
1804 + static string MapManagedPolymorphicName(string unoName)
1806 + int startIndex = unoName.LastIndexOf('<');
1807 + if (startIndex == -1)
1808 + return unoName;
1810 + // get the type list withing < and >
1811 + int endIndex = unoName.LastIndexOf('>');
1812 + string list = unoName.Substring(startIndex + 1, endIndex - startIndex - 1);
1814 + // parse the type list and replace the types with the corresponding CLI types
1815 + char[] delimiters = new char[] { ',' };
1816 + string[] unoTypes = list.Split(delimiters);
1818 + StringBuilder builder = new StringBuilder(unoName.Substring(0, startIndex + 1));
1820 + int typeCount = unoTypes.Length;
1821 + for (int i = 0; i < typeCount; ++i)
1822 + builder.Append(UString.UStringToString(MapManagedTypeName(unoTypes[i])));
1823 + builder.Append('>');
1824 + return builder.ToString();
1827 + [StructLayout(LayoutKind.Explicit)]
1828 + private unsafe struct largest
1830 + [FieldOffset(0)] long n;
1831 + [FieldOffset(0)] double d;
1832 + [FieldOffset(0)] void *p;
1833 + [FieldOffset(0)] uno.Binary.Any a;
1836 + // FIXME args[i] must be of same type as return value
1837 + public unsafe uno.Any CallUno(IntPtr unoInterface, TypeDescription *memberTD,
1838 + TypeDescriptionReference *returnType, int nParams,
1839 + MethodParameter *parameters, object[] args,
1840 + Type[] argTypes, out uno.Any exception)
1842 + int returnSize = sizeof(largest);
1844 + if (returnType != null &&
1845 + (returnType->eTypeClass == TypeClass.STRUCT ||
1846 + returnType->eTypeClass == TypeClass.EXCEPTION))
1848 + // FIXME leak
1849 + TypeDescription *td = null;
1850 + TypeDescriptionReference.GetDescription(&td, returnType);
1852 + if (td->nSize > returnSize)
1853 + returnSize = td->nSize;
1856 + // Prepare memory that contains all converted arguments and
1857 + // return values. The memory block contains first pointers to
1858 + // the arguments which are in the same block For example, 2
1859 + // arguments, 1 ret.
1860 + //
1861 + // | Pointer
1862 + // | Pointer
1863 + // | Return value
1864 + // | Arg 1
1865 + // | Arg 2
1866 + //
1867 + // If an argument is larger then struct largest, such as some
1868 + // structures, then the pointer points to an extra block of
1869 + // memory. The same goes for a big return value.
1870 + // FIXME the last sentence is bullshit. Get it deleted from cli_uno ;)
1871 + byte *mem = stackalloc byte[nParams * sizeof(void *) +
1872 + returnSize +
1873 + nParams * sizeof(largest)];
1875 + // array of pointers to args
1876 + void **unoArgPtrs = (void **)mem;
1878 + // Return Value
1879 + void *unoRetPtr = null;
1880 + largest *unoArgs = (largest *)(unoArgPtrs + nParams);
1881 + if (memberTD->eTypeClass != TypeClass.INTERFACE_ATTRIBUTE || nParams != 1)
1883 + // If an attribute is set, then unoRet must be null, e.g. void setAttribute(int)
1884 + unoRetPtr = (void *)unoArgs;
1885 + unoArgs = (largest *)((byte *)unoRetPtr + returnSize);
1888 + for (int i = 0; i < nParams; ++i)
1890 + // FIXME it's a TypeDescriptionReference
1891 + TypeDescription *type = (TypeDescription *)parameters[i].pTypeRef;
1893 + unoArgPtrs[i] = unoArgs + i;
1894 + if ((type->eTypeClass == TypeClass.STRUCT ||
1895 + type->eTypeClass == TypeClass.EXCEPTION) &&
1896 + (type->nSize > sizeof(largest)))
1898 + // stackalloc is only allowed in initializers
1899 + byte *bigArgPtr = stackalloc byte[type->nSize];
1901 + unoArgPtrs[i] = bigArgPtr;
1904 + if (parameters[i].bIn != 0)
1906 + // FIXME error handling
1907 + MapToUno(unoArgPtrs[i], args[i], type, false /* no assign */);
1911 + uno.Binary.Any unoExceptionHolder;
1912 + uno.Binary.Any *unoExc = &unoExceptionHolder;
1914 + // call binary uno
1915 + uno.Binary.Interface.Dispatch(
1916 + unoInterface, memberTD, unoRetPtr, unoArgPtrs, &unoExc);
1918 + if (unoExc == null)
1920 + exception = uno.Any.VOID;
1922 + // convert out args, destroy uno args
1923 + for (int i = 0; i < nParams; ++i)
1925 + // FIXME it's a TypeDescriptionReference
1926 + TypeDescription *type = (TypeDescription *)parameters[i].pTypeRef;
1928 + if (parameters[i].bOut != 0)
1930 + // FIXME error handling
1931 + MapToManaged(ref args[i], unoArgPtrs[i], parameters[i].pTypeRef,
1932 + argTypes != null ? argTypes[i] : null, false);
1935 + // cleanup args
1936 + if (type->eTypeClass < TypeClass.DOUBLE &&
1937 + type->eTypeClass != TypeClass.ENUM) // no need to destroy these
1938 + uno.Binary.Data.Destroy(unoArgPtrs[i], type, null);
1941 + if (returnType != null && returnType->eTypeClass != TypeClass.VOID)
1943 + // convert uno return value
1944 + object result = null;
1945 + // FIXME error handling
1946 + MapToManaged(ref result, unoRetPtr, returnType, null, false);
1947 + uno.Binary.Data.Destroy(unoRetPtr, (TypeDescription *)returnType, null);
1948 + return new uno.Any(MapUnoType(returnType), result); // FIXME is this correct?
1951 + return uno.Any.VOID;
1953 + else // exception occured
1955 + for (int i = 0; i < nParams; ++i)
1956 + if (parameters[i].bIn != 0)
1957 + uno.Binary.Data.Destroy(unoArgPtrs[i], (TypeDescription *)parameters[i].pTypeRef, null);
1959 + // FIXME needs uno.Any vs System.Object clarification
1960 + object exc = null;
1961 + MapToManaged(ref exc, unoExceptionHolder.pData,
1962 + unoExceptionHolder.pType, null, false);
1963 + exception = new uno.Any(MapUnoType(unoExceptionHolder.pType), exc);
1964 + return uno.Any.VOID;
1967 + // FIXME error handling
1970 + // FIXME rename, to say what it does, not how it does this
1971 + public void RegisterWithCliEnvironment(object managedI, string oid)
1973 + managedEnvironment.registerInterface(managedI, oid);
1976 + public void RegisterWithCliEnvironment(object managedI, string oid, Type type)
1978 + managedEnvironment.registerInterface(managedI, oid, type);
1981 + public void RegisterWithUnoEnvironment(ref IntPtr unoInterface, string oid, InterfaceTypeDescription *TD)
1983 + UString *unoOid = null;
1984 + UString.NewFromString(&unoOid, oid);
1986 + uno.Binary.Environment.RegisterInterface(unoEnvironment, ref unoInterface, unoOid, TD);
1988 + UString.Release(unoOid);
1991 + public void GetInterfaceFromUnoEnvironment(ref IntPtr unoInterface, UString* unoOid, InterfaceTypeDescription* TD)
1993 + uno.Binary.Environment.GetRegisteredInterface(unoEnvironment, ref unoInterface, unoOid, TD);
1996 + public void RevokeFromUnoEnvironment(IntPtr unoInterface)
1998 + throw new NotImplementedException();
2001 + public unsafe IntPtr CreateManagedProxy(object managedInterface,
2002 + TypeDescription* td,
2003 + UString* oid)
2005 + // register original interface
2006 + RegisterWithCliEnvironment(managedInterface,
2007 + UString.UStringToString(oid),
2008 + Bridge.MapUnoType(td));
2010 + ManagedProxy proxy = new ManagedProxy(this, managedInterface, td, oid);
2011 + GCHandle gchandle = GCHandle.Alloc(proxy);
2013 + // create binary uno uno_Interface and register proxy with target environment
2014 + IntPtr unoI = CreateBinaryProxyAndRegister(unoEnvironment, (IntPtr)gchandle,
2015 + oid, td);
2017 + proxy.NativeProxy = unoI;
2018 + return unoI;
2021 + [ DllImport("cli_uno", EntryPoint="cli_uno_environment_createMonoProxyAndRegister") ]
2022 + public static unsafe extern IntPtr CreateBinaryProxyAndRegister(
2023 + IntPtr unoEnvironment,
2024 + IntPtr monoProxy,
2025 + /* UString */ void* oid,
2026 + /* InterfaceTypeDescription */ void* td);
2028 + public unsafe void CallManaged(object managedI, Type ifaceType, MethodInfo method,
2029 + TypeDescriptionReference* returnType,
2030 + MethodParameter* parameters, int nParams, void* unoRet,
2031 + void** unoArgs, uno.Binary.Any** unoExc)
2033 + object[] args = new object[nParams];
2034 + for (int i = 0; i < nParams; ++i)
2035 + if (parameters[i].bIn != 0)
2036 + MapToManaged(ref args[i], unoArgs[i], parameters[i].pTypeRef, null, false);
2038 + object invocationResult = null;
2039 + try
2041 + invocationResult = method.Invoke(managedI, args);
2043 + catch (TargetInvocationException e)
2045 + Exception exc = e.InnerException;
2046 + TypeDescription* td = null;
2047 + // FIXME leak
2048 + TypeDescriptionReference.GetDescription(&td, MapManagedType(exc.GetType()));
2049 + void* memExc = uno.rtl.Mem.Allocate(td->nSize);
2050 + MapToUno(memExc, exc, /* FIXME !!!*/ (TypeDescription*)td->pWeakRef, false);
2051 + (*unoExc)->pType = td->pWeakRef;
2052 + (*unoExc)->pData = memExc;
2053 + return;
2055 + catch (Exception e)
2057 + // FIXME
2060 + // convert out, in/out params
2061 + for (int i = 0; i < nParams; ++i)
2063 + if (parameters[i].bOut != 0)
2065 + MapToUno(
2066 + unoArgs[i], args[i], /* FIXME !!! */(TypeDescription*)parameters[i].pTypeRef,
2067 + parameters[i].bIn != 0 /* assign if inout */);
2068 + // FIXME error handling
2072 + // return value
2073 + if (returnType != null)
2074 + MapToUno(unoRet, invocationResult, /* FIXME !!! */(TypeDescription*)returnType, false /* no assign */);
2076 + // no exception occurred
2077 + *unoExc = null;
2082 --- cli_ure/source/mono_bridge/cli_environment.cs.old 1970-01-01 00:00:00.000000000 +0000
2083 +++ cli_ure/source/mono_bridge/cli_environment.cs 2009-04-06 16:41:58.000000000 +0000
2084 @@ -0,0 +1,204 @@
2085 +/*************************************************************************
2087 + * $RCSfile: $
2089 + * $Revision: $
2091 + * last change: $Author: $ $Date: $
2093 + * The Contents of this file are made available subject to the terms of
2094 + * either of the following licenses
2096 + * - GNU Lesser General Public License Version 2.1
2097 + * - Sun Industry Standards Source License Version 1.1
2099 + * Sun Microsystems Inc., October, 2000
2101 + * GNU Lesser General Public License Version 2.1
2102 + * =============================================
2103 + * Copyright 2000 by Sun Microsystems, Inc.
2104 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
2106 + * This library is free software; you can redistribute it and/or
2107 + * modify it under the terms of the GNU Lesser General Public
2108 + * License version 2.1, as published by the Free Software Foundation.
2110 + * This library is distributed in the hope that it will be useful,
2111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2113 + * Lesser General Public License for more details.
2115 + * You should have received a copy of the GNU Lesser General Public
2116 + * License along with this library; if not, write to the Free Software
2117 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2118 + * MA 02111-1307 USA
2121 + * Sun Industry Standards Source License Version 1.1
2122 + * =================================================
2123 + * The contents of this file are subject to the Sun Industry Standards
2124 + * Source License Version 1.1 (the "License"); You may not use this file
2125 + * except in compliance with the License. You may obtain a copy of the
2126 + * License at http://www.openoffice.org/license.html.
2128 + * Software provided under this License is provided on an "AS IS" basis,
2129 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
2130 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
2131 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
2132 + * See the License for the specific provisions governing your rights and
2133 + * obligations concerning the Software.
2135 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
2137 + * Copyright: 2000 by Sun Microsystems, Inc.
2139 + * All Rights Reserved.
2141 + * Contributor(s): _______________________________________
2144 + ************************************************************************/
2146 +namespace cli_uno
2149 +using System;
2150 +using System.Collections;
2151 +using System.Runtime.Remoting;
2152 +using System.Runtime.Remoting.Proxies;
2153 +using System.Text;
2155 +using com.sun.star.bridges.mono_uno;
2157 +public class Cli_environment
2159 + static string sOidPart = ";cli[0];";
2161 + static Hashtable m_objects = Hashtable.Synchronized(new Hashtable());
2163 + static string createKey(string oid, Type t)
2165 + return oid + t.FullName;
2168 +// FIXME setup debugging info here
2169 +// public Cli_environment()
2170 +// {
2171 +// }
2173 +// FIXME assert there are no more registered objects
2174 +// public ~Cli_environment()
2175 +// {
2176 +// }
2178 + /**
2179 + Registers an UNO object as being mapped by this bridge. The resulting
2180 + cli object is represents all interfaces of the UNO object. Therefore the
2181 + object can be registered only with its OID; a type is not necessary.
2182 + */
2183 + public object registerInterface(object obj, string oid)
2185 + // FIXME debugging stuff
2186 + m_objects.Add(oid, obj); // new WeakReference(obj));
2187 + return obj;
2190 + /**
2191 + Registers a CLI object as being mapped by this bridge. The resulting
2192 + object represents exactly one UNO interface.
2193 + */
2194 + public object registerInterface(object obj, string oid, Type type)
2196 + // FIXME debugging stuff
2197 + string key = createKey(oid, type);
2198 + m_objects.Add(key, obj); // new WeakReference(obj));
2199 + return obj;
2202 + /**
2203 + By revoking an interface it is declared that the respective interface has
2204 + not been mapped. The proxy implementations call revoke interface in their
2205 + destructors.
2206 + */
2207 + public void revokeInterface(string oid)
2209 + revokeInterface(oid, null);
2212 + public void revokeInterface(string oid, Type type)
2214 + // FIXME debugging stuff
2215 + string key = type != null ? createKey(oid, type) : oid;
2216 + m_objects.Remove(key);
2219 + /**
2220 + * Retrieves an interface identified by its object id and type from this
2221 + * environment.
2223 + * @param oid object id of interface to be retrieved
2224 + * @param type the type description of the interface to be retrieved
2225 + * @see com.sun.star.uno.IEnvironment#getRegisteredInterface
2226 + */
2227 + public object getRegisteredInterface(string oid, Type type)
2229 + // try if it is a UNO interface
2230 + object ret = null;
2231 + ret = m_objects[oid];
2232 + if (ret == null)
2234 + // try if it is a proxy for a cli object
2235 + oid = createKey(oid, type);
2236 + ret = m_objects[oid];
2238 +/* if (ret != null)
2240 + WeakReference weakIface = (WeakReference)ret;
2241 + ret = weakIface.Target;
2242 + } */
2244 + if (ret == null)
2245 + m_objects.Remove(oid);
2247 + return ret;
2250 + /**
2251 + * Generates a worldwide unique object identifier (oid) for the given object. It is
2252 + * guaranteed, that subsequent calls to the method with the same object
2253 + * will give the same id.
2254 + * <p>
2255 + * @return the generated oid.
2256 + * @param object the object for which a Oid should be generated.
2257 + */
2258 + public static string getObjectIdentifier(object obj)
2260 + string oid = null;
2261 + RealProxy realProxy = null;
2263 + if (RemotingServices.IsTransparentProxy(obj))
2264 + realProxy = RemotingServices.GetRealProxy(obj);
2266 + if (realProxy != null)
2268 + UnoInterfaceProxy proxyImpl = realProxy as UnoInterfaceProxy;
2269 + if (proxyImpl != null)
2270 + oid = proxyImpl.Oid;
2273 + if (oid == null)
2275 + Guid gd = typeof(Cli_environment).GUID; // FIXME apparently not a good idea with mono
2276 + StringBuilder buf = new StringBuilder(128);
2277 + buf.Append(obj.GetHashCode());
2278 + buf.Append(sOidPart);
2279 + buf.Append(gd);
2280 + oid = buf.ToString();
2283 + return oid;
2289 --- cli_ure/source/mono_bridge/makefile.mk.old 1970-01-01 00:00:00.000000000 +0000
2290 +++ cli_ure/source/mono_bridge/makefile.mk 2009-04-06 16:41:58.000000000 +0000
2291 @@ -0,0 +1,137 @@
2292 +#*************************************************************************
2294 +# $RCSfile: $
2296 +# $Revision: $
2298 +# last change: $Author: $ $Date: $
2300 +# The Contents of this file are made available subject to the terms of
2301 +# either of the following licenses
2303 +# - GNU Lesser General Public License Version 2.1
2304 +# - Sun Industry Standards Source License Version 1.1
2306 +# Sun Microsystems Inc., October, 2000
2308 +# GNU Lesser General Public License Version 2.1
2309 +# =============================================
2310 +# Copyright 2000 by Sun Microsystems, Inc.
2311 +# 901 San Antonio Road, Palo Alto, CA 94303, USA
2313 +# This library is free software; you can redistribute it and/or
2314 +# modify it under the terms of the GNU Lesser General Public
2315 +# License version 2.1, as published by the Free Software Foundation.
2317 +# This library is distributed in the hope that it will be useful,
2318 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2319 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2320 +# Lesser General Public License for more details.
2322 +# You should have received a copy of the GNU Lesser General Public
2323 +# License along with this library; if not, write to the Free Software
2324 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2325 +# MA 02111-1307 USA
2328 +# Sun Industry Standards Source License Version 1.1
2329 +# =================================================
2330 +# The contents of this file are subject to the Sun Industry Standards
2331 +# Source License Version 1.1 (the "License"); You may not use this file
2332 +# except in compliance with the License. You may obtain a copy of the
2333 +# License at http://www.openoffice.org/license.html.
2335 +# Software provided under this License is provided on an "AS IS" basis,
2336 +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
2337 +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
2338 +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
2339 +# See the License for the specific provisions governing your rights and
2340 +# obligations concerning the Software.
2342 +# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
2344 +# Copyright: 2000 by Sun Microsystems, Inc.
2346 +# All Rights Reserved.
2348 +# Contributor(s): _______________________________________
2352 +#*************************************************************************
2354 +PRJ=..$/..
2356 +PRJNAME=bridges
2357 +TARGET=cli_uno
2358 +USE_DEFFILE=TRUE
2359 +ENABLE_EXCEPTIONS=TRUE
2361 +.IF "$(ENABLE_MONO)" != "YES"
2362 +dummy:
2363 + @echo "Mono binding disabled - skipping ..."
2364 +.ELSE
2366 +# --- Settings -----------------------------------------------------
2368 +.INCLUDE : settings.mk
2369 +CFLAGS+=$(MONO_CFLAGS)
2371 +# --- Files --------------------------------------------------------
2373 +ALLTAR : \
2374 + $(SHL1TARGETN) \
2375 + $(BIN)$/cli_uno_bridge.dll
2377 +CSFILES= \
2378 + binaryuno.cs \
2379 + bridge.cs \
2380 + cli_environment.cs \
2381 + managed_proxy.cs \
2382 + rtl_ustring.cs \
2383 + typeclass.cs \
2384 + typedescription.cs \
2385 + uik.cs \
2386 + uno_proxy.cs
2388 +ASSEMBLIES_DIR=$(SOLARVERSION)$/$(INPATH)$/bin$(EXT_UPDMINOR)
2389 +$(BIN)$/cli_uno_bridge.dll : $(CSFILES)
2390 + +$(CSC) $(CSCFLAGS) \
2391 + -target:library \
2392 + -unsafe \
2393 + -out:$@ \
2394 + -keyfile:$(BIN)$/cliuno.snk \
2395 + -reference:$(BIN)$/cli_basetypes.dll \
2396 + -reference:$(BIN)$/cli_uretypes.dll \
2397 + $(CSFILES)
2399 +SLOFILES= \
2400 + $(SLO)$/mono_bridge.obj \
2401 + $(SLO)$/mono_proxy.obj \
2402 + $(SLO)$/uno_glue.obj
2404 +SHL1TARGET=$(TARGET)
2406 +SHL1STDLIBS= \
2407 + $(CPPULIB) \
2408 + $(SALLIB) \
2409 + $(SALHELPERLIB)
2412 +SHL1STDLIBS+=$(MONO_LIBS)
2414 +# SHL1VERSIONMAP=..$/bridge_exports.map
2416 +SHL1IMPLIB=i$(TARGET)
2417 +SHL1LIBS=$(SLB)$/$(TARGET).lib
2418 +SHL1DEF=$(MISC)$/$(SHL1TARGET).def
2419 +DEF1NAME=$(SHL1TARGET)
2423 +# --- Targets ------------------------------------------------------
2425 +.ENDIF
2427 +.INCLUDE : target.mk
2429 --- cli_ure/source/mono_bridge/managed_proxy.cs.old 1970-01-01 00:00:00.000000000 +0000
2430 +++ cli_ure/source/mono_bridge/managed_proxy.cs 2009-04-06 16:41:58.000000000 +0000
2431 @@ -0,0 +1,477 @@
2432 +/*************************************************************************
2434 + * $RCSfile: $
2436 + * $Revision: $
2438 + * last change: $Author: $ $Date: $
2440 + * The Contents of this file are made available subject to the terms of
2441 + * either of the following licenses
2443 + * - GNU Lesser General Public License Version 2.1
2444 + * - Sun Industry Standards Source License Version 1.1
2446 + * Sun Microsystems Inc., October, 2000
2448 + * GNU Lesser General Public License Version 2.1
2449 + * =============================================
2450 + * Copyright 2000 by Sun Microsystems, Inc.
2451 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
2453 + * This library is free software; you can redistribute it and/or
2454 + * modify it under the terms of the GNU Lesser General Public
2455 + * License version 2.1, as published by the Free Software Foundation.
2457 + * This library is distributed in the hope that it will be useful,
2458 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2460 + * Lesser General Public License for more details.
2462 + * You should have received a copy of the GNU Lesser General Public
2463 + * License along with this library; if not, write to the Free Software
2464 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2465 + * MA 02111-1307 USA
2468 + * Sun Industry Standards Source License Version 1.1
2469 + * =================================================
2470 + * The contents of this file are subject to the Sun Industry Standards
2471 + * Source License Version 1.1 (the "License"); You may not use this file
2472 + * except in compliance with the License. You may obtain a copy of the
2473 + * License at http://www.openoffice.org/license.html.
2475 + * Software provided under this License is provided on an "AS IS" basis,
2476 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
2477 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
2478 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
2479 + * See the License for the specific provisions governing your rights and
2480 + * obligations concerning the Software.
2482 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
2484 + * Copyright: 2000 by Sun Microsystems, Inc.
2486 + * All Rights Reserved.
2488 + * Contributor(s): _______________________________________
2491 + ************************************************************************/
2493 +namespace com.sun.star.bridges.mono_uno /* FIXME use some uno.foo namespace ? */
2496 +using System;
2497 +using System.Reflection;
2498 +using System.Runtime;
2500 +using uno.Typelib;
2501 +using uno.rtl;
2503 +public unsafe class ManagedProxy
2505 + Bridge bridge;
2506 + object managedI;
2507 + TypeDescription *unoType;
2508 + UString* unoOid;
2509 + string oid;
2510 + Type type;
2511 + IntPtr nativeProxy;
2513 + enum MethodKind {METHOD = 0, SET, GET};
2515 + /** The array contains MethodInfos of the cli object. Each one reflects an
2516 + implemented interface method of the interface for which this proxy was
2517 + created. The MethodInfos are from the object's method and not from the
2518 + interface type. That is, they can be used to invoke the methods. The
2519 + order of the MethodInfo objects corresponds to the order of the
2520 + interface methods (see member m_type). Position 0 contains the
2521 + MethodInfo of the first method of the interface which represents the
2522 + root of the inheritance chain. The last MethodInfo represents the last
2523 + method of the furthest derived interface.
2525 + The array is completely initialized in the constructor of this object.
2527 + When the uno_DispatchMethod is called for this proxy then it receives
2528 + a typelib_TypeDescription of the member which is either an attribute
2529 + (setter or getter) or method. After determining the position of the
2530 + method within the UNO interface one can use the position to obtain the
2531 + MethodInfo of the corresponding cli method. To obtain the index for the
2532 + m_arMethodInfos array the function position has to be decreased by 3.
2533 + This is becaus, the cli interface does not contain the XInterface
2534 + methods.
2535 + */
2536 + MethodInfo[] methodInfos;
2538 + /** This array is similar to m_arMethodInfos but it contains the MethodInfo
2539 + objects of the interface (not the object). When a call is made from uno
2540 + to cli then the uno method name is compared to the cli method name. The
2541 + cli method name can be obtained from the MethodInfo object in this
2542 + array. The name of the actual implemented method may not be the same as
2543 + the interface method.
2544 + */
2545 + MethodInfo[] interfaceMethodInfos;
2547 + /** Maps the position of the method in the UNO interface to the position of
2548 + the corresponding MethodInfo in m_arMethodInfos. The Uno position must
2549 + not include the XInterface methods. For example,
2550 + pos 0 = XInterface::queryInterface
2551 + pos 1 = XInterface::acquire
2552 + pos 2 = XInterface::release
2554 + That is the real Uno position has to be deducted by 3. Then
2555 + arUnoPosToCliPos[pos] contains the index for m_arMethodInfos.
2557 + */
2558 + int[] unoPosToCliPos;
2560 + /** Count of inherited interfaces of the cli interface.
2561 + */
2562 + int inheritedInterfacesCount = 0;
2563 + /** Contains the number of methods of each interface.
2564 + */
2565 + int[] interfaceMethodCounts;
2567 + public unsafe ManagedProxy(Bridge bridge, object managedI,
2568 + TypeDescription* TD, UString* oid)
2570 + this.bridge = bridge;
2571 + this.managedI = managedI;
2572 + this.unoType = TD;
2573 + TypeDescription.Acquire(this.unoType);
2574 + this.unoOid = oid;
2575 + UString.Acquire(this.unoOid);
2576 + this.oid = UString.UStringToString(oid);
2578 + if (TD != null && TD->bComplete == 0)
2579 + TypeDescription.Complete(&TD);
2581 + this.type = Bridge.MapUnoType(this.unoType);
2582 + this.nativeProxy = IntPtr.Zero;
2583 + makeMethodInfos();
2586 + ~ManagedProxy()
2588 + UString.Release(this.unoOid);
2589 + TypeDescription.Release(this.unoType);
2592 + /** Prepares an array (m_arMethoInfos) containing MethodInfo object of the
2593 + interface and all inherited interfaces. At index null is the first
2594 + method of the base interface and at the last position is the last method
2595 + of the furthest derived interface.
2596 + If a UNO call is received then one can determine the position of the
2597 + method (or getter or setter for an attribute) from the passed type
2598 + information. The position minus 3 (there is no XInterface in the cli
2599 + mapping) corresponds to the index of the cli interface method in the
2600 + array.
2601 + */
2602 + void makeMethodInfos()
2604 + if (!type.IsInterface)
2605 + return;
2607 + MethodInfo[] thisMethods = type.GetMethods();
2608 + // get the inherited interfaces
2609 + Type[] inheritedIfaces = type.GetInterfaces();
2610 + inheritedInterfacesCount = inheritedIfaces.Length;
2612 + // array containing the number of methods for the interface
2613 + // and its inherited interfaces
2614 + interfaceMethodCounts = new int[inheritedInterfacesCount + 1];
2616 + // determine the number of all interface methods, including
2617 + // the inherited interfaces
2618 + int methodCount = thisMethods.Length;
2619 + foreach (Type iface in inheritedIfaces)
2620 + methodCount += iface.GetMethods().Length;
2622 + // array containing MethodInfos of the managed object
2623 + methodInfos = new MethodInfo[methodCount];
2625 + // array containing MethodInfos of the interface
2626 + interfaceMethodInfos = new MethodInfo[methodCount];
2628 + // array containing the mapping of UNO interface pos to pos in
2629 + // methodInfos
2630 + unoPosToCliPos = new int[methodCount];
2632 + for (int i = 0; i < methodCount; ++i)
2633 + unoPosToCliPos[i] = -1;
2635 + // fill methodInfos with the mappings
2636 + // !!! InterfaceMapping.TargetMethods should be MethodInfo*[] according
2637 + // to documentation
2638 + // but it is Type*[] instead. Bug in the framework?
2639 + // FIXME ^ what does mono do?
2640 + Type objType = managedI.GetType();
2641 + try
2643 + int index = 0;
2644 + // now get the methods from the inherited interface
2645 + // inheritedIfaces[0] is the direct base interface
2646 + // inheritedIfaces[n] is the furthest inherited interface
2647 + // Start with the base interface
2648 + for (int i = inheritedIfaces.Length - 1; i >= 0; --i)
2650 + InterfaceMapping mapInherited =
2651 + objType.GetInterfaceMap(inheritedIfaces[i]);
2653 + interfaceMethodCounts[i] = mapInherited.TargetMethods.Length;
2654 + for (int j = 0; j < interfaceMethodCounts[i]; ++j, ++index)
2656 + methodInfos[index] = mapInherited.TargetMethods[j] as MethodInfo;
2657 + interfaceMethodInfos[index] =
2658 + mapInherited.InterfaceMethods[j] as MethodInfo;
2662 + // At last come the methods of the furthest derived interface
2663 + InterfaceMapping map = objType.GetInterfaceMap(type);
2664 + interfaceMethodCounts[inheritedInterfacesCount] =
2665 + map.TargetMethods.Length;
2666 + for (int j = 0;
2667 + j < interfaceMethodCounts[inheritedInterfacesCount]; ++j, ++index)
2669 + methodInfos[index] = map.TargetMethods[j] as MethodInfo;
2670 + interfaceMethodInfos[index] =
2671 + map.InterfaceMethods[j] as MethodInfo;
2674 + catch (InvalidCastException)
2676 + // FIXME do something (can this happen, is "as" not the
2677 + // proper translation for "__try_cast" ?
2681 + /**Obtains a MethodInfo which can be used to invoke the cli object.
2682 + Internally it maps nUnoFunctionPos to an index that is used to get the
2683 + corresponding MethodInfo object from m_arMethoInfos. The mapping table
2684 + is dynamically initialized. If the cli interface has no base interface
2685 + or exactly one then the mapping table is initialized in one go at the
2686 + first call. In all ensuing calls the MethodInfo object is immediately
2687 + retrieved through the mapping table.
2689 + If the interface has more then one interface in its inheritance chain,
2690 + that is Type.GetInterfaces return more then one Type, then the mapping
2691 + table is partially initiallized. On the first call the mappings for the
2692 + methods of the belonging interface are created.
2694 + The implementation assumes that the order of interface methods as
2695 + provided by InterfaceMapping.InterfaceMethods corresponds to the order
2696 + of methods in the interface declaration.
2698 + @param nUnoFunctionPos
2699 + Position of the method in the uno interface.
2700 + */
2701 + unsafe MethodInfo getMethodInfo(int unoFunctionPos, UString* unoMethodName, MethodKind methodKind)
2703 + MethodInfo result = null;
2705 + // deduct 3 for XInterface methods
2706 + unoFunctionPos -= 3;
2707 + lock (unoPosToCliPos)
2709 + int cliPos = unoPosToCliPos[unoFunctionPos];
2710 + if (cliPos != -1)
2711 + return methodInfos[cliPos];
2713 + // create the method function name
2714 + string methodName = UString.UStringToString(unoMethodName);
2715 + switch (methodKind)
2717 + case MethodKind.METHOD:
2718 + break;
2719 + case MethodKind.SET:
2720 + methodName = "set_" + methodName;
2721 + break;
2722 + case MethodKind.GET:
2723 + methodName = "get_" + methodName;
2724 + break;
2725 + default:
2726 + // FIXME assert not reached
2727 + break;
2730 + // Find the cli interface method that corresponds to the Uno method
2731 + int indexCliMethod = -1;
2732 + // If the cli interfaces and their methods are in the same order
2733 + // as they were declared (inheritance chain and within the interface)
2734 + // then unoFunctionPos should lead to the correct method. However,
2735 + // the documentation does not say that this ordering is given.
2736 + if (methodName == interfaceMethodInfos[unoFunctionPos].Name)
2737 + indexCliMethod = unoFunctionPos;
2738 + else
2740 + int methodCount = interfaceMethodInfos.Length;
2741 + for (int i = 0; i < methodCount; ++i)
2743 + if (interfaceMethodInfos[i].Name == methodName)
2745 + indexCliMethod = i;
2746 + break;
2751 + if (indexCliMethod == -1 )
2753 + // FIXME throw some exception
2754 + return null;
2756 + unoPosToCliPos[unoFunctionPos] = indexCliMethod;
2757 + result = methodInfos[indexCliMethod];
2760 + return result;
2763 + void Acquire()
2765 + uno.Binary.Interface.Acquire(nativeProxy);
2768 + void Release()
2770 + uno.Binary.Interface.Release(nativeProxy);
2773 + unsafe void Dispatch(TypeDescription* memberTD, void* unoRet, void** unoArgs,
2774 + uno.Binary.Any** unoExc)
2776 + switch (memberTD->eTypeClass)
2778 + case TypeClass.INTERFACE_ATTRIBUTE:
2780 + int memberPos = ((InterfaceMemberTypeDescription*)memberTD)->nPosition;
2781 + InterfaceTypeDescription* ifaceTD = (InterfaceTypeDescription*)unoType;
2782 + int functionPos = ifaceTD->pMapMemberIndexToFunctionIndex[memberPos];
2784 + if (unoRet != null) // is getter method
2786 + MethodInfo info = getMethodInfo(
2787 + functionPos,
2788 + ((InterfaceMemberTypeDescription*)memberTD)->pMemberName,
2789 + MethodKind.GET);
2790 + bridge.CallManaged(
2791 + managedI, type, info,
2792 + ((InterfaceAttributeTypeDescription*)memberTD)->pAttributeTypeRef,
2793 + null, 0, // no params
2794 + unoRet, null, unoExc);
2796 + else // is setter method
2798 + MethodInfo info = getMethodInfo(
2799 + // set follows get method
2800 + functionPos + 1,
2801 + ((InterfaceMemberTypeDescription*)memberTD)->pMemberName,
2802 + MethodKind.SET);
2803 + MethodParameter param;
2804 + param.pTypeRef = ((InterfaceAttributeTypeDescription*)memberTD)->pAttributeTypeRef;
2805 + param.bIn = 1;
2806 + param.bOut = 0;
2808 + bridge.CallManaged(
2809 + managedI, type, info,
2810 + null /* indicated void return */, &param, 1,
2811 + null, unoArgs, unoExc);
2813 + break;
2815 + case TypeClass.INTERFACE_METHOD:
2817 + int memberPos = ((InterfaceMemberTypeDescription*)memberTD)->nPosition;
2818 + InterfaceTypeDescription* ifaceTD = (InterfaceTypeDescription*)unoType;
2819 + int functionPos = ifaceTD->pMapMemberIndexToFunctionIndex[memberPos];
2821 + switch (functionPos)
2823 + case 0: // queryInterface()
2825 + TypeDescription* requestedTD = null;
2826 + // FIXME leak
2827 + TypeDescriptionReference * argTD = *(TypeDescriptionReference **) unoArgs[0];
2828 + if (argTD != null)
2829 + TypeDescriptionReference.GetDescription(&requestedTD, argTD);
2830 + if (requestedTD == null || requestedTD->eTypeClass != TypeClass.INTERFACE)
2832 + uno.Binary.Any.Construct((uno.Binary.Any*)unoRet, null, null, null);
2833 + *unoExc = null;
2834 + break;
2837 + IntPtr unoInterface = IntPtr.Zero;
2839 + bridge.GetInterfaceFromUnoEnvironment(ref unoInterface, unoOid,
2840 + (InterfaceTypeDescription*)requestedTD);
2842 + if (unoInterface == IntPtr.Zero)
2844 + Type requestedType = Bridge.MapUnoType(requestedTD);
2845 + if (requestedType.IsInstanceOfType(managedI))
2847 + IntPtr unoI = bridge.MapManagedToUno(managedI, requestedTD);
2848 + uno.Binary.Any.Construct(
2849 + (uno.Binary.Any*)unoRet, &unoI, requestedTD, null);
2850 + uno.Binary.Interface.Release(unoI);
2852 + else // object does not support requested interface
2854 + uno.Binary.Any.Construct((uno.Binary.Any*)unoRet, null, null, null);
2856 + // no exception occurred
2857 + *unoExc = null;
2859 + else
2861 + uno.Binary.Any.Construct((uno.Binary.Any*)unoRet, &unoInterface,
2862 + requestedTD, null);
2863 + *unoExc = null;
2865 + break;
2867 + case 1: // acquire this proxy()
2868 + Acquire();
2869 + *unoExc = null;
2870 + break;
2871 + case 2: // release this proxy()
2872 + Release();
2873 + *unoExc = null;
2874 + break;
2875 + default: // arbitrary method call
2877 + InterfaceMethodTypeDescription* methodTD =
2878 + (InterfaceMethodTypeDescription*)memberTD;
2879 + UString* methodName = ((InterfaceMemberTypeDescription*)memberTD)->pMemberName;
2881 + MethodInfo info = getMethodInfo(functionPos, methodName, MethodKind.METHOD);
2883 + bridge.CallManaged(
2884 + managedI, type, info,
2885 + methodTD->pReturnTypeRef, methodTD->pParams,
2886 + methodTD->nParams,
2887 + unoRet, unoArgs, unoExc);
2888 + break;
2892 + break;
2894 + default: // Cannot happen
2896 + break;// FIXME Throw an error
2901 + public IntPtr NativeProxy
2903 + get { return nativeProxy; }
2904 + set { nativeProxy = value; }
2909 --- cli_ure/source/mono_bridge/mono_bridge.cxx.old 1970-01-01 00:00:00.000000000 +0000
2910 +++ cli_ure/source/mono_bridge/mono_bridge.cxx 2009-04-06 16:41:58.000000000 +0000
2911 @@ -0,0 +1,432 @@
2912 +/*************************************************************************
2914 + * $RCSfile: $
2916 + * $Revision: $
2918 + * last change: $Author: $ $Date: $
2920 + * The Contents of this file are made available subject to the terms of
2921 + * either of the following licenses
2923 + * - GNU Lesser General Public License Version 2.1
2924 + * - Sun Industry Standards Source License Version 1.1
2926 + * Sun Microsystems Inc., October, 2000
2928 + * GNU Lesser General Public License Version 2.1
2929 + * =============================================
2930 + * Copyright 2000 by Sun Microsystems, Inc.
2931 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
2933 + * This library is free software; you can redistribute it and/or
2934 + * modify it under the terms of the GNU Lesser General Public
2935 + * License version 2.1, as published by the Free Software Foundation.
2937 + * This library is distributed in the hope that it will be useful,
2938 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2939 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2940 + * Lesser General Public License for more details.
2942 + * You should have received a copy of the GNU Lesser General Public
2943 + * License along with this library; if not, write to the Free Software
2944 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2945 + * MA 02111-1307 USA
2948 + * Sun Industry Standards Source License Version 1.1
2949 + * =================================================
2950 + * The contents of this file are subject to the Sun Industry Standards
2951 + * Source License Version 1.1 (the "License"); You may not use this file
2952 + * except in compliance with the License. You may obtain a copy of the
2953 + * License at http://www.openoffice.org/license.html.
2955 + * Software provided under this License is provided on an "AS IS" basis,
2956 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
2957 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
2958 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
2959 + * See the License for the specific provisions governing your rights and
2960 + * obligations concerning the Software.
2962 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
2964 + * Copyright: 2000 by Sun Microsystems, Inc.
2966 + * All Rights Reserved.
2968 + * Contributor(s): _______________________________________
2971 + ************************************************************************/
2973 +#include <string.h>
2975 +#include "uno/dispatcher.h"
2976 +#include "uno/environment.h"
2977 +#include "uno/lbnames.h"
2979 +#include "osl/diagnose.h"
2980 +#include "rtl/unload.h"
2981 +#include "rtl/ustring.hxx"
2983 +#include "uno/mapping.hxx"
2985 +extern "C" {
2986 +#include "mono/metadata/appdomain.h"
2987 +#include "mono/metadata/assembly.h"
2988 +#include "mono/metadata/debug-helpers.h"
2989 +#include "mono/metadata/object.h"
2990 +#include "mono/metadata/threads.h"
2993 +#include "mono_bridge.h"
2995 +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
2997 +using namespace ::rtl;
2998 +using namespace ::mono_uno;
3000 +extern "C" {
3002 +void SAL_CALL Mapping_acquire( uno_Mapping * mapping )
3003 + SAL_THROW_EXTERN_C()
3005 + static_cast< Mapping const * >( mapping )->m_bridge->acquire();
3008 +void SAL_CALL Mapping_release( uno_Mapping * mapping )
3009 + SAL_THROW_EXTERN_C()
3011 + static_cast< Mapping const * >( mapping )->m_bridge->release();
3014 +void SAL_CALL Mapping_map_to_uno(
3015 + uno_Mapping * mapping, void ** ppOut,
3016 + void * pIn, typelib_InterfaceTypeDescription * td )
3017 + SAL_THROW_EXTERN_C()
3019 + uno_Interface ** ppUnoI = (uno_Interface **)ppOut;
3020 + void * monoI = pIn;
3022 +// FIXME do this here? OSL_ASSERT( sizeof (void *) >= sizeof (guint32))
3023 + OSL_ENSURE( ppUnoI && td, "### null ptr!" );
3025 + if (0 != *ppUnoI)
3027 + uno_Interface * pUnoI = *ppUnoI;
3028 + (*pUnoI->release)( pUnoI );
3029 + *ppUnoI = 0;
3032 + try
3034 + Bridge const *bridge =
3035 + static_cast< Mapping const * >( mapping )->m_bridge;
3036 + // FIXME any wrapper necessary around mono calls? cf. JNI_guarded_context
3037 + uno_Interface * pUnoI = bridge->map_to_uno(
3038 + monoI, (typelib_TypeDescription *)td );
3039 + *ppUnoI = pUnoI;
3041 + catch (BridgeRuntimeError & err)
3043 +#if OSL_DEBUG_LEVEL > 0
3044 + OString cstr_msg(
3045 + OUStringToOString(
3046 + OUSTR("[mono_uno bridge error] ") + err.m_message,
3047 + RTL_TEXTENCODING_ASCII_US ) );
3048 + OSL_ENSURE( 0, cstr_msg.getStr() );
3049 +#endif
3053 +void SAL_CALL Mapping_map_to_mono(
3054 + uno_Mapping * mapping, void ** ppOut,
3055 + void * pIn, typelib_InterfaceTypeDescription * td )
3056 + SAL_THROW_EXTERN_C()
3058 + void ** pMonoI = ppOut;
3059 + uno_Interface * pUnoI = (uno_Interface *)pIn;
3061 + OSL_ENSURE( ppOut && td, "### null ptr!" );
3063 + if (0 != *pMonoI)
3065 + // FIXME JNI bridge has guarded_context here
3066 + // FIXME: do the right thing in the managed bridge
3067 + // mono_gchandle_free( *pMonoI );
3070 + try
3072 + if (0 != pUnoI)
3074 + Bridge const * bridge =
3075 + static_cast< Mapping const *>( mapping )->m_bridge;
3076 + // FIXME guarded context
3077 + *ppOut = (void *)bridge->map_to_mono(
3078 + pUnoI, (typelib_TypeDescription *)td );
3079 + OSL_ASSERT( ppOut && *ppOut );
3082 + catch (BridgeRuntimeError & err)
3084 +#if OSL_DEBUG_LEVEL >= 1
3085 + rtl::OString cstr_msg(
3086 + rtl::OUStringToOString(
3087 + OUSTR("[mono_uno bridge error] ") + err.m_message,
3088 + RTL_TEXTENCODING_ASCII_US ) );
3089 + OSL_ENSURE( 0, cstr_msg.getStr() );
3090 +#endif
3094 +void SAL_CALL Bridge_free( uno_Mapping * mapping )
3095 + SAL_THROW_EXTERN_C()
3097 + Mapping * that = static_cast< Mapping * >( mapping );
3098 + delete that->m_bridge;
3101 +} // extern "C"
3103 +rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
3105 +namespace mono_uno
3108 +void Bridge::acquire() const SAL_THROW( () )
3110 + if (1 == osl_incrementInterlockedCount( &m_ref ))
3112 + if (m_registered_mono2uno)
3114 + uno_Mapping * mapping = const_cast< Mapping * >( &m_mono2uno );
3115 + uno_registerMapping(
3116 + &mapping, Bridge_free,
3117 + m_mono_env, (uno_Environment *)m_uno_env, 0 );
3119 + else
3121 + uno_Mapping * mapping = const_cast< Mapping * >( &m_uno2mono );
3122 + uno_registerMapping(
3123 + &mapping, Bridge_free,
3124 + (uno_Environment *)m_uno_env, m_mono_env, 0 );
3129 +void Bridge::release() const SAL_THROW( () )
3131 + if (! osl_decrementInterlockedCount( &m_ref ))
3133 + uno_revokeMapping(
3134 + m_registered_mono2uno
3135 + ? const_cast< Mapping * >( &m_mono2uno )
3136 + : const_cast< Mapping * >( &m_uno2mono ) );
3140 +MonoAssembly *
3141 +DoLoad (MonoDomain *domain, char *fullname)
3143 + MonoAssemblyName aname;
3144 + MonoImageOpenStatus status;
3145 + MonoAssembly *ass;
3147 + memset (&aname, 0, sizeof (aname));
3148 + aname.culture = "";
3149 + strncpy ((char *)aname.public_key_token, "ce2cb7e279207b9e", MONO_PUBLIC_KEY_TOKEN_LENGTH);
3150 + aname.name = "cli_uno_bridge";
3152 + ass = mono_assembly_load (&aname, NULL, &status);
3153 + if (status != MONO_IMAGE_OK)
3154 + return NULL;
3155 + return ass;
3158 +Bridge::Bridge(
3159 + uno_Environment * mono_env, uno_ExtEnvironment * uno_env,
3160 + bool registered_mono2uno )
3161 + : m_ref( 1 ),
3162 + m_uno_env( uno_env ),
3163 + m_mono_env( mono_env ),
3164 + m_registered_mono2uno( registered_mono2uno )
3166 + MonoDomain * pDomain = mono_get_root_domain();
3167 + // FIXME where is this freed?
3168 + MonoAssembly * pAssembly = DoLoad (pDomain, "cli_uno_bridge, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce2cb7e279207b9e");
3169 + // FIXME and this, is this needed later?
3170 + MonoClass * pClass = mono_class_from_name (
3171 + (MonoImage *)mono_assembly_get_image( pAssembly ), "com.sun.star.bridges.mono_uno", "Bridge" );
3172 + OSL_ASSERT( 0 != pClass );
3173 + /* FIXME add args to method description string */
3174 + MonoMethodDesc * pMethodDesc = mono_method_desc_new( ":.ctor", FALSE );
3175 + MonoMethod * pCtor = mono_method_desc_search_in_class( pMethodDesc, pClass );
3176 + mono_method_desc_free( pMethodDesc );
3177 + OSL_ASSERT( 0 != pCtor );
3179 + pMethodDesc = mono_method_desc_new( "Bridge:MapManagedToUno", FALSE );
3180 + m_mapManagedToUnoMethod = mono_method_desc_search_in_class( pMethodDesc, pClass );
3181 + mono_method_desc_free( pMethodDesc );
3182 + OSL_ASSERT( 0 != m_mapManagedToUnoMethod );
3184 + pMethodDesc = mono_method_desc_new( "Bridge:MapUnoToManaged", FALSE );
3185 + m_mapUnoToManagedMethod = mono_method_desc_search_in_class( pMethodDesc, pClass );
3186 + mono_method_desc_free( pMethodDesc );
3187 + OSL_ASSERT( 0 != m_mapUnoToManagedMethod );
3189 + gpointer pParams[1];
3190 + pParams[0] = &uno_env;
3191 + m_managedBridge = mono_object_new( pDomain, pClass );
3192 + mono_uno::runtime_invoke( pCtor, m_managedBridge, pParams, NULL,
3193 + mono_object_get_domain( m_managedBridge ) );
3195 + OSL_ASSERT( 0 != m_mono_env && 0 != m_uno_env );
3196 + (*((uno_Environment *)m_uno_env)->acquire)( (uno_Environment *)m_uno_env );
3197 + (*m_mono_env->acquire)( m_mono_env );
3199 + // mono2uno mapping
3200 + m_mono2uno.acquire = Mapping_acquire;
3201 + m_mono2uno.release = Mapping_release;
3202 + m_mono2uno.mapInterface = Mapping_map_to_uno;
3203 + m_mono2uno.m_bridge = this;
3204 + // uno2mono mapping
3205 + m_uno2mono.acquire = Mapping_acquire;
3206 + m_uno2mono.release = Mapping_release;
3207 + m_uno2mono.mapInterface = Mapping_map_to_mono;
3208 + m_uno2mono.m_bridge = this;
3210 + (*g_moduleCount.modCnt.acquire)( &g_moduleCount.modCnt );
3213 +Bridge::~Bridge() SAL_THROW( () )
3215 + (*m_mono_env->release)( m_mono_env );
3216 + (*((uno_Environment *)m_uno_env)->release)( (uno_Environment *)m_uno_env );
3217 + // FIXME release managed bridge
3219 + (*g_moduleCount.modCnt.release)( &g_moduleCount.modCnt );
3222 +void * Bridge::map_to_mono(
3223 + uno_Interface *pUnoI, typelib_TypeDescription * pTD ) const
3225 + gpointer pMonoParams[2];
3227 + pMonoParams[0] = &pUnoI;
3228 + pMonoParams[1] = pTD;
3230 + return
3231 + mono_uno::runtime_invoke( m_mapUnoToManagedMethod,
3232 + m_managedBridge, pMonoParams, NULL,
3233 + mono_object_get_domain( m_managedBridge ) );
3236 +uno_Interface * Bridge::map_to_uno(
3237 + void * pMonoI, typelib_TypeDescription * pTD ) const
3239 + gpointer pMonoParams[2];
3240 + uno_Interface ** ppResult;
3242 + pMonoParams[0] = pMonoI;
3243 + pMonoParams[1] = pTD;
3245 + ppResult = (uno_Interface **)mono_object_unbox(
3246 + mono_uno::runtime_invoke( m_mapManagedToUnoMethod,
3247 + m_managedBridge, pMonoParams, NULL,
3248 + mono_object_get_domain( m_managedBridge ) ) );
3250 + return *ppResult;
3253 +} // namespace mono_uno
3255 +extern "C" {
3257 +// void SAL_CALL mono_environmentDisposing( uno_Environment * mono_env )
3258 +// SAL_THROW_EXTERN_C()
3259 +// {
3260 +// }
3262 +void SAL_CALL uno_initEnvironment( uno_Environment * mono_env )
3263 + SAL_THROW_EXTERN_C()
3265 + // mono_env->environmentDisposing = mono_environmentDisposing;
3266 + mono_env->pExtEnv = 0; /* no extended support */
3269 +void SAL_CALL uno_ext_getMapping(
3270 + uno_Mapping ** ppMapping, uno_Environment *pFrom, uno_Environment *pTo )
3271 + SAL_THROW_EXTERN_C()
3273 + OSL_ASSERT( 0 != ppMapping && 0 != pFrom && 0 != pTo );
3274 + if (0 != *ppMapping)
3276 + (*(*ppMapping)->release)( *ppMapping );
3277 + *ppMapping = 0;
3280 + /* FIXME check that mono's and sal's types have matching sizes
3281 + * like jni_bridge does? */
3283 + OUString const & from_env_typename = OUString::unacquired( &pFrom->pTypeName );
3284 + OUString const & to_env_typename = OUString::unacquired( &pTo->pTypeName );
3286 + uno_Mapping * mapping = 0;
3288 + try
3290 + if (from_env_typename.equalsAsciiL(
3291 + RTL_CONSTASCII_STRINGPARAM( UNO_LB_CLI )) &&
3292 + to_env_typename.equalsAsciiL(
3293 + RTL_CONSTASCII_STRINGPARAM( UNO_LB_UNO)))
3295 + Bridge * bridge =
3296 + new Bridge( pFrom, pTo->pExtEnv, true ); // ref count = 1
3297 + mapping = &bridge->m_mono2uno;
3298 + uno_registerMapping(
3299 + &mapping, Bridge_free, pFrom,
3300 + (uno_Environment *)pTo->pExtEnv, 0);
3302 + else if (from_env_typename.equalsAsciiL(
3303 + RTL_CONSTASCII_STRINGPARAM( UNO_LB_UNO)) &&
3304 + to_env_typename.equalsAsciiL(
3305 + RTL_CONSTASCII_STRINGPARAM( UNO_LB_CLI)))
3307 + Bridge * bridge =
3308 + new Bridge( pTo, pFrom->pExtEnv, false ); // ref count = 1
3309 + mapping = &bridge->m_uno2mono;
3310 + uno_registerMapping(
3311 + &mapping, Bridge_free,
3312 + (uno_Environment *)pFrom->pExtEnv, pTo, 0);
3315 + catch (BridgeRuntimeError & err)
3317 +#if OSL_DEBUG_LEVEL >= 1
3318 + OString cstr_msg(
3319 + OUStringToOString(
3320 + OUSTR("[mono_uno bridge error] ") + err.m_message,
3321 + RTL_TEXTENCODING_ASCII_US ) );
3322 + OSL_ENSURE( 0, cstr_msg.getStr() );
3323 +#endif
3326 + *ppMapping = mapping;
3329 +sal_Bool SAL_CALL component_canUnload( TimeValue * pTime )
3330 + SAL_THROW_EXTERN_C()
3332 + return (*g_moduleCount.canUnload)( &g_moduleCount, pTime );
3335 +} // extern "C"
3337 +MonoObject*
3338 +mono_uno::runtime_invoke (MonoMethod *method, void *obj, void **params,
3339 + MonoObject **exc, MonoDomain *domain)
3341 + mono_thread_attach( domain );
3342 + return mono_runtime_invoke( method, obj, params, exc );
3344 --- cli_ure/source/mono_bridge/mono_bridge.h.old 1970-01-01 00:00:00.000000000 +0000
3345 +++ cli_ure/source/mono_bridge/mono_bridge.h 2009-04-06 16:41:58.000000000 +0000
3346 @@ -0,0 +1,158 @@
3347 +/*************************************************************************
3349 + * $RCSfile: $
3351 + * $Revision: $
3353 + * last change: $Author: $ $Date: $
3355 + * The Contents of this file are made available subject to the terms of
3356 + * either of the following licenses
3358 + * - GNU Lesser General Public License Version 2.1
3359 + * - Sun Industry Standards Source License Version 1.1
3361 + * Sun Microsystems Inc., October, 2000
3363 + * GNU Lesser General Public License Version 2.1
3364 + * =============================================
3365 + * Copyright 2000 by Sun Microsystems, Inc.
3366 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
3368 + * This library is free software; you can redistribute it and/or
3369 + * modify it under the terms of the GNU Lesser General Public
3370 + * License version 2.1, as published by the Free Software Foundation.
3372 + * This library is distributed in the hope that it will be useful,
3373 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3374 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3375 + * Lesser General Public License for more details.
3377 + * You should have received a copy of the GNU Lesser General Public
3378 + * License along with this library; if not, write to the Free Software
3379 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
3380 + * MA 02111-1307 USA
3383 + * Sun Industry Standards Source License Version 1.1
3384 + * =================================================
3385 + * The contents of this file are subject to the Sun Industry Standards
3386 + * Source License Version 1.1 (the "License"); You may not use this file
3387 + * except in compliance with the License. You may obtain a copy of the
3388 + * License at http://www.openoffice.org/license.html.
3390 + * Software provided under this License is provided on an "AS IS" basis,
3391 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
3392 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
3393 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
3394 + * See the License for the specific provisions governing your rights and
3395 + * obligations concerning the Software.
3397 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
3399 + * Copyright: 2000 by Sun Microsystems, Inc.
3401 + * All Rights Reserved.
3403 + * Contributor(s): _______________________________________
3406 + ************************************************************************/
3408 +#if ! defined INCLUDED_MONO_BRIDGE_H
3409 +#define INCLUDED_MONO_BRIDGE_H
3411 +#include "glib/gtypes.h"
3412 +#include "osl/interlck.h"
3413 +#include "rtl/ustring.hxx"
3414 +#include "typelib/typedescription.hxx"
3415 +#include "uno/dispatcher.h"
3416 +#include "uno/mapping.h"
3418 +extern "C" {
3419 +#include "mono/metadata/appdomain.h"
3420 +#include "mono/metadata/debug-helpers.h"
3421 +#include "mono/metadata/object.h"
3422 +#include "mono/metadata/threads.h"
3425 +namespace cssu = com::sun::star::uno;
3427 +typedef struct _uno_ExtEnvironment uno_ExtEnvironment;
3428 +typedef struct _uno_Environment uno_Environment;
3429 +typedef struct _typelib_TypeDescription typelib_TypeDescription;
3431 +namespace mono_uno
3434 +MonoObject* runtime_invoke (MonoMethod *method, void *obj, void **params,
3435 + MonoObject **exc, MonoDomain *domain);
3437 +//==== holds environments and mappings =========================================
3438 +struct Bridge;
3439 +struct Mapping : public uno_Mapping
3441 + Bridge * m_bridge;
3444 +//==============================================================================
3445 +struct Bridge
3447 + mutable oslInterlockedCount m_ref;
3448 + MonoObject * m_managedBridge;
3450 + uno_ExtEnvironment * m_uno_env;
3451 + uno_Environment * m_mono_env;
3453 + Mapping m_mono2uno;
3454 + Mapping m_uno2mono;
3455 + bool m_registered_mono2uno;
3457 + MonoMethod * m_mapUnoToManagedMethod;
3458 + MonoMethod * m_mapManagedToUnoMethod;
3460 + ~Bridge() SAL_THROW( () );
3461 + explicit Bridge(
3462 + uno_Environment * mono_env, uno_ExtEnvironment * uno_env,
3463 + bool registered_mono2uno );
3465 + void acquire() const;
3466 + void release() const;
3468 + void * map_to_mono(
3469 + uno_Interface * pUnoI, typelib_TypeDescription * pTD ) const;
3471 + uno_Interface * map_to_uno(
3472 + void * pMonoI, typelib_TypeDescription * pTD ) const;
3475 +struct MonoProxy : public uno_Interface
3477 + mutable oslInterlockedCount m_ref;
3478 + guint32 m_managedProxy;
3479 + uno_ExtEnvironment * m_unoEnv;
3480 + const cssu::TypeDescription m_unoType;
3481 + const rtl::OUString m_Oid;
3482 + MonoMethod * m_managedDispatch;
3484 + void acquire() const;
3485 + void release() const;
3486 + void dispatch(typelib_TypeDescription const * member_td, void * uno_ret,
3487 + void * uno_args [], uno_Any ** uno_exc);
3489 + MonoProxy(uno_ExtEnvironment * pUnoEnv, guint32 managedProxy,
3490 + rtl_uString * pOid, typelib_TypeDescription * pTD);
3493 +struct BridgeRuntimeError
3495 + ::rtl::OUString m_message;
3497 + inline BridgeRuntimeError( ::rtl::OUString const & message )
3498 + : m_message( message )
3499 + {}
3504 +#endif
3505 --- cli_ure/source/mono_bridge/mono_proxy.cxx.old 1970-01-01 00:00:00.000000000 +0000
3506 +++ cli_ure/source/mono_bridge/mono_proxy.cxx 2009-04-06 16:41:58.000000000 +0000
3507 @@ -0,0 +1,201 @@
3508 +/*************************************************************************
3510 + * $RCSfile: $
3512 + * $Revision: $
3514 + * last change: $Author: $ $Date: $
3516 + * The Contents of this file are made available subject to the terms of
3517 + * either of the following licenses
3519 + * - GNU Lesser General Public License Version 2.1
3520 + * - Sun Industry Standards Source License Version 1.1
3522 + * Sun Microsystems Inc., October, 2000
3524 + * GNU Lesser General Public License Version 2.1
3525 + * =============================================
3526 + * Copyright 2000 by Sun Microsystems, Inc.
3527 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
3529 + * This library is free software; you can redistribute it and/or
3530 + * modify it under the terms of the GNU Lesser General Public
3531 + * License version 2.1, as published by the Free Software Foundation.
3533 + * This library is distributed in the hope that it will be useful,
3534 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3535 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3536 + * Lesser General Public License for more details.
3538 + * You should have received a copy of the GNU Lesser General Public
3539 + * License along with this library; if not, write to the Free Software
3540 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
3541 + * MA 02111-1307 USA
3544 + * Sun Industry Standards Source License Version 1.1
3545 + * =================================================
3546 + * The contents of this file are subject to the Sun Industry Standards
3547 + * Source License Version 1.1 (the "License"); You may not use this file
3548 + * except in compliance with the License. You may obtain a copy of the
3549 + * License at http://www.openoffice.org/license.html.
3551 + * Software provided under this License is provided on an "AS IS" basis,
3552 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
3553 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
3554 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
3555 + * See the License for the specific provisions governing your rights and
3556 + * obligations concerning the Software.
3558 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
3560 + * Copyright: 2000 by Sun Microsystems, Inc.
3562 + * All Rights Reserved.
3564 + * Contributor(s): _______________________________________
3567 + ************************************************************************/
3569 +#include "mono_bridge.h"
3571 +#include "rtl/ustring.h"
3572 +#include "uno/dispatcher.h"
3573 +#include "uno/environment.h"
3574 +#include "typelib/typedescription.h"
3576 +extern "C" {
3577 +#include "mono/metadata/threads.h"
3580 +using namespace mono_uno;
3582 +extern "C" {
3584 +static void SAL_CALL mono_proxy_free( uno_ExtEnvironment * env, void * proxy)
3586 + MonoProxy * monoProxy = reinterpret_cast< MonoProxy * >( proxy );
3588 + delete monoProxy;
3591 +uno_Interface * SAL_CALL cli_uno_environment_createMonoProxyAndRegister(
3592 + uno_ExtEnvironment *pUnoEnv, void *pMonoProxy, rtl_uString *pOid,
3593 + typelib_TypeDescription *pTD )
3594 + SAL_THROW_EXTERN_C()
3596 + uno_Interface * proxy = static_cast< uno_Interface * >(
3597 + new MonoProxy( pUnoEnv,
3598 + static_cast< guint32 >( reinterpret_cast< sal_IntPtr >( pMonoProxy ) ),
3599 + pOid, pTD ) );
3601 + pUnoEnv->registerProxyInterface(
3602 + pUnoEnv,
3603 + reinterpret_cast< void ** >( &proxy ),
3604 + mono_proxy_free,
3605 + pOid,
3606 + (typelib_InterfaceTypeDescription*) pTD );
3608 + return proxy;
3611 +static void SAL_CALL mono_proxy_acquire( uno_Interface * pUnoI )
3613 + MonoProxy const * that = static_cast< MonoProxy const * >( pUnoI );
3614 + that->acquire();
3617 +static void SAL_CALL mono_proxy_release( uno_Interface * pUnoI )
3619 + MonoProxy const * that = static_cast< MonoProxy const * >( pUnoI );
3620 + that->release();
3623 +static void SAL_CALL mono_proxy_dispatch(
3624 + uno_Interface * pUnoI, typelib_TypeDescription const * member_td,
3625 + void * uno_ret, void * uno_args [], uno_Any ** uno_exc )
3626 + SAL_THROW_EXTERN_C()
3628 + MonoProxy * that = static_cast< MonoProxy * >( pUnoI );
3629 + that->dispatch( member_td, uno_ret, uno_args, uno_exc );
3632 +} // extern "C"
3634 +namespace mono_uno
3637 +MonoProxy::MonoProxy(uno_ExtEnvironment * pUnoEnv, guint32 managedProxy,
3638 + rtl_uString *pOid, typelib_TypeDescription * pTD):
3639 + m_ref(1),
3640 + m_unoEnv(pUnoEnv),
3641 + m_managedProxy(managedProxy), // FIXME free this in the destructor?
3642 + m_Oid(pOid),
3643 + m_unoType(pTD)
3645 + uno_Interface::acquire = mono_proxy_acquire;
3646 + uno_Interface::release = mono_proxy_release;
3647 + uno_Interface::pDispatcher = mono_proxy_dispatch;
3649 + MonoObject * pObj = mono_gchandle_get_target( m_managedProxy );
3650 + MonoClass * pClass = mono_object_get_class( pObj );
3651 + MonoMethodDesc * pMethodDesc = mono_method_desc_new( "ManagedProxy:Dispatch", FALSE );
3652 + m_managedDispatch = mono_method_desc_search_in_class( pMethodDesc, pClass );
3653 + mono_method_desc_free( pMethodDesc );
3654 + OSL_ASSERT( 0 != m_managedDispatch );
3657 +inline void MonoProxy::acquire() const
3659 + if (1 == osl_incrementInterlockedCount( &m_ref ))
3661 + // rebirth of proxy zombie
3662 + void * that = const_cast< MonoProxy * >( this );
3663 + // register at uno env
3664 + (*m_unoEnv->registerProxyInterface)(
3665 + m_unoEnv, &that,
3666 + mono_proxy_free, m_Oid.pData,
3667 + (typelib_InterfaceTypeDescription *)m_unoType.get() );
3668 +#if OSL_DEBUG_LEVEL >= 2
3669 + OSL_ASSERT( this == (void const * const)that );
3670 +#endif
3674 +inline void MonoProxy::release() const
3676 + if (0 == osl_decrementInterlockedCount( &m_ref ))
3678 + // revoke from uno env on last release,
3679 + // The proxy can be resurrected if acquire is called before the uno
3680 + // environment calls mono_proxy_free. mono_proxy_free will
3681 + //delete the proxy. The environment does not acquire a registered
3682 + //proxy.
3683 + (*m_unoEnv->revokeInterface)(
3684 + m_unoEnv, const_cast< MonoProxy * >( this ) );
3688 +inline void MonoProxy::dispatch( typelib_TypeDescription const * member_td,
3689 + void * uno_ret, void * uno_args [], uno_Any ** uno_exc )
3691 + OSL_ASSERT( m_managedDispatch != 0 );
3693 + gpointer pMonoParams[4];
3695 + pMonoParams[0] = const_cast< typelib_TypeDescription * >(member_td);
3696 + pMonoParams[1] = uno_ret;
3697 + pMonoParams[2] = uno_args;
3698 + pMonoParams[3] = uno_exc;
3700 + MonoObject *obj = mono_gchandle_get_target( m_managedProxy );
3702 + mono_uno::runtime_invoke( m_managedDispatch,
3703 + obj, pMonoParams, NULL,
3704 + mono_object_get_domain( obj ) );
3709 --- cli_ure/source/mono_bridge/rtl_ustring.cs.old 1970-01-01 00:00:00.000000000 +0000
3710 +++ cli_ure/source/mono_bridge/rtl_ustring.cs 2009-04-06 16:41:58.000000000 +0000
3711 @@ -0,0 +1,138 @@
3712 +/*************************************************************************
3714 + * $RCSfile: $
3716 + * $Revision: $
3718 + * last change: $Author: $ $Date: $
3720 + * The Contents of this file are made available subject to the terms of
3721 + * either of the following licenses
3723 + * - GNU Lesser General Public License Version 2.1
3724 + * - Sun Industry Standards Source License Version 1.1
3726 + * Sun Microsystems Inc., October, 2000
3728 + * GNU Lesser General Public License Version 2.1
3729 + * =============================================
3730 + * Copyright 2000 by Sun Microsystems, Inc.
3731 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
3733 + * This library is free software; you can redistribute it and/or
3734 + * modify it under the terms of the GNU Lesser General Public
3735 + * License version 2.1, as published by the Free Software Foundation.
3737 + * This library is distributed in the hope that it will be useful,
3738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3740 + * Lesser General Public License for more details.
3742 + * You should have received a copy of the GNU Lesser General Public
3743 + * License along with this library; if not, write to the Free Software
3744 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
3745 + * MA 02111-1307 USA
3748 + * Sun Industry Standards Source License Version 1.1
3749 + * =================================================
3750 + * The contents of this file are subject to the Sun Industry Standards
3751 + * Source License Version 1.1 (the "License"); You may not use this file
3752 + * except in compliance with the License. You may obtain a copy of the
3753 + * License at http://www.openoffice.org/license.html.
3755 + * Software provided under this License is provided on an "AS IS" basis,
3756 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
3757 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
3758 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
3759 + * See the License for the specific provisions governing your rights and
3760 + * obligations concerning the Software.
3762 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
3764 + * Copyright: 2000 by Sun Microsystems, Inc.
3766 + * All Rights Reserved.
3768 + * Contributor(s): _______________________________________
3771 + ************************************************************************/
3773 +namespace uno.rtl {
3775 +using System;
3776 +using System.Runtime.InteropServices;
3777 +using System.Text;
3779 +public unsafe struct UString
3781 + public int RefCount;
3782 + public int Length;
3783 + public char FirstChar;
3785 + [DllImport("sal")]
3786 + private static extern void rtl_uString_acquire(void* data);
3788 + [DllImport("sal")]
3789 + private static unsafe extern void rtl_uString_release(void* data);
3791 + [DllImport("sal")]
3792 + private static unsafe extern void rtl_uString_new(void* data);
3794 + [DllImport("sal")]
3795 + private static unsafe extern void rtl_uString_newFromStr_WithLength(
3796 + void* data,
3797 + // this should pass a pointer to the original string's char[]
3798 + [MarshalAs(UnmanagedType.LPWStr)] string value,
3799 + int len);
3801 + [DllImport("sal")]
3802 + private static unsafe extern void rtl_uString_newFromStr_WithLength(
3803 + void* data,
3804 + // this should pass a pointer to the stringbuilder's internal char[]
3805 + [MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer,
3806 + int len);
3808 + public static unsafe void Acquire(UString* us)
3810 + rtl_uString_acquire(us);
3813 + public static unsafe void Release(UString* us)
3815 + rtl_uString_release(us);
3818 + public static unsafe void New(UString** p)
3820 + rtl_uString_new(p);
3823 + public static unsafe void NewFromString(UString **p, string s)
3825 + rtl_uString_newFromStr_WithLength(p, s, s.Length);
3828 + public static unsafe void NewFromStringBuilder(UString **p, StringBuilder sb)
3830 + rtl_uString_newFromStr_WithLength(p, sb, sb.Length);
3833 + public static unsafe string UStringToString(UString *p)
3835 + return new String(&(p->FirstChar), 0, p->Length);
3839 +// FIXME move this to its own file or rename this file to e.g. sal
3840 +public unsafe struct Mem
3842 + // FIXME parameter is a sal_Size which is unsigned and has the
3843 + // size of a native long. Thus this is not 64bit safe. Might have
3844 + // to write a glue function that always takes 32bit.
3845 + [DllImport("sal", EntryPoint="rtl_allocateMemory")]
3846 + public static unsafe extern void *Allocate(int bytes);
3850 --- cli_ure/source/mono_bridge/typeclass.cs.old 1970-01-01 00:00:00.000000000 +0000
3851 +++ cli_ure/source/mono_bridge/typeclass.cs 2009-04-06 16:41:58.000000000 +0000
3852 @@ -0,0 +1,132 @@
3853 +/*************************************************************************
3855 + * $RCSfile: $
3857 + * $Revision: $
3859 + * last change: $Author: $ $Date: $
3861 + * The Contents of this file are made available subject to the terms of
3862 + * either of the following licenses
3864 + * - GNU Lesser General Public License Version 2.1
3865 + * - Sun Industry Standards Source License Version 1.1
3867 + * Sun Microsystems Inc., October, 2000
3869 + * GNU Lesser General Public License Version 2.1
3870 + * =============================================
3871 + * Copyright 2000 by Sun Microsystems, Inc.
3872 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
3874 + * This library is free software; you can redistribute it and/or
3875 + * modify it under the terms of the GNU Lesser General Public
3876 + * License version 2.1, as published by the Free Software Foundation.
3878 + * This library is distributed in the hope that it will be useful,
3879 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3880 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3881 + * Lesser General Public License for more details.
3883 + * You should have received a copy of the GNU Lesser General Public
3884 + * License along with this library; if not, write to the Free Software
3885 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
3886 + * MA 02111-1307 USA
3889 + * Sun Industry Standards Source License Version 1.1
3890 + * =================================================
3891 + * The contents of this file are subject to the Sun Industry Standards
3892 + * Source License Version 1.1 (the "License"); You may not use this file
3893 + * except in compliance with the License. You may obtain a copy of the
3894 + * License at http://www.openoffice.org/license.html.
3896 + * Software provided under this License is provided on an "AS IS" basis,
3897 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
3898 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
3899 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
3900 + * See the License for the specific provisions governing your rights and
3901 + * obligations concerning the Software.
3903 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
3905 + * Copyright: 2000 by Sun Microsystems, Inc.
3907 + * All Rights Reserved.
3909 + * Contributor(s): _______________________________________
3912 + ************************************************************************/
3914 +namespace uno.Typelib {
3916 +public class TypeClass
3918 + /** type class of void */
3919 + public const int VOID = 0;
3920 + /** type class of char */
3921 + public const int CHAR = 1;
3922 + /** type class of boolean */
3923 + public const int BOOLEAN = 2;
3924 + /** type class of byte */
3925 + public const int BYTE = 3;
3926 + /** type class of short */
3927 + public const int SHORT = 4;
3928 + /** type class of unsigned short */
3929 + public const int UNSIGNED_SHORT = 5;
3930 + /** type class of long */
3931 + public const int LONG = 6;
3932 + /** type class of unsigned long */
3933 + public const int UNSIGNED_LONG = 7;
3934 + /** type class of hyper */
3935 + public const int HYPER = 8;
3936 + /** type class of unsigned hyper */
3937 + public const int UNSIGNED_HYPER = 9;
3938 + /** type class of float */
3939 + public const int FLOAT = 10;
3940 + /** type class of double */
3941 + public const int DOUBLE = 11;
3942 + /** type class of string */
3943 + public const int STRING = 12;
3944 + /** type class of type */
3945 + public const int TYPE = 13;
3946 + /** type class of any */
3947 + public const int ANY = 14;
3948 + /** type class of enum */
3949 + public const int ENUM = 15;
3950 + /** type class of typedef */
3951 + public const int TYPEDEF = 16;
3952 + /** type class of struct */
3953 + public const int STRUCT = 17;
3954 + /** type class of union (not implemented) */
3955 + public const int UNION = 18;
3956 + /** type class of exception */
3957 + public const int EXCEPTION = 19;
3958 + /** type class of sequence */
3959 + public const int SEQUENCE = 20;
3960 + /** type class of array (not implemented) */
3961 + public const int ARRAY = 21;
3962 + /** type class of interface */
3963 + public const int INTERFACE = 22;
3964 + /** type class of service (not implemented) */
3965 + public const int SERVICE = 23;
3966 + /** type class of module (not implemented) */
3967 + public const int MODULE = 24;
3968 + /** type class of interface method */
3969 + public const int INTERFACE_METHOD = 25;
3970 + /** type class of interface attribute */
3971 + public const int INTERFACE_ATTRIBUTE = 26;
3972 + /** type class of unknown type */
3973 + public const int UNKNOWN = 27;
3974 + /** type class of properties */
3975 + public const int PROPERTY = 28;
3976 + /** type class of constants */
3977 + public const int CONSTANT = 29;
3978 + /** type class of constants groups */
3979 + public const int CONSTANTS = 30;
3980 + /** type class of singletons */
3981 + public const int SINGLETON = 31;
3985 --- cli_ure/source/mono_bridge/typedescription.cs.old 1970-01-01 00:00:00.000000000 +0000
3986 +++ cli_ure/source/mono_bridge/typedescription.cs 2009-04-06 16:41:58.000000000 +0000
3987 @@ -0,0 +1,645 @@
3988 +/*************************************************************************
3990 + * $RCSfile: $
3992 + * $Revision: $
3994 + * last change: $Author: $ $Date: $
3996 + * The Contents of this file are made available subject to the terms of
3997 + * either of the following licenses
3999 + * - GNU Lesser General Public License Version 2.1
4000 + * - Sun Industry Standards Source License Version 1.1
4002 + * Sun Microsystems Inc., October, 2000
4004 + * GNU Lesser General Public License Version 2.1
4005 + * =============================================
4006 + * Copyright 2000 by Sun Microsystems, Inc.
4007 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
4009 + * This library is free software; you can redistribute it and/or
4010 + * modify it under the terms of the GNU Lesser General Public
4011 + * License version 2.1, as published by the Free Software Foundation.
4013 + * This library is distributed in the hope that it will be useful,
4014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4016 + * Lesser General Public License for more details.
4018 + * You should have received a copy of the GNU Lesser General Public
4019 + * License along with this library; if not, write to the Free Software
4020 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
4021 + * MA 02111-1307 USA
4024 + * Sun Industry Standards Source License Version 1.1
4025 + * =================================================
4026 + * The contents of this file are subject to the Sun Industry Standards
4027 + * Source License Version 1.1 (the "License"); You may not use this file
4028 + * except in compliance with the License. You may obtain a copy of the
4029 + * License at http://www.openoffice.org/license.html.
4031 + * Software provided under this License is provided on an "AS IS" basis,
4032 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
4033 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
4034 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
4035 + * See the License for the specific provisions governing your rights and
4036 + * obligations concerning the Software.
4038 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
4040 + * Copyright: 2000 by Sun Microsystems, Inc.
4042 + * All Rights Reserved.
4044 + * Contributor(s): _______________________________________
4047 + ************************************************************************/
4049 +namespace uno.Typelib {
4051 +using System;
4052 +using System.Runtime.InteropServices;
4054 +/** Holds a weak reference to a type description.
4056 +[ StructLayout(LayoutKind.Sequential) ]
4057 +public unsafe struct TypeDescriptionReference
4059 + /** reference count of type; don't ever modify this by yourself, use
4060 + typedescriptionreference_acquire() and typedescriptionreference_release()
4061 + */
4062 + public int nRefCount;
4063 + /** number of static references of type, because of the fact that some types are needed
4064 + until program termination and are commonly held static.
4065 + */
4066 + public int nStaticRefCount;
4067 + /** type class of type
4068 + */
4069 + public int eTypeClass;
4070 + /** fully qualified name of type.
4071 + */
4072 + public uno.rtl.UString * pTypeName;
4073 + /** pointer to full typedescription; this value is only valid if the type is never swapped out
4074 + */
4075 + public TypeDescription * pType;
4076 + /** pointer to optimize the runtime; not for public use
4077 + */
4078 + public void * pUniqueIdentifier;
4079 + /** reserved for future use; 0 if not used
4080 + */
4081 + public void * pReserved;
4083 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescriptionreference_acquire") ]
4084 + public static extern void Acquire(/* TypeDescriptionReference */ void *td);
4086 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescriptionreference_release") ]
4087 + public static extern void Release(/* TypeDescriptionReference */ void *td);
4089 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescriptionreference_new") ]
4090 + public static extern void New(TypeDescriptionReference **ppTDR,
4091 + int /* enum typelib_TypeClass */ eTypeClass,
4092 + /* uno.rtl.UString */ void *pTypeName);
4094 + [ DllImport("uno_cppu", EntryPoint="typelib_static_type_getByTypeClass") ]
4095 + public static extern TypeDescriptionReference **GetByTypeClass(
4096 + int /* enum typelib_TypeClass */ eTypeClass);
4098 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescriptionreference_getDescription") ]
4099 + public static extern void GetDescription(
4100 + TypeDescription ** ppRet, /* TypeDescriptionReference */ void * pRef);
4103 +/** Full type description of a type. Memory layout of this struct is identical to the
4104 + TypeDescriptionReference for the first six members.
4105 + So a typedescription can be used as type reference.
4107 +[ StructLayout(LayoutKind.Sequential) ]
4108 +public unsafe struct TypeDescription
4110 + /** reference count; don't ever modify this by yourself, use
4111 + typedescription_acquire() and typedescription_release()
4112 + */
4113 + public int nRefCount;
4114 + /** number of static references of type, because of the fact that some types are needed
4115 + until program termination and are commonly held static.
4116 + */
4117 + public int nStaticRefCount;
4118 + /** type class of type
4119 + */
4120 + public int eTypeClass;
4121 + /** fully qualified name of type.
4122 + */
4123 + public uno.rtl.UString * pTypeName;
4124 + /** pointer to self to distinguish reference from description; for internal use only
4125 + */
4126 + public TypeDescription * pSelf;
4127 + /** pointer to optimize the runtime; not for public use
4128 + */
4129 + public void * pUniqueIdentifier;
4130 + /** reserved for future use; 0 if not used
4131 + */
4132 + public void * pReserved;
4134 + /** flag to determine whether the description is complete:
4135 + compound and union types lack of member names, enums lack of member types and names,
4136 + interfaces lack of members and table init.
4137 + Call typedescription_complete() if false.
4138 + */
4139 + public byte bComplete;
4140 + /** size of type
4141 + */
4142 + public int nSize;
4143 + /** alignment of type
4144 + */
4145 + public int nAlignment;
4146 + /** pointer to weak reference
4147 + */
4148 + public TypeDescriptionReference * pWeakRef;
4149 + /** determines, if type can be unloaded (and it is possible to reloaded it)
4150 + */
4151 + public byte bOnDemand;
4153 + /* FIXME move to TypeDescriptionReference */
4154 + public static TypeDescriptionReference *VoidType
4156 + get { return null; /* FIXME, use typelib_static_type_getByTypeClass(VOID) */ }
4159 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_getByName") ]
4160 + public static extern void GetByName(TypeDescription **pTD,
4161 + /* uno.rtl.UString */ void *name);
4163 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_acquire") ]
4164 + public static extern void Acquire(/* TypeDescription */ void *td);
4166 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_release") ]
4167 + public static extern void Release(/* TypeDescription */ void *td);
4169 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_complete") ]
4170 + public static extern bool Complete(TypeDescription **pTD);
4173 +/** Type description for exception types.
4175 +[ StructLayout(LayoutKind.Sequential) ]
4176 +public unsafe struct CompoundTypeDescription
4178 + /** inherits all members of TypeDescription
4179 + */
4180 + public TypeDescription aBase;
4182 + /** pointer to base type description, else 0
4183 + */
4184 + public CompoundTypeDescription * pBaseTypeDescription;
4186 + /** number of members
4187 + */
4188 + public int nMembers;
4189 + /** byte offsets of each member including the size the base type
4190 + */
4191 + public int * pMemberOffsets;
4192 + /** members of the struct or exception
4193 + */
4194 + public TypeDescriptionReference ** ppTypeRefs;
4195 + /** member names of the struct or exception.
4196 + */
4197 + public uno.rtl.UString ** ppMemberNames;
4200 +/**
4201 + Type description for struct types.
4203 + This is only used to represent plain struct types and instantiated
4204 + polymorphic struct types; there is no representation of polymorphic struct
4205 + type templates at this level.
4207 + @since UDK 3.2.0
4208 + */
4209 +[ StructLayout(LayoutKind.Sequential) ]
4210 +public unsafe struct StructTypeDescription
4212 + /**
4213 + Derived from CompoundTypeDescription.
4214 + */
4215 + public CompoundTypeDescription aBase;
4217 + /**
4218 + Flags for direct members, specifying whether they are of parameterized
4219 + type (true) or explict type (false).
4221 + For a plain struct type, this is a null pointer.
4222 + */
4223 + public byte * pParameterizedTypes;
4226 +/** Type description of a union. The type class of this description is TypeClass_UNION.
4228 +[ StructLayout(LayoutKind.Sequential) ]
4229 +public unsafe struct UnionTypeDescription
4231 + /** inherits all members of TypeDescription
4232 + */
4233 + public TypeDescription aBase;
4235 + /** type of the discriminant
4236 + */
4237 + public TypeDescriptionReference * pDiscriminantTypeRef;
4239 + /** union default descriminant
4240 + */
4241 + public long nDefaultDiscriminant;
4242 + /** union default member type (may be 0)
4243 + */
4244 + public TypeDescriptionReference * pDefaultTypeRef;
4245 + /** number of union member types
4246 + */
4247 + public int nMembers;
4248 + /** union member discriminant values (same order as idl declaration)
4249 + */
4250 + public long * pDiscriminants;
4251 + /** union member value types (same order as idl declaration)
4252 + */
4253 + public TypeDescriptionReference ** ppTypeRefs;
4254 + /** union member value names (same order as idl declaration)
4255 + */
4256 + public uno.rtl.UString ** ppMemberNames;
4257 + /** union value offset for data access
4258 + */
4259 + public int nValueOffset;
4262 +/** Type description of an array or sequence.
4264 +[ StructLayout(LayoutKind.Sequential) ]
4265 +public unsafe struct IndirectTypeDescription
4267 + /** inherits all members of TypeDescription
4268 + */
4269 + public TypeDescription aBase;
4271 + /** array, sequence: pointer to element type
4272 + */
4273 + public TypeDescriptionReference * pType;
4276 +/** Type description of an array.
4278 +[ StructLayout(LayoutKind.Sequential) ]
4279 +public unsafe struct ArrayTypeDescription
4281 + /** inherits all members of IndirectTypeDescription
4282 + */
4283 + public IndirectTypeDescription aBase;
4285 + /** number of dimensions
4286 + */
4287 + public int nDimensions;
4288 + /** number of total array elements
4289 + */
4290 + public int nTotalElements;
4291 + /** array of dimensions
4292 + */
4293 + public int * pDimensions;
4296 +/** Type description of an enum. The type class of this description is TypeClass_ENUM.
4298 +[ StructLayout(LayoutKind.Sequential) ]
4299 +public unsafe struct EnumTypeDescription
4301 + /** inherits all members of TypeDescription
4302 + */
4303 + public TypeDescription aBase;
4305 + /** first value of the enum
4306 + */
4307 + public int nDefaultEnumValue;
4308 + /** number of enum values
4309 + */
4310 + public int nEnumValues;
4311 + /** names of enum values
4312 + */
4313 + public uno.rtl.UString ** ppEnumNames;
4314 + /** values of enum (corresponding to names in similar order)
4315 + */
4316 + public int * pEnumValues;
4319 +/** Description of an interface method parameter.
4321 +[ StructLayout(LayoutKind.Sequential) ]
4322 +public unsafe struct MethodParameter
4324 + /** name of parameter
4325 + */
4326 + public uno.rtl.UString * pName;
4327 + /** type of parameter
4328 + */
4329 + public TypeDescriptionReference * pTypeRef;
4330 + /** true: the call type of this parameter is [in] or [inout]
4331 + false: the call type of this parameter is [out]
4332 + */
4333 + public byte bIn;
4334 + /** true: the call type of this parameter is [out] or [inout]
4335 + false: the call type of this parameter is [in]
4336 + */
4337 + public byte bOut;
4340 +/** Common base type description of InterfaceMethodTypeDescription and
4341 + InterfaceAttributeTypeDescription.
4343 +[ StructLayout(LayoutKind.Sequential) ]
4344 +public unsafe struct InterfaceMemberTypeDescription
4346 + /** inherits all members of TypeDescription
4347 + */
4348 + public TypeDescription aBase;
4350 + /** position of member in the interface including the number of members of
4351 + any base interfaces
4352 + */
4353 + public int nPosition;
4354 + /** name of member
4355 + */
4356 + public uno.rtl.UString * pMemberName;
4359 +/** Type description of an interface method. The type class of this description is
4360 + TypeClass_INTERFACE_METHOD. The size and the alignment are 0.
4362 +[ StructLayout(LayoutKind.Sequential) ]
4363 +public unsafe struct InterfaceMethodTypeDescription
4365 + /** inherits all members of InterfaceMemberTypeDescription
4366 + */
4367 + public InterfaceMemberTypeDescription aBase;
4369 + /** type of the return value
4370 + */
4371 + public TypeDescriptionReference * pReturnTypeRef;
4372 + /** number of parameters
4373 + */
4374 + public int nParams;
4375 + /** array of parameters
4376 + */
4377 + public MethodParameter * pParams;
4378 + /** number of exceptions
4379 + */
4380 + public int nExceptions;
4381 + /** array of exception types
4382 + */
4383 + public TypeDescriptionReference ** ppExceptions;
4384 + /** determines whether method is declared oneway
4385 + */
4386 + public byte bOneWay;
4388 + /** the interface description this method is a member of
4390 + @since #i21150#
4391 + */
4392 + public InterfaceTypeDescription * pInterface;
4393 + /** the inherited direct base method (null for a method that is not
4394 + inherited)
4396 + @since UDK 3.2.0
4397 + */
4398 + public TypeDescriptionReference * pBaseRef;
4399 + /** if pBaseRef is null, the member position of this method within
4400 + pInterface, not counting members inherited from bases; if pBaseRef is
4401 + not null, the index of the direct base within pInterface from which this
4402 + method is inherited
4404 + @since UDK 3.2.0
4405 + */
4406 + public int nIndex;
4409 +/** The description of an interface attribute. The type class of this description is
4410 + TypeClass_INTERFACE_ATTRIBUTE. The size and the alignment are 0.
4412 +[ StructLayout(LayoutKind.Sequential) ]
4413 +public unsafe struct InterfaceAttributeTypeDescription
4415 + /** inherits all members of InterfaceMemberTypeDescription
4416 + */
4417 + public InterfaceMemberTypeDescription aBase;
4419 + /** determines whether attribute is read only
4420 + */
4421 + public byte bReadOnly;
4422 + /** type of the attribute
4423 + */
4424 + public TypeDescriptionReference * pAttributeTypeRef;
4426 + /** the interface description this attribute is a member of
4428 + @since #i21150#
4429 + */
4430 + public InterfaceTypeDescription * pInterface;
4431 + /** the inherited direct base attribute (null for an attribute that is not
4432 + inherited)
4434 + @since UDK 3.2.0
4435 + */
4436 + public TypeDescriptionReference * pBaseRef;
4437 + /** if pBaseRef is null, the member position of this attribute within
4438 + pInterface, not counting members inherited from bases; if pBaseRef is
4439 + not null, the index of the direct base within pInterface from which this
4440 + attribute is inherited
4442 + @since UDK 3.2.0
4443 + */
4444 + public int nIndex;
4445 + /** number of getter exceptions
4447 + @since UDK 3.2.0
4448 + */
4449 + public int nGetExceptions;
4450 + /** array of getter exception types
4452 + @since UDK 3.2.0
4453 + */
4454 + public TypeDescriptionReference ** ppGetExceptions;
4455 + /** number of setter exceptions
4457 + @since UDK 3.2.0
4458 + */
4459 + public int nSetExceptions;
4460 + /** array of setter exception types
4462 + @since UDK 3.2.0
4463 + */
4464 + public TypeDescriptionReference ** ppSetExceptions;
4467 +/// @HTML
4468 +/** Type description of an interface.
4470 + <p>Not all members are always initialized (not yet initialized members being
4471 + null); there are three levels:</p>
4472 + <ul>
4473 + <li>Minimally, only <code>aBase</code>,
4474 + <code>pBaseTypeDescription</code>, <code>aUik</code>,
4475 + <code>nBaseTypes</code>, and <code>ppBaseTypes</code> are initialized;
4476 + <code>aBase.bComplete</code> is false. This only happens when an
4477 + interface type description is created with
4478 + <code>static_mi_interface_type_init</code> or
4479 + <code>static_interface_type_init</code>.</li>
4481 + <li>At the next level, <code>nMembers</code>, <code>ppMembers</code>,
4482 + <code>nAllMembers</code>, <code>ppAllMembers</code> are also
4483 + initialized; <code>aBase.bComplete</code> is still false. This happens
4484 + when an interface type description is created with
4485 + <code>typedescription_newMIInterface</cocde> or
4486 + <code>typedescription_newInterface</code>.</li>
4488 + <li>At the final level, <code>pMapMemberIndexToFunctionIndex</code>,
4489 + <code>nMapFunctionIndexToMemberIndex</code>, and
4490 + <code>pMapFunctionIndexToMemberIndex</code> are also initialized;
4491 + <code>aBase.bComplete</code> is true. This happens after a call to
4492 + <code>typedescription_complete</code>.</li>
4493 + </ul>
4495 +[ StructLayout(LayoutKind.Sequential) ]
4496 +public unsafe struct InterfaceTypeDescription
4497 +/// @NOHTML
4499 + /** inherits all members of TypeDescription
4500 + */
4501 + public TypeDescription aBase;
4503 + /** pointer to base type description, else 0
4505 + @deprecated
4506 + use nBaseTypes and ppBaseTypes instead
4507 + */
4508 + public InterfaceTypeDescription * pBaseTypeDescription;
4509 + /** unique identifier of interface
4510 + */
4511 + public Uik aUik;
4512 + /** number of members
4513 + */
4514 + public int nMembers;
4515 + /** array of members; references attributes or methods
4516 + */
4517 + public TypeDescriptionReference ** ppMembers;
4518 + /** number of members including members of base interface
4519 + */
4520 + public int nAllMembers;
4521 + /** array of members including members of base interface; references attributes or methods
4522 + */
4523 + public TypeDescriptionReference ** ppAllMembers;
4524 + /** array mapping index of the member description to an index doubling for read-write
4525 + attributes (called function index); size of array is nAllMembers
4526 + */
4527 + public int * pMapMemberIndexToFunctionIndex;
4528 + /** number of members plus number of read-write attributes
4529 + */
4530 + public int nMapFunctionIndexToMemberIndex;
4531 + /** array mapping function index to member index; size of arry is nMapFunctionIndexToMemberIndex
4532 + */
4533 + public int * pMapFunctionIndexToMemberIndex;
4534 + /** number of base types
4536 + @since UDK 3.2.0
4537 + */
4538 + public int nBaseTypes;
4539 + /** array of base type descriptions
4541 + @since UDK 3.2.0
4542 + */
4543 + public InterfaceTypeDescription ** ppBaseTypes;
4545 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_release") ]
4546 + public static extern void Release(/* InterfaceTypeDescription */ void *td);
4548 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_acquire") ]
4549 + public static extern void Acquire(/* InterfaceTypeDescription */ void *td);
4551 + [ DllImport("uno_cppu", EntryPoint="typelib_typedescription_equals") ]
4552 + public static extern bool Equal(/* InterfaceTypeDescription */ void *td1, /* InterfaceTypeDescription */ void *td2);
4555 +/** Init struct of compound members for typedescription_new().
4557 +[ StructLayout(LayoutKind.Sequential) ]
4558 +public unsafe struct CompoundMember_Init
4560 + /** type class of compound member
4561 + */
4562 + public int eTypeClass;
4563 + /** name of type of compound member
4565 + For a member of an instantiated polymorphic struct type that is of
4566 + parameterized type, this will be a null pointer.
4567 + */
4568 + public uno.rtl.UString * pTypeName;
4569 + /** name of compound member
4570 + */
4571 + public uno.rtl.UString * pMemberName;
4574 +/**
4575 + Init struct of members for typedescription_newStruct().
4577 + @since UDK 3.2.0
4578 + */
4579 +[ StructLayout(LayoutKind.Sequential) ]
4580 +public struct StructMember_Init
4582 + /**
4583 + Derived from CompoundMember_Init;
4584 + */
4585 + public CompoundMember_Init aBase;
4587 + /**
4588 + Flag specifying whether the member is of parameterized type (true) or
4589 + explict type (false).
4590 + */
4591 + public byte bParameterizedType;
4594 +/** Init struct of interface methods for typedescription_new().
4596 +[ StructLayout(LayoutKind.Sequential) ]
4597 +public unsafe struct Parameter_Init
4599 + /** type class of parameter
4600 + */
4601 + public int eTypeClass;
4602 + /** name of parameter
4603 + */
4604 + public uno.rtl.UString * pTypeName;
4605 + /** name of parameter
4606 + */
4607 + public uno.rtl.UString * pParamName;
4608 + /** true, if parameter is [in] or [inout]
4609 + */
4610 + public byte bIn;
4611 + /** true, if parameter is [out] or [inout]
4612 + */
4613 + public byte bOut;
4616 +/** Init struct of union types for typedescription_newUnion().
4618 +[ StructLayout(LayoutKind.Sequential) ]
4619 +public unsafe struct Union_Init
4621 + /** union member discriminant
4622 + */
4623 + public long nDiscriminant;
4624 + /** union member name
4625 + */
4626 + public uno.rtl.UString * pMemberName;
4627 + /** union member type
4628 + */
4629 + public TypeDescriptionReference * pTypeRef;
4633 --- cli_ure/source/mono_bridge/uik.cs.old 1970-01-01 00:00:00.000000000 +0000
4634 +++ cli_ure/source/mono_bridge/uik.cs 2009-04-06 16:41:58.000000000 +0000
4635 @@ -0,0 +1,78 @@
4636 +/*************************************************************************
4638 + * $RCSfile: $
4640 + * $Revision: $
4642 + * last change: $Author: $ $Date: $
4644 + * The Contents of this file are made available subject to the terms of
4645 + * either of the following licenses
4647 + * - GNU Lesser General Public License Version 2.1
4648 + * - Sun Industry Standards Source License Version 1.1
4650 + * Sun Microsystems Inc., October, 2000
4652 + * GNU Lesser General Public License Version 2.1
4653 + * =============================================
4654 + * Copyright 2000 by Sun Microsystems, Inc.
4655 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
4657 + * This library is free software; you can redistribute it and/or
4658 + * modify it under the terms of the GNU Lesser General Public
4659 + * License version 2.1, as published by the Free Software Foundation.
4661 + * This library is distributed in the hope that it will be useful,
4662 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4663 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4664 + * Lesser General Public License for more details.
4666 + * You should have received a copy of the GNU Lesser General Public
4667 + * License along with this library; if not, write to the Free Software
4668 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
4669 + * MA 02111-1307 USA
4672 + * Sun Industry Standards Source License Version 1.1
4673 + * =================================================
4674 + * The contents of this file are subject to the Sun Industry Standards
4675 + * Source License Version 1.1 (the "License"); You may not use this file
4676 + * except in compliance with the License. You may obtain a copy of the
4677 + * License at http://www.openoffice.org/license.html.
4679 + * Software provided under this License is provided on an "AS IS" basis,
4680 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
4681 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
4682 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
4683 + * See the License for the specific provisions governing your rights and
4684 + * obligations concerning the Software.
4686 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
4688 + * Copyright: 2000 by Sun Microsystems, Inc.
4690 + * All Rights Reserved.
4692 + * Contributor(s): _______________________________________
4695 + ************************************************************************/
4697 +namespace uno.Typelib {
4699 +using System.Runtime.InteropServices;
4701 +/** Binary typelib uik struct. Internally not used anymore.
4703 +[ StructLayout(LayoutKind.Sequential) ]
4704 +public struct Uik
4706 + int m_Data1;
4707 + short m_Data2;
4708 + short m_Data3;
4709 + int m_Data4;
4710 + int m_Data5;
4714 --- cli_ure/source/mono_bridge/uno_glue.cxx.old 1970-01-01 00:00:00.000000000 +0000
4715 +++ cli_ure/source/mono_bridge/uno_glue.cxx 2009-04-06 16:41:58.000000000 +0000
4716 @@ -0,0 +1,117 @@
4717 +/*************************************************************************
4719 + * $RCSfile: $
4721 + * $Revision: $
4723 + * last change: $Author: $ $Date: $
4725 + * The Contents of this file are made available subject to the terms of
4726 + * either of the following licenses
4728 + * - GNU Lesser General Public License Version 2.1
4729 + * - Sun Industry Standards Source License Version 1.1
4731 + * Sun Microsystems Inc., October, 2000
4733 + * GNU Lesser General Public License Version 2.1
4734 + * =============================================
4735 + * Copyright 2000 by Sun Microsystems, Inc.
4736 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
4738 + * This library is free software; you can redistribute it and/or
4739 + * modify it under the terms of the GNU Lesser General Public
4740 + * License version 2.1, as published by the Free Software Foundation.
4742 + * This library is distributed in the hope that it will be useful,
4743 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4744 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4745 + * Lesser General Public License for more details.
4747 + * You should have received a copy of the GNU Lesser General Public
4748 + * License along with this library; if not, write to the Free Software
4749 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
4750 + * MA 02111-1307 USA
4753 + * Sun Industry Standards Source License Version 1.1
4754 + * =================================================
4755 + * The contents of this file are subject to the Sun Industry Standards
4756 + * Source License Version 1.1 (the "License"); You may not use this file
4757 + * except in compliance with the License. You may obtain a copy of the
4758 + * License at http://www.openoffice.org/license.html.
4760 + * Software provided under this License is provided on an "AS IS" basis,
4761 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
4762 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
4763 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
4764 + * See the License for the specific provisions governing your rights and
4765 + * obligations concerning the Software.
4767 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
4769 + * Copyright: 2000 by Sun Microsystems, Inc.
4771 + * All Rights Reserved.
4773 + * Contributor(s): _______________________________________
4776 + ************************************************************************/
4778 +#include "rtl/ustring.h"
4779 +#include "uno/dispatcher.h"
4780 +#include "uno/environment.h"
4781 +#include <stdio.h>
4783 +extern "C" {
4785 +/* uno_Interface */
4787 +void SAL_CALL cli_uno_interface_acquire( uno_Interface *pInterface )
4788 + SAL_THROW_EXTERN_C()
4790 + (*pInterface->acquire)( pInterface );
4793 +void SAL_CALL cli_uno_interface_release( uno_Interface *pInterface )
4794 + SAL_THROW_EXTERN_C()
4796 + (*pInterface->release)( pInterface );
4799 +void SAL_CALL cli_uno_interface_dispatch(
4800 + uno_Interface *pInterface, const struct _typelib_TypeDescription *pMemberType,
4801 + void *pReturn, void *pArgs[], uno_Any **ppException )
4802 + SAL_THROW_EXTERN_C()
4804 + (*pInterface->pDispatcher)( pInterface, pMemberType, pReturn, pArgs, ppException );
4807 +/* uno_ExtEnvironment */
4809 +void SAL_CALL cli_uno_environment_getObjectIdentifier(
4810 + uno_ExtEnvironment *pUnoEnv, rtl_uString **ppOId, uno_Interface *pUnoI )
4811 + SAL_THROW_EXTERN_C()
4813 + (*pUnoEnv->getObjectIdentifier)( pUnoEnv, ppOId, pUnoI );
4816 +void SAL_CALL cli_uno_environment_registerInterface(
4817 + uno_ExtEnvironment *pUnoEnv, void **ppInterface, rtl_uString *pOId,
4818 + struct _typelib_InterfaceTypeDescription *pTypeDescr )
4819 + SAL_THROW_EXTERN_C()
4821 + (*pUnoEnv->registerInterface)( pUnoEnv, ppInterface, pOId, pTypeDescr );
4824 +void SAL_CALL cli_uno_environment_getRegisteredInterface(
4825 + uno_ExtEnvironment *pUnoEnv, void **ppInterface, rtl_uString *pOId,
4826 + struct _typelib_InterfaceTypeDescription *pTypeDescr )
4827 + SAL_THROW_EXTERN_C()
4829 + (*pUnoEnv->getRegisteredInterface)( pUnoEnv, ppInterface, pOId, pTypeDescr );
4834 --- cli_ure/source/mono_bridge/uno_proxy.cs.old 1970-01-01 00:00:00.000000000 +0000
4835 +++ cli_ure/source/mono_bridge/uno_proxy.cs 2009-04-06 16:41:58.000000000 +0000
4836 @@ -0,0 +1,598 @@
4837 +/*************************************************************************
4839 + * $RCSfile: $
4841 + * $Revision: $
4843 + * last change: $Author: $ $Date: $
4845 + * The Contents of this file are made available subject to the terms of
4846 + * either of the following licenses
4848 + * - GNU Lesser General Public License Version 2.1
4849 + * - Sun Industry Standards Source License Version 1.1
4851 + * Sun Microsystems Inc., October, 2000
4853 + * GNU Lesser General Public License Version 2.1
4854 + * =============================================
4855 + * Copyright 2000 by Sun Microsystems, Inc.
4856 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
4858 + * This library is free software; you can redistribute it and/or
4859 + * modify it under the terms of the GNU Lesser General Public
4860 + * License version 2.1, as published by the Free Software Foundation.
4862 + * This library is distributed in the hope that it will be useful,
4863 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4864 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4865 + * Lesser General Public License for more details.
4867 + * You should have received a copy of the GNU Lesser General Public
4868 + * License along with this library; if not, write to the Free Software
4869 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
4870 + * MA 02111-1307 USA
4873 + * Sun Industry Standards Source License Version 1.1
4874 + * =================================================
4875 + * The contents of this file are subject to the Sun Industry Standards
4876 + * Source License Version 1.1 (the "License"); You may not use this file
4877 + * except in compliance with the License. You may obtain a copy of the
4878 + * License at http://www.openoffice.org/license.html.
4880 + * Software provided under this License is provided on an "AS IS" basis,
4881 + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
4882 + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
4883 + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
4884 + * See the License for the specific provisions governing your rights and
4885 + * obligations concerning the Software.
4887 + * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
4889 + * Copyright: 2000 by Sun Microsystems, Inc.
4891 + * All Rights Reserved.
4893 + * Contributor(s): _______________________________________
4896 + ************************************************************************/
4898 +using System;
4899 +using System.Collections;
4900 +using System.Diagnostics;
4901 +using System.Reflection;
4902 +using System.Runtime.InteropServices;
4903 +using System.Runtime.Remoting;
4904 +using System.Runtime.Remoting.Messaging;
4905 +using System.Runtime.Remoting.Proxies;
4907 +using uno.Binary;
4908 +using uno.Typelib;
4909 +using uno.rtl;
4911 +namespace com.sun.star.bridges.mono_uno /* FIXME use some uno.foo namespace ? */
4914 +public unsafe class UnoInterfaceInfo
4916 + public IntPtr UnoInterface; // wrapped interface
4917 + public Type Type; // mapped type
4918 + public com.sun.star.bridges.mono_uno.Bridge Bridge;
4919 + public InterfaceTypeDescription *TypeDesc;
4921 + public UnoInterfaceInfo(com.sun.star.bridges.mono_uno.Bridge bridge,
4922 + IntPtr unoInterface,
4923 + InterfaceTypeDescription *td)
4925 + Bridge = bridge;
4926 + UnoInterface = unoInterface;
4927 + Type = Bridge.MapUnoType((TypeDescription *)td);
4928 + uno.Binary.Interface.Acquire(UnoInterface);
4929 + TypeDesc = td;
4930 + InterfaceTypeDescription.Acquire(TypeDesc);
4932 + fixed (InterfaceTypeDescription **ppTypeDesc = &TypeDesc)
4933 + if (((TypeDescription *)TypeDesc)->bComplete == 0 &&
4934 + TypeDescription.Complete((TypeDescription **)ppTypeDesc))
4936 + // FIXME throw a uno runtime exception
4940 + ~UnoInterfaceInfo()
4942 + Bridge.RevokeFromUnoEnvironment(UnoInterface);
4943 + uno.Binary.Interface.Release(UnoInterface);
4944 + InterfaceTypeDescription.Release(TypeDesc);
4948 +public unsafe class UnoInterfaceProxy: RealProxy, IRemotingTypeInfo
4950 + /** used for IRemotingTypeInfo.TypeName
4951 + */
4952 + string typeName = "System.Object";
4954 + /** The list is filled with UnoInterfaceInfo objects. The list can only
4955 + grow and elements are never changed. If an element was added it
4956 + must not be changed!
4957 + */
4958 + ArrayList interfaces = new ArrayList(10); // of UnoInterfaceInfo
4960 + /** The list is filled with additional UnoInterfaceProxy object due
4961 + to aggregation via bridges. Though the latter is strongly
4962 + discouraged, this has to be supported.
4963 + */
4964 + ArrayList additionalProxies = new ArrayList();
4966 + Bridge bridge;
4967 + string oid;
4969 + private unsafe UnoInterfaceProxy(Bridge bridge, IntPtr unoInterface,
4970 + InterfaceTypeDescription *TD, string oid)
4971 + : base(typeof(MarshalByRefObject)) // FIXME is there a better type?
4973 + this.bridge = bridge;
4974 + this.oid = oid;
4975 + AddUnoInterface(unoInterface, TD);
4978 + ~UnoInterfaceProxy()
4980 + // FIXME should revokeInterface from environment, but can't
4981 + // access managed string oid any longer.
4984 + public static unsafe object Create(Bridge bridge, IntPtr unoInterface,
4985 + InterfaceTypeDescription *TD, string oid)
4987 + UnoInterfaceProxy realProxy = new UnoInterfaceProxy(bridge, unoInterface,
4988 + TD, oid);
4989 + object proxy = realProxy.GetTransparentProxy();
4990 + bridge.RegisterWithCliEnvironment(proxy, oid);
4991 + return proxy;
4994 + // RealProxy members
4995 + public unsafe override IMessage Invoke(IMessage request)
4997 + IMethodCallMessage callmsg = (IMethodCallMessage)request;
4999 + // Find out which UNO interface is being called
5000 + string typeName = callmsg.TypeName;
5001 + typeName = typeName.Substring(0, typeName.IndexOf(','));
5003 + // Special Handling for System.Object methods
5004 + if (typeName.IndexOf("System.Object") != -1)
5006 + return InvokeObjectMethod(request);
5009 + Type typeBeingCalled = Bridge.LoadCliType(typeName);
5010 + UnoInterfaceInfo info = FindInfo(typeBeingCalled);
5012 + Trace.Assert(info != null);
5014 + string methodName = callmsg.MethodName;
5015 + TypeDescriptionReference **ppAllMembers =
5016 + info.TypeDesc->ppAllMembers;
5017 + int numMembers = info.TypeDesc->nAllMembers;
5018 + for (int i = numMembers - 1; i >= 0; --i)
5020 + TypeDescriptionReference *memberTD = *(ppAllMembers + i);
5022 + // FIXME do without string conversion?
5023 + string memberTypeName = UString.UStringToString(memberTD->pTypeName);
5024 + // check methodName against fully qualified memberTypeName
5025 + // of memberTD; memberTypeName is of the form
5026 + // <name> "::" <methodName> *(":@" <idx> "," <idx> ":" <name>)
5028 + int offset = memberTypeName.IndexOf(':') + 2;
5029 + int remainder = memberTypeName.Length - offset;
5030 + if (memberTD->eTypeClass == TypeClass.INTERFACE_METHOD)
5032 + if ((methodName.Length == remainder ||
5033 + (methodName.Length < remainder &&
5034 + memberTypeName[offset + methodName.Length] == ':')) &&
5035 + String.Compare(memberTypeName, offset,
5036 + methodName, 0, methodName.Length) == 0)
5038 + TypeDescription *methodTD = null;
5039 + // FIXME release it
5040 + TypeDescriptionReference.GetDescription(&methodTD, memberTD);
5042 + uno.Any exception;
5043 + uno.Any result =
5044 + bridge.CallUno(info.UnoInterface,
5045 + methodTD,
5046 + ((InterfaceMethodTypeDescription *)methodTD)->pReturnTypeRef,
5047 + ((InterfaceMethodTypeDescription *)methodTD)->nParams,
5048 + ((InterfaceMethodTypeDescription *)methodTD)->pParams,
5049 + callmsg.Args,
5050 + /* FIXME this is an implementation detail,
5051 + documented on MSDN, but still an implementation
5052 + detail. cli_uno does the same */
5053 + (System.Type[])callmsg.MethodSignature,
5054 + out exception);
5055 + return ConstructReturnMessage(result, callmsg.Args,
5056 + (InterfaceMethodTypeDescription *)methodTD,
5057 + callmsg, exception);
5060 + else // INTERFACE_ATTRIBUTE
5062 + if (methodName.Length > 4 &&
5063 + (methodName.Length - 4 == remainder ||
5064 + (methodName.Length - 4 < remainder &&
5065 + memberTypeName[offset + methodName.Length - 4] == ':')) &&
5066 + methodName[1] == 'e' && methodName[2] == 't' &&
5067 + String.Compare(memberTypeName, offset,
5068 + methodName, 4, methodName.Length - 4) == 0)
5070 + InterfaceAttributeTypeDescription *attributeTD = null;
5071 + // FIXME release it
5072 + TypeDescriptionReference.GetDescription( (TypeDescription **)&attributeTD,
5073 + memberTD );
5074 + uno.Any exception;
5075 + uno.Any result;
5077 + if (methodName[0] == 'g') // "get"
5079 + result = bridge.CallUno(info.UnoInterface,
5080 + (TypeDescription *)attributeTD,
5081 + attributeTD->pAttributeTypeRef,
5082 + 0, null, null, null,
5083 + out exception);
5084 + return ConstructReturnMessage(result, null, null,
5085 + callmsg, exception);
5087 + else if (methodName[0] == 's') // "set"
5089 + if (attributeTD->bReadOnly != 0)
5090 + /* FIXME should we generate an exception? */
5091 + return ConstructReturnMessage(uno.Any.VOID, null, null,
5092 + callmsg, uno.Any.VOID);
5094 + MethodParameter param;
5095 + param.pTypeRef = attributeTD->pAttributeTypeRef;
5096 + param.bIn = 1;
5097 + param.bOut = 0;
5099 + result =
5100 + bridge.CallUno(info.UnoInterface,
5101 + (TypeDescription *)attributeTD,
5102 + TypeDescription.VoidType,
5103 + 1, &param,
5104 + callmsg.Args, null, /* FIXME ??? from cli_uno */
5105 + out exception);
5106 + return ConstructReturnMessage(uno.Any.VOID, null, null,
5107 + callmsg, exception);
5109 + break;
5110 + }
5113 + // FIXME check if the message of the exception is not crippled
5115 + // the thing that should not be... no method info found!
5116 + // FIXME throw unoidl.com.sun.star.uno.RuntimeException
5118 + return null;
5121 + // IRemotingTypeInfo members
5122 + public string TypeName
5124 + get { return typeName; }
5125 + set { typeName = value; }
5128 + public unsafe bool CanCastTo(Type fromType, object o)
5130 + if (fromType == typeof(Object))
5131 + return true;
5133 + lock (this) {
5134 + if (FindInfo(fromType) != null)
5135 + // type is already in our list of Interfaces
5136 + return true;
5138 + // queryInterface for the required type
5139 + // there is always a least one interface in our list
5140 + UnoInterfaceInfo info = (UnoInterfaceInfo)interfaces[0];
5141 + // ppAllMembers[0] corresponds to queryInterface
5142 + TypeDescription *queryI = null;
5144 + TypeDescriptionReference.GetDescription( // FIXME release it when you're done
5145 + &queryI, *(info.TypeDesc->ppAllMembers));
5147 + object[] args = new object[] { fromType };
5148 + uno.Any exception;
5150 + uno.Any result = bridge.CallUno(info.UnoInterface,
5151 + queryI,
5152 + ((InterfaceMethodTypeDescription *)queryI)->pReturnTypeRef,
5153 + 1, ((InterfaceMethodTypeDescription *)queryI)->pParams, args, null,
5154 + out exception);
5156 + // queryInterface doesn't throw exceptions.
5158 + if (result.Type != typeof(void)) // result has a value
5160 + if (FindInfo(fromType) != null)
5162 + // the proxy supports the requested interface now
5163 + return true;
5166 + // via aggregation: it is possible that queryInterface() returns
5167 + // and interface with a different oid.
5168 + // That way, this type is supported for the CLI
5169 + // interpreter (CanCastTo() returns true)
5170 + object obj = result.Value;
5171 + if (RemotingServices.IsTransparentProxy(obj))
5173 + UnoInterfaceProxy proxy =
5174 + (UnoInterfaceProxy)RemotingServices.GetRealProxy(obj);
5175 + additionalProxies.Add(proxy);
5176 + return true;
5180 + return false;
5183 + // internals
5184 + public unsafe void AddUnoInterface(IntPtr unoInterface, InterfaceTypeDescription *TD)
5186 + lock (this)
5188 + foreach (UnoInterfaceInfo info in interfaces)
5190 + if (InterfaceTypeDescription.Equal(info.TypeDesc, TD))
5191 + return;
5193 + // This proxy does not contain the unoInterface. Add it.
5194 + bridge.RegisterWithUnoEnvironment(ref unoInterface,
5195 + oid, TD);
5196 + interfaces.Add(new UnoInterfaceInfo(bridge, unoInterface, TD));
5200 + UnoInterfaceInfo FindInfo(Type type)
5202 + foreach (UnoInterfaceInfo info in interfaces)
5204 + if (type.IsAssignableFrom(info.Type))
5205 + return info;
5207 + foreach (UnoInterfaceProxy proxy in additionalProxies)
5209 + UnoInterfaceInfo info = proxy.FindInfo(type);
5210 + if (info != null)
5211 + return info;
5213 + return null;
5216 + static Type MapUnoType(TypeDescription *TD)
5218 + return MapUnoType(TD->pWeakRef);
5221 + static Type MapUnoType(TypeDescriptionReference *TD)
5223 + Type result;
5225 + switch(TD->eTypeClass)
5227 + case TypeClass.VOID:
5228 + result = typeof(void);
5229 + break;
5230 + case TypeClass.CHAR:
5231 + result = typeof(char);
5232 + break;
5233 + case TypeClass.BOOLEAN:
5234 + result = typeof(bool);
5235 + break;
5236 + case TypeClass.BYTE:
5237 + result = typeof(byte);
5238 + break;
5239 + case TypeClass.SHORT:
5240 + result = typeof(short);
5241 + break;
5242 + case TypeClass.UNSIGNED_SHORT:
5243 + result = typeof(ushort);
5244 + break;
5245 + case TypeClass.LONG:
5246 + result = typeof(int);
5247 + break;
5248 + case TypeClass.UNSIGNED_LONG:
5249 + result = typeof(uint);
5250 + break;
5251 + case TypeClass.HYPER:
5252 + result = typeof(long);
5253 + break;
5254 + case TypeClass.UNSIGNED_HYPER:
5255 + result = typeof(ulong);
5256 + break;
5257 + case TypeClass.FLOAT:
5258 + result = typeof(float);
5259 + break;
5260 + case TypeClass.DOUBLE:
5261 + result = typeof(double);
5262 + break;
5263 + case TypeClass.STRING:
5264 + result = typeof(string);
5265 + break;
5266 + case TypeClass.TYPE:
5267 + result = typeof(Type);
5268 + break;
5269 + case TypeClass.ANY:
5270 + result = typeof(uno.Any);
5271 + break;
5272 + case TypeClass.ENUM:
5273 + case TypeClass.STRUCT:
5274 + case TypeClass.EXCEPTION:
5275 + result = Bridge.LoadCliType(TD->pTypeName);
5276 + break;
5277 + case TypeClass.INTERFACE:
5278 + // special handling for XInterface, since it does not exist in cli.
5279 + if (UString.UStringToString(TD->pTypeName) == "com.sun.star.uno.XInterface")
5280 + result = typeof(object);
5281 + else
5282 + result = Bridge.LoadCliType(TD->pTypeName);
5283 + break;
5284 + case TypeClass.SEQUENCE:
5286 + // FIXME do something with TD here?
5287 + TypeDescriptionReference *elementTDRef =
5288 + ((IndirectTypeDescription *)TD)->pType;
5289 + switch (elementTDRef->eTypeClass)
5291 + case TypeClass.CHAR:
5292 + result = Type.GetType("System.Char[]");
5293 + break;
5294 + case TypeClass.BOOLEAN:
5295 + result = Type.GetType("System.Boolean[]");
5296 + break;
5297 + case TypeClass.BYTE:
5298 + result = Type.GetType("System.Byte[]");
5299 + break;
5300 + case TypeClass.SHORT:
5301 + result = Type.GetType("System.Int16[]");
5302 + break;
5303 + case TypeClass.UNSIGNED_SHORT:
5304 + result = Type.GetType("System.UInt16[]");
5305 + break;
5306 + case TypeClass.LONG:
5307 + result = Type.GetType("System.Int32[]");
5308 + break;
5309 + case TypeClass.UNSIGNED_LONG:
5310 + result = Type.GetType("System.UInt32[]");
5311 + break;
5312 + case TypeClass.HYPER:
5313 + result = Type.GetType("System.Int64[]");
5314 + break;
5315 + case TypeClass.UNSIGNED_HYPER:
5316 + result = Type.GetType("System.UInt64[]");
5317 + break;
5318 + case TypeClass.FLOAT:
5319 + result = Type.GetType("System.Single[]");
5320 + break;
5321 + case TypeClass.DOUBLE:
5322 + result = Type.GetType("System.Double[]");
5323 + break;
5324 + case TypeClass.STRING:
5325 + result = Type.GetType("System.String[]");
5326 + break;
5327 + case TypeClass.TYPE:
5328 + result = Type.GetType("System.Type[]");
5329 + break;
5330 + case TypeClass.ANY:
5331 + case TypeClass.ENUM:
5332 + case TypeClass.EXCEPTION:
5333 + case TypeClass.STRUCT:
5334 + case TypeClass.INTERFACE:
5335 + case TypeClass.SEQUENCE:
5336 + result = Bridge.LoadCliType(TD->pTypeName);
5337 + break;
5338 + default:
5339 + // FIXME can't happen
5340 + result = null;
5341 + break;
5343 + break;
5345 + default:
5346 + // FIXME can't happen
5347 + result = null;
5348 + break;
5350 + return result;
5353 + IMessage InvokeObjectMethod(IMessage request)
5355 + IMethodMessage methodmsg = (IMethodMessage)request;
5356 + object ret;
5357 + switch (methodmsg.MethodName)
5359 + case "Equals":
5360 + ret = false;
5362 + if (RemotingServices.IsTransparentProxy(methodmsg.Args[0]))
5364 + UnoInterfaceProxy unoProxy =
5365 + RemotingServices.GetRealProxy(methodmsg.Args[0]) as UnoInterfaceProxy;
5367 + if (unoProxy != null)
5369 + ret = oid.Equals(unoProxy.Oid);
5370 + break;
5373 + break;
5374 + case "GetHashCode":
5375 + ret = oid.GetHashCode();
5376 + break;
5377 + case "GetType":
5378 + ret = typeof(System.Object);
5379 + break;
5380 + case "ToString":
5381 + ret = String.Format("Uno object proxy. OID: {0}", oid);
5382 + break;
5383 + default:
5384 + // Cannot happen
5385 + ret = null;
5386 + break;
5389 + return new ReturnMessage(ret, new object[0], 0,
5390 + methodmsg.LogicalCallContext,
5391 + (IMethodCallMessage)methodmsg);
5394 + public string Oid {
5395 + get { return oid; }
5398 + IMessage ConstructReturnMessage(uno.Any result, object[] args,
5399 + InterfaceMethodTypeDescription *methodTD,
5400 + IMethodCallMessage callmsg, uno.Any exception)
5402 + if (exception.hasValue())
5404 + throw (System.Exception)exception.Value;
5406 + else
5408 + if (args != null)
5410 + object[] outArgs = new object[methodTD->nParams];
5411 + int numOutArgs = 0;
5412 + for (int i = 0; i < methodTD->nParams; ++i)
5414 + if (methodTD->pParams[i].bOut == 1)
5416 + outArgs[i] = args[i];
5417 + ++numOutArgs;
5420 + return new ReturnMessage(result.Value, outArgs, numOutArgs,
5421 + callmsg.LogicalCallContext,
5422 + callmsg);
5424 + else
5426 + return new ReturnMessage(result.Value, null, 0,
5427 + callmsg.LogicalCallContext,
5428 + callmsg);