Update ooo320-m1
[ooovba.git] / pyuno / source / module / pyuno.cxx
blobb38a153121186fb588dce9b9bdf77fb882fca298
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pyuno.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "pyuno_impl.hxx"
33 #include <rtl/strbuf.hxx>
34 #include <rtl/ustrbuf.hxx>
36 #include <osl/thread.h>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/lang/XTypeProvider.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/XMaterialHolder.hpp>
43 #define TO_ASCII(x) OUStringToOString( x , RTL_TEXTENCODING_ASCII_US).getStr()
45 using rtl::OStringBuffer;
46 using rtl::OUStringBuffer;
47 using rtl::OUStringToOString;
48 using rtl::OUString;
49 using com::sun::star::uno::Sequence;
50 using com::sun::star::uno::Reference;
51 using com::sun::star::uno::XInterface;
52 using com::sun::star::uno::Any;
53 using com::sun::star::uno::makeAny;
54 using com::sun::star::uno::UNO_QUERY;
55 using com::sun::star::uno::Type;
56 using com::sun::star::uno::TypeClass;
57 using com::sun::star::uno::RuntimeException;
58 using com::sun::star::uno::Exception;
59 using com::sun::star::uno::XComponentContext;
60 using com::sun::star::lang::XSingleServiceFactory;
61 using com::sun::star::lang::XServiceInfo;
62 using com::sun::star::lang::XTypeProvider;
63 using com::sun::star::script::XTypeConverter;
64 using com::sun::star::script::XInvocation2;
65 using com::sun::star::beans::XMaterialHolder;
67 namespace pyuno
70 PyObject *PyUNO_str( PyObject * self );
72 void PyUNO_del (PyObject* self)
74 PyUNO* me = reinterpret_cast< PyUNO* > (self);
76 PyThreadDetach antiguard;
77 delete me->members;
79 PyObject_Del (self);
84 OUString val2str( const void * pVal, typelib_TypeDescriptionReference * pTypeRef , sal_Int32 mode ) SAL_THROW( () )
86 OSL_ASSERT( pVal );
87 if (pTypeRef->eTypeClass == typelib_TypeClass_VOID)
88 return OUString( RTL_CONSTASCII_USTRINGPARAM("void") );
90 OUStringBuffer buf( 64 );
91 buf.append( (sal_Unicode)'(' );
92 buf.append( pTypeRef->pTypeName );
93 buf.append( (sal_Unicode)')' );
95 switch (pTypeRef->eTypeClass)
97 case typelib_TypeClass_INTERFACE:
99 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
100 buf.append( reinterpret_cast< sal_IntPtr >(*(void **)pVal), 16 );
101 if( VAL2STR_MODE_DEEP == mode )
103 buf.appendAscii( "{" ); Reference< XInterface > r = *( Reference< XInterface > * ) pVal;
104 Reference< XServiceInfo > serviceInfo( r, UNO_QUERY);
105 Reference< XTypeProvider > typeProvider(r,UNO_QUERY);
106 if( serviceInfo.is() )
108 buf.appendAscii("implementationName=" );
109 buf.append(serviceInfo->getImplementationName() );
110 buf.appendAscii(", supportedServices={" );
111 Sequence< OUString > seq = serviceInfo->getSupportedServiceNames();
112 for( int i = 0 ; i < seq.getLength() ; i ++ )
114 buf.append( seq[i] );
115 if( i +1 != seq.getLength() )
116 buf.appendAscii( "," );
118 buf.appendAscii("}");
121 if( typeProvider.is() )
123 buf.appendAscii(", supportedInterfaces={" );
124 Sequence< Type > seq (typeProvider->getTypes());
125 for( int i = 0 ; i < seq.getLength() ; i ++ )
127 buf.append(seq[i].getTypeName());
128 if( i +1 != seq.getLength() )
129 buf.appendAscii( "," );
131 buf.appendAscii("}");
133 buf.appendAscii( "}" );
136 break;
138 case typelib_TypeClass_UNION:
140 // typelib_TypeDescription * pTypeDescr = 0;
141 // TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
142 // buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("{ ") );
143 // buf.append( val2str( (char *)pVal + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
144 // union_getSetType( pVal, pTypeDescr ) ) );
145 // buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" }") );
146 // TYPELIB_DANGER_RELEASE( pTypeDescr );
147 break;
149 case typelib_TypeClass_STRUCT:
150 case typelib_TypeClass_EXCEPTION:
152 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("{ ") );
153 typelib_TypeDescription * pTypeDescr = 0;
154 TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
155 OSL_ASSERT( pTypeDescr );
157 typelib_CompoundTypeDescription * pCompType = (typelib_CompoundTypeDescription *)pTypeDescr;
158 sal_Int32 nDescr = pCompType->nMembers;
160 if (pCompType->pBaseTypeDescription)
162 buf.append( val2str( pVal, ((typelib_TypeDescription *)pCompType->pBaseTypeDescription)->pWeakRef,mode ) );
163 if (nDescr)
164 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
167 typelib_TypeDescriptionReference ** ppTypeRefs = pCompType->ppTypeRefs;
168 sal_Int32 * pMemberOffsets = pCompType->pMemberOffsets;
169 rtl_uString ** ppMemberNames = pCompType->ppMemberNames;
171 for ( sal_Int32 nPos = 0; nPos < nDescr; ++nPos )
173 buf.append( ppMemberNames[nPos] );
174 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" = ") );
175 typelib_TypeDescription * pMemberType = 0;
176 TYPELIB_DANGER_GET( &pMemberType, ppTypeRefs[nPos] );
177 buf.append( val2str( (char *)pVal + pMemberOffsets[nPos], pMemberType->pWeakRef, mode ) );
178 TYPELIB_DANGER_RELEASE( pMemberType );
179 if (nPos < (nDescr -1))
180 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
183 TYPELIB_DANGER_RELEASE( pTypeDescr );
185 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" }") );
186 break;
188 case typelib_TypeClass_SEQUENCE:
190 typelib_TypeDescription * pTypeDescr = 0;
191 TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
193 uno_Sequence * pSequence = *(uno_Sequence **)pVal;
194 typelib_TypeDescription * pElementTypeDescr = 0;
195 TYPELIB_DANGER_GET( &pElementTypeDescr, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType );
197 sal_Int32 nElementSize = pElementTypeDescr->nSize;
198 sal_Int32 nElements = pSequence->nElements;
200 if (nElements)
202 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("{ ") );
203 char * pElements = pSequence->elements;
204 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
206 buf.append( val2str( pElements + (nElementSize * nPos), pElementTypeDescr->pWeakRef, mode ) );
207 if (nPos < (nElements -1))
208 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
210 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" }") );
212 else
214 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("{}") );
216 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
217 TYPELIB_DANGER_RELEASE( pTypeDescr );
218 break;
220 case typelib_TypeClass_ANY:
221 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("{ ") );
222 buf.append( val2str( ((uno_Any *)pVal)->pData,
223 ((uno_Any *)pVal)->pType ,
224 mode) );
225 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" }") );
226 break;
227 case typelib_TypeClass_TYPE:
228 buf.append( (*(typelib_TypeDescriptionReference **)pVal)->pTypeName );
229 break;
230 case typelib_TypeClass_STRING:
231 buf.append( (sal_Unicode)'\"' );
232 buf.append( *(rtl_uString **)pVal );
233 buf.append( (sal_Unicode)'\"' );
234 break;
235 case typelib_TypeClass_ENUM:
237 typelib_TypeDescription * pTypeDescr = 0;
238 TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
240 sal_Int32 * pValues = ((typelib_EnumTypeDescription *)pTypeDescr)->pEnumValues;
241 sal_Int32 nPos = ((typelib_EnumTypeDescription *)pTypeDescr)->nEnumValues;
242 while (nPos--)
244 if (pValues[nPos] == *(int *)pVal)
245 break;
247 if (nPos >= 0)
248 buf.append( ((typelib_EnumTypeDescription *)pTypeDescr)->ppEnumNames[nPos] );
249 else
250 buf.append( (sal_Unicode)'?' );
252 TYPELIB_DANGER_RELEASE( pTypeDescr );
253 break;
255 case typelib_TypeClass_BOOLEAN:
256 if (*(sal_Bool *)pVal)
257 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("true") );
258 else
259 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("false") );
260 break;
261 case typelib_TypeClass_CHAR:
262 buf.append( (sal_Unicode)'\'' );
263 buf.append( *(sal_Unicode *)pVal );
264 buf.append( (sal_Unicode)'\'' );
265 break;
266 case typelib_TypeClass_FLOAT:
267 buf.append( *(float *)pVal );
268 break;
269 case typelib_TypeClass_DOUBLE:
270 buf.append( *(double *)pVal );
271 break;
272 case typelib_TypeClass_BYTE:
273 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
274 buf.append( (sal_Int32)*(sal_Int8 *)pVal, 16 );
275 break;
276 case typelib_TypeClass_SHORT:
277 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
278 buf.append( (sal_Int32)*(sal_Int16 *)pVal, 16 );
279 break;
280 case typelib_TypeClass_UNSIGNED_SHORT:
281 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
282 buf.append( (sal_Int32)*(sal_uInt16 *)pVal, 16 );
283 break;
284 case typelib_TypeClass_LONG:
285 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
286 buf.append( *(sal_Int32 *)pVal, 16 );
287 break;
288 case typelib_TypeClass_UNSIGNED_LONG:
289 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
290 buf.append( (sal_Int64)*(sal_uInt32 *)pVal, 16 );
291 break;
292 case typelib_TypeClass_HYPER:
293 case typelib_TypeClass_UNSIGNED_HYPER:
294 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
295 #if defined(GCC) && defined(SPARC)
297 sal_Int64 aVal;
298 *(sal_Int32 *)&aVal = *(sal_Int32 *)pVal;
299 *((sal_Int32 *)&aVal +1)= *((sal_Int32 *)pVal +1);
300 buf.append( aVal, 16 );
302 #else
303 buf.append( *(sal_Int64 *)pVal, 16 );
304 #endif
305 break;
307 case typelib_TypeClass_VOID:
308 case typelib_TypeClass_ARRAY:
309 case typelib_TypeClass_UNKNOWN:
310 case typelib_TypeClass_SERVICE:
311 case typelib_TypeClass_MODULE:
312 default:
313 buf.append( (sal_Unicode)'?' );
316 return buf.makeStringAndClear();
320 PyObject *PyUNO_repr( PyObject * self )
322 PyUNO *me = (PyUNO * ) self;
323 PyObject * ret = 0;
325 if( me->members->wrappedObject.getValueType().getTypeClass()
326 == com::sun::star::uno::TypeClass_EXCEPTION )
328 Reference< XMaterialHolder > rHolder(me->members->xInvocation,UNO_QUERY);
329 if( rHolder.is() )
331 Any a = rHolder->getMaterial();
332 Exception e;
333 a >>= e;
334 ret = ustring2PyUnicode(e.Message ).getAcquired();
337 else
339 ret = PyUNO_str( self );
341 return ret;
344 PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args )
346 PyRef ret;
349 Runtime runtime;
351 PyRef paras,callable;
352 if( PyObject_IsInstance( object, getPyUnoClass( runtime ).get() ) )
354 PyUNO* me = (PyUNO*) object;
355 OUString attrName = OUString::createFromAscii(name);
356 if (! me->members->xInvocation->hasMethod (attrName))
358 OUStringBuffer buf;
359 buf.appendAscii( "Attribute " );
360 buf.append( attrName );
361 buf.appendAscii( " unknown" );
362 throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface > () );
364 callable = PyUNO_callable_new (
365 me->members->xInvocation,
366 attrName,
367 runtime.getImpl()->cargo->xInvocation,
368 runtime.getImpl()->cargo->xTypeConverter,
369 ACCEPT_UNO_ANY);
370 paras = args;
372 else
374 // clean the tuple from uno.Any !
375 int size = PyTuple_Size( args );
376 { // for CC, keeping ref-count of tuple being 1
377 paras = PyRef(PyTuple_New( size ), SAL_NO_ACQUIRE);
379 for( int i = 0 ; i < size ;i ++ )
381 PyObject * element = PyTuple_GetItem( args , i );
382 if( PyObject_IsInstance( element , getAnyClass( runtime ).get() ) )
384 element = PyObject_GetAttrString(
385 element, const_cast< char * >("value") );
387 else
389 Py_XINCREF( element );
391 PyTuple_SetItem( paras.get(), i , element );
393 callable = PyRef( PyObject_GetAttrString( object , (char*)name ), SAL_NO_ACQUIRE );
394 if( !callable.is() )
395 return 0;
397 ret = PyRef( PyObject_CallObject( callable.get(), paras.get() ), SAL_NO_ACQUIRE );
399 catch (::com::sun::star::lang::IllegalArgumentException &e)
401 raisePyExceptionWithAny( com::sun::star::uno::makeAny( e ) );
403 catch (::com::sun::star::script::CannotConvertException &e)
405 raisePyExceptionWithAny( com::sun::star::uno::makeAny( e ) );
407 catch (::com::sun::star::uno::RuntimeException &e)
409 raisePyExceptionWithAny( com::sun::star::uno::makeAny( e ) );
411 catch (::com::sun::star::uno::Exception &e)
413 raisePyExceptionWithAny( com::sun::star::uno::makeAny( e ) );
416 return ret.getAcquired();
419 PyObject *PyUNO_str( PyObject * self )
421 PyUNO *me = ( PyUNO * ) self;
423 OStringBuffer buf;
426 if( me->members->wrappedObject.getValueType().getTypeClass()
427 == com::sun::star::uno::TypeClass_STRUCT ||
428 me->members->wrappedObject.getValueType().getTypeClass()
429 == com::sun::star::uno::TypeClass_EXCEPTION)
431 Reference< XMaterialHolder > rHolder(me->members->xInvocation,UNO_QUERY);
432 if( rHolder.is() )
434 PyThreadDetach antiguard;
435 Any a = rHolder->getMaterial();
436 OUString s = val2str( (void*) a.getValue(), a.getValueType().getTypeLibType() );
437 buf.append( OUStringToOString(s,RTL_TEXTENCODING_ASCII_US) );
440 else
442 // a common UNO object
443 PyThreadDetach antiguard;
444 buf.append( "pyuno object " );
446 OUString s = val2str( (void*)me->members->wrappedObject.getValue(),
447 me->members->wrappedObject.getValueType().getTypeLibType() );
448 buf.append( OUStringToOString(s,RTL_TEXTENCODING_ASCII_US) );
451 return PyString_FromString( buf.getStr());
454 PyObject* PyUNO_getattr (PyObject* self, char* name)
456 PyUNO* me;
461 Runtime runtime;
463 me = (PyUNO*) self;
464 //Handle Python dir () stuff first...
465 if (strcmp (name, "__members__") == 0)
467 PyObject* member_list;
468 Sequence<OUString> oo_member_list;
470 oo_member_list = me->members->xInvocation->getMemberNames ();
471 member_list = PyList_New (oo_member_list.getLength ());
472 for (int i = 0; i < oo_member_list.getLength (); i++)
474 // setitem steals a reference
475 PyList_SetItem (member_list, i, ustring2PyString(oo_member_list[i]).getAcquired() );
477 return member_list;
480 if (strcmp (name, "__dict__") == 0)
482 Py_INCREF (Py_None);
483 return Py_None;
485 if (strcmp (name, "__methods__") == 0)
487 Py_INCREF (Py_None);
488 return Py_None;
490 if (strcmp (name, "__class__") == 0)
492 if( me->members->wrappedObject.getValueTypeClass() ==
493 com::sun::star::uno::TypeClass_STRUCT ||
494 me->members->wrappedObject.getValueTypeClass() ==
495 com::sun::star::uno::TypeClass_EXCEPTION )
497 return getClass(
498 me->members->wrappedObject.getValueType().getTypeName(), runtime ).getAcquired();
500 Py_INCREF (Py_None);
501 return Py_None;
504 OUString attrName( OUString::createFromAscii( name ) );
505 //We need to find out if it's a method...
506 if (me->members->xInvocation->hasMethod (attrName))
508 //Create a callable object to invoke this...
509 PyRef ret = PyUNO_callable_new (
510 me->members->xInvocation,
511 attrName,
512 runtime.getImpl()->cargo->xInvocation,
513 runtime.getImpl()->cargo->xTypeConverter);
514 Py_XINCREF( ret.get() );
515 return ret.get();
519 //or a property
520 if (me->members->xInvocation->hasProperty ( attrName))
522 //Return the value of the property
523 Any anyRet;
525 PyThreadDetach antiguard;
526 anyRet = me->members->xInvocation->getValue (attrName);
528 PyRef ret = runtime.any2PyObject(anyRet);
529 Py_XINCREF( ret.get() );
530 return ret.get();
533 //or else...
534 PyErr_SetString (PyExc_AttributeError, name);
536 catch( com::sun::star::reflection::InvocationTargetException & e )
538 raisePyExceptionWithAny( makeAny(e.TargetException) );
540 catch( com::sun::star::beans::UnknownPropertyException & e )
542 raisePyExceptionWithAny( makeAny(e) );
544 catch( com::sun::star::lang::IllegalArgumentException &e )
546 raisePyExceptionWithAny( makeAny(e) );
548 catch( com::sun::star::script::CannotConvertException &e )
550 raisePyExceptionWithAny( makeAny(e) );
552 catch( RuntimeException &e )
554 raisePyExceptionWithAny( makeAny(e) );
557 return NULL;
560 int PyUNO_setattr (PyObject* self, char* name, PyObject* value)
562 PyUNO* me;
564 me = (PyUNO*) self;
567 Runtime runtime;
568 Any val= runtime.pyObject2Any(value, ACCEPT_UNO_ANY);
570 OUString attrName( OUString::createFromAscii( name ) );
572 PyThreadDetach antiguard;
573 if (me->members->xInvocation->hasProperty (attrName))
575 me->members->xInvocation->setValue (attrName, val);
576 return 0; //Keep with Python's boolean system
580 catch( com::sun::star::reflection::InvocationTargetException & e )
582 raisePyExceptionWithAny( makeAny(e.TargetException) );
583 return 1;
585 catch( com::sun::star::beans::UnknownPropertyException & e )
587 raisePyExceptionWithAny( makeAny(e) );
588 return 1;
590 catch( com::sun::star::script::CannotConvertException &e )
592 raisePyExceptionWithAny( makeAny(e) );
593 return 1;
595 catch( RuntimeException & e )
597 raisePyExceptionWithAny( makeAny( e ) );
598 return 1;
600 PyErr_SetString (PyExc_AttributeError, name);
601 return 1; //as above.
604 // ensure object identity and struct equality
605 static int PyUNO_cmp( PyObject *self, PyObject *that )
607 if( self == that )
608 return 0;
609 int retDefault = self > that ? 1 : -1;
612 Runtime runtime;
613 if( PyObject_IsInstance( that, getPyUnoClass( runtime ).get() ) )
616 PyUNO *me = reinterpret_cast< PyUNO*> ( self );
617 PyUNO *other = reinterpret_cast< PyUNO *> (that );
618 com::sun::star::uno::TypeClass tcMe = me->members->wrappedObject.getValueTypeClass();
619 com::sun::star::uno::TypeClass tcOther = other->members->wrappedObject.getValueTypeClass();
621 if( tcMe == tcOther )
623 if( tcMe == com::sun::star::uno::TypeClass_STRUCT ||
624 tcMe == com::sun::star::uno::TypeClass_EXCEPTION )
626 Reference< XMaterialHolder > xMe( me->members->xInvocation,UNO_QUERY);
627 Reference< XMaterialHolder > xOther( other->members->xInvocation,UNO_QUERY );
628 if( xMe->getMaterial() == xOther->getMaterial() )
629 return 0;
631 else if( tcMe == com::sun::star::uno::TypeClass_INTERFACE )
633 if( me->members->wrappedObject == other->members->wrappedObject )
634 // if( me->members->xInvocation == other->members->xInvocation )
635 return 0;
640 catch( com::sun::star::uno::RuntimeException & e)
642 raisePyExceptionWithAny( makeAny( e ) );
644 return retDefault;
647 static PyTypeObject PyUNOType =
649 PyObject_HEAD_INIT (&PyType_Type)
651 const_cast< char * >("pyuno"),
652 sizeof (PyUNO),
654 (destructor) PyUNO_del,
655 (printfunc) 0,
656 (getattrfunc) PyUNO_getattr,
657 (setattrfunc) PyUNO_setattr,
658 (cmpfunc) PyUNO_cmp,
659 (reprfunc) PyUNO_repr,
663 (hashfunc) 0,
664 (ternaryfunc) 0,
665 (reprfunc) PyUNO_str,
666 (getattrofunc)0,
667 (setattrofunc)0,
668 NULL,
670 NULL,
671 (traverseproc)0,
672 (inquiry)0,
673 (richcmpfunc)0,
675 (getiterfunc)0,
676 (iternextfunc)0,
677 NULL,
678 NULL,
679 NULL,
680 NULL,
681 NULL,
682 (descrgetfunc)0,
683 (descrsetfunc)0,
685 (initproc)0,
686 (allocfunc)0,
687 (newfunc)0,
688 (freefunc)0,
689 (inquiry)0,
690 NULL,
691 NULL,
692 NULL,
693 NULL,
694 NULL,
695 (destructor)0
696 #if PY_VERSION_HEX >= 0x02060000
698 #endif
701 PyRef getPyUnoClass( const Runtime &)
703 return PyRef( reinterpret_cast< PyObject * > ( &PyUNOType ) );
706 PyObject* PyUNO_new (
707 const Any & targetInterface, const Reference<XSingleServiceFactory> &ssf)
709 Reference<XInterface> tmp_interface;
711 targetInterface >>= tmp_interface;
712 if (!tmp_interface.is ())
714 // empty reference !
715 Py_INCREF( Py_None );
716 return Py_None;
719 return PyUNO_new_UNCHECKED (targetInterface, ssf);
723 PyObject* PyUNO_new_UNCHECKED (
724 const Any &targetInterface,
725 const Reference<XSingleServiceFactory> &ssf )
727 PyUNO* self;
728 Sequence<Any> arguments (1);
729 Reference<XInterface> tmp_interface;
731 self = PyObject_New (PyUNO, &PyUNOType);
732 if (self == NULL)
733 return NULL; //NULL == error
734 self->members = new PyUNOInternals();
736 arguments[0] <<= targetInterface;
738 PyThreadDetach antiguard;
739 tmp_interface = ssf->createInstanceWithArguments (arguments);
740 Reference<XInvocation2> tmp_invocation (tmp_interface, UNO_QUERY);
741 self->members->xInvocation = tmp_invocation;
742 self->members->wrappedObject = targetInterface;
744 return (PyObject*) self;