update dev300-m58
[ooovba.git] / cli_ure / source / climaker / climaker_mono.cxx
blob6338011c24f28fa23b288346ed7bb9a6dfea083d
1 #include <stdio.h>
2 #include <vector>
3 #include <memory>
4 #include <cstring>
6 #include "osl/process.h"
7 #include "osl/file.hxx"
8 #include "osl/thread.h"
9 #include "rtl/ustring.hxx"
10 #include "rtl/ustrbuf.hxx"
11 #include "cppuhelper/shlib.hxx"
12 #include "cppuhelper/bootstrap.hxx"
13 #include "com/sun/star/lang/XInitialization.hpp"
14 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
15 #include "com/sun/star/lang/XComponent.hpp"
16 #include "com/sun/star/container/XSet.hpp"
17 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
18 #include "com/sun/star/reflection/XConstantTypeDescription.hpp"
19 #include "com/sun/star/reflection/XConstantsTypeDescription.hpp"
20 #include "com/sun/star/reflection/XEnumTypeDescription.hpp"
21 #include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
22 #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
23 #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp"
24 #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
25 #include "com/sun/star/reflection/XMethodParameter.hpp"
26 #include "com/sun/star/reflection/XParameter.hpp"
27 #include "com/sun/star/reflection/XServiceConstructorDescription.hpp"
28 #include "com/sun/star/reflection/XServiceTypeDescription2.hpp"
29 #include "com/sun/star/reflection/XSingletonTypeDescription2.hpp"
30 #include "com/sun/star/reflection/XStructTypeDescription.hpp"
31 #include "com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp"
32 #include "com/sun/star/registry/XSimpleRegistry.hpp"
34 using namespace ::std;
36 using namespace ::rtl;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
40 #define OUSTR(x) ::rtl::OUString(x, strlen (x), osl_getThreadTextEncoding ())
42 enum UnoTypeClass {
43 UTC_Unknown,
44 UTC_Void,
45 UTC_Char,
46 UTC_Boolean,
47 UTC_Byte,
48 UTC_Short,
49 UTC_UnsignedShort,
50 UTC_Long,
51 UTC_UnsignedLong,
52 UTC_Hyper,
53 UTC_UnsignedHyper,
54 UTC_Float,
55 UTC_Double,
56 UTC_String,
57 UTC_Type,
58 UTC_Any,
59 UTC_Enum,
60 UTC_Typedef,
61 UTC_Struct,
62 UTC_Exception,
63 UTC_Sequence,
64 UTC_Interface,
65 UTC_InterfaceAttribute,
66 UTC_InterfaceMethod,
67 UTC_Constant,
68 UTC_Constants,
69 UTC_Service,
70 UTC_Singleton,
71 UTC_Module
74 UnoTypeClass unoTypeClassToCLI (TypeClass tc)
76 switch (tc) {
77 case TypeClass_UNKNOWN:
78 return UTC_Unknown;
79 case TypeClass_VOID:
80 return UTC_Void;
81 case TypeClass_CHAR:
82 return UTC_Char;
83 case TypeClass_BOOLEAN:
84 return UTC_Boolean;
85 case TypeClass_BYTE:
86 return UTC_Byte;
87 case TypeClass_SHORT:
88 return UTC_Short;
89 case TypeClass_UNSIGNED_SHORT:
90 return UTC_UnsignedShort;
91 case TypeClass_LONG:
92 return UTC_Long;
93 case TypeClass_UNSIGNED_LONG:
94 return UTC_UnsignedLong;
95 case TypeClass_HYPER:
96 return UTC_Hyper;
97 case TypeClass_UNSIGNED_HYPER:
98 return UTC_UnsignedHyper;
99 case TypeClass_FLOAT:
100 return UTC_Float;
101 case TypeClass_DOUBLE:
102 return UTC_Double;
103 case TypeClass_STRING:
104 return UTC_String;
105 case TypeClass_TYPE:
106 return UTC_Type;
107 case TypeClass_ANY:
108 return UTC_Any;
109 case TypeClass_ENUM:
110 return UTC_Enum;
111 case TypeClass_TYPEDEF:
112 return UTC_Typedef;
113 case TypeClass_STRUCT:
114 return UTC_Struct;
115 case TypeClass_EXCEPTION:
116 return UTC_Exception;
117 case TypeClass_SEQUENCE:
118 return UTC_Sequence;
119 case TypeClass_INTERFACE:
120 return UTC_Interface;
121 case TypeClass_INTERFACE_ATTRIBUTE:
122 return UTC_InterfaceAttribute;
123 case TypeClass_INTERFACE_METHOD:
124 return UTC_InterfaceMethod;
125 case TypeClass_CONSTANT:
126 return UTC_Constant;
127 case TypeClass_CONSTANTS:
128 return UTC_Constants;
129 case TypeClass_SERVICE:
130 return UTC_Service;
131 case TypeClass_SINGLETON:
132 return UTC_Singleton;
133 case TypeClass_MODULE:
134 return UTC_Module;
135 default:
136 break;
139 throw RuntimeException(
140 OUSTR("unexpected type in unoTypeClassToCLI"),
141 Reference< XInterface >() );
144 UnoTypeClass unoTypeClass (reflection::XTypeDescription* xType)
146 return unoTypeClassToCLI (xType->getTypeClass ());
149 class UnoHelper
151 Reference< XComponentContext > mxContext;
152 Reference< lang::XSingleComponentFactory > mxTDprov_factory;
153 Reference< container::XHierarchicalNameAccess > mxTDmgr;
154 Reference< XInterface > mxTD_provider;
155 Reference< reflection::XTypeDescriptionEnumeration > mxTD_enum;
156 Reference< reflection::XTypeDescription > mxTD;
157 sal_uInt32 mnPos;
159 vector< OUString > mMandatoryRegistries;
160 vector< OUString > mExtraRegistries;
161 vector< OUString > mExplicitTypes;
163 static OUString const & path_get_working_dir()
165 static OUString s_workingDir;
166 if (! s_workingDir.getLength())
167 osl_getProcessWorkingDir( &s_workingDir.pData );
168 return s_workingDir;
171 static OUString path_make_absolute_file_url( OUString const & path )
173 OUString file_url;
174 oslFileError rc = osl_getFileURLFromSystemPath(
175 path.pData, &file_url.pData );
176 if (osl_File_E_None == rc)
178 OUString abs;
179 rc = osl_getAbsoluteFileURL(
180 path_get_working_dir().pData, file_url.pData, &abs.pData );
181 if (osl_File_E_None == rc)
183 return abs;
185 else
187 throw RuntimeException(
188 OUSTR("cannot make absolute: ") + file_url,
189 Reference< XInterface >() );
192 else
194 throw RuntimeException(
195 OUSTR("cannot get file url from system path: ") + path,
196 Reference< XInterface >() );
200 Reference< registry::XSimpleRegistry > open_registries(
201 vector< OUString > const & registries )
203 if (registries.empty())
205 throw RuntimeException(OUSTR("no registries given!"),
206 Reference< XInterface >() );
209 Reference< registry::XSimpleRegistry > xSimReg;
210 for ( size_t nPos = registries.size(); nPos--; )
212 Reference< registry::XSimpleRegistry > xReg(
213 mxContext->getServiceManager()->createInstanceWithContext(
214 OUSTR("com.sun.star.registry.SimpleRegistry"), mxContext ),
215 UNO_QUERY_THROW );
216 xReg->open( registries[ nPos ], sal_True, sal_False );
217 if (! xReg->isValid())
219 throw RuntimeException(
220 OUSTR("invalid registry: ") + registries[ nPos ],
221 Reference< XInterface >() );
224 if (xSimReg.is()) // nest?
226 Reference< registry::XSimpleRegistry > xNested(
227 mxContext->getServiceManager()->createInstanceWithContext(
228 OUSTR("com.sun.star.registry.NestedRegistry"), mxContext ),
229 UNO_QUERY_THROW );
230 Reference< lang::XInitialization > xInit(
231 xNested, UNO_QUERY_THROW );
232 Sequence< Any > args( 2 );
233 args[ 0 ] <<= xReg;
234 args[ 1 ] <<= xSimReg;
235 xInit->initialize( args );
236 xSimReg = xNested;
238 else
240 xSimReg = xReg;
244 return xSimReg;
247 public:
249 UnoHelper ()
251 // bootstrap uno
252 mxContext = ::cppu::bootstrap_InitialComponentContext(
253 Reference< registry::XSimpleRegistry >() );
254 mxTDmgr = Reference< container::XHierarchicalNameAccess > (
255 mxContext->getValueByName(
256 OUSTR("/singletons/com.sun.star.reflection."
257 "theTypeDescriptionManager") ),
258 UNO_QUERY_THROW );
260 // get rdb tdprovider factory
261 mxTDprov_factory = Reference< lang::XSingleComponentFactory > (
262 ::cppu::loadSharedLibComponentFactory(
263 OUSTR("bootstrap.uno" SAL_DLLEXTENSION), OUString(),
264 OUSTR("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"),
265 Reference< lang::XMultiServiceFactory >(
266 mxContext->getServiceManager(), UNO_QUERY ),
267 Reference< registry::XRegistryKey >() ), UNO_QUERY );
268 if (! mxTDprov_factory.is())
270 throw RuntimeException(
271 OUSTR("cannot get registry typedescription provider: "
272 "bootstrap.uno" SAL_DLLEXTENSION "!"),
273 Reference< XInterface >() );
277 void AddMandatoryRegistry (char *registry)
279 mMandatoryRegistries.push_back(
280 path_make_absolute_file_url( OUSTR( registry ) ) );
283 void AddExtraRegistry (char *registry)
285 mExtraRegistries.push_back(
286 path_make_absolute_file_url( OUSTR( registry ) ) );
289 void AddExplicitType (char *typeName)
291 mExplicitTypes.push_back( OUSTR( typeName ) );
294 void OpenRegistries ()
296 // create registry td provider for mandatory registry files
297 Any arg( makeAny( open_registries( mMandatoryRegistries ) ) );
298 mxTD_provider = Reference< XInterface >(
299 mxTDprov_factory->createInstanceWithArgumentsAndContext(
300 Sequence< Any >( &arg, 1 ), mxContext ) );
302 // insert provider to tdmgr
303 Reference< container::XSet > xSet( mxTDmgr, UNO_QUERY_THROW );
304 Any provider( makeAny( mxTD_provider ) );
305 xSet->insert( provider );
306 OSL_ASSERT( xSet->has( provider ) );
308 if (! mExtraRegistries.empty())
310 arg = makeAny( open_registries( mExtraRegistries ) );
311 provider = makeAny(
312 mxTDprov_factory->createInstanceWithArgumentsAndContext(
313 Sequence< Any >( &arg, 1 ), mxContext ) );
314 xSet->insert( provider );
315 OSL_ASSERT( xSet->has( provider ) );
318 // and emit types to it
319 if (mExplicitTypes.empty())
321 mxTD_enum = Reference< reflection::XTypeDescriptionEnumeration > (
322 Reference< reflection::XTypeDescriptionEnumerationAccess >(
323 mxTD_provider, UNO_QUERY_THROW )
324 ->createTypeDescriptionEnumeration(
325 OUString() /* all IDL modules */,
326 Sequence< TypeClass >() /* all classes of types */,
327 reflection::TypeDescriptionSearchDepth_INFINITE ) );
328 } else
329 mnPos = 0;
332 void* NextType ()
334 Reference< reflection::XTypeDescription > xTD;
336 if (mnPos < mExplicitTypes.size()) {
337 Reference< container::XHierarchicalNameAccess > xHNA(
338 mxTD_provider, UNO_QUERY_THROW );
339 xTD = Reference< reflection::XTypeDescription >(
340 xHNA->getByHierarchicalName( mExplicitTypes[ mnPos ] ),
341 UNO_QUERY_THROW );
342 mnPos ++;
343 } else if (mxTD_enum.is() && mxTD_enum->hasMoreElements())
344 xTD = Reference< reflection::XTypeDescription >(mxTD_enum->nextTypeDescription());
346 if (xTD.is()) {
347 xTD.get ()->acquire ();
349 return xTD.get ();
352 return NULL;
355 ~UnoHelper ()
360 extern "C" {
362 static char* oustr_to_char (OUString oustr)
364 OString os = OUStringToOString (oustr, osl_getThreadTextEncoding());
366 size_t len = os.getLength () + 1;
367 char *str = (char *) malloc (len);
368 memcpy (str, os.getStr (), len);
370 return str;
373 /* UnoHelper class glue */
375 void* SAL_CALL
376 cmm_uno_helper_new ()
378 return new UnoHelper ();
381 void SAL_CALL
382 cmm_uno_helper_add_mandatory_registry (void *ptr, char *registry)
384 UnoHelper *helper = (UnoHelper *) ptr;
386 helper->AddMandatoryRegistry (registry);
389 void SAL_CALL
390 cmm_uno_helper_add_extra_registry (void *ptr, char *registry)
392 UnoHelper *helper = (UnoHelper *) ptr;
394 helper->AddExtraRegistry (registry);
397 void SAL_CALL
398 cmm_uno_helper_add_explicit_type (void *ptr, char *typeName)
400 UnoHelper *helper = (UnoHelper *) ptr;
402 helper->AddExplicitType (typeName);
405 void SAL_CALL
406 cmm_uno_helper_open_registries (void *ptr)
408 UnoHelper *helper = (UnoHelper *) ptr;
410 helper->OpenRegistries ();
413 void* SAL_CALL
414 cmm_uno_helper_next_type (void *ptr)
416 UnoHelper *helper = (UnoHelper *) ptr;
418 return helper->NextType ();
421 void SAL_CALL
422 cmm_uno_helper_delete (void *ptr)
424 UnoHelper *helper = (UnoHelper *) ptr;
426 delete helper;
429 /* XTypeDescription glue */
431 char * SAL_CALL
432 cmm_x_type_description_get_name (void *ptr)
434 reflection::XTypeDescription* xTD = (reflection::XTypeDescription *) ptr;
436 return oustr_to_char (xTD->getName ());
439 int SAL_CALL
440 cmm_x_type_description_get_type_class (void *ptr)
442 reflection::XTypeDescription* xTD = (reflection::XTypeDescription *) ptr;
444 return unoTypeClass (xTD);
447 void SAL_CALL
448 cmm_x_type_description_release (void *ptr)
450 reflection::XTypeDescription* xTD = (reflection::XTypeDescription *) ptr;
452 xTD->release ();
455 /* XEnumTypeDescription glue */
457 char * SAL_CALL
458 cmm_x_enum_type_description_get_name (void *ptr, int idx)
460 reflection::XEnumTypeDescription* xTD = (reflection::XEnumTypeDescription *) ptr;
462 Sequence< OUString > seq_enum_names (xTD->getEnumNames ());
464 return oustr_to_char (seq_enum_names [idx]);
467 int SAL_CALL
468 cmm_x_enum_type_description_get_value (void *ptr, int idx)
470 reflection::XEnumTypeDescription* xTD = (reflection::XEnumTypeDescription *) ptr;
472 Sequence< sal_Int32 > seq_enum_values (xTD->getEnumValues ());
474 return seq_enum_values [idx];
477 int SAL_CALL
478 cmm_x_enum_type_description_get_length (void *ptr)
480 reflection::XEnumTypeDescription* xTD = (reflection::XEnumTypeDescription *) ptr;
482 Sequence< sal_Int32 > seq_enum_values (xTD->getEnumValues ());
484 return seq_enum_values.getLength ();
487 /* XInterfaceTypeDescription glue */
489 int SAL_CALL
490 cmm_x_interface_type_description_get_members (void *ptr, const void **handle)
492 reflection::XInterfaceTypeDescription* xTD = (reflection::XInterfaceTypeDescription *) ptr;
494 Sequence<
495 Reference< reflection::XInterfaceMemberTypeDescription > > seq_members (xTD->getMembers ());
496 Reference< reflection::XInterfaceMemberTypeDescription > const * types = seq_members.getConstArray();
498 int length = seq_members.getLength ();
499 reflection::XInterfaceMemberTypeDescription **array = (reflection::XInterfaceMemberTypeDescription**) malloc (length*sizeof (reflection::XInterfaceMemberTypeDescription *));
501 *handle = array;
503 for (int i = 0; i < length; i ++) {
504 array [i] = types [i].get ();
505 array [i]->acquire ();
508 return length;
511 void * SAL_CALL
512 cmm_x_interface_type_description_get_member (void *ptr, int idx)
514 reflection::XInterfaceMemberTypeDescription** members = (reflection::XInterfaceMemberTypeDescription**) ptr;
516 members [idx]->acquire ();
518 return members [idx];
521 void SAL_CALL
522 cmm_x_interface_type_description_members_release (void *ptr)
524 // uno_Sequence* seq = (uno_Sequence*) ptr;
526 // seq->release ();
529 /* XInterfaceTypeDescription2 glue */
531 void * SAL_CALL
532 cmm_resolveInterface (Reference< reflection::XTypeDescription > type)
534 Reference<reflection::XInterfaceTypeDescription2>
535 xIfaceTd (type, UNO_QUERY);
537 if (xIfaceTd.is()) {
538 reflection::XTypeDescription* xtd = type.get ();
540 xtd->acquire ();
542 return xtd;
543 } else {
544 Reference<reflection::XIndirectTypeDescription> xIndTd(
545 type, UNO_QUERY);
546 if (xIndTd.is() == sal_False)
547 throw uno::Exception(
548 OUSTR("resolveInterfaceTypedef was called with an invalid argument"), 0);
549 return cmm_resolveInterface (xIndTd->getReferencedType());
554 void* SAL_CALL
555 cmm_x_interface_type_description_get_base_type (void *ptr, int idx)
557 reflection::XInterfaceTypeDescription2* xTD = (reflection::XInterfaceTypeDescription2 *) ptr;
559 Sequence< Reference< reflection::XTypeDescription > > seq_base_types (xTD->getBaseTypes ());
561 Reference< reflection::XTypeDescription > type (seq_base_types [idx]);
563 return cmm_resolveInterface (type);
566 int SAL_CALL
567 cmm_x_interface_type_description_get_length (void *ptr)
569 reflection::XInterfaceTypeDescription2* xTD = (reflection::XInterfaceTypeDescription2 *) ptr;
571 Sequence< Reference< reflection::XTypeDescription > > seq_base_types (xTD->getBaseTypes ());
573 return seq_base_types.getLength ();
576 /* XInterfaceAttributeTypeDescription glue */
578 void* SAL_CALL
579 cmm_x_interface_attribute_type_description_get_type (void *ptr)
581 reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
582 Reference< reflection::XTypeDescription > xrt = xTD->getType ();
584 xrt.get ()->acquire ();
586 return xrt.get ();
589 bool SAL_CALL
590 cmm_x_interface_attribute_type_description_is_bound (void *ptr)
592 reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
594 return xTD->isBound ();
597 bool SAL_CALL
598 cmm_x_interface_attribute_type_description_is_read_only (void *ptr)
600 reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
602 return xTD->isReadOnly ();
605 static int
606 get_exception_types (const Sequence<Reference< reflection::XCompoundTypeDescription > >& seq_exceptionsCTD, void **handle)
608 int length = seq_exceptionsCTD.getLength ();
610 if (length <= 0)
611 return 0;
613 Reference< reflection::XCompoundTypeDescription > const * types = seq_exceptionsCTD.getConstArray();
614 size_t size = length*sizeof (reflection::XCompoundTypeDescription *);
615 reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) malloc (size);
617 *handle = array;
619 for (int i = 0; i < length; i ++) {
620 array [i] = types [i].get ();
621 array [i]->acquire ();
624 return length;
627 int SAL_CALL
628 cmm_x_interface_attribute_type_description_get_get_exception_types (void *ptr, void **handle)
630 reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
632 return get_exception_types (xTD->getGetExceptions (), handle);
635 int SAL_CALL
636 cmm_x_interface_attribute_type_description_get_set_exception_types (void *ptr, void **handle)
638 reflection::XInterfaceAttributeTypeDescription2* xTD = (reflection::XInterfaceAttributeTypeDescription2 *) ptr;
640 return get_exception_types (xTD->getSetExceptions (), handle);
643 void* SAL_CALL
644 cmm_x_interface_attribute_type_description_get_exception_type (void *ptr, int index)
646 reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) ptr;;
648 return array [index];
651 static void
652 free_exception_types (void *ptr, int count)
654 reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) ptr;;
655 int i;
657 for (i = 0; i < count; i ++)
658 array [i]->release ();
660 free (array);
663 void SAL_CALL
664 cmm_x_interface_attribute_type_description_free_exception_types (void *ptr, int count)
666 free_exception_types (ptr, count);
669 /* XInterfaceMemberTypeDescription glue */
671 char* SAL_CALL
672 cmm_x_interface_member_type_description_get_member_name (void *ptr)
674 reflection::XInterfaceMemberTypeDescription* xTD = (reflection::XInterfaceMemberTypeDescription *) ptr;
676 return oustr_to_char (xTD->getMemberName ());;
679 /* XInterfaceMethodTypeDescription glue */
681 int SAL_CALL
682 cmm_x_interface_method_type_description_get_parameters (void *ptr, const void **parametersHandle, const void** parametersArrayHandle)
684 reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
686 Sequence<
687 Reference< reflection::XMethodParameter > > seq_parameters (xTD->getParameters ());
688 Reference< reflection::XMethodParameter > const * parameters = seq_parameters.getConstArray();
690 *parametersHandle = seq_parameters.get ();
692 int length = seq_parameters.getLength();
693 size_t size = length*sizeof (Reference< reflection::XMethodParameter > const);
694 Reference< reflection::XMethodParameter > *copy = (Reference< reflection::XMethodParameter > *) malloc (size);
695 memcpy (copy, parameters, size);
697 *parametersArrayHandle = copy;
699 for (int i=0; i<length; i++) {
700 copy[i].get()->acquire ();
703 return length;
706 void * SAL_CALL
707 cmm_x_interface_method_type_description_get_parameter (void *ptr, int idx)
709 Reference< reflection::XMethodParameter > const * parameters = (Reference< reflection::XMethodParameter > const *) ptr;
711 reflection::XMethodParameter* parameterHandle = parameters [idx].get ();
713 parameterHandle->acquire ();
715 return parameterHandle;
718 int SAL_CALL
719 cmm_x_interface_method_type_description_get_exception_types (void *ptr, const void **exceptionTypesHandle, const void** exceptionTypesArrayHandle)
721 reflection::XInterfaceMethodTypeDescription* xMethod = (reflection::XInterfaceMethodTypeDescription *) ptr;
723 const Sequence<Reference<reflection::XTypeDescription> > seqTD = xMethod->getExceptions();
724 int length = seqTD.getLength();
725 Sequence<Reference<reflection::XCompoundTypeDescription> > seqCTD( length );
726 Reference< reflection::XCompoundTypeDescription > * arCTD = seqCTD.getArray();
728 if (length > 0) {
729 size_t size = length*sizeof (Reference< reflection::XCompoundTypeDescription > const);
730 Reference< reflection::XCompoundTypeDescription > *copy = (Reference< reflection::XCompoundTypeDescription > *) malloc (size);
732 for (int i=0; i<length; i++) {
733 arCTD[i] = Reference<reflection::XCompoundTypeDescription>(seqTD[i], UNO_QUERY_THROW);
736 memcpy (copy, arCTD, size);
738 *exceptionTypesArrayHandle = copy;
740 for (int i=0; i<length; i++) {
741 copy[i].get()->acquire ();
743 } else {
744 *exceptionTypesArrayHandle = NULL;
745 *exceptionTypesHandle = NULL;
748 return length;
751 void * SAL_CALL
752 cmm_x_interface_method_type_description_get_exception_type (void *ptr, int idx)
754 Reference< reflection::XCompoundTypeDescription > const * exceptionTypes = (Reference< reflection::XCompoundTypeDescription > const *) ptr;
756 reflection::XCompoundTypeDescription* exceptionTypeHandle = exceptionTypes [idx].get ();
758 exceptionTypeHandle->acquire ();
760 return exceptionTypeHandle;
763 void* SAL_CALL
764 cmm_x_interface_method_type_description_get_return_type (void *ptr)
766 reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
767 Reference< reflection::XTypeDescription > xrt = xTD->getReturnType ();
769 xrt.get ()->acquire ();
771 return xrt.get ();
774 bool SAL_CALL
775 cmm_x_interface_method_type_description_returns_struct (void *ptr)
777 reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
778 Reference< reflection::XStructTypeDescription > xrt (xTD->getReturnType (), UNO_QUERY);
780 return xrt.is ();
783 bool SAL_CALL
784 cmm_x_interface_method_type_description_is_oneway (void *ptr)
786 reflection::XInterfaceMethodTypeDescription* xTD = (reflection::XInterfaceMethodTypeDescription *) ptr;
788 return xTD->isOneway ();
791 /* XMethodParameter glue */
793 bool SAL_CALL
794 cmm_x_method_parameter_is_out (void *ptr)
796 reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
798 return p->isOut ();
801 bool SAL_CALL
802 cmm_x_method_parameter_is_in (void *ptr)
804 reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
806 return p->isIn ();
809 int SAL_CALL
810 cmm_x_method_parameter_position (void *ptr)
812 reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
814 return p->getPosition ();
817 char* SAL_CALL
818 cmm_x_method_parameter_name (void *ptr)
820 reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
822 return oustr_to_char (p->getName ());
825 void* SAL_CALL
826 cmm_x_method_parameter_type (void *ptr)
828 reflection::XMethodParameter* p = (reflection::XMethodParameter *) ptr;
829 Reference< reflection::XTypeDescription > xtd = p->getType ();
831 xtd.get ()->acquire ();
833 return xtd.get ();
836 /* XCompoundTypeDescription glue */
838 void* SAL_CALL
839 cmm_x_compound_type_description_get_base_type (void *ptr)
841 reflection::XCompoundTypeDescription* xTD = (reflection::XCompoundTypeDescription *) ptr;
842 Reference< reflection::XTypeDescription > xrt = xTD->getBaseType ();
844 if (!xrt.is ())
845 return NULL;
847 xrt.get ()->acquire ();
849 return xrt.get ();
852 int SAL_CALL
853 cmm_x_compound_type_description_get_member_names (void *ptr, const void **handle)
855 reflection::XCompoundTypeDescription* xTD = (reflection::XCompoundTypeDescription *) ptr;
857 Sequence< OUString > seq_member_names = xTD->getMemberNames ();
858 int length = seq_member_names.getLength ();
860 if (length <= 0)
861 return 0;
863 OUString const * parameters = seq_member_names.getConstArray();
864 char **array = (char**) malloc (length*sizeof (char *));
866 *handle = array;
868 for (int i = 0; i < length; i ++) {
869 array [i] = oustr_to_char (parameters [i]);
872 return length;
875 void * SAL_CALL
876 cmm_x_compound_type_description_get_member_name (void *ptr, int idx)
878 char** member_names = (char **) ptr;
880 return strdup (member_names [idx]);
883 int SAL_CALL
884 cmm_x_compound_type_description_get_member_types (void *ptr, const void **handle)
886 reflection::XCompoundTypeDescription* xTD = (reflection::XCompoundTypeDescription *) ptr;
888 Sequence< Reference< reflection::XTypeDescription > > seq_member_types = xTD->getMemberTypes ();
889 int length = seq_member_types.getLength ();
891 if (length <= 0)
892 return 0;
894 Reference< reflection::XTypeDescription > const * types = seq_member_types.getConstArray();
895 reflection::XTypeDescription **array = (reflection::XTypeDescription**) malloc (length*sizeof (reflection::XTypeDescription*));
897 *handle = array;
899 for (int i = 0; i < length; i ++) {
900 array [i] = types [i].get ();
901 array [i]->acquire ();
904 return length;
907 void * SAL_CALL
908 cmm_x_compound_type_description_get_member_type (void *ptr, int idx)
910 reflection::XTypeDescription** member_types = (reflection::XTypeDescription **) ptr;
911 member_types [idx]->acquire ();
913 return member_types [idx];
916 /* XStructTypeDescription glue */
918 int SAL_CALL
919 cmm_x_struct_type_description_get_type_parameters (void *ptr, const void **handle)
921 reflection::XStructTypeDescription* xTD = (reflection::XStructTypeDescription *) ptr;
923 Sequence< OUString > seq_type_parameters = xTD->getTypeParameters ();
924 int length = seq_type_parameters.getLength ();
926 if (length <= 0)
927 return 0;
929 OUString const * parameters = seq_type_parameters.getConstArray();
930 char **array = (char**) malloc (length*sizeof (char *));
932 *handle = array;
934 for (int i = 0; i < length; i ++) {
935 array [i] = oustr_to_char (parameters [i]);
938 return length;
941 void * SAL_CALL
942 cmm_x_struct_type_description_get_type_parameter (void *ptr, int idx)
944 char** type_parameters = (char **) ptr;
946 return strdup (type_parameters [idx]);
949 int SAL_CALL
950 cmm_x_struct_type_description_get_type_arguments (void *ptr, const void **typeArgumentsHandle, const void** typeArgumentsArrayHandle)
952 reflection::XStructTypeDescription* xTD = (reflection::XStructTypeDescription *) ptr;
954 Sequence<
955 Reference< reflection::XTypeDescription > > seq_type_arguments (xTD->getTypeArguments ());
956 Reference< reflection::XTypeDescription > const * type_arguments = seq_type_arguments.getConstArray();
958 *typeArgumentsHandle = seq_type_arguments.get ();
960 int length = seq_type_arguments.getLength();
961 size_t size = length*sizeof (Reference< reflection::XTypeDescription > const);
962 Reference< reflection::XTypeDescription > *copy = (Reference< reflection::XTypeDescription > *) malloc (size);
963 memcpy (copy, type_arguments, size);
965 *typeArgumentsArrayHandle = copy;
967 for (int i=0; i<length; i++) {
968 copy[i].get()->acquire ();
971 return length;
974 void * SAL_CALL
975 cmm_x_struct_type_description_get_type_argument (void *ptr, int idx)
977 Reference< reflection::XTypeDescription > const * type_arguments = (Reference< reflection::XTypeDescription > const *) ptr;
979 reflection::XTypeDescription* typeArgumentHandle = type_arguments [idx].get ();
981 typeArgumentHandle->acquire ();
983 return typeArgumentHandle;
986 /* XIndirectTypeDescription glue */
988 void* SAL_CALL
989 cmm_x_indirect_type_description_get_referenced_type (void *ptr)
991 reflection::XIndirectTypeDescription* xTD = (reflection::XIndirectTypeDescription *) ptr;
992 Reference< reflection::XTypeDescription > xrt = xTD->getReferencedType ();
994 xrt.get ()->acquire ();
996 return xrt.get ();
999 /* XConstantTypeDescription glue */
1001 UnoTypeClass SAL_CALL
1002 cmm_any_to_cli_constant (void *ptr,
1003 sal_Unicode *tChar, sal_Bool *tBool,
1004 sal_uInt8 *tByte,
1005 sal_Int16 *tInt16, sal_uInt16 *tUInt16,
1006 sal_Int32 *tInt32, sal_uInt32 *tUInt32,
1007 sal_Int64 *tInt64, sal_uInt64 *tUInt64,
1008 float *tFloat, double *tDouble)
1010 reflection::XConstantTypeDescription* xtd = (reflection::XConstantTypeDescription*) ptr;
1011 Any const & value (xtd->getConstantValue ());
1013 switch (value.getValueTypeClass ()) {
1014 case TypeClass_CHAR:
1015 *tChar = *reinterpret_cast< sal_Unicode const * > (value.getValue ());
1016 break;
1017 case TypeClass_BOOLEAN:
1018 *tBool = *reinterpret_cast< sal_Bool const * > (value.getValue ());
1019 case TypeClass_BYTE:
1020 *tByte = *reinterpret_cast< sal_uInt8 const * > (value.getValue ());
1021 break;
1022 case TypeClass_SHORT:
1023 *tInt16 = *reinterpret_cast< sal_Int16 const * > (value.getValue ());
1024 break;
1025 case TypeClass_UNSIGNED_SHORT:
1026 *tUInt16 = *reinterpret_cast< sal_uInt16 const * > (value.getValue ());
1027 break;
1028 case TypeClass_LONG:
1029 *tInt32 = *reinterpret_cast< sal_Int32 const * > (value.getValue ());
1030 break;
1031 case TypeClass_UNSIGNED_LONG:
1032 *tUInt32 = *reinterpret_cast< sal_uInt32 const * > (value.getValue ());
1033 break;
1034 case TypeClass_HYPER:
1035 *tInt64 = *reinterpret_cast< sal_Int64 const * > (value.getValue ());
1036 break;
1037 case TypeClass_UNSIGNED_HYPER:
1038 *tUInt64 = *reinterpret_cast< sal_uInt64 const * > (value.getValue ());
1039 break;
1040 case TypeClass_FLOAT:
1041 *tFloat = *reinterpret_cast< float const * > (value.getValue ());
1042 break;
1043 case TypeClass_DOUBLE:
1044 *tDouble = *reinterpret_cast< double const * > (value.getValue ());
1045 break;
1046 default:
1047 throw RuntimeException(OUSTR("unexpected constant type ") +
1048 value.getValueType().getTypeName(),
1049 Reference< XInterface >() );
1052 return unoTypeClassToCLI (value.getValueTypeClass ());
1055 /* XConstantsTypeDescription glue */
1057 int SAL_CALL
1058 cmm_x_constants_type_description_get_constants (void *ptr, const void **handle)
1060 reflection::XConstantsTypeDescription* xTD = (reflection::XConstantsTypeDescription *) ptr;
1062 Sequence< Reference< reflection::XConstantTypeDescription > > seq_member_types = xTD->getConstants ();
1063 int length = seq_member_types.getLength ();
1065 if (length <= 0)
1066 return 0;
1068 Reference< reflection::XConstantTypeDescription > const * types = seq_member_types.getConstArray();
1069 reflection::XConstantTypeDescription **array = (reflection::XConstantTypeDescription**) malloc (length*sizeof (reflection::XConstantTypeDescription*));
1071 *handle = array;
1073 for (int i = 0; i < length; i ++) {
1074 array [i] = types [i].get ();
1075 array [i]->acquire ();
1078 return length;
1081 void * SAL_CALL
1082 cmm_x_constants_type_description_get_constant (void *ptr, int idx)
1084 reflection::XConstantTypeDescription** array = (reflection::XConstantTypeDescription **) ptr;
1085 array [idx]->acquire ();
1087 return array [idx];
1090 /* XServiceTypeDescription glue */
1092 bool SAL_CALL
1093 cmm_x_service_type_description_is_single_interface_based (void *ptr)
1095 reflection::XServiceTypeDescription2* xTD = (reflection::XServiceTypeDescription2 *) ptr;
1097 return xTD->isSingleInterfaceBased ();
1100 void* SAL_CALL
1101 cmm_x_service_type_description_get_interface (void *ptr)
1103 reflection::XServiceTypeDescription2* xTD = (reflection::XServiceTypeDescription2 *) ptr;
1104 reflection::XTypeDescription* xTDiface = xTD->getInterface ().get ();
1106 xTDiface->acquire ();
1108 return xTDiface;
1111 int SAL_CALL
1112 cmm_x_service_type_description_get_constructors (void *ptr, const void **handle)
1114 reflection::XServiceTypeDescription2* xTD = (reflection::XServiceTypeDescription2 *) ptr;
1116 Sequence< Reference< reflection::XServiceConstructorDescription > > seq_member_types = xTD->getConstructors ();
1117 int length = seq_member_types.getLength ();
1119 if (length <= 0)
1120 return 0;
1122 Reference< reflection::XServiceConstructorDescription > const * types = seq_member_types.getConstArray();
1123 reflection::XServiceConstructorDescription **array = (reflection::XServiceConstructorDescription**) malloc (length*sizeof (reflection::XServiceConstructorDescription*));
1125 *handle = array;
1127 for (int i = 0; i < length; i ++) {
1128 array [i] = types [i].get ();
1129 array [i]->acquire ();
1132 return length;
1135 void * SAL_CALL
1136 cmm_x_service_type_description_get_constructor (void *ptr, int idx)
1138 reflection::XServiceConstructorDescription** array = (reflection::XServiceConstructorDescription **) ptr;
1139 array [idx]->acquire ();
1141 return array [idx];
1144 /* XServiceConstructorDescription glue */
1146 int SAL_CALL
1147 cmm_x_service_constructor_description_get_parameters (void *ptr, const void **handle)
1149 reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1151 Sequence< Reference< reflection::XParameter > > seq_member_types = xTD->getParameters ();
1152 int length = seq_member_types.getLength ();
1154 if (length <= 0)
1155 return 0;
1157 Reference< reflection::XParameter > const * types = seq_member_types.getConstArray();
1158 reflection::XParameter **array = (reflection::XParameter**) malloc (length*sizeof (reflection::XParameter*));
1160 *handle = array;
1162 for (int i = 0; i < length; i ++) {
1163 array [i] = types [i].get ();
1164 array [i]->acquire ();
1167 return length;
1170 void * SAL_CALL
1171 cmm_x_service_constructor_description_get_parameter (void *ptr, int idx)
1173 reflection::XParameter** array = (reflection::XParameter **) ptr;
1174 array [idx]->acquire ();
1176 return array [idx];
1179 char * SAL_CALL
1180 cmm_x_service_constructor_description_get_name (void *ptr)
1182 reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1184 return oustr_to_char (xTD->getName ());
1187 bool SAL_CALL
1188 cmm_x_service_constructor_description_is_default_constructor (void *ptr)
1190 reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1192 return xTD->isDefaultConstructor ();
1195 int SAL_CALL
1196 cmm_x_service_constructor_description_get_exception_types (void *ptr, void **handle)
1198 reflection::XServiceConstructorDescription* xTD = (reflection::XServiceConstructorDescription *) ptr;
1200 return get_exception_types (xTD->getExceptions (), handle);
1203 void* SAL_CALL
1204 cmm_x_service_constructor_description_get_exception_type (void *ptr, int index)
1206 reflection::XCompoundTypeDescription **array = (reflection::XCompoundTypeDescription**) ptr;;
1208 return array [index];
1211 void SAL_CALL
1212 cmm_x_service_constructor_description_free_exception_types (void *ptr, int count)
1214 free_exception_types (ptr, count);
1217 /* XParameter glue */
1219 bool SAL_CALL
1220 cmm_x_parameter_is_rest (void *ptr)
1222 reflection::XParameter* xTD = (reflection::XParameter *) ptr;
1224 return xTD->isRestParameter ();
1227 /* XServiceTypeDescription glue */
1229 bool SAL_CALL
1230 cmm_x_singleton_type_description_is_interface_based (void *ptr)
1232 reflection::XSingletonTypeDescription2* xTD = (reflection::XSingletonTypeDescription2 *) ptr;
1234 return xTD->isInterfaceBased ();
1237 void* SAL_CALL
1238 cmm_x_singleton_type_description_get_interface (void *ptr)
1240 reflection::XSingletonTypeDescription2* xTD = (reflection::XSingletonTypeDescription2 *) ptr;
1241 Reference< reflection::XTypeDescription > xrt = xTD->getInterface ();
1243 xrt.get ()->acquire ();
1245 return xrt.get ();