diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:29:57 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:29:57 +0000 |
commit | b525a3115f54576017a576ff842dede5e2e3545d (patch) | |
tree | c534b95a9e572b63896467624293a5ca1887d3a3 /cppu | |
parent | 9399c662f36c385b0c705eb34e636a9aec450282 (diff) |
initial import
Diffstat (limited to 'cppu')
60 files changed, 19502 insertions, 0 deletions
diff --git a/cppu/inc/com/sun/star/uno/Any.h b/cppu/inc/com/sun/star/uno/Any.h new file mode 100644 index 000000000000..788031178b4b --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Any.h @@ -0,0 +1,376 @@ +/************************************************************************* + * + * $RCSfile: Any.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:50 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_ANY_H_ +#define _COM_SUN_STAR_UNO_ANY_H_ + +#ifndef _CPPU_MACROS_HXX_ +#include <cppu/macros.hxx> +#endif + +#ifndef _UNO_ANY2_H_ +#include <uno/any2.h> +#endif +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_H_ +#include <com/sun/star/uno/Type.h> +#endif + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + +class BinaryCompatible_Impl; + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** C++ class representing an IDL any. + This class is used to transport any type defined in IDL. + The class inherits from the binary C representation + of <b>uno_Any</b>.<br> + You can insert a value by either using the <<= operators + or the template function makeAny(). No any can hold an any.<br> + You can extract values from an any by using the >>= operators + which return true if the any contains an assignable value + (no data loss), e.g. the any contains a short and you >>= it + into a long variable. + <br> +*/ +class Any : public uno_Any +{ +public: + // these are here to force memory de/allocation to sal lib. + inline static void * SAL_CALL operator new( size_t nSize ) throw() + { return ::rtl_allocateMemory( nSize ); } + inline static void SAL_CALL operator delete( void * pMem ) throw() + { ::rtl_freeMemory( pMem ); } + inline static void * SAL_CALL operator new( size_t, void * pMem ) throw() + { return pMem; } + inline static void SAL_CALL operator delete( void *, void * ) throw() + {} + + /** Default constructor: + Any holds no value; its type is void. + <br> + */ + inline Any(); + + /** Copy constructor: + Sets value of the given any. + <br> + @param rAny another any + */ + inline Any( const Any & rAny ); + + /** Constructor: + Sets a copy of the given data. + <br> + @param pData value + @param rType type of value + */ + inline Any( const void * pData, const Type & rType ); + + /** Constructor: + Sets a copy of the given data. + <br> + @param pData value + @param pTypeDescr type of value + */ + inline Any( const void * pData, typelib_TypeDescription * pTypeDescr ); + + /** Constructor: + Sets a copy of the given data. + <br> + @param pData value + @param pType type of value + */ + inline Any( const void * pData, typelib_TypeDescriptionReference * pType ); + + /** Destructor: + Destructs any content and frees memory. + <br> + */ + inline ~Any(); + + /** Assignment operator: + Sets the value of the given any. + <br> + @param rAny another any (right side) + @return this any + */ + inline Any & SAL_CALL operator = ( const Any & rAny ); + + /** Gets the type of the set value. + <br> + @return a Type object of the set value + */ + inline const Type & SAL_CALL getValueType() const + { return * reinterpret_cast< const Type * >( &pType ); } + /** Gets the type of the set value. + <br> + @return the <b>un</b>acquired type description reference of the set value + */ + inline typelib_TypeDescriptionReference * SAL_CALL getValueTypeRef() const + { return pType; } + + /** Gets the type description of the set value.<br> + Provides <b>ownership</b> of the type description! + Call an explicit typelib_typedescription_release() to release. + <br> + @param a pointer to type description pointer + */ + inline void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const + { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, getValueTypeRef() ); } + + /** Gets the type class of the set value. + <br> + @return the type class of the set value + */ + inline TypeClass SAL_CALL getValueTypeClass() const + { return (TypeClass)pType->eTypeClass; } + + /** Gets the type name of the set value. + <br> + @return the type name of the set value + */ + inline ::rtl::OUString SAL_CALL getValueTypeName() const + { return ::rtl::OUString( pType->pTypeName ); } + + /** Tests if any contains a value. + <br> + @return true if any has a value, false otherwise + */ + inline sal_Bool SAL_CALL hasValue() const + { return (TypeClass_VOID != getValueTypeClass()); } + + /** Gets a pointer to the set value. + <br> + @return a pointer to the set value + */ + inline const void * SAL_CALL getValue() const + { return pData; } + + /** Sets a value. If the any already contains a value, that value will be destructed + and its memory freed. + <br> + @param pData pointer to value + @param rType type of value + */ + inline void SAL_CALL setValue( const void * pData, const Type & rType ); + /** Sets a value. If the any already contains a value, that value will be destructed + and its memory freed. + <br> + @param pData pointer to value + @param pType type of value + */ + inline void SAL_CALL setValue( const void * pData, typelib_TypeDescriptionReference * pType ); + /** Sets a value. If the any already contains a value, that value will be destructed + and its memory freed. + <br> + @param pData pointer to value + @param pTypeDescr type description of value + */ + inline void SAL_CALL setValue( const void * pData, typelib_TypeDescription * pTypeDescr ); + + /** Clears this any. If the any already contains a value, that value will be destructed + and its memory freed. After this has been called, the any does not contain a value. + <br> + */ + inline void SAL_CALL clear(); + + /** Equality operator: compares two anys.<br> + The values need not be of equal type, e.g. a short integer is compared to + a long integer. + <br> + @param rAny another any (right side) + @return true if both any contains equal values + */ + inline sal_Bool SAL_CALL operator == ( const Any & rAny ) const; + /** Unequality operator: compares two anys.<br> + The values need not be of equal type, e.g. a short integer is compared to + a long integer. + <br> + @param rAny another any (right side) + @return true if both any contains unequal values + */ + inline sal_Bool SAL_CALL operator != ( const Any & rAny ) const + { return (! operator == ( rAny )); } + + // test the binary compatibility + friend class BinaryCompatible_Impl; +}; + +/** Template function to generically construct an any from a C++ value. + <br> + @param value a value + @return an any + */ +template< class C > +inline Any SAL_CALL makeAny( const C & value ); + +class BaseReference; +class Type; + +/** Template binary <<= operator to set the value of an any. + <br> + @param rAny destination any (left side) + @param value source value (right side) + */ +template< class C > +inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const C & value ); +/** Template binary >>= operator to assign a value from an any.<br> + If the any does not contain a value that can be assigned <b>without</b> + data loss, this operation will fail returning false. + <br> + @param rAny source any (left side) + @param value destination value (right side) + @return true if assignment was possible without data loss + */ +template< class C > +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, C & value ); + +/** Template equality operator: compares set value of left side any to right side value.<br> + The values need not be of equal type, e.g. a short integer is compared to + a long integer.<br> + This operator can be implemented as template member function, if + all supported compilers can cope with template member functions. + <br> + @param rAny another any (left side) + @param value a value (right side) + @return true if values are equal, false otherwise +*/ +template< class C > +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const C & value ); +/** Template unequality operator: compares set value of left side any to right side value.<br> + The values need not be of equal type, e.g. a short integer is compared to + a long integer.<br> + This operator can be implemented as template member function, if + all supported compilers can cope with template member functions. + <br> + @param rAny another any (left side) + @param value a value (right side) + @return true if values are unequal, false otherwise +*/ +template< class C > +inline sal_Bool SAL_CALL operator != ( const ::com::sun::star::uno::Any & rAny, const C & value ) +{ + return (! operator == ( rAny, value )); +} + +// additional specialized >>= and == operators +// bool +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ); +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const sal_Bool & value ); +// byte +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ); +// short +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int16 & value ); +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_uInt16 & value ); +// long +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int32 & value ); +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_uInt32 & value ); +// hyper +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int64 & value ); +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_uInt64 & value ); +// float +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, float & value ); +// double +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, double & value ); +// string +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, ::rtl::OUString & value ); +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const ::rtl::OUString & value ); +// type +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, ::com::sun::star::uno::Type & value ); +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const ::com::sun::star::uno::Type & value ); +// any +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, ::com::sun::star::uno::Any & value ); +// interface +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const ::com::sun::star::uno::BaseReference & value ); + +} +} +} +} + +/** Gets the meta type of IDL type <b>any</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>any</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Any * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_ANY ) ); +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/Any.hxx b/cppu/inc/com/sun/star/uno/Any.hxx new file mode 100644 index 000000000000..f73cfdf28b08 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Any.hxx @@ -0,0 +1,487 @@ +/************************************************************************* + * + * $RCSfile: Any.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:50 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#define _COM_SUN_STAR_UNO_ANY_HXX_ + +#ifndef _COM_SUN_STAR_UNO_ANY_H_ +#include <com/sun/star/uno/Any.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif +#ifndef _UNO_ANY2_H_ +#include <uno/any2.h> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_GENFUNC_HXX_ +#include <com/sun/star/uno/genfunc.hxx> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +//__________________________________________________________________________________________________ +inline Any::Any() +{ + ::uno_any_construct( this, 0, 0, cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const Any & rAny ) +{ + ::uno_type_any_construct( this, rAny.pData, rAny.getValueTypeRef(), cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const void * pData, const Type & rType ) +{ + ::uno_type_any_construct( this, const_cast< void * >( pData ), rType.getTypeLibType(), cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const void * pData, typelib_TypeDescription * pTypeDescr ) +{ + ::uno_any_construct( this, const_cast< void * >( pData ), pTypeDescr, cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::Any( const void * pData, typelib_TypeDescriptionReference * pType ) +{ + ::uno_type_any_construct( this, const_cast< void * >( pData ), pType, cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline Any::~Any() +{ + ::uno_any_destruct( this, cpp_release ); +} +//__________________________________________________________________________________________________ +inline Any & Any::operator = ( const Any & rAny ) +{ + if (this != &rAny) + setValue( rAny.getValue(), rAny.getValueTypeRef() ); + return *this; +} +//__________________________________________________________________________________________________ +inline void Any::setValue( const void * pData, const Type & rType ) +{ + ::uno_any_destruct( this, cpp_release ); + ::uno_type_any_construct( this, const_cast< void * >( pData ), rType.getTypeLibType(), cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline void Any::setValue( const void * pData, typelib_TypeDescriptionReference * pType ) +{ + ::uno_any_destruct( this, cpp_release ); + ::uno_type_any_construct( this, const_cast< void * >( pData ), pType, cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline void Any::setValue( const void * pData, typelib_TypeDescription * pTypeDescr ) +{ + ::uno_any_destruct( this, cpp_release ); + ::uno_any_construct( this, const_cast< void * >( pData ), pTypeDescr, cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline void Any::clear() +{ + ::uno_any_destruct( this, cpp_release ); + ::uno_any_construct( this, 0, 0, cpp_acquire ); +} +//__________________________________________________________________________________________________ +inline sal_Bool Any::operator == ( const Any & rAny ) const +{ + const Type & rType = ::getCppuType( this ); + return ::uno_type_equalData( + const_cast< void * >( getValue() ), getValueTypeRef(), + const_cast< void * >( rAny.getValue() ), rAny.getValueTypeRef(), + cpp_queryInterface, cpp_release ); +} + +//__________________________________________________________________________________________________ +template< class C > +inline Any SAL_CALL makeAny( const C & value ) +{ + return Any( &value, ::getCppuType( &value ) ); +} + +//__________________________________________________________________________________________________ +template< class C > +inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const C & value ) +{ + rAny.setValue( &value, ::getCppuType( &value ) ); +} + +//__________________________________________________________________________________________________ +template< class C > +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, C & value ) +{ + const ::com::sun::star::uno::Type & rType = ::getCppuType( &value ); + return ::uno_type_assignData( + &value, rType.getTypeLibType(), + const_cast< void * >( rAny.getValue() ), rAny.getValueTypeRef(), + ::com::sun::star::uno::cpp_queryInterface, + ::com::sun::star::uno::cpp_acquire, + ::com::sun::star::uno::cpp_release ); +} + +// bool +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) +{ + if (::com::sun::star::uno::TypeClass_BOOLEAN == rAny.getValueTypeClass()) + { + value = (* reinterpret_cast< const sal_Bool * >( rAny.getValue() ) != sal_False); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const sal_Bool & value ) +{ + return (::com::sun::star::uno::TypeClass_BOOLEAN == rAny.getValueTypeClass() && + (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.getValue() ) != sal_False)); +} +// byte +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) +{ + if (::com::sun::star::uno::TypeClass_BYTE == rAny.getValueTypeClass()) + { + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +// short +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int16 & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_uInt16 & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +// long +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int32 & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_LONG: + case ::com::sun::star::uno::TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_uInt32 & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_LONG: + case ::com::sun::star::uno::TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +// hyper +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int64 & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_HYPER: + case ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER: + value = * reinterpret_cast< const sal_Int64 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_uInt64 & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_HYPER: + case ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER: + value = * reinterpret_cast< const sal_uInt64 * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +// float +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, float & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_FLOAT: + value = * reinterpret_cast< const float * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +// double +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, double & value ) +{ + switch (rAny.getValueTypeClass()) + { + case ::com::sun::star::uno::TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_FLOAT: + value = * reinterpret_cast< const float * >( rAny.getValue() ); + return sal_True; + case ::com::sun::star::uno::TypeClass_DOUBLE: + value = * reinterpret_cast< const double * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +// string +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( + const ::com::sun::star::uno::Any & rAny, ::rtl::OUString & value ) +{ + if (::com::sun::star::uno::TypeClass_STRING == rAny.getValueTypeClass()) + { + value = * reinterpret_cast< const ::rtl::OUString * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( + const ::com::sun::star::uno::Any & rAny, const ::rtl::OUString & value ) +{ + return (::com::sun::star::uno::TypeClass_STRING == rAny.getValueTypeClass() && + value == * reinterpret_cast< const ::rtl::OUString * >( rAny.getValue() )); +} +// type +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( + const ::com::sun::star::uno::Any & rAny, ::com::sun::star::uno::Type & value ) +{ + if (::com::sun::star::uno::TypeClass_TYPE == rAny.getValueTypeClass()) + { + value = * reinterpret_cast< const ::com::sun::star::uno::Type * >( rAny.getValue() ); + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( + const ::com::sun::star::uno::Any & rAny, const ::com::sun::star::uno::Type & value ) +{ + return (::com::sun::star::uno::TypeClass_TYPE == rAny.getValueTypeClass() && + value == * reinterpret_cast< const ::com::sun::star::uno::Type * >( rAny.getValue() )); +} +// any +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator >>= ( + const ::com::sun::star::uno::Any & rAny, ::com::sun::star::uno::Any & value ) +{ + value = rAny; + return sal_True; +} +// interface +//__________________________________________________________________________________________________ +inline sal_Bool SAL_CALL operator == ( + const ::com::sun::star::uno::Any & rAny, const ::com::sun::star::uno::BaseReference & value ) +{ + if (::com::sun::star::uno::TypeClass_INTERFACE == rAny.getValueTypeClass()) + { + ::com::sun::star::uno::XInterface * p1 = + * reinterpret_cast< ::com::sun::star::uno::XInterface * const * >( rAny.getValue() ); + if (p1 && p1 == value.get()) + return sal_True; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xI1( + p1, ::com::sun::star::uno::UNO_QUERY ); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xI2( + value.get(), ::com::sun::star::uno::UNO_QUERY ); + return (xI1.is() && xI1.get() == xI2.get()); + } + return sal_False; +} + +// operator to compare to an any. +//__________________________________________________________________________________________________ +template< class C > +inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const C & value ) +{ + const ::com::sun::star::uno::Type & rType = ::getCppuType( &value ); + return ::uno_type_equalData( + const_cast< void * >( rAny.getValue() ), rAny.getValueTypeRef(), + const_cast< C * >( &value ), rType.getTypeLibType(), + ::com::sun::star::uno::cpp_queryInterface, + ::com::sun::star::uno::cpp_release ); +} + +} +} +} +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/Reference.h b/cppu/inc/com/sun/star/uno/Reference.h new file mode 100644 index 000000000000..4db47ad47402 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Reference.h @@ -0,0 +1,342 @@ +/************************************************************************* + * + * $RCSfile: Reference.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#define _COM_SUN_STAR_UNO_REFERENCE_H_ + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +class XInterface; + +/** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. + <br> +*/ +enum __UnoReference_NoAcquire +{ + /** This enum value can be used for creating a reference granting a given + interface, i.e. transferring ownership to it. + <br> + */ + UNO_REF_NO_ACQUIRE = 0xbebeef +}; + +/** Base reference class holding/ acquiring an interface.<br> + Constructors acquire an interface while the destructor releases it. + This class serves as a base class for all template reference classes and + has been introduced due to compiler problems with templated operators ==, =!. + <br> +*/ +class BaseReference +{ + /** the interface pointer<br> + */ + XInterface * _pInterface; + +protected: + /** Default Constructor: + Sets null reference. + <br> + */ + inline BaseReference(); + /** Constructor: + Sets given interface pointer. + <br> + @param pInterface an interface pointer + */ + inline BaseReference( XInterface * pInterface ); + /** Constructor: + Sets reference to given interface pointer without acquiring it. + <br> + @param pInterface interface pointer + @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline BaseReference( XInterface * pInterface, __UnoReference_NoAcquire ); + /** Copy constructor: + Copies interface reference. + <br> + @param rRef another reference + */ + inline BaseReference( const BaseReference & rRef ); + /** Destructor: + Releases interface reference. + <br> + */ + inline ~BaseReference(); + +public: + // these are here to force memory de/allocation to sal lib. + inline static void * SAL_CALL operator new( size_t nSize ) throw() + { return ::rtl_allocateMemory( nSize ); } + inline static void SAL_CALL operator delete( void * pMem ) throw() + { ::rtl_freeMemory( pMem ); } + inline static void * SAL_CALL operator new( size_t, void * pMem ) throw() + { return pMem; } + inline static void SAL_CALL operator delete( void *, void * ) throw() + {} + + /** Sets interface pointer. An interface already set will be released. + <br> + @param pInterface an interface pointer + */ + inline void SAL_CALL set( XInterface * pInterface ); + /** Clears reference, i.e. releases interface. + Reference is null after clear() call. + <br> + */ + inline void SAL_CALL clear(); + /** Gets interface pointer. + This call does <b>not</b> acquire the interface. + <br> + @return <b>un</b>acquired interface pointer + */ + inline XInterface * SAL_CALL get() const + { return _pInterface; } + /** Checks if reference is null. + <br> + @return true if reference acquires an interface, i.e. is not null + */ + inline sal_Bool SAL_CALL is() const + { return (_pInterface != 0); } + /** Equality operator: compares two interfaces<br> + Checks if both references are null or refer to the same object. + <br> + @param rRef another reference + @return true if both references are null or refer to the same object, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( const BaseReference & rRef ) const; + /** Unequality operator: compares two interfaces<br> + Checks if both references are null or refer to the same object. + <br> + @param rRef another reference + @return false if both references are null or refer to the same object, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( const BaseReference & rRef ) const + { return (! operator == ( rRef )); } + + // needed for stl container operations, though this makes no sense on pointers + inline sal_Bool SAL_CALL operator < ( const BaseReference& rRef ) const + { return (_pInterface < rRef._pInterface); } +}; + +/** Enum defining UNO_QUERY and UNO_REF_NO_ACQUIRE for query interface constructor + of reference template. + <br> +*/ +enum __UnoReference_Query +{ + /** This enum value can be used for querying interface constructor of reference template. + <br> + */ + UNO_REF_QUERY = 0xdb0e121e, + UNO_QUERY = 0xdb0 +}; + +/** Template reference class for interface type derived from BaseReference. + A special constructor given the UNO_QUERY or UNO_REF_QUERY identifier queries interfaces + for reference type. + <br> +*/ +template< class interface_type > +class Reference : public BaseReference +{ +public: + // these are here to force memory de/allocation to sal lib. + static void * SAL_CALL operator new( size_t nSize ) throw() + { return ::rtl_allocateMemory( nSize ); } + static void SAL_CALL operator delete( void * pMem ) throw() + { ::rtl_freeMemory( pMem ); } + static void * SAL_CALL operator new( size_t, void * pMem ) throw() + { return pMem; } + static void SAL_CALL operator delete( void *, void * ) throw() + {} + + /** Default Constructor: + Sets null reference. + <br> + */ + inline Reference() + : BaseReference() + {} + /** Copy constructor: + Copies interface reference. + <br> + @param rRef another reference + */ + inline Reference( const Reference< interface_type > & rRef ) + : BaseReference( rRef ) + {} + /** Constructor: + Sets given interface pointer. + <br> + @param pInterface an interface pointer + */ + inline Reference( interface_type * pInterface ) + : BaseReference( pInterface ) + {} + + /** Constructor: + Sets given interface pointer without acquiring it. + <br> + @param pInterface another reference + @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline Reference( XInterface * pInterface, __UnoReference_NoAcquire ) + : BaseReference( pInterface, UNO_REF_NO_ACQUIRE ) + {} + + /** Constructor: + Queries given interface for reference interface type (<b>interface_type</b>). + <br> + @param rRef another reference + @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to other constructors + */ + inline Reference( const BaseReference & rRef, __UnoReference_Query ) + : BaseReference( query( rRef ) ) + {} + /** Constructor: + Queries given interface for reference interface type (<b>interface_type</b>). + <br> + @param pInterface an interface pointer + @param dummy UNO_QUERY to force obvious distinction to other constructors + */ + inline Reference( XInterface * pInterface, __UnoReference_Query ) + : BaseReference( query( pInterface ) ) + {} + + /** Assignment operator: + Acquires given interface pointer and sets reference. + An interface already set will be released. + <br> + @param pInterface an interface pointer + @return this reference + */ + inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface ); + /** Assignment operator: + Acquires given interface reference and sets reference. + An interface already set will be released. + <br> + @param rRef an interface reference + @return this reference + */ + inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ) + { return operator = ( rRef.get() ); } + + /** Queries given interface for type <b>interface_type</b>. + <br> + @param pInterface interface pointer + @return interface reference of demanded type (may be null) + */ + inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ); + /** Queries given interface reference for type <b>interface_type</b>. + <br> + @param rRef interface reference + @return interface reference of demanded type (may be null) + */ + inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ) + { return query( rRef.get() ); } + + /** Cast operatory to Reference< XInterface >: + Reference objects are binary compatible and any interface must be derived + from com.sun.star.uno.XInterface. + This a useful direct cast possibility. + <br> + */ + inline SAL_CALL operator const Reference< XInterface > & () const + { return * reinterpret_cast< const Reference< XInterface > * >( this ); } + + /** Dereference operator: + Used to call interface methods. + <br> + @return <b>un</b>acquired interface pointer + */ + interface_type * SAL_CALL operator -> () const + { return static_cast< interface_type * >( BaseReference::get() ); } + + /** Gets interface pointer. + This call does <b>not</b> acquire the interface. + <br> + @return <b>un</b>acquired interface pointer + */ + interface_type * SAL_CALL get() const + { return static_cast< interface_type * >( BaseReference::get() ); } +}; + +} +} +} +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/Reference.hxx b/cppu/inc/com/sun/star/uno/Reference.hxx new file mode 100644 index 000000000000..adcc32fd493f --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Reference.hxx @@ -0,0 +1,170 @@ +/************************************************************************* + * + * $RCSfile: Reference.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#define _COM_SUN_STAR_UNO_REFERENCE_HXX_ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HDL_ +#include <com/sun/star/uno/XInterface.hdl> +#endif +#ifndef _COM_SUN_STAR_UNO_GENFUNC_HXX_ +#include <com/sun/star/uno/genfunc.hxx> +#endif + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +//__________________________________________________________________________________________________ +inline BaseReference::BaseReference() + : _pInterface( 0 ) +{ +} +//__________________________________________________________________________________________________ +inline BaseReference::BaseReference( XInterface * pInterface ) + : _pInterface( pInterface ) +{ + if (_pInterface) + _pInterface->acquire(); +} +//__________________________________________________________________________________________________ +inline BaseReference::BaseReference( XInterface * pInterface, __UnoReference_NoAcquire ) + : _pInterface( pInterface ) +{ +} +//__________________________________________________________________________________________________ +inline BaseReference::BaseReference( const BaseReference & rRef ) + : _pInterface( rRef._pInterface ) +{ + if (_pInterface) + _pInterface->acquire(); +} +//__________________________________________________________________________________________________ +inline BaseReference::~BaseReference() +{ + if (_pInterface) + _pInterface->release(); +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const +{ + if (_pInterface == rRef._pInterface) + return sal_True; + // only the query to XInterface must return the same pointer if they belong to same objects + Reference< XInterface > x1( _pInterface, UNO_QUERY ); + Reference< XInterface > x2( rRef, UNO_QUERY ); + return (x1.get() == x2.get()); +} +//__________________________________________________________________________________________________ +inline void BaseReference::set( XInterface * pInterface ) +{ + if (pInterface != _pInterface) + { + if (pInterface) + pInterface->acquire(); + if (_pInterface) + _pInterface->release(); + _pInterface = pInterface; + } +} +//__________________________________________________________________________________________________ +inline void BaseReference::clear() +{ + if (_pInterface) + { + _pInterface->release(); + _pInterface = 0; + } +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > & Reference< interface_type >::operator = ( interface_type * pInterface ) +{ + BaseReference::set( pInterface ); + return *this; +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > Reference< interface_type >::query( XInterface * pInterface ) +{ + const Type & rType = ::getCppuType( (const Reference< interface_type > *)0 ); + return Reference< interface_type >( reinterpret_cast< XInterface * >( + cpp_queryInterface( pInterface, rType.getTypeLibType() ) ), UNO_REF_NO_ACQUIRE ); +} + +} +} +} +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/Sequence.h b/cppu/inc/com/sun/star/uno/Sequence.h new file mode 100644 index 000000000000..f87e78122e74 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Sequence.h @@ -0,0 +1,291 @@ +/************************************************************************* + * + * $RCSfile: Sequence.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_ +#define _COM_SUN_STAR_UNO_SEQUENCE_H_ + +#ifndef _CPPU_MACROS_HXX_ +#include <cppu/macros.hxx> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _UNO_SEQUENCE2_H_ +#include <uno/sequence2.h> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_H_ +#include <com/sun/star/uno/Type.h> +#endif + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + + +namespace rtl +{ +class ByteSequence; +} + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** Template C++ class representing an IDL sequence<>. Template argument is + sequence element type<br> + C++ Sequences are reference counted and shared, so the sequence keeps a handle + to its data. + To keep value semantics, copies are only generated if the sequence is to be modified + (new handle). + <br> +*/ +template< class E > +class Sequence +{ + /** sequence handle<br> + */ + uno_Sequence * _pSequence; + +public: + // these are here to force memory de/allocation to sal lib. + inline static void * SAL_CALL operator new( size_t nSize ) throw() + { return ::rtl_allocateMemory( nSize ); } + inline static void SAL_CALL operator delete( void * pMem ) throw() + { ::rtl_freeMemory( pMem ); } + inline static void * SAL_CALL operator new( size_t, void * pMem ) throw() + { return pMem; } + inline static void SAL_CALL operator delete( void *, void * ) throw() + {} + + /** typedefs the element type of the sequence + <br> + */ + typedef E ElementType; + + /** Default constructor: + Creates an empty sequence. + <br> + */ + inline Sequence< E >(); + /** Copy constructor: + Creates a copy of given sequence. + <br> + @param rSeq another sequence of same type + */ + inline Sequence< E >( const Sequence< E > & rSeq ); + /** Constructor: + Creates a copy of given elements. + <br> + @param pElement an array of elements + @param len length of array + */ + inline Sequence< E >( const E * pElements, sal_Int32 len ); + /** Constructor: + Creates a default constructed sequence of given length. + <br> + @param len initial sequence length + */ + inline Sequence< E >( sal_Int32 len ); + /** Destructor: + Releases sequence handle. Last handle will destruct elements and free memory. + <br> + */ + inline ~Sequence< E >(); + + /** Assignment operator: + Acquires given sequence handle and releases previously set handle. + <br> + @param rSeq another sequence of same type + @return this sequence + */ + inline Sequence< E > & SAL_CALL operator = ( const Sequence< E > & rSeq ); + + /** Gets type of elements. + <br> + @return type of element + */ + inline const Type & getElementType() const + { return ::getCppuType( (const ElementType *)0 ); } + /** Gets length of sequence. + <br> + @return length of sequence + */ + inline sal_Int32 SAL_CALL getLength() const + { return _pSequence->nElements; } + + /** Gets a pointer to elements array for <b>reading</b>. + If the sequence has a length of 0, then the returned pointer is undefined. + <br> + @return pointer to elements array + */ + inline const E * SAL_CALL getConstArray() const + { return reinterpret_cast< const E * >( _pSequence->elements ); } + /** Gets a pointer to elements array for <b>reading and writing</b>.<br> + In general if the sequence has a handle acquired by other sequences + (reference count > 1), then a new sequence is created copy constructing + all elements to keep value semantics!<br> + If the sequence has a length of 0, then the returned pointer is undefined. + <br> + @return pointer to elements array + */ + inline E * SAL_CALL getArray(); + + /** Non-const index operator: + Obtains a reference to element indexed at given position.<br> + The implementation does <b>not</b> check for array bounds!<br> + In general if the sequence has a handle acquired by other sequences + (reference count > 1), then a new sequence is created copy constructing + all elements to keep value semantics! + <br> + @param nIndex index + @return non-const C++ reference to element + */ + inline E & SAL_CALL operator [] ( sal_Int32 nIndex ) + { return getArray()[ nIndex ]; } + /** Const index operator: + Obtains a reference to element indexed at given position.<br> + The implementation does <b>not</b> check for array bounds!<br> + <br> + @param nIndex index + @return const C++ reference to element + */ + inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const + { return getConstArray()[ nIndex ]; } + + /** Equality operator: + Compares two sequences. + <br> + @param rSeq another sequence of same type (right side) + @return true if both sequences are equal, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( const Sequence< E > & rSeq ) const; + /** Unequality operator: + Compares two sequences. + <br> + @param rSeq another sequence of same type (right side) + @return false if both sequences are equal, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const + { return (! operator == ( rSeq )); } + + /** Reallocates sequence to new length. + If the new length is smaller than the former, then upper elements + will be destructed (and their memory freed). + If the new length is greater than the former, then upper (new) elements + are default constructed.<br> + If the sequence has a handle acquired by other sequences + (reference count > 1), then the remaining elements are copy constructed + to a new sequence handle to keep value semantics! + <br> + @param nSize new size of sequence + */ + inline void SAL_CALL realloc( sal_Int32 nSize ); +}; + +/** Creates an UNO byte sequence from a SAL byte sequence. + <br> + @param rByteSequence a byte sequence + @return an UNO byte sequence +*/ +inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence( + const ::rtl::ByteSequence & rByteSequence ); + +} +} +} +} + +/** Gets the meta type of IDL sequence. + <br> + @param dummy typed pointer for function signature + @return type of IDL sequence +*/ +template< class S > +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__)) +inline const ::com::sun::star::uno::Type +#else +inline const ::com::sun::star::uno::Type & +#endif +SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< S > * ); + +/** Gets the meta type of IDL <b>sequence< char ></b>. + This function has been introduced due to ambiguities with unsigned short. + <br> + @param dummy typed pointer for function signature + @return type of IDL <b>sequence< char ></b> +*/ +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__)) +inline const ::com::sun::star::uno::Type +#else +inline const ::com::sun::star::uno::Type & +#endif +SAL_CALL getCharSequenceCppuType(); + +#endif diff --git a/cppu/inc/com/sun/star/uno/Sequence.hxx b/cppu/inc/com/sun/star/uno/Sequence.hxx new file mode 100644 index 000000000000..7b9e3065571e --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Sequence.hxx @@ -0,0 +1,236 @@ +/************************************************************************* + * + * $RCSfile: Sequence.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#define _COM_SUN_STAR_UNO_SEQUENCE_HXX_ + +#ifndef _CPPU_MACROS_HXX_ +#include <cppu/macros.hxx> +#endif + +#ifndef _OSL_INTERLCK_H_ +#include <osl/interlck.h> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_ +#include <com/sun/star/uno/Sequence.h> +#endif +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif +#ifndef _COM_SUN_STAR_UNO_GENFUNC_HXX_ +#include <com/sun/star/uno/genfunc.hxx> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +//__________________________________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence() +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_construct( &_pSequence, rType.getTypeLibType(), 0, 0, cpp_acquire ); +} +//__________________________________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) +{ + ::osl_incrementInterlockedCount( &rSeq._pSequence->nRefCount ); + _pSequence = rSeq._pSequence; +} +//__________________________________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len ) + : _pSequence( 0 ) +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_construct( &_pSequence, rType.getTypeLibType(), + const_cast< E * >( pElements ), len, cpp_acquire ); +} +//__________________________________________________________________________________________________ +template< class E > +inline Sequence< E >::Sequence( sal_Int32 len ) + : _pSequence( 0 ) +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_construct( &_pSequence, rType.getTypeLibType(), 0, len, cpp_acquire ); +} +//__________________________________________________________________________________________________ +template< class E > +inline Sequence< E >::~Sequence() +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_destructData( this, rType.getTypeLibType(), cpp_release ); +} +//__________________________________________________________________________________________________ +template< class E > +inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_assign( &_pSequence, rSeq._pSequence, rType.getTypeLibType(), cpp_release ); + return *this; +} +//__________________________________________________________________________________________________ +template< class E > +inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const +{ + if (_pSequence == rSeq._pSequence) + return sal_True; + const Type & rType = ::getCppuType( this ); + return ::uno_type_equalData( const_cast< Sequence< E > * >( this ), rType.getTypeLibType(), + const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(), + cpp_queryInterface, cpp_release ); +} +//__________________________________________________________________________________________________ +template< class E > +inline E * Sequence< E >::getArray() +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_reference2One( &_pSequence, rType.getTypeLibType(), cpp_acquire, cpp_release ); + return reinterpret_cast< E * >( _pSequence->elements ); +} +//__________________________________________________________________________________________________ +template< class E > +inline void Sequence< E >::realloc( sal_Int32 nSize ) +{ + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_realloc( &_pSequence, rType.getTypeLibType(), nSize, cpp_acquire, cpp_release ); +} + +//-------------------------------------------------------------------------------------------------- +inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence( + const ::rtl::ByteSequence & rByteSequence ) +{ + return ::com::sun::star::uno::Sequence< sal_Int8 >( + * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) ); +} + +} +} +} +} + +// generic sequence template +template< class S > +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__)) +inline const ::com::sun::star::uno::Type +#else +inline const ::com::sun::star::uno::Type & +#endif +SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< S > * ) +{ +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__)) + typelib_TypeDescriptionReference * s_pType = 0; +#else + static typelib_TypeDescriptionReference * s_pType = 0; + if (! s_pType) + { +#endif + const ::com::sun::star::uno::Type & rElementType = ::getCppuType( + (::com::sun::star::uno::Sequence< S >::ElementType *)0 ); + ::typelib_static_sequence_type_init( &s_pType, rElementType.getTypeLibType() ); +#if !( (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__))) + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( &s_pType ); +#else + return ::com::sun::star::uno::Type( s_pType ); +#endif +} + +// char sequence +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__)) +inline const ::com::sun::star::uno::Type +#else +inline const ::com::sun::star::uno::Type & +#endif +SAL_CALL getCharSequenceCppuType() +{ +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__)) + typelib_TypeDescriptionReference * s_pType = 0; +#else + static typelib_TypeDescriptionReference * s_pType = 0; + if (! s_pType) + { +#endif + const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType(); + ::typelib_static_sequence_type_init( &s_pType, rElementType.getTypeLibType() ); +#if ! ((defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) || (defined(__GNUC__) && defined(__APPLE__))) + } + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( &s_pType ); +#else + return ::com::sun::star::uno::Type( s_pType ); +#endif +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/Type.h b/cppu/inc/com/sun/star/uno/Type.h new file mode 100644 index 000000000000..7765d4e910ce --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Type.h @@ -0,0 +1,364 @@ +/************************************************************************* + * + * $RCSfile: Type.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_TYPE_H_ +#define _COM_SUN_STAR_UNO_TYPE_H_ + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPECLASS_HDL_ +#include <com/sun/star/uno/TypeClass.hdl> +#endif +#ifndef _CPPU_MACROS_HXX_ +#include <cppu/macros.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** Enum defining UNO_TYPE_NO_ACQUIRE for type description reference transfer. + <br> +*/ +enum __UnoType_NoAcquire +{ + /** This enum value can be used for creating a Type object granting a given + type description reference, i.e. transferring ownership to it. + <br> + */ + UNO_TYPE_NO_ACQUIRE = 0xbebeef1e +}; + +/** C++ class representing an IDL meta type. + This class is used to represent a a type, i.e. a type name and its type class.<br> + Internally the type holds a C type description reference of the runtime. + You can obtain a full type description of a type by calling member function + getDescription(). + <br> +*/ +class Type +{ + /** the C typelib reference pointer<br> + */ + typelib_TypeDescriptionReference * _pType; + +public: + // these are here to force memory de/allocation to sal lib. + inline static void * SAL_CALL operator new( size_t nSize ) throw() + { return ::rtl_allocateMemory( nSize ); } + inline static void SAL_CALL operator delete( void * pMem ) throw() + { ::rtl_freeMemory( pMem ); } + inline static void * SAL_CALL operator new( size_t, void * pMem ) throw() + { return pMem; } + inline static void SAL_CALL operator delete( void *, void * ) throw() + {} + + /** Default Constructor: + Type is set to void. + <br> + */ + inline Type(); + + /** Constructor: + Type is constructed by given name and type class. + <br> + @param eTypeClass type class of type + @param rTypeName name of type + */ + inline Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ); + + /** Constructor: + Type is constructed by given name and type class. + <br> + @param eTypeClass type class of type + @param pTypeName name of type + */ + inline Type( TypeClass eTypeClass, const sal_Char * pTypeName ); + + /** Constructor: + Type is (copy) constructed by given C type description reference. + <br> + @param pType C type description reference + */ + inline Type( typelib_TypeDescriptionReference * pType ); + + /** Constructor: + Type is (copy) constructed by given C type description reference without acquiring it. + <br> + @param pType C type description reference + @param dummy UNO_TYPE_NO_ACQUIRE to force obvious distinction to other constructors + */ + inline Type( typelib_TypeDescriptionReference * pType, __UnoType_NoAcquire ); + + /** Copy constructor: + Type is copy constructed by given type. + <br> + @param rType another type + */ + inline Type( const Type & rType ); + + /** Destructor: + Releases acquired C type description reference. + <br> + */ + inline ~Type() + { ::typelib_typedescriptionreference_release( _pType ); } + + /** Assignment operator: + Acquires right side type and releases previously set type. + <br> + @param rType another type (right side) + @return this type + */ + inline Type & SAL_CALL operator = ( const Type & rType ); + + /** Gets the type class of set type. + <br> + @return type class of set type + */ + inline TypeClass SAL_CALL getTypeClass() const + { return (TypeClass)_pType->eTypeClass; } + + /** Gets the name of the set type. + <br> + @return name of the set type + */ + inline ::rtl::OUString SAL_CALL getTypeName() const + { return ::rtl::OUString( _pType->pTypeName ); } + + /** Obtains a full type description of set type. + <br> + @param ppDescr [inout] type description + */ + inline void SAL_CALL getDescription( typelib_TypeDescription ** ppDescr ) const + { ::typelib_typedescriptionreference_getDescription( ppDescr, _pType ); } + + /** Gets the C typelib type description reference pointer. + Does <b>not</b> acquire the reference! + <br> + @return <b>un</b>acquired type description reference + */ + inline typelib_TypeDescriptionReference * SAL_CALL getTypeLibType() const + { return _pType; } + + /** Compares two types. + <br> + @param rType another type + @return true if both types refer the same type, false otherwise + */ + inline sal_Bool SAL_CALL equals( const Type & rType ) const + { return ::typelib_typedescriptionreference_equals( _pType, rType._pType ); } + /** Equality operator: + Compares two types. + <br> + @param rType another type + @return true if both types refer the same type, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( const Type & rType ) const + { return equals( rType ); } + /** Unequality operator: + Compares two types. + <br> + @param rType another type + @return false if both types refer the same type, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( const Type & rType ) const + { return (! equals( rType )); } +}; + +} +} +} +} + +/** Gets the meta type of IDL type <b>type</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>type</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Type * ); + +/** Gets the meta type of IDL type <b>void</b>. + @return type of IDL type <b>void</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType(); +/** Gets the meta type of IDL type <b>void</b>. + <br> + @return type of IDL type <b>void</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getVoidCppuType(); + +/** Gets the meta type of IDL type <b>boolean</b>. + <br> + @return type of IDL type <b>boolean</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuBooleanType(); +/** Gets the meta type of IDL type <b>boolean</b>. + <br> + @return type of IDL type <b>boolean</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getBooleanCppuType(); +/** Gets the meta type of IDL type <b>boolean</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>boolean</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Bool * ); + +/** Gets the meta type of IDL type <b>char</b>. + <br> + @return type of IDL type <b>char</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCharCppuType(); +/** Gets the meta type of IDL type <b>char</b>. + <br> + @return type of IDL type <b>char</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType(); + +/** Gets the meta type of IDL type <b>byte</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>byte</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int8 * ); + +/** Gets the meta type of IDL type <b>string</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>string</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::rtl::OUString * ); + +/** Gets the meta type of IDL type <b>short</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>short</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int16 * ); + +/** Gets the meta type of IDL type <b>unsigned short</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>unsigned short</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt16 * ); + +/** Gets the meta type of IDL type <b>long</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>long</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int32 * ); + +/** Gets the meta type of IDL type <b>unsigned long</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>unsigned long</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt32 * ); + +/** Gets the meta type of IDL type <b>hyper</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>hyper</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int64 * ); + +/** Gets the meta type of IDL type <b>unsigned hyper</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>unsigned hyper</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt64 * ); + +/** Gets the meta type of IDL type <b>float</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>float</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const float * ); + +/** Gets the meta type of IDL type <b>double</b>. + <br> + @param dummy typed pointer for function signature + @return type of IDL type <b>double</b> +*/ +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const double * ); + +#endif diff --git a/cppu/inc/com/sun/star/uno/Type.hxx b/cppu/inc/com/sun/star/uno/Type.hxx new file mode 100644 index 000000000000..f40eb7fb602d --- /dev/null +++ b/cppu/inc/com/sun/star/uno/Type.hxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * $RCSfile: Type.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#define _COM_SUN_STAR_UNO_TYPE_HXX_ + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _COM_SUN_STAR_UNO_TYPE_H_ +#include <com/sun/star/uno/Type.h> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +//__________________________________________________________________________________________________ +inline Type::Type() +{ + _pType = reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ) )->getTypeLibType(); + ::typelib_typedescriptionreference_acquire( _pType ); +} +//__________________________________________________________________________________________________ +inline Type::Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ) + : _pType( 0 ) +{ + ::typelib_typedescriptionreference_new( &_pType, (typelib_TypeClass)eTypeClass, rTypeName.pData ); +} +//__________________________________________________________________________________________________ +inline Type::Type( TypeClass eTypeClass, const sal_Char * pTypeName ) + : _pType( 0 ) +{ + ::typelib_typedescriptionreference_newByAsciiName( &_pType, (typelib_TypeClass)eTypeClass, pTypeName ); +} +//__________________________________________________________________________________________________ +inline Type::Type( typelib_TypeDescriptionReference * pType ) + : _pType( pType ) +{ + ::typelib_typedescriptionreference_acquire( _pType ); +} +//__________________________________________________________________________________________________ +inline Type::Type( typelib_TypeDescriptionReference * pType, __UnoType_NoAcquire ) + : _pType( pType ) +{ +} +//__________________________________________________________________________________________________ +inline Type::Type( const Type & rType ) + : _pType( rType._pType ) +{ + ::typelib_typedescriptionreference_acquire( _pType ); +} +//__________________________________________________________________________________________________ +inline Type & Type::operator = ( const Type & rType ) +{ + ::typelib_typedescriptionreference_assign( &_pType, rType._pType ); + return *this; +} + +} +} +} +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Type * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_TYPE ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType() +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ) ); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getVoidCppuType() +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuBooleanType() +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_BOOLEAN ) ); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getBooleanCppuType() +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_BOOLEAN ) ); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Bool * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_BOOLEAN ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCharCppuType() +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_CHAR ) ); +} +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType() +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_CHAR ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int8 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_BYTE ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::rtl::OUString * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_STRING ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int16 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_SHORT ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt16 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_UNSIGNED_SHORT ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int32 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_LONG ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt32 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_UNSIGNED_LONG ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int64 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_HYPER ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt64 * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_UNSIGNED_HYPER ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const float * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_FLOAT ) ); +} + +inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const double * ) +{ + return * reinterpret_cast< const ::com::sun::star::uno::Type * >( + ::typelib_static_type_getByTypeClass( typelib_TypeClass_DOUBLE ) ); +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/genfunc.h b/cppu/inc/com/sun/star/uno/genfunc.h new file mode 100644 index 000000000000..853fb6828020 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/genfunc.h @@ -0,0 +1,105 @@ +/************************************************************************* + * + * $RCSfile: genfunc.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_GENFUNC_H_ +#define _COM_SUN_STAR_UNO_GENFUNC_H_ + +typedef struct _typelib_TypeDescriptionReference typelib_TypeDescriptionReference; + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +extern "C" +{ +/** C function to acquire a C++ interface. + <br> + @param pCppI C++ interface pointer +*/ +inline void SAL_CALL cpp_acquire( void * pCppI ); +/** C function to release a C++ interface. + <br> + @param pCppI C++ interface pointer +*/ +inline void SAL_CALL cpp_release( void * pCppI ); +/** C function to query for a C++ interface. + <br> + @param pCppI C++ interface pointer + @param pType demanded interface type + @return acquired C++ interface pointer or null +*/ +inline void * SAL_CALL cpp_queryInterface( void * pCppI, typelib_TypeDescriptionReference * pType ); +} + +} +} +} +} + +#endif diff --git a/cppu/inc/com/sun/star/uno/genfunc.hxx b/cppu/inc/com/sun/star/uno/genfunc.hxx new file mode 100644 index 000000000000..e392126a76c9 --- /dev/null +++ b/cppu/inc/com/sun/star/uno/genfunc.hxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * $RCSfile: genfunc.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UNO_GENFUNC_HXX_ +#define _COM_SUN_STAR_UNO_GENFUNC_HXX_ + +#ifndef _COM_SUN_STAR_UNO_GENFUNC_H_ +#include <com/sun/star/uno/genfunc.h> +#endif +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include <com/sun/star/uno/Any.hxx> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +extern "C" +{ +//================================================================================================== +inline void SAL_CALL cpp_acquire( void * pCppI ) +{ + reinterpret_cast< XInterface * >( pCppI )->acquire(); +} +//================================================================================================== +inline void SAL_CALL cpp_release( void * pCppI ) +{ + reinterpret_cast< XInterface * >( pCppI )->release(); +} +//================================================================================================== +inline void * SAL_CALL cpp_queryInterface( void * pCppI, typelib_TypeDescriptionReference * pType ) +{ + if (pCppI) + { + Any aRet( reinterpret_cast< XInterface * >( pCppI )->queryInterface( + * reinterpret_cast< const Type * >( &pType ) ) ); + if (aRet.hasValue()) + { + XInterface * pRet = * reinterpret_cast< XInterface * const * >( aRet.getValue() ); + pRet->acquire(); + return pRet; + } + } + return 0; +} +} + +} +} +} +} + +#endif diff --git a/cppu/inc/cppu/macros.hxx b/cppu/inc/cppu/macros.hxx new file mode 100644 index 000000000000..5c9f6f62b9d0 --- /dev/null +++ b/cppu/inc/cppu/macros.hxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: macros.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CPPU_MACROS_HXX_ +#define _CPPU_MACROS_HXX_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _UNO_LBNAMES_H_ +#include <uno/lbnames.h> +#endif + + +// Microsoft Visual C++ 4.x, 5.0, 6.0 +#if defined(_MSC_VER) +# if ( _MSC_VER < 1000 ) +# define CPPU_COMPILER_ERROR "msc version must be between 4.2 and 6.x" +# elif (_MSC_VER < 1100) // MSVC 4.x +# pragma warning( disable: 4290 ) +# define CPPU_CLBN_TMP UNO_LB_MSCI +# define CPPU_CLBN_NS_TMP UNO_LB_MSCI_NAMESPACE +# elif(_MSC_VER < 1200) // MSVC 5.0 +# define CPPU_CLBN_TMP UNO_LB_MSCI +# define CPPU_CLBN_NS_TMP UNO_LB_MSCI_NAMESPACE +# elif(_MSC_VER < 1300) // MSVC 6.0 +# define CPPU_CLBN_TMP UNO_LB_MSCI +# define CPPU_CLBN_NS_TMP UNO_LB_MSCI_NAMESPACE +# else +# define CPPU_COMPILER_ERROR "msc version must be between 4.2 and 6.x" +# endif + +// AIX xlC 3.1 , 3.0.1 ==0x301 +// Visual Age C++ 3.x +#elif ( defined (__xlC__) && __xlC__ < 0x400 ) || \ + ( defined ( __IBMCPP__ ) && ( __IBMCPP__ < 400 ) ) +# define CPPU_COMPILER_ERROR "visual age on aix not supported" + +// Borland C++ ( 5.x ) +#elif defined (BC50) +# define CPPU_COMPILER_ERROR "borland compiler not supported" + +#elif defined(__SUNPRO_CC) +# if ( __SUNPRO_CC < 0x500 ) +# define CPPU_COMPILER_ERROR "sunpro cc version must be 5.x" +# elif( __SUNPRO_CC < 0x600 ) +# define CPPU_CLBN_TMP UNO_LB_SUNPRO5 +# define CPPU_CLBN_NS_TMP UNO_LB_SUNPRO5_NAMESPACE +# else +# define CPPU_COMPILER_ERROR "sunpro cc version must be 5.x" +# endif + +// g++ 2.7.x +#elif defined __GNUC__ +// cygnus have a lot of version, let's assume the best. +// no specific definitions known except this one +# if ( __GNUC__ == 2 && __GNUC_MINOR__ == 7 ) +# define CPPU_COMPILER_ERROR "gcc 2.7 compiler not supported" +# elif ( __GNUC__ == 2 && __GNUC_MINOR__ == 91 ) +# define CPPU_CLBN_TMP UNO_LB_GCC2 +# define CPPU_CLBN_NS_TMP UNO_LB_GCC2_NAMESPACE +# elif ( __GNUC__ == 2 && __GNUC_MINOR__ == 95 ) +# define CPPU_CLBN_TMP UNO_LB_GCC2 +# define CPPU_CLBN_NS_TMP UNO_LB_GCC2_NAMESPACE +# else +# define CPPU_COMPILER_ERROR "gcc unknown version" +# endif + +#elif defined (__WATCOM_CPLUSPLUS__) +# define CPPU_COMPILER_ERROR "watcom compiler not supported" + +// Symantec 7.5 +#elif defined (__SC__) +# define CPPU_COMPILER_ERROR "symantec compiler not supported" + +// HP-UX und aCC +#elif defined(HPUX) && !defined(__GNUC__) +# define CPPU_COMPILER_ERROR "HP-UX compiler not supported" + +// MAC Metrowerks +#elif defined (__MWERKS__) +# define CPPU_COMPILER_ERROR "Metroworks compiler not supported" +#else +# define CPPU_COMPILER_ERROR "unknown compiler" +#endif + +#ifdef CPPU_COMPILER_ERROR +// set to unknown +# error CPPU_COMPILER_ERROR +#endif + +/** + The compiler and systems defines to identify compatibilities + use to mark an unknown system, processor or compiler +*/ +#define CPPU_CURRENT_LANGUAGE_BINDING_NAME CPPU_CLBN_TMP +#define CPPU_CURRENT_NAMESPACE CPPU_CLBN_NS_TMP + +#endif // _USR_MACROS_HXX_ + + + diff --git a/cppu/inc/typelib/typeclass.h b/cppu/inc/typelib/typeclass.h new file mode 100644 index 000000000000..7cace8fe0a6a --- /dev/null +++ b/cppu/inc/typelib/typeclass.h @@ -0,0 +1,133 @@ +/************************************************************************* + * + * $RCSfile: typeclass.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TYPELIB_TYPECLASS_H_ +#define _TYPELIB_TYPECLASS_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +/** This type class enum is binary compatible with the IDL enum + com.sun.star.uno.TypeClass. + <br> +*/ +enum typelib_TypeClass +{ + /** type class of void<br> */ + typelib_TypeClass_VOID = 0, + /** type class of char<br> */ + typelib_TypeClass_CHAR = 1, + /** type class of boolean<br> */ + typelib_TypeClass_BOOLEAN = 2, + /** type class of byte<br> */ + typelib_TypeClass_BYTE = 3, + /** type class of short<br> */ + typelib_TypeClass_SHORT = 4, + /** type class of unsigned short<br> */ + typelib_TypeClass_UNSIGNED_SHORT = 5, + /** type class of long<br> */ + typelib_TypeClass_LONG = 6, + /** type class of unsigned long<br> */ + typelib_TypeClass_UNSIGNED_LONG = 7, + /** type class of hyper<br> */ + typelib_TypeClass_HYPER = 8, + /** type class of unsigned hyper<br> */ + typelib_TypeClass_UNSIGNED_HYPER = 9, + /** type class of float<br> */ + typelib_TypeClass_FLOAT = 10, + /** type class of double<br> */ + typelib_TypeClass_DOUBLE = 11, + /** type class of string<br> */ + typelib_TypeClass_STRING = 12, + /** type class of type<br> */ + typelib_TypeClass_TYPE = 13, + /** type class of any<br> */ + typelib_TypeClass_ANY = 14, + /** type class of enum<br> */ + typelib_TypeClass_ENUM = 15, + /** type class of typedef<br> */ + typelib_TypeClass_TYPEDEF = 16, + /** type class of struct<br> */ + typelib_TypeClass_STRUCT = 17, + /** type class of union<br> */ + typelib_TypeClass_UNION = 18, + /** type class of exception<br> */ + typelib_TypeClass_EXCEPTION = 19, + /** type class of sequence<br> */ + typelib_TypeClass_SEQUENCE = 20, + /** type class of array (not impl)<br> */ + typelib_TypeClass_ARRAY = 21, + /** type class of interface<br> */ + typelib_TypeClass_INTERFACE = 22, + /** type class of service (not impl)<br> */ + typelib_TypeClass_SERVICE = 23, + /** type class of module (not impl)<br> */ + typelib_TypeClass_MODULE = 24, + /** type class of interface method<br> */ + typelib_TypeClass_INTERFACE_METHOD = 25, + /** type class of interface attribute<br> */ + typelib_TypeClass_INTERFACE_ATTRIBUTE = 26, + /** type class of unknown<br> */ + typelib_TypeClass_UNKNOWN = 27, + typelib_TypeClass_MAKE_FIXED_SIZE = SAL_MAX_ENUM +}; + +#endif diff --git a/cppu/inc/typelib/typedescription.h b/cppu/inc/typelib/typedescription.h new file mode 100644 index 000000000000..81244f0d5158 --- /dev/null +++ b/cppu/inc/typelib/typedescription.h @@ -0,0 +1,910 @@ +/************************************************************************* + * + * $RCSfile: typedescription.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#define _TYPELIB_TYPEDESCRIPTION_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _TYPELIB_UIK_H_ +#include <typelib/uik.h> +#endif +#ifndef _TYPELIB_TYPECLASS_H_ +#include <typelib/typeclass.h> +#endif +#ifndef _RTL_USTRING_H_ +#include <rtl/ustring.h> +#endif + +typedef struct _typelib_TypeDescription typelib_TypeDescription; + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +/** Holds a weak reference to a type description. + <br> +*/ +typedef struct _typelib_TypeDescriptionReference +{ + /** reference count of reference; + don't ever modify this by yourself, use + typelib_typedescriptionreference_acquire() and + typelib_typedescriptionreference_release() + <br> + */ + sal_Int32 nRefCount; + /** type class of type<br> + */ + typelib_TypeClass eTypeClass; + /** fully qualified name of type<br> + */ + rtl_uString * pTypeName; + /** pointer to full typedescription; this value is only valid if + the type is never swapped out<br> + */ + typelib_TypeDescription * pType; + /** pointer to optimize the runtime; not for public use<br> + */ + void * pUniqueIdentifier; + /** reserved for future use; 0 if not used<br> + */ + void * pReserved; +} typelib_TypeDescriptionReference; + +/** Full type description of a type. Memory layout of this struct + is identical to the typelib_TypeDescriptionReference for the first six members. + So a typedescription can be used as type reference. + <br> +*/ +typedef struct _typelib_TypeDescription +{ + /** reference count; + don't ever modify this by yourself, use + typelib_typedescription_acquire() and + typelib_typedescription_release() + <br> + */ + sal_Int32 nRefCount; + /** type class of type<br> + */ + typelib_TypeClass eTypeClass; + /** fully qualified name of type<br> + */ + rtl_uString * pTypeName; + /** pointer to self to distinguish reference from description; + for internal use only<br> + */ + typelib_TypeDescription * pSelf; + /** pointer to optimize the runtime; not for public use<br> + */ + void * pUniqueIdentifier; + /** reserved for future use; 0 if not used<br> + */ + void * pReserved; + + /** flag to determine whether the description is complete: + compound and union types lack of member names, + enums lack of member types and names, + interfaces lack of members and table init. + Call typelib_typedescription_complete() if false. + <br> + */ + sal_Bool bComplete; + /** size of type<br> + */ + sal_Int32 nSize; + /** alignment of type<br> + */ + sal_Int32 nAlignment; + /** pointer to weak reference<br> + */ + typelib_TypeDescriptionReference * pWeakRef; + /** determines, if type can be unloaded (and it is possible to reloaded it)<br> + */ + sal_Bool bOnDemand; +} typelib_TypeDescription; + +typedef struct _typelib_CompoundTypeDescription typelib_CompoundTypeDescription; + +/** Type description of a struct or exception. + <br> +*/ +typedef struct _typelib_CompoundTypeDescription +{ + /** inherits all members of typelib_TypeDescription<br> + */ + typelib_TypeDescription aBase; + + /** pointer to base type description, else 0<br> + */ + typelib_CompoundTypeDescription * pBaseTypeDescription; + + /** number of members<br> + */ + sal_Int32 nMembers; + /** byte offsets of each member including the size the base type<br> + */ + sal_Int32 * pMemberOffsets; + /** members of the struct or exception<br> + */ + typelib_TypeDescriptionReference ** ppTypeRefs; + /** member names of the struct or exception<br> + */ + rtl_uString ** ppMemberNames; +} typelib_CompoundTypeDescription; + +/** Type description of a union.<br> + The type class of this description is typelib_TypeClass_UNION. + <br> +*/ +typedef struct _typelib_UnionTypeDescription +{ + /** inherits all members of typelib_TypeDescription<br> + */ + typelib_TypeDescription aBase; + + /** type of the discriminant<br> + */ + typelib_TypeDescriptionReference * pDiscriminantTypeRef; + + /** union default descriminant<br> + */ + sal_Int64 nDefaultDiscriminant; + /** union default member type (may be 0)<br> + */ + typelib_TypeDescriptionReference * pDefaultTypeRef; + /** number of union member types<br> + */ + sal_Int32 nMembers; + /** union member discriminant values (same order as idl declaration)<br> + */ + sal_Int64 * pDiscriminants; + /** union member value types (same order as idl declaration)<br> + */ + typelib_TypeDescriptionReference ** ppTypeRefs; + /** union member value names (same order as idl declaration)<br> + */ + rtl_uString ** ppMemberNames; + /** union value offset for data access<br> + */ + sal_Int32 nValueOffset; +} typelib_UnionTypeDescription; + +/** Type description of an array or sequence. + <br> +*/ +typedef struct _typelib_IndirectTypeDescription +{ + /** inherits all members of typelib_TypeDescription<br> + */ + typelib_TypeDescription aBase; + + /** array, sequence: pointer to element type<br> + */ + typelib_TypeDescriptionReference * pType; +} typelib_IndirectTypeDescription; + +/** Type description of an enum.<br> + The type class of this description is typelib_TypeClass_ENUM. + <br> +*/ +typedef struct _typelib_EnumTypeDescription +{ + /** inherits all members of typelib_TypeDescription<br> + */ + typelib_TypeDescription aBase; + + /** first value of the enum<br> + */ + sal_Int32 nDefaultEnumValue; + /** number of enum values<br> + */ + sal_Int32 nEnumValues; + /** names of enum values<br> + */ + rtl_uString ** ppEnumNames; + /** values of enum (corresponding to names in similar order)<br> + */ + sal_Int32 * pEnumValues; +} typelib_EnumTypeDescription; + +/** Description of an interface method parameter. + <br> +*/ +typedef struct _typelib_MethodParameter +{ + /** name of parameter<br> + */ + rtl_uString * pName; + /** type of parameter<br> + */ + typelib_TypeDescriptionReference * pTypeRef; + /** true: the call type of this parameter is [in] or [inout] + false: the call type of this parameter is [out]<br> + */ + sal_Bool bIn; + /** true: the call type of this parameter is [out] or [inout] + false: the call type of this parameter is [in]<br> + */ + sal_Bool bOut; +} typelib_MethodParameter; + +/** Common base type description of + typelib_InterfaceMemberTypeDescription and + typelib_InterfaceAttributeTypeDescription. + <br> +*/ +typedef struct _typelib_InterfaceMemberTypeDescription +{ + /** inherits all members of typelib_TypeDescription<br> + */ + typelib_TypeDescription aBase; + + /** position of member in the interface including the number of members + of the base interface<br> + */ + sal_Int32 nPosition; + /** name of member<br> + */ + rtl_uString * pMemberName; +} typelib_InterfaceMemberTypeDescription; + +/** Type description of an interface method.<br> + The type class of this description is typelib_TypeClass_INTERFACE_METHOD. + The size and the alignment are 0. + <br> +*/ +typedef struct _typelib_InterfaceMethodTypeDescription +{ + /** inherits all members of typelib_InterfaceMemberTypeDescription<br> + */ + typelib_InterfaceMemberTypeDescription aBase; + + /** type of the return value<br> + */ + typelib_TypeDescriptionReference * pReturnTypeRef; + /** number of parameters<br> + */ + sal_Int32 nParams; + /** array of parameters<br> + */ + typelib_MethodParameter * pParams; + /** number of exceptions<br> + */ + sal_Int32 nExceptions; + /** array of exception types<br> + */ + typelib_TypeDescriptionReference ** ppExceptions; + /** determines whether method is declared oneway<br> + */ + sal_Bool bOneWay; +} typelib_InterfaceMethodTypeDescription; + +/** The description of an interface attribute.<br> + The type class of this description is typelib_TypeClass_INTERFACE_ATTRIBUTE. + The size and the alignment are 0. + <br> +*/ +typedef struct _typelib_InterfaceAttributeTypeDescription +{ + /** inherits all members of typelib_InterfaceMemberTypeDescription<br> + */ + typelib_InterfaceMemberTypeDescription aBase; + + /** determines whether attribute is read only<br> + */ + sal_Bool bReadOnly; + /** type of the attribute<br> + */ + typelib_TypeDescriptionReference * pAttributeTypeRef; +} typelib_InterfaceAttributeTypeDescription; + +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; + +/** Type description of an interface. + <br> +*/ +typedef struct _typelib_InterfaceTypeDescription +{ + /** inherits all members of typelib_TypeDescription<br> + */ + typelib_TypeDescription aBase; + + /** pointer to base type description, else 0<br> + */ + typelib_InterfaceTypeDescription * pBaseTypeDescription; + /** unique identifier of interface<br> + */ + typelib_Uik aUik; + /** number of members<br> + */ + sal_Int32 nMembers; + /** array of members; references attributes or methods<br> + */ + typelib_TypeDescriptionReference ** ppMembers; + /** number of members including members of base interface<br> + */ + sal_Int32 nAllMembers; + /** array of members including members of base interface; + references attributes or methods<br> + */ + typelib_TypeDescriptionReference ** ppAllMembers; + /** array mapping index of the member description to an index + doubling for read-write attributes (called function index); + size of array is nAllMembers<br> + */ + sal_Int32 * pMapMemberIndexToFunctionIndex; + /** number of members plus number of read-write attributes<br> + */ + sal_Int32 nMapFunctionIndexToMemberIndex; + /** array mapping function index to member index; + size of arry is nMapFunctionIndexToMemberIndex<br> + */ + sal_Int32 * pMapFunctionIndexToMemberIndex; +} typelib_InterfaceTypeDescription; + +/** Init struct of compound members for typelib_typedescription_new(). + <br> +*/ +typedef struct _typelib_CompoundMember_Init +{ + /** type class of compound member<br> + */ + typelib_TypeClass eTypeClass; + /** name of type of compound member<br> + */ + rtl_uString * pTypeName; + /** name of compound member<br> + */ + rtl_uString * pMemberName; +} typelib_CompoundMember_Init; + +/** Init struct of interface methods for typelib_typedescription_new(). + <br> +*/ +typedef struct _typelib_Parameter_Init +{ + /** type class of parameter<br> + */ + typelib_TypeClass eTypeClass; + /** name of parameter<br> + */ + rtl_uString * pTypeName; + /** name of parameter<br> + */ + rtl_uString * pParamName; + /** true, if parameter is [in] or [inout]<br> + */ + sal_Bool bIn; + /** true, if parameter is [out] or [inout]<br> + */ + sal_Bool bOut; +} typelib_Parameter_Init; + +/** Init struct of union types for typelib_typedescription_newUnion(). + <br> +*/ +typedef struct _typelib_Union_Init +{ + /** union member discriminant<br> + */ + sal_Int64 nDiscriminant; + /** union member name<br> + */ + rtl_uString * pMemberName; + /** union member type<br> + */ + typelib_TypeDescriptionReference* pTypeRef; +} typelib_Union_Init; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + + +/** Creates a union type description.<br> + All discriminants are handled as int64 values. + The pDiscriminantTypeRef must be of type byte, short, ..., up to hyper. + <br> + @param ppRet inout union type description + @param pTypeName name of union type + @param pDiscriminantTypeRef discriminant type + @param nDefaultDiscriminant default discriminant + @param pDefaultTypeRef default value type of union + @param nMembers number of union members + @param pMembers init members +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newUnion( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pDiscriminantTypeRef, + sal_Int64 nDefaultDiscriminant, + typelib_TypeDescriptionReference * pDefaultTypeRef, + sal_Int32 nMembers, + typelib_Union_Init * pMembers ); + +/** Creates an enum type description. + <br> + @param ppRet inout enum type description + @param pTypeName name of enum + @param nDefaultEnumValue default enum value + @param nEnumValues number of enum values + @param ppEnumNames names of enum values + @param pEnumValues enum values +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newEnum( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_Int32 nDefaultValue, + sal_Int32 nEnumValues, + rtl_uString ** ppEnumNames, + sal_Int32 * pEnumValues ); + +/** Creates a new type description. + <br> + @param ppRet inout type description + @param eTypeClass type class + @param pTypeName name of type + @param pType sequence, array: element type; + struct, Exception: base type; + @param nMembers number of members if struct, exception + @param pMember array of members if struct, exception +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_new( + typelib_TypeDescription ** ppRet, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pType, + sal_Int32 nMembers, + typelib_CompoundMember_Init * pMembers ); + +/** Creates an interface type description. + <br> + @param ppRet inout interface type description + @param pTypeName the fully qualified name of the interface. + @param nUik1 uik part + @param nUik2 uik part + @param nUik3 uik part + @param nUik4 uik part + @param nUik5 uik part + @param pBaseInterface base interface type, else 0 + @param nMembers number of members + @param ppMembers members; attributes or methods +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newInterface( + typelib_InterfaceTypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_uInt32 nUik1, sal_uInt16 nUik2, sal_uInt16 nUik3, sal_uInt32 nUik4, sal_uInt32 nUik5, + typelib_TypeDescriptionReference * pBaseInterface, + sal_Int32 nMembers, + typelib_TypeDescriptionReference ** ppMembers ); + +/** Creates an interface method type description. + <br> + @param ppRet inout method type description + @param nAbsolutePosition position of member including all members of base interfaces + @param bOneWay determines whether method is declared oneway + @param pTypeName fully qualified name of method including interface name + @param eReturnTypeClass type class of return type + @param pReturnTypeName type name of the return type + @param nParams number of parameters + @param pParams parameter types + @param nExceptions number of exceptions + @param ppExceptionNames type names of exceptions +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newInterfaceMethod( + typelib_InterfaceMethodTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + sal_Bool bOneWay, + rtl_uString * pMethodName, + typelib_TypeClass eReturnTypeClass, + rtl_uString * pReturnTypeName, + sal_Int32 nParams, + typelib_Parameter_Init * pParams, + sal_Int32 nExceptions, + rtl_uString ** ppExceptionNames ); + +/** Creates an interface attribute type description. + <br> + @param ppRet inout attribute type description + @param nAbsolutePosition position of this attribute including all members of base interfaces + @param pTypeName fully qualified name of attribute including interface name + @param eAttributeTypeClass type class of attribute type + @param pAttributeTypeName type name of attribute type +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newInterfaceAttribute( + typelib_InterfaceAttributeTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + rtl_uString * pAttributeName, + typelib_TypeClass eAttributeTypeClass, + rtl_uString * pAttributeTypeName, + sal_Bool bReadOnly ); + +/** Increments reference count of given type description. + <br> + @param pDesc type description +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_acquire( typelib_TypeDescription * pDesc ); + +/** Decrements reference count of given type.<br> + If reference count reaches 0, the trype description is deleted. + <br> + @param pDesc type description +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_release( typelib_TypeDescription * pDesc ); + +/** Registers a type description and creates a type description reference.<br> + Type descriptions will be registered automatically if they are provided + via the callback chain. + @param ppNewDescription inout description to be registered; +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_register( + typelib_TypeDescription ** ppNewDescription ); + +/** Tests whether two types descriptions are equal, i.e. type class and names are equal. + <br> + @param p1 a type description + @param p2 another type description + @return true, if type descriptions are equal +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescription_equals( + const typelib_TypeDescription * p1, const typelib_TypeDescription * p2 ); + +/** Retrieves a type description via its fully qualified name. + <br> + @param ppRet inout type description; *ppRet is 0, if type description was not found + @param pName name demanded type description +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_getByName( + typelib_TypeDescription ** ppRet, rtl_uString * pName ); + +/** Sets size of type description cache. + <br> + @param nNewSize new size of cache +*/ +SAL_DLLEXPORT void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize ); + +/** Function pointer declaration of callback function get additional descriptions. + Callbacks <b>must</b> provide <b>complete</b> type descriptions! + <br> + @param pContext callback context + @param ppRet inout type description + @param pTypeName name of demanded type description +*/ +typedef void (SAL_CALL * typelib_typedescription_Callback)( + void * pContext, typelib_TypeDescription ** ppRet, rtl_uString * pTypeName ); + +/** Registers callback function providing additional type descriptions. + <br> + @param pContext callback context + @param pCallback callback function +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_registerCallback( + void * pContext, typelib_typedescription_Callback pCallback ); + +/** Revokes a previously registered callback function. + <br> + @param pContext callback context + @param pCallback registered callback function +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescription_revokeCallback( + void * pContext, typelib_typedescription_Callback pCallback ); + + +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/* Returns true, if the type description reference may lose the type + description. Otherwise pType is a valid pointer and cannot + be discarded through the lifetime of this reference. + Remark: If the pWeakObj of the type is set too, you can avoid + the call of ...getDescription(...) and use the description + direct. pWeakObj == 0 means, that the description is not + initialized. +*/ +#define TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( eTypeClass ) \ + ((eTypeClass) == typelib_TypeClass_INTERFACE_METHOD || \ + (eTypeClass) == typelib_TypeClass_INTERFACE_ATTRIBUTE) + +/* Gets a description from the reference. The description may not be locked + by this call. You must use the TYPELIB_DANGER_RELEASE macro to release + the description fetched with this macro. +*/ +#define TYPELIB_DANGER_GET( ppDescription, pTypeRef ) \ +{ \ + typelib_TypeDescriptionReference * __pMacroTypeRef = (pTypeRef); \ + if (TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( __pMacroTypeRef->eTypeClass )) \ + { \ + typelib_typedescriptionreference_getDescription( ppDescription, __pMacroTypeRef ); \ + } \ + else if (! __pMacroTypeRef->pType->pWeakRef) \ + { \ + typelib_typedescriptionreference_getDescription( ppDescription, __pMacroTypeRef ); \ + typelib_typedescription_release( *(ppDescription) ); \ + } \ + else \ + { \ + *(ppDescription) = __pMacroTypeRef->pType; \ + } \ +} + +/* Releases the description previouse fetched by TYPELIB_DANGER_GET. +*/ +#define TYPELIB_DANGER_RELEASE( pDescription ) \ +{ \ + if (TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( (pDescription)->eTypeClass )) \ + typelib_typedescription_release( pDescription ); \ +} + +/** Creates a type description reference.<br> + This is a weak reference <b>not</b> holding the description. + If the description is already registered, the previous one is returned. + <br> + @param ppTDR inout type description reference + @param eTypeClass type class of type + @param pTypeName name of type +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_new( + typelib_TypeDescriptionReference ** ppTDR, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName ); + +/** Creates a type description reference.<br> + This is a weak reference <b>not</b> holding the description. + If the description is already registered, the previous one is returned. + <br> + @param ppTDR inout type description reference + @param eTypeClass type class of type + @param pTypeName ascii name of type +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_newByAsciiName( + typelib_TypeDescriptionReference ** ppTDR, + typelib_TypeClass eTypeClass, + const sal_Char * pTypeName ); + +/** Increments reference count of type description reference. + <br> + @param pRef type description reference +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_acquire( + typelib_TypeDescriptionReference * pRef ); + +/** Increments reference count of type description reference. + If the reference count reaches 0, the reference is deleted. + <br> + @param pRef type description reference +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_release( + typelib_TypeDescriptionReference * pRef ); + +/** Retrieves the type description for a given reference.<br> + If it is not possible to resolve the reference, null is returned. + <br> + @param ppRet inout type description +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_getDescription( + typelib_TypeDescription ** ppRet, typelib_TypeDescriptionReference * pRef ); + +/** Tests whether two types description references are equal, i.e. type class and names are equal. + <br> + @param p1 a type description reference + @param p2 another type description reference + @return true, if type description references are equal +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescriptionreference_equals( + const typelib_TypeDescriptionReference * p1, const typelib_TypeDescriptionReference * p2 ); + +/** Assigns a type. + <br> + @param ppDest destination type + @param pSource source type +*/ +SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_assign( + typelib_TypeDescriptionReference ** ppDest, + typelib_TypeDescriptionReference * pSource ); + +/** Tests if values of type pAssignable can be assigned by values of type pFrom. + This includes widening conversion (e.g., long assignable from short), as long + as there is <b>no</b> data loss. + <br> + @param pAssignable type description of value to be assigned + @param pFrom type description of value +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescription_isAssignableFrom( + typelib_TypeDescription * pAssignable, + typelib_TypeDescription * pFrom ); + +/** Tests if values of type pAssignable can be assigned by values of type pFrom. + This includes widening conversion (e.g., long assignable from short), as long + as there is <b>no</b> data loss. + <br> + @param pAssignable type of value to be assigned + @param pFrom type of value +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescriptionreference_isAssignableFrom( + typelib_TypeDescriptionReference * pAssignable, + typelib_TypeDescriptionReference * pFrom ); + +/** Gets static type reference of standard types by type class. + ==OPTIMIZATION HACK==: + provides Type com.sun.star.uno.Exception for typelib_TypeClass_EXCEPTION + and com.sun.star.uno.XInterface for typelib_TypeClass_INTERFACE. + <br> + Thread synchronizes on typelib mutex. + <br> + @param eTypeClass type class of basic type + @return pointer to type reference pointer +*/ +SAL_DLLEXPORT typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass( + typelib_TypeClass eTypeClass ); + +/** Inits static type reference. + Thread synchronizes on typelib init mutex. + <br> + @param ppRef pointer to type reference pointer + @param eTypeClass type class of type + @param pTypeName ascii name of type +*/ +SAL_DLLEXPORT void SAL_CALL typelib_static_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeClass eTypeClass, const sal_Char * pTypeName ); + +/** Inits static sequence type reference. + Thread synchronizes on typelib init mutex. + <br> + @param ppRef pointer to type reference pointer + @param pElementType element type of sequence +*/ +SAL_DLLEXPORT void SAL_CALL typelib_static_sequence_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeDescriptionReference * pElementType ); + +/** Inits <b>in</b>complete static compound type reference. + Thread synchronizes on typelib init mutex. + <br> + @param ppRef pointer to type reference pointer + @param eTypeClass typelib_TypeClass_STRUCT or typelib_TypeClass_EXCEPTION + @param pTypeName name of type + @param pBaseType base type + @param nMembers number of members + @param ppMembers member types +*/ +SAL_DLLEXPORT void SAL_CALL typelib_static_compound_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeClass eTypeClass, const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType, + sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers ); + +/** Inits <b>in</b>complete static interface type reference. + Thread synchronizes on typelib init mutex. + <br> + @param ppRef pointer to type reference pointer + @param pTypeName name of interface + @param pBaseType base type +*/ +SAL_DLLEXPORT void SAL_CALL typelib_static_interface_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType ); + +/** Inits <b>in</b>complete static enum type reference. + Thread synchronizes on typelib init mutex. + <br> + @param ppRef pointer to type reference pointer + @param pTypeName name of enum + @param nDefaultEnumValue default enum value +*/ +SAL_DLLEXPORT void SAL_CALL typelib_static_enum_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + sal_Int32 nDefaultValue ); + +/** Inits <b>in</b>complete static compound type reference. + Thread synchronizes on typelib init mutex. + All discriminants are handled as int64 values. + The pDiscriminantTypeRef must be of type byte, short, ..., up to hyper. + <br> + @param ppRef pointer to type reference pointer + @param pTypeName name of union type + @param pDiscriminantType discriminant type + @param nDefaultDiscriminant default discriminant + @param pDefaultType default value type of union + @param nMembers number of union members + @param pDiscriminants member discriminants + @param pMemberTypes member types +*/ +SAL_DLLEXPORT void SAL_CALL typelib_static_union_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pDiscriminantType, + sal_Int64 nDefaultDiscriminant, + typelib_TypeDescriptionReference * pDefaultType, + sal_Int32 nMembers, + sal_Int64 * pDiscriminants, + typelib_TypeDescriptionReference ** pMemberTypes ); + +/** Completes a typedescription to be used for, e.g., marshalling values. + COMPOUND, UNION, INTERFACE and ENUM type descriptions may be partly + initialized (see typelib_static_...(), typelib_TypeDescription::bComplete). + For interface type descriptions, this will also init index tables. + <br> + @param ppTypeDescr [inout] type description to be completed (may be exchanged!) + @return true, if type description is complete +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescription_complete( + typelib_TypeDescription ** ppTypeDescr ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppu/inc/typelib/typedescription.hxx b/cppu/inc/typelib/typedescription.hxx new file mode 100644 index 000000000000..305e54b59acc --- /dev/null +++ b/cppu/inc/typelib/typedescription.hxx @@ -0,0 +1,256 @@ +/************************************************************************* + * + * $RCSfile: typedescription.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_ +#define _TYPELIB_TYPEDESCRIPTION_HXX_ + +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_H_ +#include <com/sun/star/uno/Type.h> +#endif +#ifndef _TYPELIB_TYPEDESCRIPTION_H +#include <typelib/typedescription.h> +#endif + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** C++ wrapper for typelib_TypeDescription. + Constructors by name, type, type description reference will get + the full type description. + <br> +*/ +class TypeDescription +{ + /** C typelib type description<br> + */ + mutable typelib_TypeDescription * _pTypeDescr; + +public: + /** Constructor: + <br> + @param pTypeDescr a type description + */ + inline TypeDescription( typelib_TypeDescription * pTypeDescr = 0 ); + /** Constructor: + <br> + @param pTypeDescrRef a type description reference + */ + inline TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef ); + /** Constructor: + <br> + @param rType a type + */ + inline TypeDescription( const ::com::sun::star::uno::Type & rType ); + /** Copy constructor: + <br> + @param rDescr another TypeDescription + */ + inline TypeDescription( const TypeDescription & rDescr ); + /** Constructor: + <br> + @param pTypeName a type name + */ + inline TypeDescription( rtl_uString * pTypeName ); + /** Constructor: + <br> + @param rTypeName a type name + */ + inline TypeDescription( const ::rtl::OUString & rTypeName ); + /** Destructor: + <br> + releases type description + */ + inline ~TypeDescription(); + + /** Assignment operator: + acquires given type description and releases a set one. + <br> + @param pTypeDescr another type description + @return this TypeDescription + */ + inline TypeDescription & operator = ( typelib_TypeDescription * pTypeDescr ); + /** Assignment operator: + acquires given type description and releases a set one. + <br> + @param rTypeDescr another type description + @return this TypeDescription + */ + inline TypeDescription & operator =( const TypeDescription & rTypeDescr ) + { return this->operator =( rTypeDescr.get() ); } + + /** Tests if two type descriptions are equal. + <br> + @param pTypeDescr another type description + @return true, if both type descriptions are equal, false otherwise + */ + inline sal_Bool equals( const typelib_TypeDescription * pTypeDescr ) const; + /** Tests if two type descriptions are equal. + <br> + @param rTypeDescr another type description + @return true, if both type descriptions are equal, false otherwise + */ + inline sal_Bool equals( const TypeDescription & rTypeDescr ) const + { return equals( rTypeDescr._pTypeDescr ); } + + /** Makes stored type description complete. + <br> + */ + inline void makeComplete() const; + + /** Gets the <b>un</b>acquired type description pointer. + <br> + @return stored pointer of type description + */ + inline typelib_TypeDescription * get() const + { return _pTypeDescr; } + /** Tests if a type description is set. + <br> + @return true, if a type description is set, false otherwise + */ + inline sal_Bool is() const + { return (_pTypeDescr != 0); } +}; +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( typelib_TypeDescription * pTypeDescr ) + : _pTypeDescr( pTypeDescr ) +{ + if (_pTypeDescr) + typelib_typedescription_acquire( _pTypeDescr ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( typelib_TypeDescriptionReference * pTypeDescrRef ) + : _pTypeDescr( 0 ) +{ + if (pTypeDescrRef) + typelib_typedescriptionreference_getDescription( &_pTypeDescr, pTypeDescrRef ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( const ::com::sun::star::uno::Type & rType ) + : _pTypeDescr( 0 ) +{ + if (rType.getTypeLibType()) + typelib_typedescriptionreference_getDescription( &_pTypeDescr, rType.getTypeLibType() ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( const TypeDescription & rTypeDescr ) + : _pTypeDescr( rTypeDescr._pTypeDescr ) +{ + if (_pTypeDescr) + typelib_typedescription_acquire( _pTypeDescr ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( rtl_uString * pTypeName ) + : _pTypeDescr( 0 ) +{ + typelib_typedescription_getByName( &_pTypeDescr , pTypeName ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::TypeDescription( const ::rtl::OUString & rTypeName ) + : _pTypeDescr( 0 ) +{ + typelib_typedescription_getByName( &_pTypeDescr , rTypeName.pData ); +} +//__________________________________________________________________________________________________ +inline TypeDescription::~TypeDescription() +{ + if (_pTypeDescr) + typelib_typedescription_release( _pTypeDescr ); +} +//__________________________________________________________________________________________________ +inline TypeDescription & TypeDescription::operator =( typelib_TypeDescription * pTypeDescr ) +{ + if (_pTypeDescr) + typelib_typedescription_release( _pTypeDescr ); + if (_pTypeDescr = pTypeDescr) + typelib_typedescription_acquire( _pTypeDescr ); + return *this; +} +//__________________________________________________________________________________________________ +inline sal_Bool TypeDescription::equals( const typelib_TypeDescription * pTypeDescr ) const +{ + return (_pTypeDescr && pTypeDescr && + typelib_typedescription_equals( _pTypeDescr, pTypeDescr )); +} +//__________________________________________________________________________________________________ +inline void TypeDescription::makeComplete() const +{ + if (_pTypeDescr && !_pTypeDescr->bComplete) + ::typelib_typedescription_complete( &_pTypeDescr ); +} + +} +} +} +} + +#endif diff --git a/cppu/inc/typelib/uik.h b/cppu/inc/typelib/uik.h new file mode 100644 index 000000000000..7012817625f9 --- /dev/null +++ b/cppu/inc/typelib/uik.h @@ -0,0 +1,92 @@ +/************************************************************************* + * + * $RCSfile: uik.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TYPELIB_UIK_H_ +#define _TYPELIB_UIK_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifdef SAL_W32 +# pragma pack(push, 8) +#elif defined(SAL_OS2) +# pragma pack(8) +#endif + +/** Binary typelib uik struct. + <br> +*/ +struct typelib_Uik +{ + sal_uInt32 m_Data1; + sal_uInt16 m_Data2; + sal_uInt16 m_Data3; + sal_uInt32 m_Data4; + sal_uInt32 m_Data5; +}; + +#ifdef SAL_W32 +# pragma pack(pop) +#elif defined(SAL_OS2) +# pragma pack() +#endif + +#endif diff --git a/cppu/inc/uno/any2.h b/cppu/inc/uno/any2.h new file mode 100644 index 000000000000..2cab2d06a446 --- /dev/null +++ b/cppu/inc/uno/any2.h @@ -0,0 +1,162 @@ +/************************************************************************* + * + * $RCSfile: any2.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_ANY2_H_ +#define _UNO_ANY2_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +typedef struct _typelib_TypeDescription typelib_TypeDescription; + +/** This is the binary specification of an UNO any. + <br> +*/ +typedef struct _uno_Any +{ + /** type of value<br> + */ + typelib_TypeDescriptionReference * pType; + /** pointer to value<br> + */ + void * pData; +} uno_Any; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + +/** Constructs an any with a given value. + Interfaces are acquired by the given callback function. + <br> + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_any_construct( + uno_Any * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire ); +/** Constructs an any with a given value. + Interfaces are acquired by the given callback function. + <br> + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_any_construct( + uno_Any * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire ); + +/** Constructs an any with a given value and converts/ maps interfaces. + <br> + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pTypeDescr type description of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +SAL_DLLEXPORT void SAL_CALL uno_any_constructAndConvert( + uno_Any * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_Mapping * mapping ); +/** Constructs an any with a given value and converts/ maps interfaces. + <br> + @param pDest pointer memory of destination any + @param pSource pointer to source value; defaults (0) to default constructed value + @param pType type of value; defaults (0) to void + @param mapping mapping to convert/ map interfaces +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_any_constructAndConvert( + uno_Any * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, + uno_Mapping * mapping ); + +/** Destructs an any. + <br> + @param pValue pointer to any + @param release function called each time an interface needs to be released. defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_any_destruct( + uno_Any * pValue, uno_ReleaseFunc release ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppu/inc/uno/data.h b/cppu/inc/uno/data.h new file mode 100644 index 000000000000..83fd327fa9a1 --- /dev/null +++ b/cppu/inc/uno/data.h @@ -0,0 +1,245 @@ +/************************************************************************* + * + * $RCSfile: data.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_DATA_H_ +#define _UNO_DATA_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct _uno_Mapping uno_Mapping; +typedef struct _typelib_TypeDescription typelib_TypeDescription; +typedef struct _typelib_TypeDescriptionReference typelib_TypeDescriptionReference; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; + +/** Generic function pointer declaration to query for an interface. + <br> + @param pInterface interface + @param pTypedemanded interface type + @return interface pointer +*/ +typedef void * (SAL_CALL * uno_QueryInterfaceFunc)( + void * pInterface, typelib_TypeDescriptionReference * pType ); +/** Generic function pointer declaration to acquire an interface. + <br> + @param pInterface interface to be acquired +*/ +typedef void (SAL_CALL * uno_AcquireFunc)( void * pInterface ); +/** Generic function pointer declaration to release an interface. + <br> + @param pInterface interface to be release +*/ +typedef void (SAL_CALL * uno_ReleaseFunc)( void * pInterface ); + +/** Tests if two values are equal. May compare different types (e.g., short to long). + <br> + @param pVal1 pointer to a value + @param pVal1TypeDescr type description of pVal1 + @param pVal2 pointer to another value + @param pVal2TypeDescr type description of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL uno_equalData( + void * pVal1, typelib_TypeDescription * pVal1TypeDescr, + void * pVal2, typelib_TypeDescription * pVal2TypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ); +/** Tests if two values are equal. May compare different types (e.g., short to long). + <br> + @param pVal1 pointer to a value + @param pVal1Type type of pVal1 + @param pVal2 pointer to another value + @param pVal2Type type of pVal2 + @param queryInterface function called each time two interfaces are tested whether they belong + to the same object; defaults (0) to uno + @param release function to release queried interfaces; defaults (0) to uno + @return true if values are equal +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL uno_type_equalData( + void * pVal1, typelib_TypeDescriptionReference * pVal1Type, + void * pVal2, typelib_TypeDescriptionReference * pVal2Type, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ); + +/** Copy construct memory with given value. + The size of the destination value must be larger or equal to the size of the source value. + <br> + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_copyData( + void * pDest, void * pSource, typelib_TypeDescription * pTypeDescr, uno_AcquireFunc acquire ); +/** Copy construct memory with given value. + The size of the destination value must be larger or equal to the size of the source value. + <br> + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_copyData( + void * pDest, void * pSource, typelib_TypeDescriptionReference * pType, uno_AcquireFunc acquire ); + +/** Copy construct memory with given value. + The size of the destination value must be larger or equal to the size of the source value.<br> + Interfaces are converted/ mapped by mapping parameter. + <br> + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pTypeDescr type description of source + @param mapping mapping to convert/ map interfaces +*/ +SAL_DLLEXPORT void SAL_CALL uno_copyAndConvertData( + void * pDest, void * pSource, typelib_TypeDescription * pTypeDescr, uno_Mapping * mapping ); +/** Copy construct memory with given value. + The size of the destination value must be larger or equal to the size of the source value.<br> + Interfaces are converted/ mapped by mapping parameter. + <br> + @param pDest pointer to destination value memory + @param pSource pointer to source value + @param pType type of source + @param mapping mapping to convert/ map interfaces +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_copyAndConvertData( + void * pDest, void * pSource, typelib_TypeDescriptionReference * pType, uno_Mapping * mapping ); + +/** Destructs a given value; does <b>not</b> free its memory! + <br> + @param pValue value to be destructed + @param pTypeDescr type description of value + @param release function called each time an interface pointer needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_destructData( + void * pValue, typelib_TypeDescription * pTypeDescr, uno_ReleaseFunc release ); +/** Destructs a given value; does <b>not</b> free its memory! + <br> + @param pValue value to be destructed + @param pType type of value + @param release function called each time an interface pointer needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_destructData( + void * pValue, typelib_TypeDescriptionReference * pType, uno_ReleaseFunc release ); + +/** Default constructs a value. All simple types are set to 0, enums are set to their default + value. + <br> + @param pMem pointer to memory of value to be constructed + @param pTypeDescr type description of value to be constructed +*/ +SAL_DLLEXPORT void SAL_CALL uno_constructData( + void * pMem, typelib_TypeDescription * pTypeDescr ); +/** Default constructs a value. All simple types are set to 0, enums are set to their default + value. + <br> + @param pMem pointer to memory of value to be constructed + @param pType type of value to be constructed +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_constructData( + void * pMem, typelib_TypeDescriptionReference * pType ); + +/** Assigns a destination value with a source value. Widening conversion + <b>without</b> data loss is allowed (e.g., assigning a long with a short). + Assignment from any value to a value of type Any and vice versa is allowed. + <br> + @param pDest pointer to destination value + @param pDestTypeDescr type description of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned to default value + @param pSourceTypeDescr type destination of source value + @param queryInterface function called each time an interface needs to be queried; defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno + @param release function called each time an interface needs to be released; defaults (0) to uno + @return true if destination has been successfully assigned +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL uno_assignData( + void * pDest, typelib_TypeDescription * pDestTypeDescr, + void * pSource, typelib_TypeDescription * pSourceTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ); +/** Assigns a destination value with a source value. Widening conversion + <b>without</b> data loss is allowed (e.g., assigning a long with a short). + Assignment from any value to a value of type Any and vice versa is allowed. + <br> + @param pDest pointer to destination value + @param pDestType type of destination value + @param pSource pointer to source value; if 0, then destination value will be assigned to default value + @param pSourceType type of source value + @param queryInterface function called each time an interface needs to be queried; defaults (0) to uno + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno + @param release function called each time an interface needs to be released; defaults (0) to uno + @return true if destination has been successfully assigned +*/ +SAL_DLLEXPORT sal_Bool SAL_CALL uno_type_assignData( + void * pDest, typelib_TypeDescriptionReference * pDestType, + void * pSource, typelib_TypeDescriptionReference * pSourceType, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppu/inc/uno/dispatcher.h b/cppu/inc/uno/dispatcher.h new file mode 100644 index 000000000000..bfdf1ad4bfb7 --- /dev/null +++ b/cppu/inc/uno/dispatcher.h @@ -0,0 +1,134 @@ +/************************************************************************* + * + * $RCSfile: dispatcher.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_DISPATCHER_H_ +#define _UNO_DISPATCHER_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _RTL_USTRING_H_ +#include <rtl/ustring.h> +#endif + +#ifndef _UNO_ANY2_H_ +#include <uno/any2.h> +#endif + +typedef struct _typelib_TypeDescription typelib_TypeDescription; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; +typedef struct _uno_Interface uno_Interface; + +/** Function pointer declaration for the binary C uno dispatch function.<br> + Any pure out or return value will be constructed by the callee, iff + no exception is signalled.<br> + If an exception is signalled, the any *ppException is properly constructed + by the callee, otherwise the pointer *ppException is set to 0.<br> + An attribute <b>get</b> call is indicated by a non-null return pointer. + <br> + @param pUnoI uno interface the call is performed on + @param pMemberType member type description of a method or attribute + @param pReturn pointer to return value memory; + pointer may be undefined if void method, null if attribute set call. + @param pArgs an array of pointers to arguments values. + (remark: the value of an interface reference stores a + uno_interface *, so you get it by *(uno_Interface **)pArgs[n]) + @param ppException pointer to pointer to unconstructed any to signal an exception. +*/ +typedef void (SAL_CALL * uno_DispatchMethod)( + uno_Interface * pUnoI, + const typelib_TypeDescription * pMemberType, + void * pReturn, + void * pArgs[], + uno_Any ** ppException ); + +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +/** The binary C uno interface description. + <br> +*/ +typedef struct _uno_Interface +{ + /** Acquires uno interface. + <br> + @param pInterface uno interface + */ + void (SAL_CALL * acquire)( uno_Interface * pInterface ); + /** Releases uno interface. + <br> + @param pInterface uno interface + */ + void (SAL_CALL * release)( uno_Interface * pInterface ); + /** dispatch function<br> + */ + uno_DispatchMethod pDispatcher; +} uno_Interface; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + +#endif diff --git a/cppu/inc/uno/environment.h b/cppu/inc/uno/environment.h new file mode 100644 index 000000000000..552b1bb919b9 --- /dev/null +++ b/cppu/inc/uno/environment.h @@ -0,0 +1,344 @@ +/************************************************************************* + * + * $RCSfile: environment.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_ENVIRONMENT_H_ +#define _UNO_ENVIRONMENT_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _RTL_USTRING_H_ +#include <rtl/ustring.h> +#endif + +typedef struct _uno_Environment uno_Environment; +typedef struct _uno_ExtEnvironment uno_ExtEnvironment; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; + +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +/** The binary specification of an UNO environment. + <br> +*/ +typedef struct _uno_Environment +{ + /** reserved for future use (0 if not used)<br> + */ + void * pReserved; + + /** type name of environment<br> + */ + rtl_uString * pTypeName; + + /** free context pointer to be used for specific classes of environments + (e.g., a jvm pointer)<br> + */ + void * pContext; + + /** pointer to extended environment (interface registration functionality), if supported<br> + */ + uno_ExtEnvironment * pExtEnv; + + /** Acquires this environment. + <br> + @param pEnv this environment + */ + void (SAL_CALL * acquire)( uno_Environment * pEnv ); + + /** Releases this environment; + last release of environment will revoke the environment from runtime. + <br> + @param pEnv this environment + */ + void (SAL_CALL * release)( uno_Environment * pEnv ); + + /** Call this function to <b>explicitly</b> dispose this environment + (e.g., release all interfaces).<br> + You might want to call this function before shutting down due to a runtime error. + <br> + @param pEnv this environment + */ + void (SAL_CALL * dispose)( uno_Environment * pEnv ); + + /* ===== the following part will be late initialized by a matching bridge ===== * + * ===== and is NOT for public use. ===== */ + + /** <b>CALLBACK</b><br> + Disposing callback function pointer that can be set to get signalled before the environment + is destroyed. + <br> + @param pEnv environment that is being disposed + */ + void (SAL_CALL * environmentDisposing)( uno_Environment * pEnv ); +} uno_Environment; + +/** Generic function pointer declaration to free a proxy object if it is not needed + by the environment anymore.<br> + Any proxy object must register itself on first acquire() call and revoke + itself on last release() call. + This can happen several times because the environment caches proxy objects + until the environment <b>explicitly</b> frees the proxy object calling this function. + <br> + @param pEnv environment + @param pProxy proxy pointer +*/ +typedef void (SAL_CALL * uno_freeProxyFunc)( uno_ExtEnvironment * pEnv, void * pProxy ); + +/** Generic function pointer declaration to allocate memory. Used with getRegisteredInterfaces(). + <br> + @param nBytes amount of memory in bytes + @return pointer to allocated memory +*/ +typedef void * (SAL_CALL * uno_memAlloc)( sal_uInt32 nBytes ); + +/** The binary specification of an UNO environment supporting interface registration. + <br> +*/ +typedef struct _uno_ExtEnvironment +{ + /** inherits all members of an uno_Environment<br> + */ + uno_Environment aBase; + + /** Registers an interface of this environment. + <br> + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerInterface)( + uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Registers a proxy interface of this environment that can be reanimated and is + freed <b>explicitly</b> by this environment. + <br> + @param pEnv this environment + @param ppInterface inout parameter of interface to be registered + @param freeProxy function to free proxy object + @param pOId object id of interface + @param pTypeDescr type description of interface + */ + void (SAL_CALL * registerProxyInterface)( + uno_ExtEnvironment * pEnv, + void ** ppProxy, + uno_freeProxyFunc freeProxy, + rtl_uString * pOId, + typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Revokes an interface from this environment.<br> + You have to revoke <b>any</b> interface that has been registered via this method. + <br> + @param pEnv this environment + @param pInterface interface to be revoked + */ + void (SAL_CALL * revokeInterface)( + uno_ExtEnvironment * pEnv, + void * pInterface ); + + /** Provides the object id of a given interface. + <br> + @param ppOut inout oid + @param pInterface interface of object + */ + void (SAL_CALL * getObjectIdentifier)( + uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, + void * pInterface ); + + /** Retrieves an interface identified by its object id and type from this environment. + Interfaces are retrieved in the same order as they are registered. + <br> + @param pEnv this environment + @param ppInterface inout parameter for the registered interface; (0) if none was found + @param pOId object id of interface to be retrieved + @param pTypeDescr type description of interface to be retrieved + */ + void (SAL_CALL * getRegisteredInterface)( + uno_ExtEnvironment * pEnv, + void ** ppInterface, + rtl_uString * pOId, + typelib_InterfaceTypeDescription * pTypeDescr ); + + /** Returns all currently registered interfaces of this environment. + The memory block allocated might be slightly larger than (*pnLen * sizeof(void *)). + <br> + @param pEnv this environment + @param pppInterfaces out param; pointer to array of interface pointers + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + */ + void (SAL_CALL * getRegisteredInterfaces)( + uno_ExtEnvironment * pEnv, + void *** pppInterfaces, + sal_Int32 * pnLen, + uno_memAlloc memAlloc ); + + + /* ===== the following part will be late initialized by a matching bridge ===== * + * ===== and is NOT for public use. ===== */ + + /** Computes an object id of the given interface; is called by the environment + implementation. + <br> + @param pEnv corresponding environment + @param ppOId out param: computed id + @param pInterface an interface + */ + void (SAL_CALL * computeObjectIdentifier)( + uno_ExtEnvironment * pEnv, + rtl_uString ** ppOId, void * pInterface ); + + /** Function to acquire an interface. + <br> + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * acquireInterface)( uno_ExtEnvironment * pEnv, void * pInterface ); + + /** Function to release an interface. + <br> + @param pEnv corresponding environment + @param pInterface an interface + */ + void (SAL_CALL * releaseInterface)( uno_ExtEnvironment * pEnv, void * pInterface ); +} uno_ExtEnvironment; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Function exported by some bridge library providing + acquireInterface(), releaseInterface(); may set a disposing callback. + <br> + @param pEnv environment to be initialized +*/ +typedef void (SAL_CALL * uno_initEnvironmentFunc)( uno_Environment * pEnv ); +#define UNO_INIT_ENVIRONMENT "uno_initEnvironment" + +/** Gets a specific environment. If the specified environment does + not exist, then a default one is created and registered. + The environment revokes itself on last release() call. + <br> + @param ppEnv inout parameter of environment; given environment will be released + @param pEnvTypeName type name of environment + @param pContext some context pointer (e.g., to distinguish java vm; set 0 if not needed) +*/ +SAL_DLLEXPORT void SAL_CALL uno_getEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvTypeName, void * pContext ); + +/** Gets all specified environments. Caller has to release returned environments and + free allocated memory. + <br> + @param pppEnvs out param; pointer to array of environments + @param pnLen out param; length of array + @param memAlloc function for allocating memory that is passed back + @param pEnvTypeName type name of environments; 0 defaults to all +*/ +SAL_DLLEXPORT void SAL_CALL uno_getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + rtl_uString * pEnvTypeName ); + +/** Creates an environment. The new environment is anonymous + (<b>NOT</b> publicly registered/ accessible). + <br> + @param ppEnv out parameter of environment; given environment will be released + @param pEnvTypeName name of environment + @param pContext context pointer (e.g., to distinguish java vm); set 0 if not needed +*/ +SAL_DLLEXPORT void SAL_CALL uno_createEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvTypeName, void * pContext ); + +/** Dumps out environment information, i.e. registered interfaces. + <br> + @param stream output stream (FILE *) + @param pEnv environment to be dumped + @param pFilter if not null, filters output +*/ +SAL_DLLEXPORT void SAL_CALL uno_dumpEnvironment( + void * stream, uno_Environment * pEnv, const sal_Char * pFilter ); +/** Dumps out environment information, i.e. registered interfaces. + <br> + @param stream output stream (FILE *) + @param pEnvTypeName type name of environment to be dumped + @param pFilter if not null, filters output +*/ +SAL_DLLEXPORT void SAL_CALL uno_dumpEnvironmentByName( + void * stream, rtl_uString * pEnvTypeName, const sal_Char * pFilter ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppu/inc/uno/environment.hxx b/cppu/inc/uno/environment.hxx new file mode 100644 index 000000000000..f8aa6ae3f6d7 --- /dev/null +++ b/cppu/inc/uno/environment.hxx @@ -0,0 +1,205 @@ +/************************************************************************* + * + * $RCSfile: environment.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_ENVIRONMENT_HXX_ +#define _UNO_ENVIRONMENT_HXX_ + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _UNO_ENVIRONMENT_H_ +#include <uno/environment.h> +#endif + + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** C++ wrapper for binary C uno_Environment. + <br> +*/ +class Environment +{ + /** binary C uno_Environment<br> + */ + uno_Environment * _pEnv; + +public: + /** Constructor: acquires given environment + <br> + @param pEnv environment + */ + inline Environment( uno_Environment * pEnv = 0 ); + + /** Copy constructor: acquires given environment + <br> + @param rEnv another environment + */ + inline Environment( const Environment & rEnv ); + + /** Destructor: + <br> + Releases a set environment. + */ + inline ~Environment(); + + /** Sets a given environment, i.e. acquires given one and releases a set one. + <br> + @param pEnv another environment + @return this environment + */ + inline Environment & SAL_CALL operator = ( uno_Environment * pEnv ); + /** Sets a given environment, i.e. acquires given one and releases a set one. + <br> + @param rEnv another environment + @return this environment + */ + inline Environment & SAL_CALL operator = ( const Environment & rEnv ) + { return operator = ( rEnv._pEnv ); } + + /** Provides <b>un</b>acquired pointer to the set C environment. + <br> + @return <b>un</b>acquired pointer to the C environment struct + */ + inline uno_Environment * SAL_CALL get() const + { return _pEnv; } + + /** Gets type name of set environment. + <br> + @return type name of set environment + */ + inline ::rtl::OUString SAL_CALL getTypeName() const + { return _pEnv->pTypeName; } + + /** Gets free context pointer of set environment. + <br> + @return free context pointer of set environment + */ + inline void * SAL_CALL getContext() const + { return _pEnv->pContext; } + + /** Tests if a environment is set. + <br> + @return true, if a environment is set, false otherwise + */ + inline sal_Bool SAL_CALL is() const + { return (_pEnv != 0); } + + /** Releases a set environment. + <br> + */ + inline void SAL_CALL clear(); +}; +//__________________________________________________________________________________________________ +inline Environment::Environment( uno_Environment * pEnv ) + : _pEnv( pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} +//__________________________________________________________________________________________________ +inline Environment::Environment( const Environment & rEnv ) + : _pEnv( rEnv._pEnv ) +{ + if (_pEnv) + (*_pEnv->acquire)( _pEnv ); +} +//__________________________________________________________________________________________________ +inline Environment::~Environment() +{ + if (_pEnv) + (*_pEnv->release)( _pEnv ); +} +//__________________________________________________________________________________________________ +inline void Environment::clear() +{ + if (_pEnv) + { + (*_pEnv->release)( _pEnv ); + _pEnv = 0; + } +} +//__________________________________________________________________________________________________ +inline Environment & Environment::operator = ( uno_Environment * pEnv ) +{ + if (pEnv) + (*pEnv->acquire)( pEnv ); + if (_pEnv) + (*_pEnv->release)( _pEnv ); + _pEnv = pEnv; + return *this; +} + +} +} +} +} + +#endif diff --git a/cppu/inc/uno/lbnames.h b/cppu/inc/uno/lbnames.h new file mode 100644 index 000000000000..5ef7c0899c6d --- /dev/null +++ b/cppu/inc/uno/lbnames.h @@ -0,0 +1,86 @@ +/************************************************************************* + * + * $RCSfile: lbnames.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:51 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_LBNAMES_H_ +#define _UNO_LBNAMES_H_ + +/** A java 1.1 compatible virtual machine<br> +*/ +#define UNO_LB_JAVA_NAMESPACE java +#define UNO_LB_JAVA "java" +/** Miscrosoft VC++ 4.2 - 6.0 compiler; RTTI is not supported<br> +*/ +#define UNO_LB_MSCI_NAMESPACE msci +#define UNO_LB_MSCI "msci" +/** GCC 2 with RTTI or compatible; RTTI is not supported<br> +*/ +#define UNO_LB_GCC2_NAMESPACE gcc2 +#define UNO_LB_GCC2 "gcc2" +/** WorkShop Compiler 5.0 or compatible; RTTI is not supported<br> +*/ +#define UNO_LB_SUNPRO5_NAMESPACE sunpro5 +#define UNO_LB_SUNPRO5 "sunpro5" + +/** Binary C UNO<br> +*/ +#define UNO_LB_UNO_NAMESPACE uno +#define UNO_LB_UNO "uno" + +#endif diff --git a/cppu/inc/uno/mapping.h b/cppu/inc/uno/mapping.h new file mode 100644 index 000000000000..68937cfcdff6 --- /dev/null +++ b/cppu/inc/uno/mapping.h @@ -0,0 +1,233 @@ +/************************************************************************* + * + * $RCSfile: mapping.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_MAPPING_H_ +#define _UNO_MAPPING_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _RTL_USTRING_H_ +#include <rtl/ustring.h> +#endif + +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; +typedef struct _uno_Mapping uno_Mapping; +typedef struct _uno_Environment uno_Environment; + +/** Function pointer declaration to map an interface from one environment to another. + <br> + @param pMapping mapping + @param ppOut [inout] destination interface; existing interfaces are released + @param pInterface source interface + @param pInterfaceTypeDescr type description of the interface +*/ +typedef void (SAL_CALL * uno_MapInterfaceFunc)( + uno_Mapping * pMapping, + void ** ppOut, void * pInterface, + typelib_InterfaceTypeDescription * pInterfaceTypeDescr ); + + +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +/** This is the binary specification of a mapping. + <br> +*/ +typedef struct _uno_Mapping +{ + /** Acquires mapping + <br> + @param pMapping mapping + */ + void (SAL_CALL * acquire)( uno_Mapping * pMapping ); + /** Releases mapping. + The last release may unload bridges. + <br> + @param pMapping mapping + */ + void (SAL_CALL * release)( uno_Mapping * pMapping ); + + /** mapping function<br> + */ + uno_MapInterfaceFunc mapInterface; +} uno_Mapping; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Gets an interface mapping from one environment to another. + <br> + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment + @param pTo destination environment + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +SAL_DLLEXPORT void SAL_CALL uno_getMapping( + uno_Mapping ** ppMapping, + uno_Environment * pFrom, + uno_Environment * pTo, + rtl_uString * pAddPurpose ); + +/** Callback function pointer declaration to get a mapping. + <br> + @param ppMapping inout mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose +*/ +typedef void (SAL_CALL * uno_getMappingFunc)( + uno_Mapping ** ppMapping, + uno_Environment * pFrom, + uno_Environment * pTo, + rtl_uString * pAddPurpose ); + +/** Registers a callback being called each time a mapping is demanded. + <br> + @param pCallback callback function +*/ +SAL_DLLEXPORT void SAL_CALL uno_registerMappingCallback( + uno_getMappingFunc pCallback ); + +/** Revokes a mapping callback registration. + <br> + @param pCallback callback function +*/ +SAL_DLLEXPORT void SAL_CALL uno_revokeMappingCallback( + uno_getMappingFunc pCallback ); + +/** Function pointer declaration to free a mapping. + <br> + @param pMapping mapping to be freed +*/ +typedef void (SAL_CALL * uno_freeMappingFunc)( uno_Mapping * pMapping ); + +/** Registers a mapping.<br> + A mapping registers itself on first acquire and revokes itself on last release. + The given freeMapping function is called by the runtime to cleanup + any resources. + <br> + @param ppMapping inout mapping to be registered + @param freeMapping called by runtime to delete mapping + @param pFrom source environment + @param pTo destination environment + @param pAddPurpose additional purpose string; defaults to 0 +*/ +SAL_DLLEXPORT void SAL_CALL uno_registerMapping( + uno_Mapping ** ppMapping, uno_freeMappingFunc freeMapping, + uno_Environment * pFrom, uno_Environment * pTo, rtl_uString * pAddPurpose ); + +/** Revokes a mapping.<br> + A mapping registers itself on first acquire and revokes itself on last release. + <br> + @param pMapping mapping to be revoked +*/ +SAL_DLLEXPORT void SAL_CALL uno_revokeMapping( + uno_Mapping * pMapping ); + +/** Gets an interface mapping from one language environment to another by + corresponding environment type names. + <br> + @param ppMapping [inout] mapping; existing mapping will be released + @param pFrom source environment type name + @param pTo destination environment type name + (interfaces resulting in mapInterface() call can be used + in this language environment) + @param pAddPurpose additional purpose of mapping (e.g., protocolling); defaults to 0 (none) +*/ +SAL_DLLEXPORT void SAL_CALL uno_getMappingByName( + uno_Mapping ** ppMapping, + rtl_uString * pFrom, + rtl_uString * pTo, + rtl_uString * pAddPurpose ); + +/* symbol exported by each language binding library */ +#define UNO_EXT_GETMAPPING "uno_ext_getMapping" + +/** Function pointer declaration to get a mapping from a loaded bridge.<br> + Bridges export a function called <b>uno_ext_getMapping</b> of this signature. + <br> + @param ppMapping [inout] mapping; existing mapping will be released + @pFrom source environment + @pTo destination environment +*/ +typedef void (SAL_CALL * uno_ext_getMappingFunc)( + uno_Mapping ** ppMapping, + uno_Environment * pFrom, + uno_Environment * pTo ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppu/inc/uno/mapping.hxx b/cppu/inc/uno/mapping.hxx new file mode 100644 index 000000000000..1b784cbb595d --- /dev/null +++ b/cppu/inc/uno/mapping.hxx @@ -0,0 +1,333 @@ +/************************************************************************* + * + * $RCSfile: mapping.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_MAPPING_HXX_ +#define _UNO_MAPPING_HXX_ + +#ifndef _CPPU_MACROS_HXX_ +#include <cppu/macros.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _UNO_MAPPING_H_ +#include <uno/mapping.h> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif + +typedef struct _typelib_TypeDescription typelib_TypeDescription; +typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; +typedef struct _uno_Interface uno_Interface; + +/** */ //for docpp +namespace com +{ +/** */ //for docpp +namespace sun +{ +/** */ //for docpp +namespace star +{ +/** */ //for docpp +namespace uno +{ + +/** C++ wrapper for C uno_Mapping. + <br> +*/ +class Mapping +{ + uno_Mapping * _pMapping; + +public: + /** Holds a mapping from the specified source to the specified destination by + environment type names. + <br> + @param rFrom type name of source environment + @param rTo type name of destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Holds a mapping from the specified source to the specified destination. + <br> + @param pFrom source environment + @param pTo destination environment + @param rAddPurpose additional purpose + */ + inline Mapping( uno_Environment * pFrom, uno_Environment * pTo, + const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ); + + /** Constructor. + <br> + @param pMapping another mapping + */ + inline Mapping( uno_Mapping * pMapping = 0 ); + + /** Copy constructor. + <br> + @param rMapping another mapping + */ + inline Mapping( const Mapping & rMapping ); + + /** Destructor. + <br> + */ + inline ~Mapping(); + + /** Sets a given mapping. + <br> + @param pMapping another mapping + @return this mapping + */ + inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ); + /** Sets a given mapping. + <br> + @param rMapping another mapping + @return this mapping + */ + inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) + { return operator = ( rMapping._pMapping ); } + + /** Provides a pointer to the C mapping. The returned mapping is <b>not</b> acquired! + <br> + @return <b>un</b>acquired C mapping + */ + inline uno_Mapping * SAL_CALL get() const + { return _pMapping; } + + /** Tests if a mapping is set. + <br> + @return true if a mapping is set + */ + inline sal_Bool SAL_CALL is() const + { return (_pMapping != 0); } + + /** Releases a set mapping. + <br> + */ + inline void SAL_CALL clear(); + + /** Maps an interface from one environment to another. + <br> + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const; + /** Maps an interface from one environment to another. + <br> + @param pInterface source interface + @param pTypeDescr type description of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const + { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); } + + /** Maps an interface from one environment to another. + <br> + @param pInterface source interface + @param rType type of interface + @return mapped interface + */ + inline void * SAL_CALL mapInterface( void * pInterface, const ::com::sun::star::uno::Type & rType ) const; + + /** Maps an interface from one environment to another. + <br> + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); } + /** Maps an interface from one environment to another. + <br> + @param ppOut inout mapped interface + @param pInterface source interface + @param pTypeDescr type description of interface + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const + { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); } + + /** Maps an interface from one environment to another. + <br> + @param ppOut inout mapped interface + @param pInterface source interface + @param rType type of interface to be mapped + */ + inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const; +}; +//__________________________________________________________________________________________________ +inline Mapping::Mapping( const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, + const ::rtl::OUString & rAddPurpose ) + : _pMapping( 0 ) +{ + uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( uno_Environment * pFrom, uno_Environment * pTo, + const ::rtl::OUString & rAddPurpose ) + : _pMapping( 0 ) +{ + uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( uno_Mapping * pMapping ) + : _pMapping( pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} +//__________________________________________________________________________________________________ +inline Mapping::Mapping( const Mapping & rMapping ) + : _pMapping( rMapping._pMapping ) +{ + if (_pMapping) + (*_pMapping->acquire)( _pMapping ); +} +//__________________________________________________________________________________________________ +inline Mapping::~Mapping() +{ + if (_pMapping) + (*_pMapping->release)( _pMapping ); +} +//__________________________________________________________________________________________________ +inline void Mapping::clear() +{ + if (_pMapping) + { + (*_pMapping->release)( _pMapping ); + _pMapping = 0; + } +} +//__________________________________________________________________________________________________ +inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) +{ + if (pMapping) + (*pMapping->acquire)( pMapping ); + if (_pMapping) + (*_pMapping->release)( _pMapping ); + _pMapping = pMapping; + return *this; +} +//__________________________________________________________________________________________________ +inline void Mapping::mapInterface( void ** ppOut, void * pInterface, + const ::com::sun::star::uno::Type & rType ) const +{ + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + if (pTD) + { + (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD ); + TYPELIB_DANGER_RELEASE( pTD ); + } +} +//__________________________________________________________________________________________________ +inline void * Mapping::mapInterface( void * pInterface, + typelib_InterfaceTypeDescription * pTypeDescr ) const +{ + void * pOut = 0; + (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr ); + return pOut; +} +//__________________________________________________________________________________________________ +inline void * Mapping::mapInterface( void * pInterface, + const ::com::sun::star::uno::Type & rType ) const +{ + void * pOut = 0; + mapInterface( &pOut, pInterface, rType ); + return pOut; +} + +//-------------------------------------------------------------------------------------------------- +template< class C > +inline sal_Bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) +{ + Mapping aMapping( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( (void **)ppRet, pUnoI, ::getCppuType( ppRet ) ); + return (0 != *ppRet); +} +//-------------------------------------------------------------------------------------------------- +template< class C > +inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) +{ + Mapping aMapping( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) ); + OSL_ASSERT( aMapping.is() ); + aMapping.mapInterface( (void **)ppRet, x.get(), ::getCppuType( &x ) ); + return (0 != *ppRet); +} + +} +} +} +} + +#endif diff --git a/cppu/inc/uno/sequence2.h b/cppu/inc/uno/sequence2.h new file mode 100644 index 000000000000..828db39c9106 --- /dev/null +++ b/cppu/inc/uno/sequence2.h @@ -0,0 +1,192 @@ +/************************************************************************* + * + * $RCSfile: sequence2.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _UNO_SEQUENCE2_H_ +#define _UNO_SEQUENCE2_H_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef sal_Sequence uno_Sequence; + +/** Assign a sequence. + <br> + @param ppDest destinstaion sequence + @param pSource source sequence + @param pTypeDescr type description of the <B>sequence</B> and <b>not</b> of an element + @param release function called each time an interface needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ); +/** Assign a sequence. + <br> + @param ppDest destinstaion sequence + @param pSource source sequence + @param pType type of the <B>sequence</B> and <b>not</b> of an element + @param release function called each time an interface needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + typelib_TypeDescriptionReference * pType, + uno_ReleaseFunc release ); + +/** Constructs a new sequence with given elements. + <br> + @param ppSequence <b>out</b> parameter sequence + @param pTypeDescr type description of the <B>sequence</B> and <b>not</b> of an element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_sequence_construct( + uno_Sequence ** ppSequence, + typelib_TypeDescription * pTypeDescr, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ); +/** Constructs a new sequence with given elements. + <br> + @param ppSequence <b>out</b> parameter sequence + @param pType type of the <B>sequence</B> and <b>not</b> of an element + @param pElements if 0, then all elements are default constructed + @param len number of elements + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_construct( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pType, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ); + +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count of one. + <br> + @param ppSequence sequence + @param pTypeDescr type description of sequence + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno + @param release function called each time an interface needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_sequence_reference2One( + uno_Sequence ** ppSequence, + typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ); +/** Assures that the reference count of the given sequence is one. + Otherwise a new copy of the sequence is created with a reference count of one. + <br> + @param ppSequence sequence + @param pType type of sequence + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno + @param release function called each time an interface needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_reference2One( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ); + +/** Reallocates length of a sequence. This truncates a sequence or enlarges it + default constructing appended elements. + <br> + @param ppSequence sequence + @param pTypeDescr type description of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno + @param release function called each time an interface needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_sequence_realloc( + uno_Sequence ** ppSequence, + typelib_TypeDescription * pTypeDescr, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ); +/** Reallocates length of a sequence. This truncates a sequence or enlarges it + default constructing appended elements. + <br> + @param ppSequence sequence + @param pType type of sequence + @param nSize new size of sequence + @param acquire function called each time an interface needs to be acquired; defaults (0) to uno + @param release function called each time an interface needs to be released; defaults (0) to uno +*/ +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_realloc( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pType, + sal_Int32 nSize, + uno_AcquireFunc acquire, + uno_ReleaseFunc release ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cppu/inc/uno/threadpool.h b/cppu/inc/uno/threadpool.h new file mode 100644 index 000000000000..f27564607287 --- /dev/null +++ b/cppu/inc/uno/threadpool.h @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: threadpool.h,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <sal/types.h> +#include <rtl/byteseq.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/*** + * Thread identifier administration. + ***/ +/** + * Establishs an association between the current thread an the given thread identifier. + * There can be only one association at a time. The association must be broken by + * uno_releaseIdFromCurrentThread. + * This method is in general called by a bridge, that wants to bind a remote threadId + * to a new thread. + * + * @param pThreadId a byte sequence, that contains the identifier of the current thread. + * @return true, when the identifier was registered. <br> + * false, when the thread has already an identifier. The identifier was not + * altered. ( This is in general a bug ). <br> + **/ +SAL_DLLEXPORT sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ); + + +/** + * Get the identifier of the current thread. + * If no id has been bound for the thread before, a new one is generated and bound + * to the thread. + * For each call to uno_getIdOfCurrentThread, a call to uno_releaseIdFromCurrentThread + * must be done. + * + * @param ppThreadId [out] Contains the (acquired) ThreadId. + **/ +SAL_DLLEXPORT void SAL_CALL uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ); + + +/** + * If the internal refcount drops to zero, the association betwen threadId and + * thread is broken. + **/ +SAL_DLLEXPORT void SAL_CALL uno_releaseIdFromCurrentThread(); + + + + + + + +/** + * The threadpool + **/ +struct uno_threadpool_Handle; +/** + * Create a handle for the current thread before entering waiting pool. This method must be + * called, BEFORE the request is sent (to avoid a race between this thread and an incoming + * reply). + * This method shall only be called for synchronous requests. + * + * @param nDisposeId An ID, that uniquely identifies a bridge within the + * local process. The pointer to the bridge object should be used. + * @see uno_threadpool_disposeThreads + ***/ +SAL_DLLEXPORT struct uno_threadpool_Handle * SAL_CALL +uno_threadpool_createHandle( sal_Int64 nDisposeId ); + +/** + * This method is called to wait for a reply of a previously sent request. This is a + * blocking method. + * + * @param pHandle the handle that was previously created by uno_threadpool_createHandle. + * @param ppThreadSpecificData [out] the pointer, that was given by uno_threadpool_reply. + * If the threads for this bridge were disposed, + * *ppThreadSpecificData is null. + **/ +SAL_DLLEXPORT void SAL_CALL +uno_threadpool_enter( struct uno_threadpool_Handle * pHandle , void **ppThreadSpecificData ); + + +/** + * A request is put into a queue of waiting requests. This method is non-blocking. + * + * If the request is synchronous, it is first looked up, + * if there exists a handle with the given + * identifier. If this is the case, the thread is woken up and the doRequest + * function is called with the given pThreadSpecificData. If no handle exists, + * a new thread is created and the given threadId is bound to the new thread. + * + * If the request is asynchronous, it is put into the queue of asynchronous + * requests for the current threadid. The requests are always executed in a new + * thread, even if the thread with the given Id waiting in the pool. No Id is bound + * to the newly created thread. The responsibilty is left to the bridge ( if it + * wishes to bind a name). + * + * @param pThreadId The Id of thread, that initialized this request. (In general a + * remote threadid). + * @param pThreadSpecificData The argument, that doRequest will get. + * @param doRequest The function, that shall be called to execute the request. + * @param bIsOneway True, if the request is asynchrons. False, if it is synchronous + * + **/ +SAL_DLLEXPORT void SAL_CALL +uno_threadpool_putRequest( sal_Sequence *pThreadId, + void *pThreadSpecificData, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), + sal_Bool bIsOneway ); + + +/** + * A reply is put into the threadpool. There MUST be a thread with the given threadId waiting + * for this reply. This method is non-blocking. + * + * @param pThreadSpecificData The pointer, that is returned by uno_threadpool_enter. + **/ +SAL_DLLEXPORT void SAL_CALL +uno_threadpool_putReply( sal_Sequence *pThreadId, void *pThreadSpecificData ); + + +/** + * All threads, that are waiting on handles, that were created with + * nDisposeId, are forced out of the pool. + * (@see uno_threadpool_createTicket) These threads will return from + * uno_threadpool_enter with 0 == *ppThreadSpecificData. + * Later calls to uno_threadpool_enter with the given disposeId also + * return immeadiatly. + * + * @param nDisposeId Identfies the caller of uno_threadpool_createTicket + * + * This function is called i.e. by a bridge, that is forced to dispose itself. + * When disposing of the bridge has finished, the bridge MUST call + * uno_threadpool_stopDisposeThreads. + **/ +SAL_DLLEXPORT void SAL_CALL +uno_threadpool_disposeThreads( sal_Int64 nDisposeId ); + + +/** + * Informs the threadpool, that no special treatment is needed for the given nDisposeId. + * This allows the threadpool to release internal resources + * and must be called after all threads originated from this bridge have returned. + * (This can in general be done in the bridge destructor). + * + * @param nDisposeId Identifies the caller of uno_threadpool_createTicket + * @see uno_threadpool_disposeThreads + **/ +SAL_DLLEXPORT void SAL_CALL +uno_threadpool_stopDisposeThreads( sal_Int64 nDisposeId ); + +#ifdef __cplusplus +} +#endif diff --git a/cppu/prj/d.lst b/cppu/prj/d.lst new file mode 100644 index 000000000000..18c002a150ac --- /dev/null +++ b/cppu/prj/d.lst @@ -0,0 +1,42 @@ +mkdir: %_DEST%\inc%_EXT%\cppu +mkdir: %_DEST%\inc%_EXT%\com +mkdir: %_DEST%\inc%_EXT%\com\sun +mkdir: %_DEST%\inc%_EXT%\com\sun\star +mkdir: %_DEST%\inc%_EXT%\com\sun\star\uno +mkdir: %_DEST%\inc%_EXT%\typelib +mkdir: %_DEST%\inc%_EXT%\uno + +..\inc\cppu\macros.hxx %_DEST%\inc%_EXT%\cppu\macros.hxx + +..\inc\com\sun\star\uno\Reference.h %_DEST%\inc%_EXT%\com\sun\star\uno\Reference.h +..\inc\com\sun\star\uno\Reference.hxx %_DEST%\inc%_EXT%\com\sun\star\uno\Reference.hxx +..\inc\com\sun\star\uno\Type.h %_DEST%\inc%_EXT%\com\sun\star\uno\Type.h +..\inc\com\sun\star\uno\Type.hxx %_DEST%\inc%_EXT%\com\sun\star\uno\Type.hxx +..\inc\com\sun\star\uno\Any.h %_DEST%\inc%_EXT%\com\sun\star\uno\Any.h +..\inc\com\sun\star\uno\Any.hxx %_DEST%\inc%_EXT%\com\sun\star\uno\Any.hxx +..\inc\com\sun\star\uno\Sequence.h %_DEST%\inc%_EXT%\com\sun\star\uno\Sequence.h +..\inc\com\sun\star\uno\Sequence.hxx %_DEST%\inc%_EXT%\com\sun\star\uno\Sequence.hxx +..\inc\com\sun\star\uno\genfunc.h %_DEST%\inc%_EXT%\com\sun\star\uno\genfunc.h +..\inc\com\sun\star\uno\genfunc.hxx %_DEST%\inc%_EXT%\com\sun\star\uno\genfunc.hxx + +..\inc\typelib\typeclass.h %_DEST%\inc%_EXT%\typelib\typeclass.h +..\inc\typelib\typedescription.h %_DEST%\inc%_EXT%\typelib\typedescription.h +..\inc\typelib\typedescription.hxx %_DEST%\inc%_EXT%\typelib\typedescription.hxx +..\inc\typelib\uik.h %_DEST%\inc%_EXT%\typelib\uik.h + +..\inc\uno\dispatcher.h %_DEST%\inc%_EXT%\uno\dispatcher.h +..\inc\uno\any2.h %_DEST%\inc%_EXT%\uno\any2.h +..\inc\uno\sequence2.h %_DEST%\inc%_EXT%\uno\sequence2.h +..\inc\uno\data.h %_DEST%\inc%_EXT%\uno\data.h +..\inc\uno\lbnames.h %_DEST%\inc%_EXT%\uno\lbnames.h +..\inc\uno\environment.h %_DEST%\inc%_EXT%\uno\environment.h +..\inc\uno\environment.hxx %_DEST%\inc%_EXT%\uno\environment.hxx +..\inc\uno\mapping.h %_DEST%\inc%_EXT%\uno\mapping.h +..\inc\uno\mapping.hxx %_DEST%\inc%_EXT%\uno\mapping.hxx +..\inc\uno\threadpool.h %_DEST%\inc%_EXT%\uno\threadpool.h + +..\%__SRC%\lib\icppu.lib %_DEST%\lib%_EXT%\icppu.lib +..\%__SRC%\bin\cppu* %_DEST%\bin%_EXT%\* +..\%__SRC%\lib\libcppu* %_DEST%\lib%_EXT%\* + +..\version.mk %_DEST%\inc%_EXT%\cppu\version.mk diff --git a/cppu/source/cppu/makefile.mk b/cppu/source/cppu/makefile.mk new file mode 100644 index 000000000000..79e2ee6f7557 --- /dev/null +++ b/cppu/source/cppu/makefile.mk @@ -0,0 +1,76 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME= cppu +TARGET= cppu_cppu + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +.INCLUDE : ..$/..$/util$/target.pmk +.INCLUDE : target.mk diff --git a/cppu/source/threadpool/jobqueue.cxx b/cppu/source/threadpool/jobqueue.cxx new file mode 100644 index 000000000000..46f263042221 --- /dev/null +++ b/cppu/source/threadpool/jobqueue.cxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * $RCSfile: jobqueue.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "jobqueue.hxx" +#include "threadpool.hxx" + +#include <osl/diagnose.h> + +using namespace ::osl; + +namespace cppu_threadpool { + + JobQueue::JobQueue( sal_Bool bAsynchron ) : + m_cndWait( osl_createCondition() ), + m_bSuspended( sal_False ), + m_nToDo( 0 ) + { + osl_resetCondition( m_cndWait ); + } + + JobQueue::~JobQueue() + { + osl_destroyCondition( m_cndWait ); + } + + + void JobQueue::add( void *pThreadSpecificData , + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ) ) + { + MutexGuard guard( m_mutex ); + Job job = { pThreadSpecificData , doRequest }; + m_lstJob.push_back( job ); + if( ! m_bSuspended ) + { + osl_setCondition( m_cndWait ); + } + m_nToDo ++; + } + + void *JobQueue::enter( sal_Int64 nDisposeId , sal_Bool bReturnWhenNoJob ) + { + void *pReturn = 0; + { + // synchronize with the dispose calls + MutexGuard guard( m_mutex ); + if( DisposedCallerAdmin::getInstance()->isDisposed( nDisposeId ) ) + { + return 0; + } + m_lstCallstack.push_front( nDisposeId ); + } + + + while( sal_True ) + { + if( bReturnWhenNoJob ) + { + MutexGuard guard( m_mutex ); + if( m_lstJob.empty() ) + { + break; + } + } + + osl_waitCondition( m_cndWait , 0 ); + + struct Job job={0,0}; + { + // synchronize with add and dispose calls + MutexGuard guard( m_mutex ); + + if( 0 == m_lstCallstack.front() ) + { + // disposed ! + break; + } + + OSL_ASSERT( ! m_lstJob.empty() ); + if( ! m_lstJob.empty() ) + { + job = m_lstJob.front(); + m_lstJob.pop_front(); + } + if( m_lstJob.empty() ) + { + osl_resetCondition( m_cndWait ); + } + } + + if( job.doRequest ) + { + job.doRequest( job.pThreadSpecificData ); + m_nToDo --; + } + else + { + m_nToDo --; + pReturn = job.pThreadSpecificData; + break; + } + } + + { + // synchronize with the dispose calls + MutexGuard guard( m_mutex ); + m_lstCallstack.pop_front(); + } + + return pReturn; + } + + void JobQueue::dispose( sal_Int64 nDisposeId ) + { + MutexGuard guard( m_mutex ); + for( CallStackList::iterator ii = m_lstCallstack.begin() ; + ii != m_lstCallstack.end() ; + ++ii ) + { + if( (*ii) == nDisposeId ) + { + (*ii) = 0; + } + } + + if( !m_lstCallstack.empty() && ! m_lstCallstack.front() ) + { + // The thread is waiting for a disposed pCallerId, let it go + osl_setCondition( m_cndWait ); + } + } + + void JobQueue::suspend() + { + MutexGuard guard( m_mutex ); + m_bSuspended = sal_True; + } + + void JobQueue::resume() + { + MutexGuard guard( m_mutex ); + m_bSuspended = sal_False; + if( ! m_lstJob.empty() ) + { + osl_setCondition( m_cndWait ); + } + } + + sal_Bool JobQueue::isEmpty() + { + MutexGuard guard( m_mutex ); + return m_lstJob.empty(); + } + + sal_Bool JobQueue::isCallstackEmpty() + { + MutexGuard guard( m_mutex ); + return m_lstCallstack.empty(); + } + + sal_Bool JobQueue::isBusy() + { + return m_nToDo > 0; + } + + +} diff --git a/cppu/source/threadpool/jobqueue.hxx b/cppu/source/threadpool/jobqueue.hxx new file mode 100644 index 000000000000..53ba018a71a5 --- /dev/null +++ b/cppu/source/threadpool/jobqueue.hxx @@ -0,0 +1,112 @@ +/************************************************************************* + * + * $RCSfile: jobqueue.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CPPU_THREADPOOL_JOBQUEUE_HXX_ +#define _CPPU_THREADPOOL_JOBQUEUE_HXX_ + +#include <list> + +#include <osl/types.h> +#include <osl/conditn.h> +#include <osl/mutex.hxx> + +namespace cppu_threadpool +{ + struct Job + { + void *pThreadSpecificData; + void ( SAL_CALL *doRequest ) ( void * ); + }; + + typedef ::std::list < struct Job > JobList; + + typedef ::std::list < sal_Int64 > CallStackList; + + class JobQueue + { + public: + JobQueue( sal_Bool bAsynchron ); + ~JobQueue(); + + void add( void *pThreadSpecificData , + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ) ); + + void *enter( sal_Int64 nDisposeId , sal_Bool bReturnWhenNoJob = sal_False ); + void dispose( sal_Int64 nDisposeId ); + + void suspend(); + void resume(); + + sal_Bool isEmpty(); + sal_Bool isCallstackEmpty(); + sal_Bool isBusy(); + + private: + ::osl::Mutex m_mutex; + JobList m_lstJob; + CallStackList m_lstCallstack; + sal_Int32 m_nToDo; + sal_Bool m_bSuspended; + oslCondition m_cndWait; + }; +} + +#endif diff --git a/cppu/source/threadpool/makefile.mk b/cppu/source/threadpool/makefile.mk new file mode 100644 index 000000000000..7a82725ba517 --- /dev/null +++ b/cppu/source/threadpool/makefile.mk @@ -0,0 +1,88 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=cppu +TARGET=cppu_threadpool + +# --- Settings ----------------------------------------------------- + +.INCLUDE : ..$/..$/util$/makefile.pmk +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# ------------------------------------------------------------------ + +SLOFILES=\ + $(SLO)$/threadpool.obj\ + $(SLO)$/jobqueue.obj\ + $(SLO)$/thread.obj\ + $(SLO)$/threadident.obj + +# $(SLO)$/threadpool.obj \ +# $(SLO)$/process.obj \ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : ..$/..$/util$/target.pmk +.INCLUDE : target.mk diff --git a/cppu/source/threadpool/thread.cxx b/cppu/source/threadpool/thread.cxx new file mode 100644 index 000000000000..9d006ff142f2 --- /dev/null +++ b/cppu/source/threadpool/thread.cxx @@ -0,0 +1,170 @@ +/************************************************************************* + * + * $RCSfile: thread.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <stdio.h> +#include <osl/diagnose.h> +#include <uno/threadpool.h> + +#include "thread.hxx" +#include "jobqueue.hxx" +#include "threadpool.hxx" + + +extern "C" { + +void SAL_CALL cppu_requestThreadWorker( void *pVoid ) +{ + ::cppu_threadpool::ORequestThread *pThread = ( ::cppu_threadpool::ORequestThread * ) pVoid; + + pThread->run(); + pThread->onTerminated(); +} + +} +namespace cppu_threadpool { + + ORequestThread::ORequestThread( JobQueue *pQueue, + const ByteSequence &aThreadId, + sal_Bool bAsynchron ) + : m_pQueue( pQueue ) + , m_thread( 0 ) + , m_aThreadId( aThreadId ) + , m_bAsynchron( bAsynchron ) + { + + } + + + ORequestThread::~ORequestThread() + { + if (m_thread != 0) + { + osl_freeThreadHandle(m_thread); + } + } + + + void ORequestThread::setTask( JobQueue *pQueue, + const ByteSequence &aThreadId, + sal_Bool bAsynchron ) + { + m_pQueue = pQueue; + m_aThreadId = aThreadId; + m_bAsynchron = bAsynchron; + } + + sal_Bool ORequestThread::create() + { + OSL_ASSERT(m_thread == 0); // only one running thread per instance + + if ( m_thread = osl_createSuspendedThread( cppu_requestThreadWorker, (void*)this)) + { + osl_resumeThread( m_thread ); + } + + return m_thread != 0; + } + + void ORequestThread::onTerminated() + { + delete this; + } + + // hack during no proper threadlocalstorage support + void SAL_CALL destructCurrentId(); + + void ORequestThread::run() + { + while ( m_pQueue ) + { + if( ! m_bAsynchron ) + { + sal_Bool bReturn = uno_bindIdToCurrentThread( m_aThreadId.getHandle() ); + OSL_ASSERT( bReturn ); + } + + while( ! m_pQueue->isEmpty() ) + { + // Note : Oneways should not get a disposable disposeid, + // It does not make sense to dispose a call in this state. + // That's way we put it an disposeid, that can't be used otherwise. + m_pQueue->enter( (sal_Int64 ) this , sal_True ); + + if( m_pQueue->isEmpty() ) + { + ThreadPool::getInstance()->revokeQueue( m_aThreadId , m_bAsynchron ); + // Note : revokeQueue might have failed because m_pQueue.isEmpty() + // may be false (race). + } + } + + delete m_pQueue; + m_pQueue = 0; + + if( ! m_bAsynchron ) + { + uno_releaseIdFromCurrentThread(); + } + + cppu_threadpool::ThreadPool::getInstance()->waitInPool( this ); + } + destructCurrentId(); + } +} diff --git a/cppu/source/threadpool/thread.hxx b/cppu/source/threadpool/thread.hxx new file mode 100644 index 000000000000..0099150b71ee --- /dev/null +++ b/cppu/source/threadpool/thread.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * $RCSfile: thread.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CPPU_THREADPOOL_THREAD_HXX +#define _CPPU_THREADPOOL_THREAD_HXX + +#include <osl/types.h> +#include <osl/thread.h> + +#include "jobqueue.hxx" + +namespace cppu_threadpool { + + class JobQueue; + + //----------------------------------------- + // private thread class for the threadpool + // independent from vos + //----------------------------------------- + class ORequestThread + { + public: + ORequestThread( JobQueue * , + const ::rtl::ByteSequence &aThreadId, + sal_Bool bAsynchron ); + ~ORequestThread(); + + void setTask( JobQueue * , const ::rtl::ByteSequence & aThreadId , sal_Bool bAsynchron ); + + sal_Bool create(); + void onTerminated(); + void run(); + + private: + oslThread m_thread; + JobQueue *m_pQueue; + ::rtl::ByteSequence m_aThreadId; + sal_Bool m_bAsynchron; + }; + +} // end cppu_threadpool + + +#endif + diff --git a/cppu/source/threadpool/threadident.cxx b/cppu/source/threadpool/threadident.cxx new file mode 100644 index 000000000000..cedf69b6e869 --- /dev/null +++ b/cppu/source/threadpool/threadident.cxx @@ -0,0 +1,218 @@ +/************************************************************************* + * + * $RCSfile: threadident.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <stdio.h> +#include <assert.h> + +#include <list> +#include <hash_map> + +#include <osl/mutex.hxx> +#include <osl/thread.h> +#include <osl/diagnose.h> + +#include <rtl/process.h> +#include <rtl/byteseq.hxx> + +#include <uno/threadpool.h> + +#include <com/sun/star/uno/Sequence.hxx> + +using namespace ::std; +using namespace ::osl; +using namespace ::rtl; + + +static sal_Bool g_bInitialized; +static oslThreadKey g_key; + +namespace cppu_threadpool +{ +struct IdContainer +{ + sal_Sequence *pLocalThreadId; + sal_Int32 nRefCountOfCurrentId; + sal_Sequence *pCurrentId; +}; +} +using namespace cppu_threadpool; + +static inline oslThreadKey getKey() +{ + if( ! g_bInitialized ) + { + ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); + if( ! g_bInitialized ) + { + g_key = osl_createThreadKey(); + g_bInitialized = sal_True; + } + } + return g_key; +} + +static inline void createLocalId( sal_Sequence **ppThreadId ) +{ + rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 ); + *((sal_Int32*) ((*ppThreadId)->elements)) = osl_getThreadIdentifier(0); + + rtl_getGlobalProcessId( (sal_uInt8 * ) &( (*ppThreadId)->elements[4]) ); +} + + +static void SAL_CALL destructIdContainer( void *p ) +{ + if( p ) + { + IdContainer *pId = (IdContainer * ) p; + rtl_byte_sequence_release( pId->pLocalThreadId ); + rtl_byte_sequence_release( pId->pCurrentId ); + rtl_freeMemory( p ); + } +} + + +//-------------------------------------------------------- +// private hack as long as no proper threadlocal storage is provided +//-------------------------------------------------------- +namespace cppu_threadpool { +void SAL_CALL destructCurrentId() +{ + destructIdContainer( osl_getThreadKeyData( getKey() ) ); +} +} + + +extern "C" SAL_DLLEXPORT void SAL_CALL +uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) +{ + IdContainer * p = (IdContainer * ) osl_getThreadKeyData( getKey() ); + if( ! p ) + { + // first time, that the thread enters the bridge + createLocalId( ppThreadId ); + + // TODO + // note : this is a leak ! + IdContainer *p = (IdContainer *) rtl_allocateMemory( sizeof( IdContainer ) ); + p->pLocalThreadId = *ppThreadId; + p->pCurrentId = *ppThreadId; + p->nRefCountOfCurrentId = 1; + rtl_byte_sequence_acquire( p->pLocalThreadId ); + rtl_byte_sequence_acquire( p->pCurrentId ); + + OSL_VERIFY( osl_setThreadKeyData( getKey(), p ) ); + } + else + { + p->nRefCountOfCurrentId ++; + if( *ppThreadId ) + { + rtl_byte_sequence_release( *ppThreadId ); + } + *ppThreadId = p->pCurrentId; + rtl_byte_sequence_acquire( *ppThreadId ); + } +} + + +extern "C" SAL_DLLEXPORT void SAL_CALL uno_releaseIdFromCurrentThread() +{ + IdContainer *p = (IdContainer * ) osl_getThreadKeyData( getKey() ); + OSL_ASSERT( p ); + OSL_ASSERT( p->nRefCountOfCurrentId ); + + p->nRefCountOfCurrentId --; + if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) ) + { + rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId ); + } +} + +extern "C" SAL_DLLEXPORT sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) +{ + IdContainer *p = (IdContainer * ) osl_getThreadKeyData( getKey() ); + if( ! p ) + { + IdContainer *p = (IdContainer * ) rtl_allocateMemory( sizeof( IdContainer ) ); + + p->pLocalThreadId = 0; + createLocalId( &(p->pLocalThreadId) ); + p->nRefCountOfCurrentId = 1; + p->pCurrentId = pThreadId; + rtl_byte_sequence_acquire( p->pCurrentId ); + osl_setThreadKeyData( getKey() , p ); + } + else + { + OSL_ASSERT( 0 == p->nRefCountOfCurrentId ); + if( 0 == p->nRefCountOfCurrentId ) + { + rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId ); + p->nRefCountOfCurrentId ++; + } + else + { + return sal_False; + } + + } + return sal_True; +} diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx new file mode 100644 index 000000000000..7133eeb149e3 --- /dev/null +++ b/cppu/source/threadpool/threadpool.cxx @@ -0,0 +1,473 @@ +/************************************************************************* + * + * $RCSfile: threadpool.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> + +#include <osl/diagnose.h> +#include <osl/mutex.hxx> +#include <osl/thread.h> + +#include <uno/threadpool.h> + +#include "threadpool.hxx" +#include "thread.hxx" + +using namespace ::std; +using namespace ::osl; + +struct uno_threadpool_Handle +{ + /** + * Global Threadidentifier of the waiting thread + **/ + uno_threadpool_Handle( const ByteSequence &aThreadId_ , sal_Int64 nDisposeId_ ) + : aThreadId( aThreadId_ ) + , nDisposeId( nDisposeId_ ) + {} + + ByteSequence aThreadId; + sal_Int64 nDisposeId; +}; + +namespace cppu_threadpool +{ + DisposedCallerAdmin *DisposedCallerAdmin::getInstance() + { + static DisposedCallerAdmin *pDisposedCallerAdmin = 0; + if( ! pDisposedCallerAdmin ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pDisposedCallerAdmin ) + { + static DisposedCallerAdmin admin; + pDisposedCallerAdmin = &admin; + } + } + return pDisposedCallerAdmin; + } + + DisposedCallerAdmin::~DisposedCallerAdmin() + { +#ifdef DEBUG + if( !m_lst.empty() ) + { + printf( "DisposedCallerList : %d left\n" , m_lst.size( )); + } +#endif + } + + void DisposedCallerAdmin::dispose( sal_Int64 nDisposeId ) + { + MutexGuard guard( m_mutex ); + m_lst.push_back( nDisposeId ); + } + + void DisposedCallerAdmin::stopDisposing( sal_Int64 nDisposeId ) + { + MutexGuard guard( m_mutex ); + for( DisposedCallerList::iterator ii = m_lst.begin() ; + ii != m_lst.end() ; + ++ ii ) + { + if( (*ii) == nDisposeId ) + { + m_lst.erase( ii ); + break; + } + } + } + + sal_Bool DisposedCallerAdmin::isDisposed( sal_Int64 nDisposeId ) + { + MutexGuard guard( m_mutex ); + for( DisposedCallerList::iterator ii = m_lst.begin() ; + ii != m_lst.end() ; + ++ ii ) + { + if( (*ii) == nDisposeId ) + { + return sal_True; + } + } + return sal_False; + } + + + //------------------------------------------------------------------------------- + ThreadPool::~ThreadPool() + { +#ifdef DEBUG + if( m_mapQueue.size() ) + { + printf( "ThreadIdHashMap : %d left\n" , m_mapQueue.size() ); + } +#endif + } + ThreadPool *ThreadPool::getInstance() + { + static ThreadPool *pThreadPool = 0; + if( ! pThreadPool ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pThreadPool ) + { + static ThreadPool pool; + pThreadPool = &pool; + } + } + return pThreadPool; + } + + + void ThreadPool::dispose( sal_Int64 nDisposeId ) + { + DisposedCallerAdmin::getInstance()->dispose( nDisposeId ); + + MutexGuard guard( m_mutex ); + for( ThreadIdHashMap::iterator ii = m_mapQueue.begin() ; + ii != m_mapQueue.end(); + ++ii) + { + if( (*ii).second.first ) + { + (*ii).second.first->dispose( nDisposeId ); + } + if( (*ii).second.second ) + { + (*ii).second.second->dispose( nDisposeId ); + } + } + } + + void ThreadPool::stopDisposing( sal_Int64 nDisposeId ) + { + DisposedCallerAdmin::getInstance()->stopDisposing( nDisposeId ); + } + + /****************** + * This methods lets the thread wait a certain amount of time. If within this timespan + * a new request comes in, this thread is reused. This is done only to improve performance, + * it is not required for threadpool functionality. + ******************/ + void ThreadPool::waitInPool( ORequestThread * pThread ) + { + struct WaitingThread waitingThread; + waitingThread.condition = osl_createCondition(); + waitingThread.thread = pThread; + { + MutexGuard guard( m_mutexWaitingThreadList ); + m_lstThreads.push_front( &waitingThread ); + } + + // let the thread wait 2 seconds + osl_resetCondition( waitingThread.condition ); + TimeValue time = { 2 , 0 }; + osl_waitCondition( waitingThread.condition , &time ); + + { + MutexGuard guard ( m_mutexWaitingThreadList ); + if( waitingThread.thread ) + { + // thread wasn't reused, remove it from the list + WaitingThreadList::iterator ii = find( + m_lstThreads.begin(), m_lstThreads.end(), &waitingThread ); + OSL_ASSERT( ii != m_lstThreads.end() ); + m_lstThreads.erase( ii ); + } + } + + osl_destroyCondition( waitingThread.condition ); + } + + void ThreadPool::createThread( JobQueue *pQueue , + const ByteSequence &aThreadId, + sal_Bool bAsynchron ) + { + sal_Bool bCreate = sal_True; + { + // Can a thread be reused ? + MutexGuard guard( m_mutexWaitingThreadList ); + if( ! m_lstThreads.empty() ) + { + // inform the thread and let it go + struct WaitingThread *pWaitingThread = m_lstThreads.back(); + pWaitingThread->thread->setTask( pQueue , aThreadId , bAsynchron ); + pWaitingThread->thread = 0; + + // remove from list + m_lstThreads.pop_back(); + + // let the thread go + osl_setCondition( pWaitingThread->condition ); + bCreate = sal_False; + } + } + + if( bCreate ) + { + ORequestThread *pThread = + new ORequestThread( pQueue , aThreadId, bAsynchron); + // deletes itself ! + pThread->create(); + } + } + + sal_Bool ThreadPool::revokeQueue( const ByteSequence &aThreadId, sal_Bool bAsynchron ) + { + MutexGuard guard( m_mutex ); + + ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); + OSL_ASSERT( ii != m_mapQueue.end() ); + + if( bAsynchron ) + { + if( ! (*ii).second.second->isEmpty() ) + { + // another thread has put something into the queue + return sal_False; + } + + (*ii).second.second = 0; + if( (*ii).second.first ) + { + // all oneway request have been processed, now + // synchronus requests may go on + (*ii).second.first->resume(); + } + } + else + { + if( ! (*ii).second.first->isEmpty() ) + { + // another thread has put something into the queue + return sal_False; + } + (*ii).second.first = 0; + } + + if( 0 == (*ii).second.first && 0 == (*ii).second.second ) + { + m_mapQueue.erase( ii ); + } + + return sal_True; + } + + + void ThreadPool::addJob( + const ByteSequence &aThreadId , + sal_Bool bAsynchron, + void *pThreadSpecificData, + void ( SAL_CALL * doRequest ) ( void * ) ) + { + sal_Bool bCreateThread = sal_False; + JobQueue *pQueue = 0; + { + MutexGuard guard( m_mutex ); + + ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); + + if( ii == m_mapQueue.end() ) + { + m_mapQueue[ aThreadId ] = pair < JobQueue * , JobQueue * > ( 0 , 0 ); + ii = m_mapQueue.find( aThreadId ); + OSL_ASSERT( ii != m_mapQueue.end() ); + } + + if( bAsynchron ) + { + if( ! (*ii).second.second ) + { + (*ii).second.second = new JobQueue( bAsynchron ); + bCreateThread = sal_True; + } + pQueue = (*ii).second.second; + } + else + { + if( ! (*ii).second.first ) + { + (*ii).second.first = new JobQueue( bAsynchron ); + bCreateThread = sal_True; + } + pQueue = (*ii).second.first; + + if( (*ii).second.second && ( (*ii).second.second->isBusy() ) ) + { + pQueue->suspend(); + } + } + pQueue->add( pThreadSpecificData , doRequest ); + } + + if( bCreateThread ) + { + createThread( pQueue , aThreadId , bAsynchron); + } + } + + void ThreadPool::prepare( const ByteSequence &aThreadId ) + { + MutexGuard guard( m_mutex ); + + ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); + + if( ii == m_mapQueue.end() ) + { + JobQueue *p = new JobQueue( sal_False ); + m_mapQueue[ aThreadId ] = pair< JobQueue * , JobQueue * > ( p , 0 ); + } + else if( 0 == (*ii).second.first ) + { + (*ii).second.first = new JobQueue( sal_False ); + } + } + + void * ThreadPool::enter( const ByteSequence & aThreadId , sal_Int64 nDisposeId ) + { + JobQueue *pQueue = 0; + { + MutexGuard guard( m_mutex ); + + ThreadIdHashMap::iterator ii = m_mapQueue.find( aThreadId ); + + OSL_ASSERT( ii != m_mapQueue.end() ); + pQueue = (*ii).second.first; + } + + OSL_ASSERT( pQueue ); + void *pReturn = pQueue->enter( nDisposeId ); + + if( pQueue->isCallstackEmpty() ) + { + if( revokeQueue( aThreadId , sal_False) ) + { + // remove queue + delete pQueue; + } + } + return pReturn; + } +} + + +using namespace cppu_threadpool; + + +//------------------------------ +// +// The C-Interface +// +//------------------------------- +extern "C" SAL_DLLEXPORT void SAL_CALL uno_threadpool_putRequest( + sal_Sequence *pThreadId, void *pThreadSpecificData, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), sal_Bool bIsOneway ) +{ + ThreadPool::getInstance()->addJob( pThreadId, bIsOneway, pThreadSpecificData,doRequest ); +} + + + +extern "C" SAL_DLLEXPORT void SAL_CALL uno_threadpool_putReply( + sal_Sequence *pThreadId, void *pThreadSpecificData ) +{ + ThreadPool::getInstance()->addJob( pThreadId, sal_False, pThreadSpecificData, 0 ); +} + + +extern "C" SAL_DLLEXPORT struct uno_threadpool_Handle * SAL_CALL +uno_threadpool_createHandle( sal_Int64 nDisposeId ) +{ + sal_Sequence *pThreadId = 0; + uno_getIdOfCurrentThread( &pThreadId ); + + struct uno_threadpool_Handle *pHandle = new uno_threadpool_Handle( pThreadId, nDisposeId ); + ThreadPool::getInstance()->prepare( pThreadId ); + + rtl_byte_sequence_release( pThreadId ); + + return pHandle; +} + +extern "C" SAL_DLLEXPORT void SAL_CALL uno_threadpool_enter( + struct uno_threadpool_Handle *pHandle , void **ppThreadSpecificData ) +{ + OSL_ASSERT( ppThreadSpecificData ); + + *ppThreadSpecificData = + ThreadPool::getInstance()->enter( pHandle->aThreadId , pHandle->nDisposeId ); + + uno_releaseIdFromCurrentThread(); + delete pHandle; +} + + +extern "C" SAL_DLLEXPORT void SAL_CALL +uno_threadpool_disposeThreads( sal_Int64 nDisposeId ) +{ + ThreadPool::getInstance()->dispose( nDisposeId ); +} + +extern "C" SAL_DLLEXPORT void SAL_CALL +uno_threadpool_stopDisposeThreads( sal_Int64 nDisposeId ) +{ + ThreadPool::getInstance()->stopDisposing( nDisposeId ); +} diff --git a/cppu/source/threadpool/threadpool.hxx b/cppu/source/threadpool/threadpool.hxx new file mode 100644 index 000000000000..46b822b8b09b --- /dev/null +++ b/cppu/source/threadpool/threadpool.hxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * $RCSfile: threadpool.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <hash_map> + +#include <osl/conditn.h> + +#include <rtl/byteseq.hxx> + +#include "jobqueue.hxx" + + +using namespace ::rtl; +namespace cppu_threadpool { + class ORequestThread; + + struct EqualThreadId + { + sal_Int32 operator () ( const ::rtl::ByteSequence &a , const ::rtl::ByteSequence &b ) const + { + return a == b; + } + }; + + struct HashThreadId + { + sal_Int32 operator () ( const ::rtl::ByteSequence &a ) const + { + if( a.getLength() >= 4 ) + { + return *(sal_Int32 *)a.getConstArray(); + } + return 0; + } + }; + + typedef ::std::hash_map + < + ByteSequence, // ThreadID + ::std::pair < JobQueue * , JobQueue * >, + HashThreadId, + EqualThreadId + > ThreadIdHashMap; + + typedef ::std::list < sal_Int64 > DisposedCallerList; + + + struct WaitingThread + { + oslCondition condition; + ORequestThread *thread; + }; + + typedef ::std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList; + + class DisposedCallerAdmin + { + public: + ~DisposedCallerAdmin(); + + static DisposedCallerAdmin *getInstance(); + + void dispose( sal_Int64 nDisposeId ); + void stopDisposing( sal_Int64 nDisposeId ); + sal_Bool isDisposed( sal_Int64 nDisposeId ); + + private: + ::osl::Mutex m_mutex; + DisposedCallerList m_lst; + }; + + class ThreadPool + { + public: + ~ThreadPool(); + static ThreadPool *getInstance(); + + void dispose( sal_Int64 nDisposeId ); + void stopDisposing( sal_Int64 nDisposeId ); + + void addJob( const ByteSequence &aThreadId, + sal_Bool bAsynchron, + void *pThreadSpecificData, + void ( SAL_CALL * doRequest ) ( void * ) ); + + void prepare( const ByteSequence &aThreadId ); + void * enter( const ByteSequence &aThreadId, sal_Int64 nDisposeId ); + + /******** + * @return true, if queue could be succesfully revoked. + ********/ + sal_Bool revokeQueue( const ByteSequence & aThreadId , sal_Bool bAsynchron ); + + void waitInPool( ORequestThread *pThread ); + private: + void createThread( JobQueue *pQueue, const ByteSequence &aThreadId, sal_Bool bAsynchron); + + + ThreadIdHashMap m_mapQueue; + ::osl::Mutex m_mutex; + + ::osl::Mutex m_mutexWaitingThreadList; + WaitingThreadList m_lstThreads; + }; + +} // end namespace cppu_threadpool diff --git a/cppu/source/typelib/makefile.mk b/cppu/source/typelib/makefile.mk new file mode 100644 index 000000000000..4b10ad15e65b --- /dev/null +++ b/cppu/source/typelib/makefile.mk @@ -0,0 +1,81 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=cppu +TARGET=cppu_typelib + +# --- Settings ----------------------------------------------------- + +.INCLUDE : ..$/..$/util$/makefile.pmk +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/typelib.obj \ + $(SLO)$/static_types.obj + +.INCLUDE : ..$/..$/util$/target.pmk +.INCLUDE : target.mk diff --git a/cppu/source/typelib/static_types.cxx b/cppu/source/typelib/static_types.cxx new file mode 100644 index 000000000000..5705596a3352 --- /dev/null +++ b/cppu/source/typelib/static_types.cxx @@ -0,0 +1,626 @@ +/************************************************************************* + * + * $RCSfile: static_types.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <osl/mutex.hxx> +#include <osl/interlck.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/memory.h> + +#include <typelib/typedescription.h> + + +using namespace osl; +using namespace rtl; + +//------------------------------------------------------------------------ +sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( + const typelib_TypeDescription * pTypeDescription, + sal_Int32 nOffset, + sal_Int32 & rMaxIntegralTypeSize ); +//------------------------------------------------------------------------ +void SAL_CALL typelib_typedescription_newEmpty( + typelib_TypeDescription ** ppRet, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName ); +//----------------------------------------------------------------------------- +void SAL_CALL typelib_typedescriptionreference_getByName( + typelib_TypeDescriptionReference ** ppRet, + rtl_uString * pName ); + +extern "C" +{ + +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +/** + * The double member determin the alignment. + * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ). + * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type + * determine the aligment. + */ +struct AlignSize_Impl +{ + sal_Int16 nInt16; + double dDouble; +}; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + +// the value of the maximal alignment +static sal_Int32 nMaxAlignment = (sal_Int32)&((AlignSize_Impl *) 16)->dDouble - 16; + +static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment ) +{ + if( nRequestedAlignment > nMaxAlignment ) + nRequestedAlignment = nMaxAlignment; + return nRequestedAlignment; +} + +/** + * Calculate the new size of the struktur. + */ +static inline sal_Int32 newAlignedSize( sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment ) +{ + NeededAlignment = adjustAlignment( NeededAlignment ); + return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize; +} + +//-------------------------------------------------------------------------------------------------- +static Mutex & typelib_getStaticInitMutex() +{ + static Mutex * s_pMutex = 0; + if (! s_pMutex) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_pMutex) + { + static Mutex s_aMutex; + s_pMutex = &s_aMutex; + } + } + return *s_pMutex; +} + +//################################################################################################## +SAL_DLLEXPORT typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass( + typelib_TypeClass eTypeClass ) +{ + static typelib_TypeDescriptionReference * s_aTypes[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 }; + + if (! s_aTypes[eTypeClass]) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! s_aTypes[eTypeClass]) + { + static const char * s_aTypeNames[] = { + "void", "char", "boolean", "byte", + "short", "unsigned short", "long", "unsigned long", + "hyper", "unsigned hyper", "float", "double", + "string", "type", "any" }; + + switch (eTypeClass) + { + case typelib_TypeClass_EXCEPTION: + case typelib_TypeClass_INTERFACE: + { + // type + if (! s_aTypes[typelib_TypeClass_TYPE]) + { + OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("type") ); + ::typelib_typedescriptionreference_new( + &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData ); +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&s_aTypes[typelib_TypeClass_TYPE]->pReserved); +#endif + } + // any + if (! s_aTypes[typelib_TypeClass_ANY]) + { + OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("any") ); + ::typelib_typedescriptionreference_new( + &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData ); +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&s_aTypes[typelib_TypeClass_ANY]->pReserved); +#endif + } + // string + if (! s_aTypes[typelib_TypeClass_STRING]) + { + OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("string") ); + ::typelib_typedescriptionreference_new( + &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData ); +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&s_aTypes[typelib_TypeClass_STRING]->pReserved); +#endif + } + // XInterface + if (! s_aTypes[typelib_TypeClass_INTERFACE]) + { + OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") ); + + typelib_InterfaceTypeDescription * pTD = 0; + + typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 }; + OUString sMethodName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::queryInterface") ); + ::typelib_typedescriptionreference_new( + &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData ); + OUString sMethodName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::acquire") ); + ::typelib_typedescriptionreference_new( + &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData ); + OUString sMethodName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::release") ); + ::typelib_typedescriptionreference_new( + &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData ); + + ::typelib_typedescription_newInterface( + &pTD, sTypeName.pData, 0xe227a391, 0x33d6, 0x11d1, 0xaabe00a0, 0x249d5590, + 0, 3, pMembers ); + + ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD ); + ::typelib_typedescriptionreference_acquire( + s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef ); +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&s_aTypes[typelib_TypeClass_INTERFACE]->pReserved); +#endif + ::typelib_typedescription_release( (typelib_TypeDescription*)pTD ); + + ::typelib_typedescriptionreference_release( pMembers[0] ); + ::typelib_typedescriptionreference_release( pMembers[1] ); + ::typelib_typedescriptionreference_release( pMembers[2] ); + // Exception + OSL_ASSERT( ! s_aTypes[typelib_TypeClass_EXCEPTION] ); + { + typelib_TypeDescription * pTD = 0; + OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception") ); + + typelib_CompoundMember_Init aMembers[2]; + OUString sMemberType0( RTL_CONSTASCII_USTRINGPARAM("string") ); + OUString sMemberName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception::Message") ); + aMembers[0].eTypeClass = typelib_TypeClass_STRING; + aMembers[0].pTypeName = sMemberType0.pData; + aMembers[0].pMemberName = sMemberName0.pData; + OUString sMemberType1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") ); + OUString sMemberName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception::Context") ); + aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE; + aMembers[1].pTypeName = sMemberType1.pData; + aMembers[1].pMemberName = sMemberName1.pData; + + ::typelib_typedescription_new( + &pTD, typelib_TypeClass_EXCEPTION, sTypeName.pData, 0, 2, aMembers ); + typelib_typedescription_register( &pTD ); + typelib_typedescriptionreference_acquire( + s_aTypes[typelib_TypeClass_EXCEPTION] = pTD->pWeakRef ); +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&s_aTypes[typelib_TypeClass_EXCEPTION]->pReserved); +#endif + // RuntimeException + OUString sTypeName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") ); + ::typelib_typedescription_new( + &pTD, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 ); + ::typelib_typedescription_register( &pTD ); + ::typelib_typedescription_release( pTD ); + } + // XInterface members + typelib_InterfaceMethodTypeDescription * pMethod = 0; + typelib_Parameter_Init aParameters[1]; + OUString sParamName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::aType") ); + OUString sParamType0( RTL_CONSTASCII_USTRINGPARAM("type") ); + aParameters[0].pParamName = sParamName0.pData; + aParameters[0].eTypeClass = typelib_TypeClass_TYPE; + aParameters[0].pTypeName = sParamType0.pData; + aParameters[0].bIn = sal_True; + aParameters[0].bOut = sal_False; + rtl_uString * pExceptions[1]; + OUString sExceptionName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") ); + pExceptions[0] = sExceptionName0.pData; + OUString sReturnType0( RTL_CONSTASCII_USTRINGPARAM("any") ); + typelib_typedescription_newInterfaceMethod( + &pMethod, 0, sal_False, sMethodName0.pData, + typelib_TypeClass_ANY, sReturnType0.pData, + 1, aParameters, 1, pExceptions ); + ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod ); + + OUString sReturnType1( RTL_CONSTASCII_USTRINGPARAM("void") ); + ::typelib_typedescription_newInterfaceMethod( + &pMethod, 1, sal_True, sMethodName1.pData, + typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 ); + ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod ); + + ::typelib_typedescription_newInterfaceMethod( + &pMethod, 2, sal_True, sMethodName2.pData, + typelib_TypeClass_VOID, sReturnType1.pData, + 0, 0, 0, 0 ); + ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod ); + ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod ); + } + break; + } + default: + { + OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) ); + ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData ); +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&s_aTypes[eTypeClass]->pReserved); +#endif + } + } + } + } + return &s_aTypes[eTypeClass]; +} + +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL typelib_static_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeClass eTypeClass, const sal_Char * pTypeName ) +{ + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OUString aTypeName( OUString::createFromAscii( pTypeName ) ); + ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData ); + +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} + +// !for NOT REALLY WEAK TYPES only! +static inline typelib_TypeDescriptionReference * __getTypeByName( rtl_uString * pTypeName ) +{ + typelib_TypeDescriptionReference * pRef = 0; + ::typelib_typedescriptionreference_getByName( &pRef, pTypeName ); + if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td + return pRef; + else + return 0; +} + +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL typelib_static_sequence_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeDescriptionReference * pElementType ) +{ + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OUStringBuffer aBuf( 32 ); + aBuf.appendAscii( "[]" ); + aBuf.append( pElementType->pTypeName ); + OUString aTypeName( aBuf.makeStringAndClear() ); + + OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) ); + if (! (*ppRef = __getTypeByName( aTypeName.pData ))) + { + typelib_TypeDescription * pReg = 0; + ::typelib_typedescription_new( + &pReg, typelib_TypeClass_SEQUENCE, + aTypeName.pData, pElementType, 0, 0 ); + + ::typelib_typedescription_register( &pReg ); + *ppRef = (typelib_TypeDescriptionReference *)pReg; + OSL_ASSERT( *ppRef == pReg->pWeakRef ); + } +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} + +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL typelib_static_compound_type_init( + typelib_TypeDescriptionReference ** ppRef, + typelib_TypeClass eTypeClass, const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType, + sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers ) +{ + OSL_ENSHURE( typelib_TypeClass_STRUCT == eTypeClass || + typelib_TypeClass_EXCEPTION == eTypeClass, "### unexpected type class!" ); + + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) ); + OUString aTypeName( OUString::createFromAscii( pTypeName ) ); + if (! (*ppRef = __getTypeByName( aTypeName.pData ))) + { + typelib_CompoundTypeDescription * pComp = 0; + ::typelib_typedescription_newEmpty( + (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData ); + + sal_Int32 nOffset = 0; + if (pBaseType) + { + ::typelib_typedescriptionreference_getDescription( + (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType ); + OSL_ASSERT( pComp->pBaseTypeDescription ); + nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize; + OSL_ENSHURE( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, "### unexpected offset!" ); + } + + if (nMembers) + { + pComp->nMembers = nMembers; + pComp->pMemberOffsets = new sal_Int32[ nMembers ]; + pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ]; + for ( sal_Int32 i = 0 ; i < nMembers; ++i ) + { + ::typelib_typedescriptionreference_acquire( + pComp->ppTypeRefs[i] = ppMembers[i] ); + // write offset + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] ); + OSL_ENSHURE( pTD->nSize, "### void member?" ); + nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment ); + pComp->pMemberOffsets[i] = nOffset - pTD->nSize; + TYPELIB_DANGER_RELEASE( pTD ); + } + } + + typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp; + pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg; + // sizeof( void ) not allowed + pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment ); + pReg->nAlignment = adjustAlignment( pReg->nAlignment ); + pReg->bComplete = sal_False; + + ::typelib_typedescription_register( &pReg ); + *ppRef = (typelib_TypeDescriptionReference *)pReg; + OSL_ASSERT( *ppRef == pReg->pWeakRef ); + } +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL typelib_static_interface_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pBaseType ) +{ + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) ); + OUString aTypeName( OUString::createFromAscii( pTypeName ) ); + if (! (*ppRef = __getTypeByName( aTypeName.pData ))) + { + typelib_InterfaceTypeDescription * pIface = 0; + ::typelib_typedescription_newEmpty( + (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData ); + + if (pBaseType) + { + ::typelib_typedescriptionreference_getDescription( + (typelib_TypeDescription **)&pIface->pBaseTypeDescription, pBaseType ); + } + else + { + ::typelib_typedescriptionreference_getDescription( + (typelib_TypeDescription **)&pIface->pBaseTypeDescription, + * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) ); + } + OSL_ASSERT( pIface->pBaseTypeDescription ); + + typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface; + pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg; + // sizeof( void ) not allowed + pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment ); + + pReg->nAlignment = adjustAlignment( pReg->nAlignment ); + pReg->bComplete = sal_False; + + ::typelib_typedescription_register( &pReg ); + *ppRef = (typelib_TypeDescriptionReference *)pReg; + OSL_ASSERT( *ppRef == pReg->pWeakRef ); + } +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL typelib_static_enum_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + sal_Int32 nDefaultValue ) +{ + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) ); + OUString aTypeName( OUString::createFromAscii( pTypeName ) ); + if (! (*ppRef = __getTypeByName( aTypeName.pData ))) + { + typelib_TypeDescription * pReg = 0; + ::typelib_typedescription_newEmpty( + &pReg, typelib_TypeClass_ENUM, aTypeName.pData ); + typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg; + + pEnum->nDefaultEnumValue = nDefaultValue; + + pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg; + // sizeof( void ) not allowed + pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment ); + pReg->nAlignment = ::adjustAlignment( pReg->nAlignment ); + pReg->bComplete = sal_False; + + ::typelib_typedescription_register( &pReg ); + *ppRef = (typelib_TypeDescriptionReference *)pReg; + OSL_ASSERT( *ppRef == pReg->pWeakRef ); + } +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} + +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL typelib_static_union_type_init( + typelib_TypeDescriptionReference ** ppRef, + const sal_Char * pTypeName, + typelib_TypeDescriptionReference * pDiscriminantTypeRef, + sal_Int64 nDefaultDiscriminant, + typelib_TypeDescriptionReference * pDefaultTypeRef, + sal_Int32 nMembers, + sal_Int64 * pDiscriminants, + typelib_TypeDescriptionReference ** pMemberTypes ) +{ + if (! *ppRef) + { + MutexGuard aGuard( typelib_getStaticInitMutex() ); + if (! *ppRef) + { + OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_UNION) ); + OUString aTypeName( OUString::createFromAscii( pTypeName ) ); + if (! (*ppRef = __getTypeByName( aTypeName.pData ))) + { + typelib_UnionTypeDescription * pUnion = 0; + ::typelib_typedescription_newEmpty( + (typelib_TypeDescription **)&pUnion, typelib_TypeClass_UNION, aTypeName.pData ); + // discriminant type + ::typelib_typedescriptionreference_acquire( pUnion->pDiscriminantTypeRef = pDiscriminantTypeRef ); + + sal_Int32 nPos; + + pUnion->nMembers = nMembers; + // default discriminant + if (nMembers) + { + pUnion->pDiscriminants = new sal_Int64[ nMembers ]; + for ( nPos = nMembers; nPos--; ) + { + pUnion->pDiscriminants[nPos] = pDiscriminants[nPos]; + } + } + // default default discriminant + pUnion->nDefaultDiscriminant = nDefaultDiscriminant; + + // union member types + pUnion->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ]; + for ( nPos = nMembers; nPos--; ) + { + ::typelib_typedescriptionreference_acquire( + pUnion->ppTypeRefs[nPos] = pMemberTypes[nPos] ); + } + + // default union type + ::typelib_typedescriptionreference_acquire( pUnion->pDefaultTypeRef = pDefaultTypeRef ); + + typelib_TypeDescription * pReg = (typelib_TypeDescription *)pUnion; + + pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg; + pReg->nSize = typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment ); + pReg->nAlignment = adjustAlignment( pReg->nAlignment ); + pReg->bComplete = sal_False; + + ::typelib_typedescription_register( &pReg ); + *ppRef = (typelib_TypeDescriptionReference *)pReg; + OSL_ASSERT( *ppRef == pReg->pWeakRef ); + } +#ifndef CPPU_LEAK_STATIC_DATA + // another static ref + ++(*(sal_Int32 *)&(*ppRef)->pReserved); +#endif + } + } +} + +} diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx new file mode 100644 index 000000000000..573a4961cce3 --- /dev/null +++ b/cppu/source/typelib/typelib.cxx @@ -0,0 +1,2112 @@ +/************************************************************************* + * + * $RCSfile: typelib.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifdef CPPU_ASSERTIONS +#define CPPU_TRACE(x) OSL_TRACE(x) +#else +#define CPPU_TRACE(x) +#endif + +#include <stl/hash_map> +#include <stl/list> + +#include <stdarg.h> +#include <stdlib.h> +#include <memory.h> +#ifdef MACOSX +#include <sys/types.h> +#include <sys/malloc.h> +#else +#include <malloc.h> +#endif +#if defined(SOLARIS) +#include <alloca.h> +#endif +#include <new.h> + +#ifndef _OSL_INTERLCK_H_ +#include <osl/interlck.h> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _UNO_ANY2_H_ +#include <uno/any2.h> +#endif + +using namespace rtl; +using namespace std; +using namespace osl; + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#ifdef SAL_W32 +#pragma pack(push, 8) +#elif defined(SAL_OS2) +#pragma pack(8) +#endif + +/** + * The double member determin the alignment. + * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ). + * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type + * determine the aligment. + */ +struct AlignSize_Impl +{ + sal_Int16 nInt16; + double dDouble; +}; + +#ifdef SAL_W32 +#pragma pack(pop) +#elif defined(SAL_OS2) +#pragma pack() +#endif + +// the value of the maximal alignment +static sal_Int32 nMaxAlignment = (sal_Int32)&((AlignSize_Impl *) 16)->dDouble - 16; + +static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment ) +{ + if( nRequestedAlignment > nMaxAlignment ) + nRequestedAlignment = nMaxAlignment; + return nRequestedAlignment; +} + +/** + * Calculate the new size of the struktur. + */ +static inline sal_Int32 newAlignedSize( sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment ) +{ + NeededAlignment = adjustAlignment( NeededAlignment ); + return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize; +} + +inline sal_Bool reallyWeak( typelib_TypeClass eTypeClass ) +{ + return TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( eTypeClass ); +} + +inline sal_Int32 getDescriptionSize( typelib_TypeClass eTypeClass ) +{ + OSL_ASSERT( typelib_TypeClass_TYPEDEF != eTypeClass ); + + sal_Int32 nSize; + // The reference is the description + // if the description is empty, than it must be filled with + // the new description + switch( eTypeClass ) + { + case typelib_TypeClass_ARRAY: + case typelib_TypeClass_SEQUENCE: + nSize = (sal_Int32)sizeof( typelib_IndirectTypeDescription ); + break; + + case typelib_TypeClass_UNION: + nSize = (sal_Int32)sizeof( typelib_UnionTypeDescription ); + break; + + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + nSize = (sal_Int32)sizeof( typelib_CompoundTypeDescription ); + break; + + case typelib_TypeClass_ENUM: + nSize = (sal_Int32)sizeof( typelib_EnumTypeDescription ); + break; + + case typelib_TypeClass_INTERFACE: + nSize = (sal_Int32)sizeof( typelib_InterfaceTypeDescription ); + break; + + case typelib_TypeClass_INTERFACE_METHOD: + nSize = (sal_Int32)sizeof( typelib_InterfaceMethodTypeDescription ); + break; + + case typelib_TypeClass_INTERFACE_ATTRIBUTE: + nSize = (sal_Int32)sizeof( typelib_InterfaceAttributeTypeDescription ); + break; + + default: + nSize = (sal_Int32)sizeof( typelib_TypeDescription ); + } + return nSize; +} + + +//----------------------------------------------------------------------------- +void SAL_CALL typelib_typedescriptionreference_getByName( + typelib_TypeDescriptionReference ** ppRet, + rtl_uString * pName ); + +//----------------------------------------------------------------------------- +struct equalStr_Impl +{ + sal_Bool operator()(const sal_Unicode * const & s1, const sal_Unicode * const & s2) const + { return 0 == rtl_ustr_compare( s1, s2 ); } +}; + +//----------------------------------------------------------------------------- +struct hashStr_Impl +{ + size_t operator()(const sal_Unicode * const & s) const + { return rtl_ustr_hashCode( s ); } +}; + + +//----------------------------------------------------------------------------- +// Heavy hack, the const sal_Unicode * is hold by the typedescription reference +typedef hash_map< const sal_Unicode *, typelib_TypeDescriptionReference *, + hashStr_Impl, equalStr_Impl > WeakMap_Impl; + +typedef pair< void *, typelib_typedescription_Callback > CallbackEntry; +typedef list< CallbackEntry > CallbackSet_Impl; +typedef list< typelib_TypeDescription * > TypeDescriptionList_Impl; + +// # of cached elements +static sal_Int32 nCacheSize = 256; + +//----------------------------------------------------------------------------- +/** + * All members must set initial to 0 and no constructor is needed. So it + * doesn't care, when this class is static initialized.<BR> + */ +struct TypeDescriptor_Init_Impl +{ + //sal_Bool bDesctructorCalled; + // all type description references + WeakMap_Impl * pWeakMap; + // all type description callbacks + CallbackSet_Impl * pCallbacks; + // A cache to hold descriptions + TypeDescriptionList_Impl * pCache; + // The mutex to guard all type library accesses + Mutex * pMutex; + + inline Mutex & getMutex(); + + inline void callChain( + typelib_TypeDescription ** ppRet, rtl_uString * pName ); + +#ifdef CPPU_ASSERTIONS + // only for debugging + sal_Int32 nTypeDescriptionCount; + sal_Int32 nCompoundTypeDescriptionCount; + sal_Int32 nUnionTypeDescriptionCount; + sal_Int32 nIndirectTypeDescriptionCount; + sal_Int32 nEnumTypeDescriptionCount; + sal_Int32 nInterfaceMethodTypeDescriptionCount; + sal_Int32 nInterfaceAttributeTypeDescriptionCount; + sal_Int32 nInterfaceTypeDescriptionCount; + sal_Int32 nTypeDescriptionReferenceCount; +#endif + ~TypeDescriptor_Init_Impl(); +}; +//__________________________________________________________________________________________________ +inline Mutex & TypeDescriptor_Init_Impl::getMutex() +{ + if( !pMutex ) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if( !pMutex ) + pMutex = new Mutex(); + } + return * pMutex; +} +//__________________________________________________________________________________________________ +inline void TypeDescriptor_Init_Impl::callChain( + typelib_TypeDescription ** ppRet, rtl_uString * pName ) +{ + if (pCallbacks) + { + CallbackSet_Impl::const_iterator aIt = pCallbacks->begin(); + while( aIt != pCallbacks->end() ) + { + const CallbackEntry & rEntry = *aIt; + (*rEntry.second)( rEntry.first, ppRet, pName ); + if( *ppRet ) + return; + ++aIt; + } + } + if (*ppRet) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } +} + +// never called +#if defined(CPPU_LEAK_STATIC_DATA) && defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500) +static void dumb_sunpro5_must_have_dtor_stl_hashmap_code_if_compiled_with_minus_g() +{ + delete (WeakMap_Impl *)0xbeef1e; +} +#endif +//__________________________________________________________________________________________________ +TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() +{ +#ifndef CPPU_LEAK_STATIC_DATA + if( pCache ) + { + TypeDescriptionList_Impl::const_iterator aIt = pCache->begin(); + while( aIt != pCache->end() ) + { + typelib_typedescription_release( (*aIt) ); + aIt++; + } + delete pCache; + pCache = 0; + } + + if( pWeakMap ) + { + sal_Int32 nSize = pWeakMap->size(); + typelib_TypeDescriptionReference ** ppTDR = new typelib_TypeDescriptionReference *[ nSize ]; + // save al weak references + WeakMap_Impl::const_iterator aIt = pWeakMap->begin(); + sal_Int32 i = 0; + while( aIt != pWeakMap->end() ) + { + typelib_typedescriptionreference_acquire( ppTDR[i++] = (*aIt).second ); + ++aIt; + } + + for( i = 0; i < nSize; i++ ) + { + sal_Int32 nStaticCounts = (sal_Int32)ppTDR[i]->pReserved; + OSL_ASSERT( ppTDR[i]->nRefCount > nStaticCounts ); + ppTDR[i]->nRefCount -= nStaticCounts; + + if( ppTDR[i]->pType && !ppTDR[i]->pType->bOnDemand ) + { + ppTDR[i]->pType->bOnDemand = sal_True; + typelib_typedescription_release( ppTDR[i]->pType ); + } + typelib_typedescriptionreference_release( ppTDR[i] ); + } + + delete[] ppTDR; + +#ifdef CPPU_ASSERTIONS + aIt = pWeakMap->begin(); + while( aIt != pWeakMap->end() ) + { + CPPU_TRACE( "\n" ); + typelib_TypeDescriptionReference * pTDR = (*aIt).second; + if (pTDR) + { + OString aTypeName( OUStringToOString( pTDR->pTypeName, RTL_TEXTENCODING_ASCII_US ) ); + OString aRef( OString::valueOf( pTDR->nRefCount ) ); + CPPU_TRACE( "### remaining type: " ); + CPPU_TRACE( aTypeName.getStr() ); + CPPU_TRACE( ", ref count = " ); + CPPU_TRACE( aRef.getStr() ); + } + else + { + CPPU_TRACE( "### remaining null type entry!?" ); + } + ++aIt; + } +#endif + + delete pWeakMap; + pWeakMap = 0; + } +#ifdef CPPU_ASSERTIONS + OSL_ASSERT( nTypeDescriptionCount == 0 ); + OSL_ASSERT( nCompoundTypeDescriptionCount == 0 ); + OSL_ASSERT( nUnionTypeDescriptionCount == 0 ); + OSL_ASSERT( nIndirectTypeDescriptionCount == 0 ); + OSL_ASSERT( nEnumTypeDescriptionCount == 0 ); + OSL_ASSERT( nInterfaceMethodTypeDescriptionCount == 0 ); + OSL_ASSERT( nInterfaceAttributeTypeDescriptionCount == 0 ); + OSL_ASSERT( nInterfaceTypeDescriptionCount == 0 ); + OSL_ASSERT( nTypeDescriptionReferenceCount == 0 ); + + OSL_ASSERT( !pCallbacks || pCallbacks->empty() ); +#endif + delete pCallbacks; + pCallbacks = 0; +#endif // CPPU_LEAK_STATIC_DATA + + // todo: maybe into leak block + if( pMutex ) + { + delete pMutex; + pMutex = 0; + } +}; + +static TypeDescriptor_Init_Impl aInit; + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_registerCallback( + void * pContext, typelib_typedescription_Callback pCallback ) +{ + // todo mt safe: guard is no solution, can not acquire while calling callback! +// OslGuard aGuard( aInit.getMutex() ); + if( !aInit.pCallbacks ) + aInit.pCallbacks = new CallbackSet_Impl; + aInit.pCallbacks->push_back( CallbackEntry( pContext, pCallback ) ); +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_revokeCallback( + void * pContext, typelib_typedescription_Callback pCallback ) +{ + if( aInit.pCallbacks ) + { + // todo mt safe: guard is no solution, can not acquire while calling callback! +// OslGuard aGuard( aInit.getMutex() ); + CallbackEntry aEntry( pContext, pCallback ); + CallbackSet_Impl::iterator iPos( aInit.pCallbacks->begin() ); + while (!(iPos == aInit.pCallbacks->end())) + { + if (*iPos == aEntry) + { + aInit.pCallbacks->erase( iPos ); + iPos = aInit.pCallbacks->begin(); + } + else + { + ++iPos; + } + } + } +} + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( + const typelib_TypeDescription * pTypeDescription, + sal_Int32 nOffset, + sal_Int32 & rMaxIntegralTypeSize ); + +//------------------------------------------------------------------------ +inline static void typelib_typedescription_initTables( + typelib_TypeDescription * pTD ) +{ + typelib_InterfaceTypeDescription * pITD = (typelib_InterfaceTypeDescription *)pTD; + OSL_ASSERT( !pITD->nMapFunctionIndexToMemberIndex ); + { + sal_Bool * pReadWriteAttributes = (sal_Bool *)alloca( pITD->nAllMembers ); +// { +// MutexGuard aGuard( aInit.getMutex() ); + for ( sal_Int32 i = pITD->nAllMembers; i--; ) + { + pReadWriteAttributes[i] = sal_False; + if( typelib_TypeClass_INTERFACE_ATTRIBUTE == pITD->ppAllMembers[i]->eTypeClass ) + { + typelib_TypeDescription * pM = 0; + TYPELIB_DANGER_GET( &pM, pITD->ppAllMembers[i] ); + OSL_ASSERT( pM ); + if (pM) + { + pReadWriteAttributes[i] = !((typelib_InterfaceAttributeTypeDescription *)pM)->bReadOnly; + TYPELIB_DANGER_RELEASE( pM ); + } +#ifdef CPPU_ASSERTIONS + else + { + OString aStr( OUStringToOString( pITD->ppAllMembers[i]->pTypeName, RTL_TEXTENCODING_ASCII_US ) ); + CPPU_TRACE( "\n### cannot get attribute type description: " ); + CPPU_TRACE( aStr.getStr() ); + } +#endif + } + } +// } + + if( !pITD->nMapFunctionIndexToMemberIndex ) + { + // create the index table from member to function table + pITD->pMapMemberIndexToFunctionIndex = new sal_Int32[ pITD->nAllMembers ]; + sal_Int32 nAdditionalOffset = 0; // +1 for read/write attributes + sal_Int32 i; + for( i = 0; i < pITD->nAllMembers; i++ ) + { + // index to the get method of the attribute + pITD->pMapMemberIndexToFunctionIndex[i] = i + nAdditionalOffset; + // extra offset if it is a read/write attribute? + if( pReadWriteAttributes[i] ) + { + // a read/write attribute + nAdditionalOffset++; + } + } + + // create the index table from function to member table + pITD->pMapFunctionIndexToMemberIndex = new sal_Int32[ pITD->nAllMembers + nAdditionalOffset ]; + nAdditionalOffset = 0; // +1 for read/write attributes + for( i = 0; i < pITD->nAllMembers; i++ ) + { + // index to the get method of the attribute + pITD->pMapFunctionIndexToMemberIndex[i + nAdditionalOffset] = i; + // extra offset if it is a read/write attribute? + if( pReadWriteAttributes[i] ) + { + // a read/write attribute + pITD->pMapFunctionIndexToMemberIndex[i + ++nAdditionalOffset] = i; + } + } + // must be the last action after all initialization is done + pITD->nMapFunctionIndexToMemberIndex = pITD->nAllMembers + nAdditionalOffset; + } + } +} + +//------------------------------------------------------------------------ +void SAL_CALL typelib_typedescription_newEmpty( + typelib_TypeDescription ** ppRet, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName ) +{ + if( *ppRet ) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } + + OSL_ASSERT( typelib_TypeClass_TYPEDEF != eTypeClass ); + + typelib_TypeDescription * pRet; + switch( eTypeClass ) + { + case typelib_TypeClass_ARRAY: + case typelib_TypeClass_SEQUENCE: + { + typelib_IndirectTypeDescription * pTmp = new typelib_IndirectTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nIndirectTypeDescriptionCount ); +#endif + pTmp->pType = 0; + } + break; + + case typelib_TypeClass_UNION: + { + typelib_UnionTypeDescription * pTmp; + pTmp = new typelib_UnionTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nUnionTypeDescriptionCount ); +#endif + pTmp->nMembers = 0; + pTmp->pDiscriminantTypeRef = 0; + pTmp->pDiscriminants = 0; + pTmp->ppTypeRefs = 0; + pTmp->ppMemberNames = 0; + pTmp->pDefaultTypeRef = 0; + } + break; + + case typelib_TypeClass_EXCEPTION: + case typelib_TypeClass_STRUCT: + { + // FEATURE_EMPTYCLASS + typelib_CompoundTypeDescription * pTmp; + pTmp = new typelib_CompoundTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nCompoundTypeDescriptionCount ); +#endif + pTmp->pBaseTypeDescription = 0; + pTmp->nMembers = 0; + pTmp->pMemberOffsets = 0; + pTmp->ppTypeRefs = 0; + pTmp->ppMemberNames = 0; + } + break; + case typelib_TypeClass_ENUM: + { + typelib_EnumTypeDescription * pTmp = new typelib_EnumTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nEnumTypeDescriptionCount ); +#endif + pTmp->nDefaultEnumValue = 0; + pTmp->nEnumValues = 0; + pTmp->ppEnumNames = 0; + pTmp->pEnumValues = 0; + } + break; + + case typelib_TypeClass_INTERFACE: + { + typelib_InterfaceTypeDescription * pTmp = new typelib_InterfaceTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nInterfaceTypeDescriptionCount ); +#endif + pTmp->pBaseTypeDescription = 0; + pTmp->nMembers = 0; + pTmp->ppMembers = 0; + pTmp->nAllMembers = 0; + pTmp->ppAllMembers = 0; + pTmp->nMapFunctionIndexToMemberIndex = 0; + pTmp->pMapFunctionIndexToMemberIndex = 0; + pTmp->pMapMemberIndexToFunctionIndex= 0; + } + break; + + case typelib_TypeClass_INTERFACE_METHOD: + { + typelib_InterfaceMethodTypeDescription * pTmp = new typelib_InterfaceMethodTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nInterfaceMethodTypeDescriptionCount ); +#endif + pTmp->aBase.pMemberName = 0; + pTmp->pReturnTypeRef = 0; + pTmp->nParams = 0; + pTmp->pParams = 0; + pTmp->nExceptions = 0; + pTmp->ppExceptions = 0; + } + break; + + case typelib_TypeClass_INTERFACE_ATTRIBUTE: + { + typelib_InterfaceAttributeTypeDescription * pTmp = new typelib_InterfaceAttributeTypeDescription(); + pRet = (typelib_TypeDescription *)pTmp; +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nInterfaceAttributeTypeDescriptionCount ); +#endif + pTmp->aBase.pMemberName = 0; + pTmp->pAttributeTypeRef = 0; + } + break; + + default: + { + pRet = new typelib_TypeDescription(); +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nTypeDescriptionCount ); +#endif + } + } + + pRet->nRefCount = 1; // reference count is initially 1 + pRet->eTypeClass = eTypeClass; + pRet->pTypeName = 0; + pRet->pUniqueIdentifier = 0; + pRet->pReserved = 0; + rtl_uString_acquire( pRet->pTypeName = pTypeName ); + pRet->pSelf = pRet; + pRet->bComplete = sal_True; + pRet->nSize = 0; + pRet->nAlignment = 0; + pRet->pWeakRef = 0; + pRet->bOnDemand = sal_False; + *ppRet = pRet; +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_new( + typelib_TypeDescription ** ppRet, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pType, + sal_Int32 nMembers, + typelib_CompoundMember_Init * pMembers ) +{ + if (typelib_TypeClass_TYPEDEF == eTypeClass) + { + CPPU_TRACE( "### unexpected typedef!" ); + typelib_typedescriptionreference_getDescription( ppRet, pType ); + return; + } + + typelib_typedescription_newEmpty( ppRet, eTypeClass, pTypeName ); + + switch( eTypeClass ) + { + case typelib_TypeClass_ARRAY: + case typelib_TypeClass_SEQUENCE: + { + OSL_ASSERT( nMembers == 0 ); + typelib_typedescriptionreference_acquire( pType ); + ((typelib_IndirectTypeDescription *)*ppRet)->pType = pType; + } + break; + + case typelib_TypeClass_EXCEPTION: + case typelib_TypeClass_STRUCT: + { + // FEATURE_EMPTYCLASS + typelib_CompoundTypeDescription * pTmp = (typelib_CompoundTypeDescription*)*ppRet; + + sal_Int32 nOffset = 0; + if( pType ) + { + typelib_typedescriptionreference_getDescription( + (typelib_TypeDescription **)&pTmp->pBaseTypeDescription, pType ); + nOffset = ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nSize; + OSL_ENSHURE( newAlignedSize( 0, ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pTmp->pBaseTypeDescription)->nSize, "### unexpected offset!" ); + } + if( nMembers ) + { + pTmp->nMembers = nMembers; + pTmp->pMemberOffsets = new sal_Int32[ nMembers ]; + pTmp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ]; + pTmp->ppMemberNames = new rtl_uString *[ nMembers ]; + for( sal_Int32 i = 0 ; i < nMembers; i++ ) + { + // read the type name + pTmp->ppTypeRefs[i] = 0; + typelib_typedescriptionreference_new( + pTmp->ppTypeRefs +i, pMembers[i].eTypeClass, pMembers[i].pTypeName ); + // read the member name + rtl_uString_acquire( pTmp->ppMemberNames[i] = pMembers[i].pMemberName ); + // write offset + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, pTmp->ppTypeRefs[i] ); + OSL_ENSHURE( pTD->nSize, "### void member?" ); + nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment ); + pTmp->pMemberOffsets[i] = nOffset - pTD->nSize; + TYPELIB_DANGER_RELEASE( pTD ); + } + } + } + } + + if( !reallyWeak( eTypeClass ) ) + (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet; + if( eTypeClass != typelib_TypeClass_VOID ) + { + // sizeof( void ) not allowed + (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( (*ppRet), 0, (*ppRet)->nAlignment ); + (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment ); + } +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newUnion( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + typelib_TypeDescriptionReference * pDiscriminantTypeRef, + sal_Int64 nDefaultDiscriminant, + typelib_TypeDescriptionReference * pDefaultTypeRef, + sal_Int32 nMembers, + typelib_Union_Init * pMembers ) +{ + typelib_typedescription_newEmpty( ppRet, typelib_TypeClass_UNION, pTypeName ); + // discriminant type + typelib_UnionTypeDescription * pTmp = (typelib_UnionTypeDescription *)*ppRet; + typelib_typedescriptionreference_acquire( pTmp->pDiscriminantTypeRef = pDiscriminantTypeRef ); + + sal_Int32 nPos; + + pTmp->nMembers = nMembers; + // default discriminant + if (nMembers) + { + pTmp->pDiscriminants = new sal_Int64[ nMembers ]; + for ( nPos = nMembers; nPos--; ) + { + pTmp->pDiscriminants[nPos] = pMembers[nPos].nDiscriminant; + } + } + // default default discriminant + pTmp->nDefaultDiscriminant = nDefaultDiscriminant; + + // union member types + pTmp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ]; + for ( nPos = nMembers; nPos--; ) + { + typelib_typedescriptionreference_acquire( pTmp->ppTypeRefs[nPos] = pMembers[nPos].pTypeRef ); + } + // union member names + pTmp->ppMemberNames = new rtl_uString *[ nMembers ]; + for ( nPos = nMembers; nPos--; ) + { + rtl_uString_acquire( pTmp->ppMemberNames[nPos] = pMembers[nPos].pMemberName ); + } + + // default union type + typelib_typedescriptionreference_acquire( pTmp->pDefaultTypeRef = pDefaultTypeRef ); + + if (! reallyWeak( typelib_TypeClass_UNION )) + (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet; + (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( (*ppRet), 0, (*ppRet)->nAlignment ); + (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment ); +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newEnum( + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_Int32 nDefaultValue, + sal_Int32 nEnumValues, + rtl_uString ** ppEnumNames, + sal_Int32 * pEnumValues ) +{ + typelib_typedescription_newEmpty( ppRet, typelib_TypeClass_ENUM, pTypeName ); + typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)*ppRet; + + pEnum->nDefaultEnumValue = nDefaultValue; + pEnum->nEnumValues = nEnumValues; + pEnum->ppEnumNames = new rtl_uString * [ nEnumValues ]; + for ( sal_Int32 nPos = nEnumValues; nPos--; ) + { + rtl_uString_acquire( pEnum->ppEnumNames[nPos] = ppEnumNames[nPos] ); + } + pEnum->pEnumValues = new sal_Int32[ nEnumValues ]; + ::memcpy( pEnum->pEnumValues, pEnumValues, nEnumValues * sizeof(sal_Int32) ); + + (*ppRet)->pWeakRef = (typelib_TypeDescriptionReference *)*ppRet; + // sizeof( void ) not allowed + (*ppRet)->nSize = typelib_typedescription_getAlignedUnoSize( (*ppRet), 0, (*ppRet)->nAlignment ); + (*ppRet)->nAlignment = adjustAlignment( (*ppRet)->nAlignment ); +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newInterface( + typelib_InterfaceTypeDescription ** ppRet, + rtl_uString * pTypeName, + sal_uInt32 nUik1, sal_uInt16 nUik2, sal_uInt16 nUik3, sal_uInt32 nUik4, sal_uInt32 nUik5, + typelib_TypeDescriptionReference * pBaseInterface, + sal_Int32 nMembers, + typelib_TypeDescriptionReference ** ppMembers ) +{ + typelib_InterfaceTypeDescription * pITD = 0; + typelib_typedescription_newEmpty( + (typelib_TypeDescription **)&pITD, typelib_TypeClass_INTERFACE, pTypeName ); + + if( pBaseInterface ) + { + // set the base interface, may be 0 + ::typelib_typedescriptionreference_getDescription( + (typelib_TypeDescription **)&pITD->pBaseTypeDescription, pBaseInterface ); + OSL_ASSERT( pITD->pBaseTypeDescription ); + } + // set the + pITD->aUik.m_Data1 = nUik1; + pITD->aUik.m_Data2 = nUik2; + pITD->aUik.m_Data3 = nUik3; + pITD->aUik.m_Data4 = nUik4; + pITD->aUik.m_Data5 = nUik5; + + sal_Int32 nSuperMembers = pITD->pBaseTypeDescription ? pITD->pBaseTypeDescription->nAllMembers : 0; + pITD->nAllMembers = nMembers + nSuperMembers; + pITD->nMembers = nMembers; + + if( pITD->nAllMembers ) + { + // at minimum one member exist, allocate the memory + pITD->ppAllMembers = new typelib_TypeDescriptionReference *[ pITD->nAllMembers ]; + // the superclass references must not acquired + if( nSuperMembers ) + { + rtl_moveMemory( pITD->ppAllMembers, pITD->pBaseTypeDescription->ppAllMembers, + nSuperMembers * sizeof( void * ) ); + } + + if( nMembers ) + { + pITD->ppMembers = pITD->ppAllMembers + nSuperMembers; + } + + sal_Int32 n = 0; + // add own members + for( sal_Int32 i = nSuperMembers; i < pITD->nAllMembers; i++ ) + { + typelib_typedescriptionreference_acquire( ppMembers[n] ); + pITD->ppAllMembers[i] = ppMembers[n]; + ++n; + } + } + + typelib_TypeDescription * pTmp = (typelib_TypeDescription *)pITD; + if( !reallyWeak( typelib_TypeClass_INTERFACE ) ) + pTmp->pWeakRef = (typelib_TypeDescriptionReference *)pTmp; + pTmp->nSize = typelib_typedescription_getAlignedUnoSize( pTmp, 0, pTmp->nAlignment ); + pTmp->nAlignment = adjustAlignment( pTmp->nAlignment ); + pTmp->bComplete = sal_False; + + if (*ppRet) + ::typelib_typedescription_release( (typelib_TypeDescription *)*ppRet ); + *ppRet = pITD; +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newInterfaceMethod( + typelib_InterfaceMethodTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + sal_Bool bOneWay, + rtl_uString * pTypeName, + typelib_TypeClass eReturnTypeClass, + rtl_uString * pReturnTypeName, + sal_Int32 nParams, + typelib_Parameter_Init * pParams, + sal_Int32 nExceptions, + rtl_uString ** ppExceptionNames ) +{ + typelib_typedescription_newEmpty( + (typelib_TypeDescription **)ppRet, typelib_TypeClass_INTERFACE_METHOD, pTypeName ); + typelib_TypeDescription * pTmp = (typelib_TypeDescription *)*ppRet; + + sal_Int32 nOffset = rtl_ustr_lastIndexOfChar_WithLength( + pTypeName->buffer, pTypeName->length, ':' ); + + if( nOffset == -1 ) + { + // not found + rtl_uString_acquire( (*ppRet)->aBase.pMemberName = pTypeName ); + } + else + { + rtl_uString_newFromStr_WithLength( &(*ppRet)->aBase.pMemberName, + pTypeName->buffer + nOffset +1, + pTypeName->length - nOffset -1 ); + } + + (*ppRet)->aBase.nPosition = nAbsolutePosition; + (*ppRet)->bOneWay = bOneWay; + typelib_typedescriptionreference_new( &(*ppRet)->pReturnTypeRef, eReturnTypeClass, pReturnTypeName ); + (*ppRet)->nParams = nParams; + (*ppRet)->nExceptions = nExceptions; + if( nParams ) + { + (*ppRet)->pParams = new typelib_MethodParameter[ nParams ]; + + for( sal_Int32 i = 0; i < nParams; i++ ) + { + // get the name of the parameter + (*ppRet)->pParams[ i ].pName = 0; + rtl_uString_acquire( (*ppRet)->pParams[ i ].pName = pParams[i].pParamName ); + (*ppRet)->pParams[ i ].pTypeRef = 0; + // get the type name of the parameter and create the weak reference + typelib_typedescriptionreference_new( + &(*ppRet)->pParams[ i ].pTypeRef, pParams[i].eTypeClass, pParams[i].pTypeName ); + (*ppRet)->pParams[ i ].bIn = pParams[i].bIn; + (*ppRet)->pParams[ i ].bOut = pParams[i].bOut; + } + } + if( nExceptions ) + { + (*ppRet)->ppExceptions = new typelib_TypeDescriptionReference *[ nExceptions ]; + + for( sal_Int32 i = 0; i < nExceptions; i++ ) + { + (*ppRet)->ppExceptions[i] = 0; + typelib_typedescriptionreference_new( + (*ppRet)->ppExceptions + i, typelib_TypeClass_EXCEPTION, ppExceptionNames[i] ); + } + } + if( !reallyWeak( typelib_TypeClass_INTERFACE_METHOD ) ) + pTmp->pWeakRef = (typelib_TypeDescriptionReference *)pTmp; +} + + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_newInterfaceAttribute( + typelib_InterfaceAttributeTypeDescription ** ppRet, + sal_Int32 nAbsolutePosition, + rtl_uString * pTypeName, + typelib_TypeClass eAttributeTypeClass, + rtl_uString * pAttributeTypeName, + sal_Bool bReadOnly ) +{ + typelib_typedescription_newEmpty( + (typelib_TypeDescription **)ppRet, typelib_TypeClass_INTERFACE_ATTRIBUTE, pTypeName ); + typelib_TypeDescription * pTmp = (typelib_TypeDescription *)*ppRet; + + sal_Int32 nOffset = rtl_ustr_lastIndexOfChar_WithLength( + pTypeName->buffer, pTypeName->length, ':' ); + + if( nOffset == -1 ) + { + // not found + rtl_uString_acquire( (*ppRet)->aBase.pMemberName = pTypeName ); + } + else + { + rtl_uString_newFromStr_WithLength( &(*ppRet)->aBase.pMemberName, + pTypeName->buffer + nOffset +1, + pTypeName->length - nOffset -1 ); + } + + (*ppRet)->aBase.nPosition = nAbsolutePosition; + typelib_typedescriptionreference_new( &(*ppRet)->pAttributeTypeRef, eAttributeTypeClass, pAttributeTypeName ); + (*ppRet)->bReadOnly = bReadOnly; + + if( !reallyWeak( typelib_TypeClass_INTERFACE_ATTRIBUTE ) ) + pTmp->pWeakRef = (typelib_TypeDescriptionReference *)pTmp; +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_acquire( + typelib_TypeDescription * pTypeDescription ) +{ + osl_incrementInterlockedCount( &pTypeDescription->nRefCount ); +} + +//------------------------------------------------------------------------ +// frees anything except typelib_TypeDescription base! +static inline void typelib_typedescription_destructExtendedMembers( + typelib_TypeDescription * pTD ) +{ + OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTD->eTypeClass ); + + switch( pTD->eTypeClass ) + { + case typelib_TypeClass_ARRAY: + case typelib_TypeClass_SEQUENCE: + if( ((typelib_IndirectTypeDescription*)pTD)->pType ) + typelib_typedescriptionreference_release( ((typelib_IndirectTypeDescription*)pTD)->pType ); + break; + case typelib_TypeClass_UNION: + { + typelib_typedescriptionreference_release( + ((typelib_UnionTypeDescription *)pTD)->pDiscriminantTypeRef ); + typelib_typedescriptionreference_release( + ((typelib_UnionTypeDescription *)pTD)->pDefaultTypeRef ); + sal_Int32 nPos; + for ( nPos = ((typelib_UnionTypeDescription *)pTD)->nMembers; nPos--; ) + { + typelib_typedescriptionreference_release( + ((typelib_UnionTypeDescription *)pTD)->ppTypeRefs[nPos] ); + } + + for ( nPos = ((typelib_UnionTypeDescription *)pTD)->nMembers; nPos--; ) + { + rtl_uString_release( + ((typelib_UnionTypeDescription *)pTD)->ppMemberNames[nPos] ); + } + delete [] ((typelib_UnionTypeDescription *)pTD)->ppMemberNames; + delete [] ((typelib_UnionTypeDescription *)pTD)->pDiscriminants; + delete [] ((typelib_UnionTypeDescription *)pTD)->ppTypeRefs; + } + break; + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_CompoundTypeDescription * pCTD = (typelib_CompoundTypeDescription*)pTD; + if( pCTD->pBaseTypeDescription ) + typelib_typedescription_release( (typelib_TypeDescription *)pCTD->pBaseTypeDescription ); + sal_Int32 i; + for( i = 0; i < pCTD->nMembers; i++ ) + { + typelib_typedescriptionreference_release( pCTD->ppTypeRefs[i] ); + } + if (pCTD->ppMemberNames) + { + for ( i = 0; i < pCTD->nMembers; i++ ) + { + rtl_uString_release( pCTD->ppMemberNames[i] ); + } + delete [] pCTD->ppMemberNames; + } + delete [] pCTD->ppTypeRefs; + delete [] pCTD->pMemberOffsets; + } + break; + case typelib_TypeClass_INTERFACE: + { + typelib_InterfaceTypeDescription * pITD = (typelib_InterfaceTypeDescription*)pTD; + // The members in this array are not allocated + sal_Int32 nSuperMembers = pITD->pBaseTypeDescription ? pITD->pBaseTypeDescription->nAllMembers : 0; + // release only the descriptions of this class and not the one of the superclass + for( sal_Int32 i = nSuperMembers; i < pITD->nAllMembers; i++ ) + { + typelib_typedescriptionreference_release( pITD->ppAllMembers[i] ); + } + delete [] pITD->ppAllMembers; + delete [] pITD->pMapMemberIndexToFunctionIndex; + delete [] pITD->pMapFunctionIndexToMemberIndex; + if (pITD->pBaseTypeDescription) + typelib_typedescription_release( (typelib_TypeDescription *)pITD->pBaseTypeDescription ); + break; + } + case typelib_TypeClass_INTERFACE_METHOD: + { + typelib_InterfaceMethodTypeDescription * pIMTD = (typelib_InterfaceMethodTypeDescription*)pTD; + if( pIMTD->pReturnTypeRef ) + typelib_typedescriptionreference_release( pIMTD->pReturnTypeRef ); + sal_Int32 i; + for( i = 0; i < pIMTD->nParams; i++ ) + { + rtl_uString_release( pIMTD->pParams[ i ].pName ); + typelib_typedescriptionreference_release( pIMTD->pParams[ i ].pTypeRef ); + } + delete [] pIMTD->pParams; + for( i = 0; i < pIMTD->nExceptions; i++ ) + { + typelib_typedescriptionreference_release( pIMTD->ppExceptions[ i ] ); + } + delete [] pIMTD->ppExceptions; + rtl_uString_release( pIMTD->aBase.pMemberName ); + } + break; + case typelib_TypeClass_INTERFACE_ATTRIBUTE: + { + typelib_InterfaceAttributeTypeDescription * pIATD = (typelib_InterfaceAttributeTypeDescription*)pTD; + if( pIATD->pAttributeTypeRef ) + typelib_typedescriptionreference_release( pIATD->pAttributeTypeRef ); + if( pIATD->aBase.pMemberName ) + rtl_uString_release( pIATD->aBase.pMemberName ); + } + break; + case typelib_TypeClass_ENUM: + { + typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pTD; + for ( sal_Int32 nPos = pEnum->nEnumValues; nPos--; ) + { + rtl_uString_release( pEnum->ppEnumNames[nPos] ); + } + delete [] pEnum->ppEnumNames; + delete [] pEnum->pEnumValues; + } + break; + } +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_release( + typelib_TypeDescription * pTD ) +{ + OSL_ASSERT(pTD->nRefCount > 0); + + if( !osl_decrementInterlockedCount( &pTD->nRefCount ) ) + { + if( reallyWeak( pTD->eTypeClass ) ) + { + if( pTD->pWeakRef ) + { + { + MutexGuard aGuard( aInit.getMutex() ); + // remove this description from the weak reference + pTD->pWeakRef->pType = 0; + } + typelib_typedescriptionreference_release( pTD->pWeakRef ); + } + } + else + { + // this description is a reference too, so remove it from the hash table + if( aInit.pWeakMap ) + { + MutexGuard aGuard( aInit.getMutex() ); + WeakMap_Impl::iterator aIt = aInit.pWeakMap->find( (sal_Unicode*)pTD->pTypeName->buffer ); + if( aIt != aInit.pWeakMap->end() && (void *)(*aIt).second == (void *)pTD ) + { + // remove only if it contains the same object + aInit.pWeakMap->erase( aIt ); + } + } + } + + typelib_typedescription_destructExtendedMembers( pTD ); + rtl_uString_release( pTD->pTypeName ); + +#ifdef CPPU_ASSERTIONS + switch( pTD->eTypeClass ) + { + case typelib_TypeClass_ARRAY: + case typelib_TypeClass_SEQUENCE: + osl_decrementInterlockedCount( &aInit.nIndirectTypeDescriptionCount ); + break; + case typelib_TypeClass_UNION: + osl_decrementInterlockedCount( &aInit.nUnionTypeDescriptionCount ); + break; + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + osl_decrementInterlockedCount( &aInit.nCompoundTypeDescriptionCount ); + break; + case typelib_TypeClass_INTERFACE: + osl_decrementInterlockedCount( &aInit.nInterfaceTypeDescriptionCount ); + break; + case typelib_TypeClass_INTERFACE_METHOD: + osl_decrementInterlockedCount( &aInit.nInterfaceMethodTypeDescriptionCount ); + break; + case typelib_TypeClass_INTERFACE_ATTRIBUTE: + osl_decrementInterlockedCount( &aInit.nInterfaceAttributeTypeDescriptionCount ); + break; + case typelib_TypeClass_ENUM: + osl_decrementInterlockedCount( &aInit.nEnumTypeDescriptionCount ); + break; + default: + osl_decrementInterlockedCount( &aInit.nTypeDescriptionCount ); + } +#endif + + delete pTD; + } +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_register( + typelib_TypeDescription ** ppNewDescription ) +{ + // connect the description with the weak reference + ClearableMutexGuard aGuard( aInit.getMutex() ); + + typelib_TypeDescriptionReference * pTDR = 0; + typelib_typedescriptionreference_getByName( &pTDR, (*ppNewDescription)->pTypeName ); + + OSL_ASSERT( (*ppNewDescription)->pWeakRef || reallyWeak( (*ppNewDescription)->eTypeClass ) ); + if( pTDR ) + { + OSL_ASSERT( (*ppNewDescription)->eTypeClass == pTDR->eTypeClass ); + if( pTDR->pType ) + { + if (reallyWeak( pTDR->eTypeClass )) + { + // pRef->pType->pWeakRef == 0 means that the description is empty + if (pTDR->pType->pWeakRef) + { + if (osl_incrementInterlockedCount( &pTDR->pType->nRefCount ) > 1) + { + // The refence is incremented. The object cannot be destroyed. + // Release the guard at the earliest point. + aGuard.clear(); + ::typelib_typedescription_release( *ppNewDescription ); + *ppNewDescription = pTDR->pType; + ::typelib_typedescriptionreference_release( pTDR ); + return; + } + else + { + // destruction of this type in progress (another thread!) + osl_decrementInterlockedCount( &pTDR->pType->nRefCount ); + } + } + // take new descr + pTDR->pType = *ppNewDescription; + OSL_ASSERT( ! (*ppNewDescription)->pWeakRef ); + (*ppNewDescription)->pWeakRef = pTDR; + return; + } + // !reallyWeak + + if (((void *)pTDR != (void *)*ppNewDescription) && // if different + (!pTDR->pType->pWeakRef || // uninit: ref data only set + // new one is complete: + (!pTDR->pType->bComplete && (*ppNewDescription)->bComplete) || + // new one may be partly initialized interface (except of tables): + (typelib_TypeClass_INTERFACE == pTDR->pType->eTypeClass && + !((typelib_InterfaceTypeDescription *)pTDR->pType)->ppAllMembers && + (*(typelib_InterfaceTypeDescription **)ppNewDescription)->ppAllMembers))) + { + // uninitialized or incomplete + + if (pTDR->pType->pWeakRef) // if init + { + typelib_typedescription_destructExtendedMembers( pTDR->pType ); + } + + // pTDR->pType->pWeakRef == 0 means that the description is empty + // description is not weak and the not the same + sal_Int32 nSize = getDescriptionSize( (*ppNewDescription)->eTypeClass ); + + // copy all specific data for the descriptions + ::rtl_copyMemory( + pTDR->pType +1, + *ppNewDescription +1, + nSize - sizeof(typelib_TypeDescription) ); + + pTDR->pType->bComplete = (*ppNewDescription)->bComplete; + pTDR->pType->nSize = (*ppNewDescription)->nSize; + pTDR->pType->nAlignment = (*ppNewDescription)->nAlignment; + + ::rtl_zeroMemory( + *ppNewDescription +1, nSize - sizeof( typelib_TypeDescription ) ); + + if( pTDR->pType->bOnDemand && !(*ppNewDescription)->bOnDemand ) + { + // switch from OnDemand to !OnDemand, so the description must be acquired + typelib_typedescription_acquire( pTDR->pType ); + } + else if( !pTDR->pType->bOnDemand && (*ppNewDescription)->bOnDemand ) + { + // switch from !OnDemand to OnDemand, so the description must be relesed + typelib_typedescription_release( pTDR->pType ); + } + + pTDR->pType->bOnDemand = (*ppNewDescription)->bOnDemand; + // initialized + pTDR->pType->pWeakRef = pTDR; + } + + typelib_typedescription_release( *ppNewDescription ); + // pTDR was acquired by getByName(), so it must not be acquired again + *ppNewDescription = pTDR->pType; + return; + } + } + else if( reallyWeak( (*ppNewDescription)->eTypeClass) ) + { + typelib_typedescriptionreference_new( + &pTDR, (*ppNewDescription)->eTypeClass, (*ppNewDescription)->pTypeName ); + } + else + { + pTDR = (typelib_TypeDescriptionReference *)*ppNewDescription; + if( !aInit.pWeakMap ) + aInit.pWeakMap = new WeakMap_Impl; + + // description is the weak itself, so register it + (*aInit.pWeakMap)[pTDR->pTypeName->buffer] = pTDR; + OSL_ASSERT( (void *)*ppNewDescription == (void *)pTDR ); + } + + // By default this reference is not really weak. The reference hold the description + // and the description hold the reference. + if( !(*ppNewDescription)->bOnDemand ) + { + // nor OnDemand so the description must be acquired if registered + typelib_typedescription_acquire( *ppNewDescription ); + } + + pTDR->pType = *ppNewDescription; + (*ppNewDescription)->pWeakRef = pTDR; + OSL_ASSERT( rtl_ustr_compare( pTDR->pTypeName->buffer, (*ppNewDescription)->pTypeName->buffer ) == 0 ); + OSL_ASSERT( pTDR->eTypeClass == (*ppNewDescription)->eTypeClass ); +} + +//------------------------------------------------------------------------ +inline static sal_Bool type_equals( + typelib_TypeDescriptionReference * p1, typelib_TypeDescriptionReference * p2 ) +{ + return (p1 == p2 || + (p1->eTypeClass == p2->eTypeClass && + p1->pTypeName->length == p2->pTypeName->length && + rtl_ustr_compare( p1->pTypeName->buffer, p2->pTypeName->buffer ) == 0)); +} +extern "C" SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescription_equals( + const typelib_TypeDescription * p1, const typelib_TypeDescription * p2 ) +{ + return type_equals( + (typelib_TypeDescriptionReference *)p1, (typelib_TypeDescriptionReference *)p2 ); +} + +//------------------------------------------------------------------------ +sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize( + const typelib_TypeDescription * pTypeDescription, + sal_Int32 nOffset, + sal_Int32 & rMaxIntegralTypeSize ) +{ + sal_Int32 nSize; + if( pTypeDescription->nSize ) + { + // size and alignment are set + rMaxIntegralTypeSize = pTypeDescription->nAlignment; + nSize = pTypeDescription->nSize; + } + else + { + nSize = 0; + rMaxIntegralTypeSize = 1; + + OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTypeDescription->eTypeClass ); + + switch( pTypeDescription->eTypeClass ) + { + case typelib_TypeClass_INTERFACE: + // FEATURE_INTERFACE + nSize = rMaxIntegralTypeSize = sizeof( void * ); + break; + case typelib_TypeClass_UNION: + { + nSize = rMaxIntegralTypeSize = sizeof(sal_Int64); + for ( sal_Int32 nPos = ((typelib_UnionTypeDescription *)pTypeDescription)->nMembers; nPos--; ) + { + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, ((typelib_UnionTypeDescription *)pTypeDescription)->ppTypeRefs[nPos] ); + sal_Int32 nMaxIntegralTypeSize; + sal_Int32 nMemberSize = typelib_typedescription_getAlignedUnoSize( pTD, sizeof(sal_Int64), nMaxIntegralTypeSize ); + TYPELIB_DANGER_RELEASE( pTD ); + if (nSize < nMemberSize) + nSize = nMemberSize; + if (rMaxIntegralTypeSize < nMaxIntegralTypeSize) + rMaxIntegralTypeSize = nMaxIntegralTypeSize; + } + ((typelib_UnionTypeDescription *)pTypeDescription)->nValueOffset = rMaxIntegralTypeSize; + } + break; + case typelib_TypeClass_ENUM: + nSize = rMaxIntegralTypeSize = sizeof( typelib_TypeClass ); + break; + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + // FEATURE_EMPTYCLASS + { + typelib_CompoundTypeDescription * pTmp = (typelib_CompoundTypeDescription *)pTypeDescription; + sal_Int32 nStructSize = 0; + if( pTmp->pBaseTypeDescription ) + { + // inherit structs extends the base struct. + nStructSize = pTmp->pBaseTypeDescription->aBase.nSize; + rMaxIntegralTypeSize = pTmp->pBaseTypeDescription->aBase.nAlignment; + } + for( sal_Int32 i = 0; i < pTmp->nMembers; i++ ) + { + typelib_TypeDescription * pMemberType = 0; + typelib_TypeDescriptionReference * pMemberRef = pTmp->ppTypeRefs[i]; + + sal_Int32 nMaxIntegral; + if (pMemberRef->eTypeClass == typelib_TypeClass_INTERFACE || + pMemberRef->eTypeClass == typelib_TypeClass_SEQUENCE) + { + nMaxIntegral = sizeof(void *); + nStructSize = newAlignedSize( nStructSize, nMaxIntegral, nMaxIntegral ); + } + else + { + TYPELIB_DANGER_GET( &pMemberType, pMemberRef ); + nStructSize = typelib_typedescription_getAlignedUnoSize( + pMemberType, nStructSize, nMaxIntegral ); + TYPELIB_DANGER_RELEASE( pMemberType ); + } + if( nMaxIntegral > rMaxIntegralTypeSize ) + rMaxIntegralTypeSize = nMaxIntegral; + } + // Example: A { double; int; } structure has a size of 16 instead of 10. The + // compiler must follow this rule if it is possible to access memvers in arrays through: + // (Element *)((char *)pArray + sizeof( Element ) * ElementPos) + nStructSize = (nStructSize + rMaxIntegralTypeSize -1) + / rMaxIntegralTypeSize * rMaxIntegralTypeSize; + nSize += nStructSize; + } + break; + case typelib_TypeClass_ARRAY: + OSL_ENSHURE( sal_False, "not implemented" ); + break; + case typelib_TypeClass_SEQUENCE: + nSize = rMaxIntegralTypeSize = sizeof( void * ); + break; + case typelib_TypeClass_ANY: + // FEATURE_ANY + nSize = sizeof( uno_Any ); + rMaxIntegralTypeSize = sizeof( void * ); + break; + case typelib_TypeClass_TYPE: + nSize = rMaxIntegralTypeSize = sizeof( typelib_TypeDescriptionReference * ); + break; + case typelib_TypeClass_BOOLEAN: + nSize = rMaxIntegralTypeSize = sizeof( sal_Bool ); + break; + case typelib_TypeClass_CHAR: + nSize = rMaxIntegralTypeSize = sizeof( sal_Unicode ); + break; + case typelib_TypeClass_STRING: + // FEATURE_STRING + nSize = rMaxIntegralTypeSize = sizeof( rtl_uString * ); + break; + case typelib_TypeClass_FLOAT: + nSize = rMaxIntegralTypeSize = sizeof( float ); + break; + case typelib_TypeClass_DOUBLE: + nSize = rMaxIntegralTypeSize = sizeof( double ); + break; + + case typelib_TypeClass_BYTE: + nSize = rMaxIntegralTypeSize = sizeof( sal_Int8 ); + break; + + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + nSize = rMaxIntegralTypeSize = sizeof( sal_Int16 ); + break; + + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + nSize = rMaxIntegralTypeSize = sizeof( sal_Int32 ); + break; + + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + nSize = rMaxIntegralTypeSize = sizeof( sal_Int64 ); + break; + + case typelib_TypeClass_UNKNOWN: + case typelib_TypeClass_SERVICE: + case typelib_TypeClass_MODULE: + default: + OSL_ENSHURE( sal_False, "not convertable type" ); + }; + } + + return newAlignedSize( nOffset, nSize, rMaxIntegralTypeSize ); +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescription_getByName( + typelib_TypeDescription ** ppRet, rtl_uString * pName ) +{ + if( *ppRet ) + { + typelib_typedescription_release( (*ppRet) ); + *ppRet = 0; + } + + static sal_Bool bInited = sal_False; + + if( !bInited ) + { + // guard against multi thread access + MutexGuard aGuard( aInit.getMutex() ); + if( !bInited ) + { + // avoid recursion during the next ...new calls + bInited = sal_True; + + rtl_uString * pTypeName = 0; + typelib_TypeDescription * pType = 0; + rtl_uString_newFromAscii( &pTypeName, "type" ); + typelib_typedescription_new( &pType, typelib_TypeClass_TYPE, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "void" ); + typelib_typedescription_new( &pType, typelib_TypeClass_VOID, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "boolean" ); + typelib_typedescription_new( &pType, typelib_TypeClass_BOOLEAN, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "char" ); + typelib_typedescription_new( &pType, typelib_TypeClass_CHAR, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "byte" ); + typelib_typedescription_new( &pType, typelib_TypeClass_BYTE, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "string" ); + typelib_typedescription_new( &pType, typelib_TypeClass_STRING, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "short" ); + typelib_typedescription_new( &pType, typelib_TypeClass_SHORT, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "unsigned short" ); + typelib_typedescription_new( &pType, typelib_TypeClass_UNSIGNED_SHORT, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "long" ); + typelib_typedescription_new( &pType, typelib_TypeClass_LONG, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "unsigned long" ); + typelib_typedescription_new( &pType, typelib_TypeClass_UNSIGNED_LONG, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "hyper" ); + typelib_typedescription_new( &pType, typelib_TypeClass_HYPER, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "unsigned hyper" ); + typelib_typedescription_new( &pType, typelib_TypeClass_UNSIGNED_HYPER, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "float" ); + typelib_typedescription_new( &pType, typelib_TypeClass_FLOAT, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "double" ); + typelib_typedescription_new( &pType, typelib_TypeClass_DOUBLE, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + rtl_uString_newFromAscii( &pTypeName, "any" ); + typelib_typedescription_new( &pType, typelib_TypeClass_ANY, pTypeName, 0, 0, 0 ); + typelib_typedescription_register( &pType ); + typelib_typedescription_release( pType ); + rtl_uString_release( pTypeName ); + } + } + + typelib_TypeDescriptionReference * pTDR = 0; + typelib_typedescriptionreference_getByName( &pTDR, pName ); + if( pTDR ) + { + { + // guard against multi thread access + MutexGuard aGuard( aInit.getMutex() ); + // pTDR->pType->pWeakRef == 0 means that the description is empty + if( pTDR->pType && pTDR->pType->pWeakRef ) + { + typelib_typedescription_acquire( pTDR->pType ); + *ppRet = pTDR->pType; + } + } + typelib_typedescriptionreference_release( pTDR ); + } + + if( !*ppRet ) + { + // on demand access + aInit.callChain( ppRet, pName ); + if( *ppRet ) + { + // typedescription found + if (typelib_TypeClass_TYPEDEF == (*ppRet)->eTypeClass) + { + typelib_TypeDescription * pTD = 0; + typelib_typedescriptionreference_getDescription( + &pTD, ((typelib_IndirectTypeDescription *)*ppRet)->pType ); + typelib_typedescription_release( *ppRet ); + *ppRet = pTD; + } + else + { + // set to on demand + (*ppRet)->bOnDemand = sal_True; + // The type description is hold by the reference until + // on demand is activated. + typelib_typedescription_register( ppRet ); + + // insert into the chache + MutexGuard aGuard( aInit.getMutex() ); + if( !aInit.pCache ) + aInit.pCache = new TypeDescriptionList_Impl; + if( aInit.pCache->size() >= nCacheSize ) + { + typelib_typedescription_release( aInit.pCache->front() ); + aInit.pCache->pop_front(); + } + // descriptions in the cache must be acquired! + typelib_typedescription_acquire( *ppRet ); + aInit.pCache->push_back( *ppRet ); + } + } + } +} + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_newByAsciiName( + typelib_TypeDescriptionReference ** ppTDR, + typelib_TypeClass eTypeClass, + const sal_Char * pTypeName ) +{ + OUString aTypeName( OUString::createFromAscii( pTypeName ) ); + typelib_typedescriptionreference_new( ppTDR, eTypeClass, aTypeName.pData ); +} +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_new( + typelib_TypeDescriptionReference ** ppTDR, + typelib_TypeClass eTypeClass, + rtl_uString * pTypeName ) +{ + if( eTypeClass == typelib_TypeClass_TYPEDEF ) + { + // on demand access + typelib_TypeDescription * pRet = 0; + aInit.callChain( &pRet, pTypeName ); + if( pRet ) + { + // typedescription found + if (typelib_TypeClass_TYPEDEF == pRet->eTypeClass) + { + typelib_typedescriptionreference_acquire( + ((typelib_IndirectTypeDescription *)pRet)->pType ); + if (*ppTDR) + typelib_typedescriptionreference_release( *ppTDR ); + *ppTDR = ((typelib_IndirectTypeDescription *)pRet)->pType; + typelib_typedescription_release( pRet ); + } + else + { + // set to on demand + pRet->bOnDemand = sal_True; + // The type description is hold by the reference until + // on demand is activated. + typelib_typedescription_register( &pRet ); + + // insert into the chache + MutexGuard aGuard( aInit.getMutex() ); + if( !aInit.pCache ) + aInit.pCache = new TypeDescriptionList_Impl; + if( aInit.pCache->size() >= nCacheSize ) + { + typelib_typedescription_release( aInit.pCache->front() ); + aInit.pCache->pop_front(); + } + aInit.pCache->push_back( pRet ); + // pRet kept acquired for cache + + typelib_typedescriptionreference_acquire( pRet->pWeakRef ); + if (*ppTDR) + typelib_typedescriptionreference_release( *ppTDR ); + *ppTDR = pRet->pWeakRef; + } + } + else if (*ppTDR) + { +#ifdef CPPU_ASSERTIONS + OString aStr( OUStringToOString( pTypeName, RTL_TEXTENCODING_ASCII_US ) ); + OSL_ENSURE( !"### typedef not found: ", aStr.getStr() ); +#endif + typelib_typedescriptionreference_release( *ppTDR ); + *ppTDR = 0; + } + return; + } + + MutexGuard aGuard( aInit.getMutex() ); + typelib_typedescriptionreference_getByName( ppTDR, pTypeName ); + if( *ppTDR ) + return; + + if( reallyWeak( eTypeClass ) ) + { + typelib_TypeDescriptionReference * pTDR = new typelib_TypeDescriptionReference(); +#ifdef CPPU_ASSERTIONS + osl_incrementInterlockedCount( &aInit.nTypeDescriptionReferenceCount ); +#endif + pTDR->nRefCount = 1; + pTDR->eTypeClass = eTypeClass; + pTDR->pUniqueIdentifier = 0; + pTDR->pReserved = 0; + rtl_uString_acquire( pTDR->pTypeName = pTypeName ); + pTDR->pType = 0; + *ppTDR = pTDR; + } + else + { + typelib_typedescription_newEmpty( (typelib_TypeDescription ** )ppTDR, eTypeClass, pTypeName ); + // description will be registered but not acquired + (*(typelib_TypeDescription ** )ppTDR)->bOnDemand = sal_True; + (*(typelib_TypeDescription ** )ppTDR)->bComplete = sal_False; + } + + if( !aInit.pWeakMap ) + aInit.pWeakMap = new WeakMap_Impl; + // Heavy hack, the const sal_Unicode * is hold by the typedescription reference + // not registered + aInit.pWeakMap->operator[]( (*ppTDR)->pTypeName->buffer ) = *ppTDR; +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_acquire( + typelib_TypeDescriptionReference * pRef ) +{ + osl_incrementInterlockedCount( &pRef->nRefCount ); +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_release( + typelib_TypeDescriptionReference * pRef ) +{ + // Is it a type description? + if( reallyWeak( pRef->eTypeClass ) ) + { + if( !osl_decrementInterlockedCount( &pRef->nRefCount ) ) + { + if( aInit.pWeakMap ) + { + MutexGuard aGuard( aInit.getMutex() ); + WeakMap_Impl::iterator aIt = aInit.pWeakMap->find( (sal_Unicode*)pRef->pTypeName->buffer ); + if( !(aIt == aInit.pWeakMap->end()) && (*aIt).second == pRef ) + { + // remove only if it contains the same object + aInit.pWeakMap->erase( aIt ); + } + } + + rtl_uString_release( pRef->pTypeName ); + OSL_ASSERT( pRef->pType == 0 ); +#ifdef CPPU_ASSERTIONS + osl_decrementInterlockedCount( &aInit.nTypeDescriptionReferenceCount ); +#endif + delete pRef; + } + } + else + { + typelib_typedescription_release( (typelib_TypeDescription *)pRef ); + } +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_getDescription( + typelib_TypeDescription ** ppRet, + typelib_TypeDescriptionReference * pRef ) +{ + if( *ppRet ) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } + + if( !reallyWeak( pRef->eTypeClass ) && pRef->pType && pRef->pType->pWeakRef ) + { + // reference is a description and initialized + osl_incrementInterlockedCount( &((typelib_TypeDescription *)pRef)->nRefCount ); + *ppRet = (typelib_TypeDescription *)pRef; + return; + } + + { + MutexGuard aGuard( aInit.getMutex() ); + // pRef->pType->pWeakRef == 0 means that the description is empty + if( pRef->pType && pRef->pType->pWeakRef ) + { + sal_Int32 n = osl_incrementInterlockedCount( &pRef->pType->nRefCount ); + if( n > 1 ) + { + // The refence is incremented. The object cannot be destroyed. + // Release the guard at the earliest point. + *ppRet = pRef->pType; + return; + } + else + { + osl_decrementInterlockedCount( &pRef->pType->nRefCount ); + // detruction of this type in progress (another thread!) + // no acces through this weak reference + pRef->pType = 0; + } + } + } + + typelib_typedescription_getByName( ppRet, pRef->pTypeName ); + OSL_ASSERT( !*ppRet || rtl_ustr_compare( pRef->pTypeName->buffer, (*ppRet)->pTypeName->buffer ) == 0 ); + OSL_ASSERT( !*ppRet || pRef->eTypeClass == (*ppRet)->eTypeClass ); + OSL_ASSERT( !*ppRet || pRef == (*ppRet)->pWeakRef ); + pRef->pType = *ppRet; +} + +//------------------------------------------------------------------------ +void SAL_CALL typelib_typedescriptionreference_getByName( + typelib_TypeDescriptionReference ** ppRet, + rtl_uString * pName ) +{ + if( *ppRet ) + { + typelib_typedescriptionreference_release( *ppRet ); + *ppRet = 0; + } + if( aInit.pWeakMap ) + { + MutexGuard aGuard( aInit.getMutex() ); + WeakMap_Impl::const_iterator aIt = aInit.pWeakMap->find( (sal_Unicode*)pName->buffer ); + if( !(aIt == aInit.pWeakMap->end()) ) // != failed on msc4.2 + { + sal_Int32 n = osl_incrementInterlockedCount( &(*aIt).second->nRefCount ); + if( n > 1 ) + // The refence is incremented. The object cannot be destroyed. + // Release the guard at the earliest point. + *ppRet = (*aIt).second; + else + // detruction of this type in progress (another thread!) + // no acces through this weak reference + osl_decrementInterlockedCount( &(*aIt).second->nRefCount ); + } + } +} + +//------------------------------------------------------------------------ +extern "C" SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescriptionreference_equals( + const typelib_TypeDescriptionReference * p1, + const typelib_TypeDescriptionReference * p2 ) +{ + return (p1 == p2 || + (p1->eTypeClass == p2->eTypeClass && + p1->pTypeName->length == p2->pTypeName->length && + rtl_ustr_compare( p1->pTypeName->buffer, p2->pTypeName->buffer ) == 0)); +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_typedescriptionreference_assign( + typelib_TypeDescriptionReference ** ppDest, + typelib_TypeDescriptionReference * pSource ) +{ + if (*ppDest != pSource) + { + ::typelib_typedescriptionreference_acquire( pSource ); + ::typelib_typedescriptionreference_release( *ppDest ); + *ppDest = pSource; + } +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize ) +{ + OSL_ENSHURE( nNewSize >= 0, "### illegal cache size given!" ); + if (nNewSize >= 0) + { + MutexGuard aGuard( aInit.getMutex() ); + if ((nNewSize < nCacheSize) && aInit.pCache) + { + while (aInit.pCache->size() != nNewSize) + { + typelib_typedescription_release( aInit.pCache->front() ); + aInit.pCache->pop_front(); + } + } + nCacheSize = nNewSize; + } +} + + +static sal_Bool s_aAssignableFromTab[11][11] = +{ + /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */ +/* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, +/* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, +/* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, +/* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, +/* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0 }, +/* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1 } +}; + +//################################################################################################## +extern "C" SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescriptionreference_isAssignableFrom( + typelib_TypeDescriptionReference * pAssignable, + typelib_TypeDescriptionReference * pFrom ) +{ + if (pAssignable && pFrom) + { + typelib_TypeClass eAssignable = pAssignable->eTypeClass; + typelib_TypeClass eFrom = pFrom->eTypeClass; + + if (eAssignable == typelib_TypeClass_ANY) // anything can be assigned to an any .) + return sal_True; + if (eAssignable == eFrom) + { + if (type_equals( pAssignable, pFrom )) // first shot + { + return sal_True; + } + else + { + switch (eAssignable) + { + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pFromDescr = 0; + TYPELIB_DANGER_GET( &pFromDescr, pFrom ); + if (! ((typelib_CompoundTypeDescription *)pFromDescr)->pBaseTypeDescription) + { + TYPELIB_DANGER_RELEASE( pFromDescr ); + return sal_False; + } + sal_Bool bRet = typelib_typedescriptionreference_isAssignableFrom( + pAssignable, + ((typelib_TypeDescription *)((typelib_CompoundTypeDescription *)pFromDescr)->pBaseTypeDescription)->pWeakRef ); + TYPELIB_DANGER_RELEASE( pFromDescr ); + return bRet; + } + case typelib_TypeClass_INTERFACE: + { + typelib_TypeDescription * pFromDescr = 0; + TYPELIB_DANGER_GET( &pFromDescr, pFrom ); + if ( !((typelib_InterfaceTypeDescription *)pFromDescr)->pBaseTypeDescription ) + { + TYPELIB_DANGER_RELEASE( pFromDescr ); + return sal_False; + } + sal_Bool bRet = typelib_typedescriptionreference_isAssignableFrom( + pAssignable, + ((typelib_TypeDescription *)((typelib_InterfaceTypeDescription *)pFromDescr)->pBaseTypeDescription)->pWeakRef ); + TYPELIB_DANGER_RELEASE( pFromDescr ); + return bRet; + } + } + return sal_False; + } + } + return (eAssignable >= typelib_TypeClass_CHAR && eAssignable <= typelib_TypeClass_DOUBLE && + eFrom >= typelib_TypeClass_CHAR && eFrom <= typelib_TypeClass_DOUBLE && + s_aAssignableFromTab[eAssignable-1][eFrom-1]); + } + return sal_False; +} +//################################################################################################## +extern "C" SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescription_isAssignableFrom( + typelib_TypeDescription * pAssignable, + typelib_TypeDescription * pFrom ) +{ + return typelib_typedescriptionreference_isAssignableFrom( + pAssignable->pWeakRef, pFrom->pWeakRef ); +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT sal_Bool SAL_CALL typelib_typedescription_complete( + typelib_TypeDescription ** ppTypeDescr ) +{ + if (! (*ppTypeDescr)->bComplete) + { + OSL_ASSERT( (typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || + typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || + typelib_TypeClass_UNION == (*ppTypeDescr)->eTypeClass || + typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && + !reallyWeak( (*ppTypeDescr)->eTypeClass ) ); + + if (typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass && + ((typelib_InterfaceTypeDescription *)*ppTypeDescr)->ppAllMembers) + { + // complete except of tables init + MutexGuard aGuard( aInit.getMutex() ); // type is registered + if (! (*ppTypeDescr)->bComplete) + { + typelib_typedescription_initTables( *ppTypeDescr ); + (*ppTypeDescr)->bComplete = sal_True; + } + return sal_True; + } + // obsolete +// else +// { +// MutexGuard aGuard( aInit.getMutex() ); +// typelib_TypeDescriptionReference * pRef = 0; +// ::typelib_typedescriptionreference_getByName( &pRef, (*ppTypeDescr)->pTypeName ); +// if (pRef) +// { +// if (pRef->pType && pRef->pType->pWeakRef && pRef->pType->bComplete) +// { +// // found registered and complete td +// ::typelib_typedescription_release( *ppTypeDescr ); +// *ppTypeDescr = pRef->pType; +// return sal_True; +// } +// ::typelib_typedescriptionreference_release( pRef ); +// } +// } + + typelib_TypeDescription * pTD = 0; + // on demand access of complete td + aInit.callChain( &pTD, (*ppTypeDescr)->pTypeName ); + if (pTD) + { + if (typelib_TypeClass_TYPEDEF == pTD->eTypeClass) + { + typelib_typedescriptionreference_getDescription( + &pTD, ((typelib_IndirectTypeDescription *)pTD)->pType ); + OSL_ASSERT( pTD ); + if (! pTD) + return sal_False; + } + + OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTD->eTypeClass ); + // typedescription found + // set to on demand + pTD->bOnDemand = sal_True; + + if (typelib_TypeClass_INTERFACE == pTD->eTypeClass && !pTD->bComplete) + { + // mandatory info from callback chain + OSL_ASSERT( ((typelib_InterfaceTypeDescription *)pTD)->ppAllMembers ); + // complete except of tables init + typelib_typedescription_initTables( pTD ); + pTD->bComplete = sal_True; + } + + // The type description is hold by the reference until + // on demand is activated. + ::typelib_typedescription_register( &pTD ); // replaces incomplete one + OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one + + // insert into the chache + MutexGuard aGuard( aInit.getMutex() ); + if( !aInit.pCache ) + aInit.pCache = new TypeDescriptionList_Impl; + if( aInit.pCache->size() >= nCacheSize ) + { + typelib_typedescription_release( aInit.pCache->front() ); + aInit.pCache->pop_front(); + } + // descriptions in the cache must be acquired! + typelib_typedescription_acquire( pTD ); + aInit.pCache->push_back( pTD ); + + OSL_ASSERT( pTD->bComplete ); + + ::typelib_typedescription_release( *ppTypeDescr ); + *ppTypeDescr = pTD; + } + else + { +#ifdef CPPU_ASSERTIONS + OString aStr( OUStringToOString( (*ppTypeDescr)->pTypeName, RTL_TEXTENCODING_ASCII_US ) ); + CPPU_TRACE( "\n### type cannot be completed: " ); + CPPU_TRACE( aStr.getStr() ); +#endif + return sal_False; + } + } + return sal_True; +} + diff --git a/cppu/source/uno/any.cxx b/cppu/source/uno/any.cxx new file mode 100644 index 000000000000..9aa695b891ae --- /dev/null +++ b/cppu/source/uno/any.cxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * $RCSfile: any.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "copy.hxx" +#include "destr.hxx" + +using namespace cppu; + + +extern "C" +{ +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_any_construct( + uno_Any * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire ) +{ + if (pType) + { + __copyConstructAny( pDest, pSource, pType, 0, acquire, 0 ); + } + else + { + __CONSTRUCT_EMPTY_ANY( (uno_Any *)pDest ); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_any_construct( + uno_Any * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire ) +{ + if (pTypeDescr) + { + __copyConstructAny( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, acquire, 0 ); + } + else + { + __CONSTRUCT_EMPTY_ANY( pDest ); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_any_constructAndConvert( + uno_Any * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, + uno_Mapping * mapping ) +{ + if (pType) + { + __copyConstructAny( pDest, pSource, pType, 0, 0, mapping ); + } + else + { + __CONSTRUCT_EMPTY_ANY( pDest ); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_any_constructAndConvert( + uno_Any * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_Mapping * mapping ) +{ + if (pTypeDescr) + { + __copyConstructAny( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, 0, mapping ); + } + else + { + __CONSTRUCT_EMPTY_ANY( pDest ); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_any_destruct( uno_Any * pValue, uno_ReleaseFunc release ) +{ + __destructAny( pValue, release ); +} +} diff --git a/cppu/source/uno/assign.hxx b/cppu/source/uno/assign.hxx new file mode 100644 index 000000000000..aabd48326b7e --- /dev/null +++ b/cppu/source/uno/assign.hxx @@ -0,0 +1,545 @@ +/************************************************************************* + * + * $RCSfile: assign.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef __ASSIGN_HXX__ +#define __ASSIGN_HXX__ + +#include "prim.hxx" +#include "destr.hxx" +#include "constr.hxx" +#include "copy.hxx" + +namespace cppu +{ + + +//################################################################################################## +//#### assignment ################################################################################## +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +inline void __assignInterface( + void ** ppDest, void * pSource, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + void * pDest = *ppDest; + if (pSource) + { + if (acquire) + (*acquire)( pSource ); + else + (*((uno_Interface *)pSource)->acquire)( (uno_Interface *)pSource ); + } + if (pDest) + { + if (release) + (*release)( pDest ); + else + (*((uno_Interface *)pDest)->release)( (uno_Interface *)pDest ); + } + *ppDest = pSource; +} +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __queryAndAssignInterface( + void ** ppDest, void * pSource, + typelib_TypeDescriptionReference * pDestType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + void * pDest = *ppDest; + if (pSource) + { + if (queryInterface) + { + pSource = (*queryInterface)( pSource, pDestType ); + } + else + { + uno_Any aRet, aExc; + uno_Any * pExc = &aExc; + + void * aArgs[1]; + aArgs[0] = &pDestType; + + typelib_TypeDescription * pMTqueryInterface = __getQueryInterfaceTypeDescr(); + (*((uno_Interface *)pSource)->pDispatcher)( + (uno_Interface *)pSource, pMTqueryInterface, &aRet, aArgs, &pExc ); + + OSL_ENSHURE( !pExc, "### Exception occured during queryInterface()!" ); + if (pExc) + { + __destructAny( pExc, 0 ); + pSource = 0; + } + else + { + if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass) + { + // tweaky... avoiding acquire/ release pair + ::typelib_typedescriptionreference_release( aRet.pType ); + pSource = *(void **)aRet.pData; // serving acquired interface + ::rtl_freeMemory( aRet.pData ); + } + else + { + pSource = 0; + } + } + ::typelib_typedescription_release( pMTqueryInterface ); + } + } + if (pDest) + { + if (release) + (*release)( pDest ); + else + (*((uno_Interface *)pDest)->release)( (uno_Interface *)pDest ); + } + *ppDest = pSource; + return (pSource != 0); +} +//================================================================================================== +sal_Bool assignStruct( + void * pDest, void * pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ); +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __assignStruct( + void * pDest, void * pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + if (pTypeDescr->pBaseTypeDescription) + { + // copy base value + if (! assignStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, + queryInterface, acquire, release )) + { + return sal_False; + } + } + // then copy members + typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs; + sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; + sal_Int32 nDescr = pTypeDescr->nMembers; + while (nDescr--) + { + if (! ::uno_type_assignData( (char *)pDest + pMemberOffsets[nDescr], + ppTypeRefs[nDescr], + (char *)pSource + pMemberOffsets[nDescr], + ppTypeRefs[nDescr], + queryInterface, acquire, release )) + { + return sal_False; + } + } + return sal_True; +} +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __assignData( + void * pDest, + typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr, + void * pSource, + typelib_TypeDescriptionReference * pSourceType, typelib_TypeDescription * pSourceTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + if (pDest == pSource) + return sal_True; + + if (! pSource) + { + __destructData( pDest, pDestType, pDestTypeDescr, release ); + __defaultConstructData( pDest, pDestType, pDestTypeDescr ); + return sal_True; + } + while (typelib_TypeClass_ANY == pSourceType->eTypeClass) + { + pSourceTypeDescr = 0; + pSourceType = ((uno_Any *)pSource)->pType; + pSource = ((uno_Any *)pSource)->pData; + } + + switch (pDestType->eTypeClass) + { + case typelib_TypeClass_VOID: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_VOID: + return sal_True; + } + return sal_False; + case typelib_TypeClass_CHAR: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_CHAR: + *(sal_Unicode *)pDest = *(sal_Unicode *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_BOOLEAN: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BOOLEAN: + *(sal_Bool *)pDest = *(sal_Bool *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_BYTE: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_Int8 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_SHORT: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_Int16 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_Int16 *)pDest = *(sal_Int16 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_UNSIGNED_SHORT: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_uInt16 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_uInt16 *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_LONG: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_Int32 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + *(sal_Int32 *)pDest = *(sal_Int16 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_Int32 *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + *(sal_Int32 *)pDest = *(sal_Int32 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_UNSIGNED_LONG: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_uInt32 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + *(sal_uInt32 *)pDest = *(sal_Int16 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_uInt32 *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + *(sal_uInt32 *)pDest = *(sal_uInt32 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_HYPER: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_Int64 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + *(sal_Int64 *)pDest = *(sal_Int16 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_Int64 *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + case typelib_TypeClass_LONG: + *(sal_Int64 *)pDest = *(sal_Int32 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_LONG: + *(sal_Int64 *)pDest = *(sal_uInt32 *)pSource; + return sal_True; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + *(sal_Int64 *)pDest = *(sal_Int64 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_UNSIGNED_HYPER: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(sal_uInt64 *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + *(sal_uInt64 *)pDest = *(sal_Int16 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_uInt64 *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + case typelib_TypeClass_LONG: + *(sal_uInt64 *)pDest = *(sal_Int32 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_LONG: + *(sal_uInt64 *)pDest = *(sal_uInt32 *)pSource; + return sal_True; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + *(sal_uInt64 *)pDest = *(sal_uInt64 *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_FLOAT: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(float *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + *(float *)pDest = *(sal_Int16 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + *(float *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + case typelib_TypeClass_FLOAT: + *(float *)pDest = *(float *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_DOUBLE: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_BYTE: + *(double *)pDest = *(sal_Int8 *)pSource; + return sal_True; + case typelib_TypeClass_SHORT: + *(double *)pDest = *(sal_Int16 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_SHORT: + *(double *)pDest = *(sal_uInt16 *)pSource; + return sal_True; + case typelib_TypeClass_LONG: + *(double *)pDest = *(sal_Int32 *)pSource; + return sal_True; + case typelib_TypeClass_UNSIGNED_LONG: + *(double *)pDest = *(sal_uInt32 *)pSource; + return sal_True; + case typelib_TypeClass_FLOAT: + *(double *)pDest = *(float *)pSource; + return sal_True; + case typelib_TypeClass_DOUBLE: + *(double *)pDest = *(double *)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_STRING: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_STRING: + ::rtl_uString_assign( (rtl_uString **)pDest, *(rtl_uString **)pSource ); + return sal_True; + } + return sal_False; + case typelib_TypeClass_TYPE: + switch (pSourceType->eTypeClass) + { + case typelib_TypeClass_TYPE: + ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference **)pDest ); + TYPE_ACQUIRE( + *(typelib_TypeDescriptionReference **)pDest = *(typelib_TypeDescriptionReference **)pSource ); + return sal_True; + } + return sal_False; + case typelib_TypeClass_ANY: + __destructAny( (uno_Any *)pDest, release ); + __copyConstructAny( (uno_Any *)pDest, pSource, pSourceType, pSourceTypeDescr, acquire, 0 ); + return sal_True; + case typelib_TypeClass_ENUM: + if (__type_equals( pDestType, pSourceType )) + { + *(int *)pDest = *(int *)pSource; + return sal_True; + } + return sal_False; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + return sal_False; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (typelib_TypeClass_STRUCT == pSourceType->eTypeClass || + typelib_TypeClass_EXCEPTION == pSourceType->eTypeClass) + { + sal_Bool bRet = sal_False; + if (pSourceTypeDescr) + { + typelib_CompoundTypeDescription * pTypeDescr = + (typelib_CompoundTypeDescription *)pSourceTypeDescr; + while (pTypeDescr && !__type_equals( ((typelib_TypeDescription *)pTypeDescr)->pWeakRef, pDestType )) + pTypeDescr = pTypeDescr->pBaseTypeDescription; + if (pTypeDescr) + bRet = __assignStruct( pDest, pSource, pTypeDescr, queryInterface, acquire, release ); + } + else + { + TYPELIB_DANGER_GET( &pSourceTypeDescr, pSourceType ); + typelib_CompoundTypeDescription * pTypeDescr = + (typelib_CompoundTypeDescription *)pSourceTypeDescr; + while (pTypeDescr && !__type_equals( ((typelib_TypeDescription *)pTypeDescr)->pWeakRef, pDestType )) + pTypeDescr = pTypeDescr->pBaseTypeDescription; + if (pTypeDescr) + bRet = __assignStruct( pDest, pSource, pTypeDescr, queryInterface, acquire, release ); + TYPELIB_DANGER_RELEASE( pSourceTypeDescr ); + } + return bRet; + } + return sal_False; + case typelib_TypeClass_UNION: + if (__type_equals( pDestType, pSourceType )) + { + if (pDestTypeDescr) + { + __destructUnion( pDest, pDestTypeDescr, release ); + __copyConstructUnion( pDest, pSource, pDestTypeDescr, acquire, 0 ); + } + else + { + TYPELIB_DANGER_GET( &pDestTypeDescr, pDestType ); + __destructUnion( pDest, pDestTypeDescr, release ); + __copyConstructUnion( pDest, pSource, pDestTypeDescr, acquire, 0 ); + TYPELIB_DANGER_RELEASE( pDestTypeDescr ); + } + return sal_True; + } + return sal_False; + case typelib_TypeClass_SEQUENCE: + if (*(uno_Sequence **)pSource == *(uno_Sequence **)pDest) // self assignment + return sal_True; + if (__type_equals( pDestType, pSourceType )) + { + __destructSequence( *(uno_Sequence **)pDest, pDestType, pDestTypeDescr, release ); + ::osl_incrementInterlockedCount( &(*(uno_Sequence **)pSource)->nRefCount ); + *(uno_Sequence **)pDest = *(uno_Sequence **)pSource; + return sal_True; + } + return sal_False; + case typelib_TypeClass_INTERFACE: + if (typelib_TypeClass_INTERFACE != pSourceType->eTypeClass) + return sal_False; + if (__type_equals( pDestType, pSourceType )) + { + __assignInterface( (void **)pDest, *(void **)pSource, acquire, release ); + return sal_True; + } + else + { + sal_Bool bRet; + if (pSourceTypeDescr) + { + typelib_TypeDescription * pTD = pSourceTypeDescr; + while (pTD && !__type_equals( pTD->pWeakRef, pDestType )) + pTD = (typelib_TypeDescription *)((typelib_InterfaceTypeDescription *)pTD)->pBaseTypeDescription; + if (pTD) // is base of dest + { + __assignInterface( (void **)pDest, *(void **)pSource, acquire, release ); + bRet = sal_True; + } + else + { + // query for interface + bRet = __queryAndAssignInterface( + (void **)pDest, *(void **)pSource, pDestType, queryInterface, release ); + } + } + else + { + if (__type_equals( pSourceType, pDestType )) + { + __assignInterface( (void **)pDest, *(void **)pSource, acquire, release ); + bRet = sal_True; + } + else + { + // query for interface + bRet = __queryAndAssignInterface( + (void **)pDest, *(void **)pSource, pDestType, queryInterface, release ); + } + } + return bRet; + } + } + return sal_False; +} + +} + +#endif diff --git a/cppu/source/uno/constr.hxx b/cppu/source/uno/constr.hxx new file mode 100644 index 000000000000..0391f167b135 --- /dev/null +++ b/cppu/source/uno/constr.hxx @@ -0,0 +1,206 @@ +/************************************************************************* + * + * $RCSfile: constr.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef __CONSTR_HXX__ +#define __CONSTR_HXX__ + +#include "prim.hxx" + +namespace cppu +{ + +//################################################################################################## +//#### construction ################################################################################ +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +inline void __defaultConstructUnion( + void * pMem, + typelib_TypeDescription * pTypeDescr ) +{ + ::uno_type_constructData( + (char *)pMem + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, + ((typelib_UnionTypeDescription *)pTypeDescr)->pDefaultTypeRef ); + *(sal_Int64 *)pMem = ((typelib_UnionTypeDescription *)pTypeDescr)->nDefaultDiscriminant; +} +//================================================================================================== +void defaultConstructStruct( + void * pMem, + typelib_CompoundTypeDescription * pCompType ); +//-------------------------------------------------------------------------------------------------- +inline void __defaultConstructStruct( + void * pMem, + typelib_CompoundTypeDescription * pTypeDescr ) +{ + if (pTypeDescr->pBaseTypeDescription) + { + defaultConstructStruct( pMem, pTypeDescr->pBaseTypeDescription ); + } + + typelib_TypeDescriptionReference ** ppTypeRefs = (pTypeDescr)->ppTypeRefs; + sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; + sal_Int32 nDescr = pTypeDescr->nMembers; + + while (nDescr--) + { + ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] ); + } +} + +//-------------------------------------------------------------------------------------------------- +inline void __defaultConstructData( + void * pMem, + typelib_TypeDescriptionReference * pType, + typelib_TypeDescription * pTypeDescr ) +{ + switch (pType->eTypeClass) + { + case typelib_TypeClass_CHAR: + *(sal_Unicode *)pMem = '\0'; + break; + case typelib_TypeClass_BOOLEAN: + *(sal_Bool *)pMem = sal_False; + break; + case typelib_TypeClass_BYTE: + *(sal_Int8 *)pMem = 0; + break; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_Int16 *)pMem = 0; + break; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + *(sal_Int32 *)pMem = 0; + break; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + *(sal_Int64 *)pMem = 0; + break; + case typelib_TypeClass_FLOAT: + *(float *)pMem = 0.0; + break; + case typelib_TypeClass_DOUBLE: + *(double *)pMem = 0.0; + break; + case typelib_TypeClass_STRING: + *(rtl_uString **)pMem = 0; + RTL_USTRING_NEW( (rtl_uString **)pMem ); + break; + case typelib_TypeClass_TYPE: + *(typelib_TypeDescriptionReference **)pMem = __getVoidType(); + break; + case typelib_TypeClass_ANY: + __CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem ); + break; + case typelib_TypeClass_ENUM: + if (pTypeDescr) + { + *(int *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue; + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + *(int *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue; + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (pTypeDescr) + { + __defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_UNION: + if (pTypeDescr) + { + __defaultConstructUnion( pMem, pTypeDescr ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __defaultConstructUnion( pMem, pTypeDescr ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_SEQUENCE: + *(uno_Sequence **)pMem = __getEmptySequence(); + break; + case typelib_TypeClass_INTERFACE: + *(void **)pMem = 0; // either cpp or c-uno interface + break; + } +} + +} + +#endif diff --git a/cppu/source/uno/copy.hxx b/cppu/source/uno/copy.hxx new file mode 100644 index 000000000000..4147db4beb5c --- /dev/null +++ b/cppu/source/uno/copy.hxx @@ -0,0 +1,715 @@ +/************************************************************************* + * + * $RCSfile: copy.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef __COPY_HXX__ +#define __COPY_HXX__ + +#include "prim.hxx" +#include "constr.hxx" + +namespace cppu +{ + + +//################################################################################################## +//#### copy construction ########################################################################### +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +void copyConstructStruct( + void * pDest, void * pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ); +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructStruct( + void * pDest, void * pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + if (pTypeDescr->pBaseTypeDescription) + { + // copy base value + copyConstructStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, acquire, mapping ); + } + + // then copy members + typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs; + sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; + sal_Int32 nDescr = pTypeDescr->nMembers; + + if (mapping) + { + while (nDescr--) + { + ::uno_type_copyAndConvertData( (char *)pDest + pMemberOffsets[nDescr], + (char *)pSource + pMemberOffsets[nDescr], + ppTypeRefs[nDescr], mapping ); + } + } + else + { + while (nDescr--) + { + ::uno_type_copyData( (char *)pDest + pMemberOffsets[nDescr], + (char *)pSource + pMemberOffsets[nDescr], + ppTypeRefs[nDescr], acquire ); + } + } +} +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructUnion( + void * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + typelib_TypeDescriptionReference * pSetType = __unionGetSetType( pSource, pTypeDescr ); + if (mapping) + { + ::uno_type_copyAndConvertData( + (char *)pDest + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, + (char *)pSource + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, + pSetType, mapping ); + } + else + { + ::uno_type_copyData( + (char *)pDest + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, + (char *)pSource + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, + pSetType, acquire ); + } + *(sal_Int64 *)pDest = *(sal_Int64 *)pSource; + typelib_typedescriptionreference_release( pSetType ); +} +//-------------------------------------------------------------------------------------------------- +void copyConstructSequence( + uno_Sequence ** ppDest, uno_Sequence * pSource, + typelib_TypeDescriptionReference * pElementType, + uno_AcquireFunc acquire, uno_Mapping * mapping ); +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructAnyFromData( + uno_Any * pDestAny, void * pSource, + typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + TYPE_ACQUIRE( pType ); + pDestAny->pType = pType; + + switch (pType->eTypeClass) + { + case typelib_TypeClass_CHAR: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Unicode) ); + *(sal_Unicode *)pDestAny->pData = *(sal_Unicode *)pSource; + break; + case typelib_TypeClass_BOOLEAN: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Bool) ); + *(sal_Bool *)pDestAny->pData = *(sal_Bool *)pSource; + break; + case typelib_TypeClass_BYTE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int8) ); + *(sal_Int8 *)pDestAny->pData = *(sal_Int8 *)pSource; + break; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int16) ); + *(sal_Int16 *)pDestAny->pData = *(sal_Int16 *)pSource; + break; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int32) ); + *(sal_Int32 *)pDestAny->pData = *(sal_Int32 *)pSource; + break; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) ); + *(sal_Int64 *)pDestAny->pData = *(sal_Int64 *)pSource; + break; + case typelib_TypeClass_FLOAT: + pDestAny->pData = ::rtl_allocateMemory( sizeof(float) ); + *(float *)pDestAny->pData = *(float *)pSource; + break; + case typelib_TypeClass_DOUBLE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(double) ); + *(double *)pDestAny->pData = *(double *)pSource; + break; + case typelib_TypeClass_STRING: + ::rtl_uString_acquire( *(rtl_uString **)pSource ); + pDestAny->pData = ::rtl_allocateMemory( sizeof(rtl_uString *) ); + *(rtl_uString **)pDestAny->pData = *(rtl_uString **)pSource; + break; + case typelib_TypeClass_TYPE: + TYPE_ACQUIRE( *(typelib_TypeDescriptionReference **)pSource ); + pDestAny->pData = ::rtl_allocateMemory( sizeof(typelib_TypeDescriptionReference *) ); + *(typelib_TypeDescriptionReference **)pDestAny->pData = *(typelib_TypeDescriptionReference **)pSource; + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_ANY: + OSL_ENSHURE( sal_False, "### unexpected nested any!" ); + break; +#endif + case typelib_TypeClass_ENUM: + pDestAny->pData = ::rtl_allocateMemory( sizeof(int) ); + *(int *)pDestAny->pData = *(int *)pSource; + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (pTypeDescr) + { + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __copyConstructStruct( + pDestAny->pData, pSource, + (typelib_CompoundTypeDescription *)pTypeDescr, + acquire, mapping ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __copyConstructStruct( + pDestAny->pData, pSource, + (typelib_CompoundTypeDescription *)pTypeDescr, + acquire, mapping ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_UNION: + if (pTypeDescr) + { + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __copyConstructUnion( pDestAny->pData, pSource, pTypeDescr, acquire, mapping ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __copyConstructUnion( pDestAny->pData, pSource, pTypeDescr, acquire, mapping ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_SEQUENCE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(uno_Sequence *) ); + if (pTypeDescr) + { + copyConstructSequence( + (uno_Sequence **)pDestAny->pData, *(uno_Sequence **)pSource, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + acquire, mapping ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + copyConstructSequence( + (uno_Sequence **)pDestAny->pData, *(uno_Sequence **)pSource, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + acquire, mapping ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_INTERFACE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(void *) ); + if (mapping) + { + *(void **)pDestAny->pData = __map( *(void **)pSource, pType, pTypeDescr, mapping ); + } + else + { + __acquire( *(void **)pDestAny->pData = *(void **)pSource, acquire ); + } + break; + } +} +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructAny( + uno_Any * pDestAny, void * pSource, + typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + if (typelib_TypeClass_VOID == pType->eTypeClass) + { + __CONSTRUCT_EMPTY_ANY( pDestAny ); + } + else + { + if (typelib_TypeClass_ANY == pType->eTypeClass) + { + if (pSource) + { + pType = ((uno_Any *)pSource)->pType; + if (typelib_TypeClass_VOID == pType->eTypeClass) + { + __CONSTRUCT_EMPTY_ANY( pDestAny ); + return; + } + pTypeDescr = 0; + pSource = ((uno_Any *)pSource)->pData; + } + else + { + __CONSTRUCT_EMPTY_ANY( pDestAny ); + return; + } + } + if (pSource) + { + __copyConstructAnyFromData( pDestAny, pSource, pType, pTypeDescr, acquire, mapping ); + } + else // default construct + { + TYPE_ACQUIRE( pType ); + pDestAny->pType = pType; + switch (pType->eTypeClass) + { + case typelib_TypeClass_CHAR: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Unicode) ); + *(sal_Unicode *)pDestAny->pData = '\0'; + break; + case typelib_TypeClass_BOOLEAN: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Bool) ); + *(sal_Bool *)pDestAny->pData = sal_False; + break; + case typelib_TypeClass_BYTE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int8) ); + *(sal_Int8 *)pDestAny->pData = 0; + break; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int16) ); + *(sal_Int16 *)pDestAny->pData = 0; + break; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int32) ); + *(sal_Int32 *)pDestAny->pData = 0; + break; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + pDestAny->pData = ::rtl_allocateMemory( sizeof(sal_Int64) ); + *(sal_Int64 *)pDestAny->pData = 0; + break; + case typelib_TypeClass_FLOAT: + pDestAny->pData = ::rtl_allocateMemory( sizeof(float) ); + *(float *)pDestAny->pData = 0.0; + break; + case typelib_TypeClass_DOUBLE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(double) ); + *(double *)pDestAny->pData = 0.0; + break; + case typelib_TypeClass_STRING: + pDestAny->pData = ::rtl_allocateMemory( sizeof(rtl_uString *) ); + *(rtl_uString **)pDestAny->pData = 0; + RTL_USTRING_NEW( (rtl_uString **)pDestAny->pData ); + break; + case typelib_TypeClass_TYPE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(typelib_TypeDescriptionReference *) ); + *(typelib_TypeDescriptionReference **)pDestAny->pData = __getVoidType(); + break; + case typelib_TypeClass_ENUM: + pDestAny->pData = ::rtl_allocateMemory( sizeof(int) ); + if (pTypeDescr) + { + *(int *)pDestAny->pData = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue; + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + *(int *)pDestAny->pData = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue; + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (pTypeDescr) + { + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __defaultConstructStruct( + pDestAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __defaultConstructStruct( + pDestAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_UNION: + if (pTypeDescr) + { + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __defaultConstructUnion( pDestAny->pData, pTypeDescr ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + pDestAny->pData = ::rtl_allocateMemory( pTypeDescr->nSize ); + __defaultConstructUnion( pDestAny->pData, pTypeDescr ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_SEQUENCE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(uno_Sequence *) ); + *(uno_Sequence **)pDestAny->pData = __getEmptySequence(); + break; + case typelib_TypeClass_INTERFACE: + pDestAny->pData = ::rtl_allocateMemory( sizeof(void *) ); + *(void **)pDestAny->pData = 0; // either cpp or c-uno interface + break; + } + } + } +} +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructSequence( + uno_Sequence ** ppDest, uno_Sequence * pSource, + typelib_TypeDescriptionReference * pElementType, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + typelib_TypeClass eTypeClass = pElementType->eTypeClass; + if (!mapping || + (eTypeClass <= typelib_TypeClass_ENUM && eTypeClass != typelib_TypeClass_ANY)) + { + ::osl_incrementInterlockedCount( &pSource->nRefCount ); + *ppDest = pSource; + } + else // create new sequence + { + uno_Sequence * pDest; + sal_Int32 nElements = pSource->nElements; + if (nElements) + { + switch (eTypeClass) + { + case typelib_TypeClass_ANY: + { + pDest = (uno_Sequence *)::rtl_allocateMemory( + SAL_SEQUENCE_HEADER_SIZE + (nElements * sizeof(uno_Any)) ); + uno_Any * pDestElements = (uno_Any *)pDest->elements; + uno_Any * pSourceElements = (uno_Any *)pSource->elements; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + typelib_TypeDescriptionReference * pType = pSourceElements[nPos].pType; + if (typelib_TypeClass_VOID == pType->eTypeClass) + { + __CONSTRUCT_EMPTY_ANY( &pDestElements[nPos] ); + } + else + { + __copyConstructAnyFromData( + &pDestElements[nPos], pSourceElements[nPos].pData, + pType, 0, + acquire, mapping ); + } + } + break; + } + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + char * pSourceElements = pSource->elements; + pDest = (uno_Sequence *)::rtl_allocateMemory( + SAL_SEQUENCE_HEADER_SIZE + (nElements * nElementSize) ); + char * pElements = pDest->elements; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + __copyConstructStruct( + pElements + (nPos * nElementSize), + pSourceElements + (nPos * nElementSize), + (typelib_CompoundTypeDescription *)pElementTypeDescr, + acquire, mapping ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_UNION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + sal_Int32 nValueOffset = ((typelib_UnionTypeDescription *)pElementTypeDescr)->nValueOffset; + pDest = (uno_Sequence *)::rtl_allocateMemory( + SAL_SEQUENCE_HEADER_SIZE + (nElements * nElementSize) ); + char * pElements = pDest->elements; + char * pSourceElements = pSource->elements; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + char * pDest = pElements + (nPos * nElementSize); + char * pSource = pSourceElements + (nPos * nElementSize); + + typelib_TypeDescriptionReference * pSetType = __unionGetSetType( pSource, pElementTypeDescr ); + ::uno_type_copyAndConvertData( pDest + nValueOffset, pSource + nValueOffset, + pSetType, mapping ); + *(sal_Int64 *)pDest = *(sal_Int64 *)pSource; + ::typelib_typedescriptionreference_release( pSetType ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_SEQUENCE: // sequence of sequence + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + typelib_TypeDescriptionReference * pSeqElementType = + ((typelib_IndirectTypeDescription *)pElementTypeDescr)->pType; + pDest = (uno_Sequence *)::rtl_allocateMemory( + SAL_SEQUENCE_HEADER_SIZE + (nElements * sizeof(uno_Sequence *)) ); + char * pElements = pDest->elements; + uno_Sequence ** pSourceElements = (uno_Sequence **)pSource->elements; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + copyConstructSequence( + (uno_Sequence **)pElements + nPos, pSourceElements[nPos], + pSeqElementType, + acquire, mapping ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_INTERFACE: + { + pDest = (uno_Sequence *)::rtl_allocateMemory( + SAL_SEQUENCE_HEADER_SIZE + (nElements * sizeof(void *)) ); + char * pElements = pDest->elements; + void ** pSourceElements = (void **)pSource->elements; + if (mapping) + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + for ( sal_Int32 nPos = nElements; nPos--; ) + { + ((void **)pElements)[nPos] = 0; + if (((void **)pSourceElements)[nPos]) + { + (*mapping->mapInterface)( + mapping, (void **)pElements + nPos, + pSourceElements[nPos], + (typelib_InterfaceTypeDescription *)pElementTypeDescr ); + } + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + } + else + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + __acquire( ((void **)pElements)[nPos] = pSourceElements[nPos], acquire ); + } + } + break; + } + default: + pDest = (uno_Sequence *)::rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE ); + break; + } + } + else + { + pDest = (uno_Sequence *)::rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE ); + } + pDest->nElements = nElements; + pDest->nRefCount = 1; + *ppDest = pDest; + } +} + +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructData( + void * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + switch (pType->eTypeClass) + { + case typelib_TypeClass_CHAR: + *(sal_Unicode *)pDest = *(sal_Unicode *)pSource; + break; + case typelib_TypeClass_BOOLEAN: + *(sal_Bool *)pDest = *(sal_Bool *)pSource; + break; + case typelib_TypeClass_BYTE: + *(sal_Int8 *)pDest = *(sal_Int8 *)pSource; + break; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + *(sal_Int16 *)pDest = *(sal_Int16 *)pSource; + break; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + *(sal_Int32 *)pDest = *(sal_Int32 *)pSource; + break; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: +#if defined(GCC) && defined(SPARC) + *(sal_Int32 *)pDest = *(sal_Int32 *)pSource; + *(((sal_Int32 *)pDest) +1) = *(((sal_Int32 *)pSource) +1); +#else + *(sal_Int64 *)pDest = *(sal_Int64 *)pSource; +#endif + break; + case typelib_TypeClass_FLOAT: + *(float *)pDest = *(float *)pSource; + break; + case typelib_TypeClass_DOUBLE: + *(double *)pDest = *(double *)pSource; + break; + case typelib_TypeClass_STRING: + ::rtl_uString_acquire( *(rtl_uString **)pSource ); + *(rtl_uString **)pDest = *(rtl_uString **)pSource; + break; + case typelib_TypeClass_TYPE: + TYPE_ACQUIRE( *(typelib_TypeDescriptionReference **)pSource ); + *(typelib_TypeDescriptionReference **)pDest = *(typelib_TypeDescriptionReference **)pSource; + break; + case typelib_TypeClass_ANY: + __copyConstructAny( + (uno_Any *)pDest, ((uno_Any *)pSource)->pData, + ((uno_Any *)pSource)->pType, 0, + acquire, mapping ); + break; + case typelib_TypeClass_ENUM: + *(int *)pDest = *(int *)pSource; + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (pTypeDescr) + { + __copyConstructStruct( + pDest, pSource, + (typelib_CompoundTypeDescription *)pTypeDescr, + acquire, mapping ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __copyConstructStruct( + pDest, pSource, + (typelib_CompoundTypeDescription *)pTypeDescr, + acquire, mapping ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_UNION: + if (pTypeDescr) + { + __copyConstructUnion( pDest, pSource, pTypeDescr, acquire, mapping ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __copyConstructUnion( pDest, pSource, pTypeDescr, acquire, mapping ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_SEQUENCE: + if (mapping) + { + if (pTypeDescr) + { + __copyConstructSequence( + (uno_Sequence **)pDest, *(uno_Sequence **)pSource, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + acquire, mapping ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __copyConstructSequence( + (uno_Sequence **)pDest, *(uno_Sequence **)pSource, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + acquire, mapping ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + } + else + { + ::osl_incrementInterlockedCount( &(*(uno_Sequence **)pSource)->nRefCount ); + *(uno_Sequence **)pDest = *(uno_Sequence **)pSource; + } + break; + case typelib_TypeClass_INTERFACE: + if (mapping) + *(void **)pDest = __map( *(void **)pSource, pType, pTypeDescr, mapping ); + else + __acquire( *(void **)pDest = *(void **)pSource, acquire ); + break; + } +} + +} + +#endif diff --git a/cppu/source/uno/data.cxx b/cppu/source/uno/data.cxx new file mode 100644 index 000000000000..a188354ee45a --- /dev/null +++ b/cppu/source/uno/data.cxx @@ -0,0 +1,357 @@ +/************************************************************************* + * + * $RCSfile: data.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "constr.hxx" +#include "destr.hxx" +#include "copy.hxx" +#include "assign.hxx" +#include "eq.hxx" + +using namespace cppu; +using namespace rtl; +using namespace com::sun::star::uno; + + +namespace cppu +{ + +//================================================================================================== +void defaultConstructStruct( + void * pMem, + typelib_CompoundTypeDescription * pCompType ) +{ + __defaultConstructStruct( pMem, pCompType ); +} +//================================================================================================== +void copyConstructStruct( + void * pDest, void * pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + __copyConstructStruct( pDest, pSource, pTypeDescr, acquire, mapping ); +} +//================================================================================================== +void destructStruct( + void * pValue, + typelib_CompoundTypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + __destructStruct( pValue, pTypeDescr, release ); +} +//================================================================================================== +sal_Bool equalStruct( + void * pDest, void *pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + return __equalStruct( pDest, pSource, pTypeDescr, queryInterface, release ); +} +//================================================================================================== +sal_Bool assignStruct( + void * pDest, void * pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + return __assignStruct( pDest, pSource, pTypeDescr, queryInterface, acquire, release ); +} +//================================================================================================== +void copyConstructSequence( + uno_Sequence ** ppDest, uno_Sequence * pSource, + typelib_TypeDescriptionReference * pElementType, + uno_AcquireFunc acquire, uno_Mapping * mapping ) +{ + __copyConstructSequence( ppDest, pSource, pElementType, acquire, mapping ); +} +//================================================================================================== +void destructSequence( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pElementType, + uno_ReleaseFunc release ) +{ + uno_Sequence * pSequence = *ppSequence; + OSL_ASSERT( pSequence ); + if (! ::osl_decrementInterlockedCount( &pSequence->nRefCount )) + { + if (pSequence->nElements) + { + __destructElements( pSequence->elements, pElementType, 0, pSequence->nElements, release ); + } + ::rtl_freeMemory( pSequence ); + } +} +//================================================================================================== +sal_Bool equalSequence( + uno_Sequence * pDest, uno_Sequence * pSource, + typelib_TypeDescriptionReference * pElementType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + return __equalSequence( pDest, pSource, pElementType, queryInterface, release ); +} + +extern "C" +{ +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_constructData( + void * pMem, typelib_TypeDescriptionReference * pType ) +{ + __defaultConstructData( pMem, pType, 0 ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_constructData( + void * pMem, typelib_TypeDescription * pTypeDescr ) +{ + __defaultConstructData( pMem, pTypeDescr->pWeakRef, pTypeDescr ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_destructData( + void * pValue, typelib_TypeDescriptionReference * pType, + uno_ReleaseFunc release ) +{ + __destructData( pValue, pType, 0, release ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_destructData( + void * pValue, + typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + __destructData( pValue, pTypeDescr->pWeakRef, pTypeDescr, release ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_copyData( + void * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire ) +{ + __copyConstructData( pDest, pSource, pType, 0, acquire, 0 ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_copyData( + void * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire ) +{ + __copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, acquire, 0 ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_copyAndConvertData( + void * pDest, void * pSource, + typelib_TypeDescriptionReference * pType, + uno_Mapping * mapping ) +{ + __copyConstructData( pDest, pSource, pType, 0, 0, mapping ); +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_copyAndConvertData( + void * pDest, void * pSource, + typelib_TypeDescription * pTypeDescr, + uno_Mapping * mapping ) +{ + __copyConstructData( pDest, pSource, pTypeDescr->pWeakRef, pTypeDescr, 0, mapping ); +} +//################################################################################################## +SAL_DLLEXPORT sal_Bool SAL_CALL uno_type_equalData( + void * pVal1, typelib_TypeDescriptionReference * pVal1Type, + void * pVal2, typelib_TypeDescriptionReference * pVal2Type, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + return __equalData( pVal1, pVal1Type, 0, + pVal2, pVal2Type, 0, + queryInterface, release ); +} +//################################################################################################## +SAL_DLLEXPORT sal_Bool SAL_CALL uno_equalData( + void * pVal1, typelib_TypeDescription * pVal1TD, + void * pVal2, typelib_TypeDescription * pVal2TD, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + return __equalData( pVal1, pVal1TD->pWeakRef, pVal1TD, + pVal2, pVal2TD->pWeakRef, pVal2TD, + queryInterface, release ); +} +//################################################################################################## +SAL_DLLEXPORT sal_Bool SAL_CALL uno_type_assignData( + void * pDest, typelib_TypeDescriptionReference * pDestType, + void * pSource, typelib_TypeDescriptionReference * pSourceType, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + return __assignData( pDest, pDestType, 0, + pSource, pSourceType, 0, + queryInterface, acquire, release ); +} +//################################################################################################## +SAL_DLLEXPORT sal_Bool SAL_CALL uno_assignData( + void * pDest, typelib_TypeDescription * pDestTD, + void * pSource, typelib_TypeDescription * pSourceTD, + uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + return __assignData( pDest, pDestTD->pWeakRef, pDestTD, + pSource, pSourceTD->pWeakRef, pSourceTD, + queryInterface, acquire, release ); +} +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + + +#ifdef _DEBUG +#ifdef SAL_W32 +# pragma pack(push, 8) +#elif defined(SAL_OS2) +# pragma pack(8) +#endif + +struct M +{ + sal_Int32 n; + sal_Int16 o; +}; + +struct N : public M +{ + sal_Int16 p; +}; + +struct O : public M +{ + double p; +}; + +struct empty +{ +}; +struct second : public empty +{ + int a; +}; + +class BinaryCompatible_Impl +{ +public: + BinaryCompatible_Impl() + { + if ((SAL_SEQUENCE_HEADER_SIZE % 8) != 0) + abort(); + + /* + If the feature failed search FEATURE_ and correct it. + */ + // the sizeof enum must be the size of an integer + // FEATURE_ENUM + if( sizeof( TypeClass ) != sizeof( int ) ) + abort(); + + // the sizeof any must be sizeof( void * ) * 2, + // the first is a pointer to typelib_TypeDescription, the second is the pointer to the data + // FEATURE_ANY + if( sizeof( Any ) != sizeof( uno_Any ) ) + abort(); + if( sizeof( Any ) != sizeof( void * ) * 2 ) + abort(); + if( (sal_Int32)&((Any *) 16)->pType != 16 ) + abort(); + if( (sal_Int32)&((Any *) 16)->pData != 16 + sizeof( void * ) ) + abort(); + + // All types can moved from one one memory location to another + // without calling the copy constructor and the destructor. + // FEATURE_MEMORYMOVE_INVARIANT + + // All types can moved from one one memory location to another + // without calling the copy constructor and the destructor. + // FEATURE_ZEROCONSTRUCTOR + + // The reference class must be a pointer to XInterface or a subclass of XInterface + // FEATURE_INTERFACE + if( sizeof( Reference< XInterface > ) != sizeof( XInterface * ) ) + abort(); + + // The reference class must be a pointer to XInterface or a subclass of XInterface + // FEATURE_WSTRING + if( sizeof( OUString ) != sizeof( rtl_uString * ) ) + abort(); + + // The reference class must be a pointer to XInterface or a subclass of XInterface + // FEATURE_ALIGN + if( sizeof( M ) != 8 || sizeof( N ) != 12 || sizeof( O ) != 16 ) + abort(); + +#ifndef __GNUC__ + // An empty superclass have a size of 0 except for gcc + // FEATURE_EMPTYCLASS + if( sizeof( second ) != sizeof( int ) ) + abort(); +#endif + } +}; +#ifdef SAL_W32 +# pragma pack(pop) +#elif defined(SAL_OS2) +# pragma pack() +#endif + +static BinaryCompatible_Impl aTest; +#endif + +} diff --git a/cppu/source/uno/destr.hxx b/cppu/source/uno/destr.hxx new file mode 100644 index 000000000000..d2fef7e6eff8 --- /dev/null +++ b/cppu/source/uno/destr.hxx @@ -0,0 +1,411 @@ +/************************************************************************* + * + * $RCSfile: destr.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef __DESTR_HXX__ +#define __DESTR_HXX__ + +#include "prim.hxx" + +namespace cppu +{ + + +//################################################################################################## +//#### destruction ################################################################################# +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +inline void __destructUnion( + void * pValue, + typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + typelib_TypeDescriptionReference * pType = __unionGetSetType( pValue, pTypeDescr ); + ::uno_type_destructData( + (char *)pValue + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset, + pType, release ); + ::typelib_typedescriptionreference_release( pType ); +} +//================================================================================================== +void destructStruct( + void * pValue, + typelib_CompoundTypeDescription * pTypeDescr, + uno_ReleaseFunc release ); +//-------------------------------------------------------------------------------------------------- +inline void __destructStruct( + void * pValue, + typelib_CompoundTypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + if (pTypeDescr->pBaseTypeDescription) + { + destructStruct( pValue, pTypeDescr->pBaseTypeDescription, release ); + } + + typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs; + sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; + sal_Int32 nDescr = pTypeDescr->nMembers; + while (nDescr--) + { + ::uno_type_destructData( + (char *)pValue + pMemberOffsets[nDescr], ppTypeRefs[nDescr], release ); + } +} +//================================================================================================== +void destructSequence( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pElementType, + uno_ReleaseFunc release ); +//-------------------------------------------------------------------------------------------------- +inline void __destructAny( + uno_Any * pAny, + uno_ReleaseFunc release ) +{ + typelib_TypeDescriptionReference * pType = pAny->pType; + + if (typelib_TypeClass_VOID != pType->eTypeClass) + { + switch (pType->eTypeClass) + { + case typelib_TypeClass_STRING: + ::rtl_uString_release( *(rtl_uString **)pAny->pData ); + break; + case typelib_TypeClass_TYPE: + ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference **)pAny->pData ); + break; + case typelib_TypeClass_ANY: + OSL_ENSHURE( sal_False, "### unexpected nested any!" ); + ::uno_any_destruct( (uno_Any *)pAny->pData, release ); + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __destructStruct( pAny->pData, (typelib_CompoundTypeDescription *)pTypeDescr, release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + break; + } + case typelib_TypeClass_UNION: + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __destructUnion( pAny->pData, pTypeDescr, release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + break; + } + case typelib_TypeClass_SEQUENCE: + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + destructSequence( + (uno_Sequence **)pAny->pData, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + break; + } + case typelib_TypeClass_INTERFACE: + __releaseRef( (void **)pAny->pData, release ); + break; + } + ::rtl_freeMemory( pAny->pData ); +#ifdef DEBUG + pAny->pData = (void *)0xdeadbeef; +#endif + } + ::typelib_typedescriptionreference_release( pType ); +} +//-------------------------------------------------------------------------------------------------- +inline sal_Int32 __destructElements( + void * pElements, typelib_TypeDescriptionReference * pElementType, + sal_Int32 nStartIndex, sal_Int32 nStopIndex, + uno_ReleaseFunc release ) +{ + switch (pElementType->eTypeClass) + { + case typelib_TypeClass_CHAR: + return sizeof(sal_Unicode); + case typelib_TypeClass_BOOLEAN: + return sizeof(sal_Bool); + case typelib_TypeClass_BYTE: + return sizeof(sal_Int8); + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + return sizeof(sal_Int16); + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + return sizeof(sal_Int32); + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + return sizeof(sal_Int64); + case typelib_TypeClass_FLOAT: + return sizeof(float); + case typelib_TypeClass_DOUBLE: + return sizeof(double); + + case typelib_TypeClass_STRING: + { + rtl_uString ** pDest = (rtl_uString **)pElements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + ::rtl_uString_release( pDest[nPos] ); + } + return sizeof(rtl_uString *); + } + case typelib_TypeClass_TYPE: + { + typelib_TypeDescriptionReference ** pDest = (typelib_TypeDescriptionReference **)pElements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + ::typelib_typedescriptionreference_release( pDest[nPos] ); + } + return sizeof(typelib_TypeDescriptionReference *); + } + case typelib_TypeClass_ANY: + { + uno_Any * pDest = (uno_Any *)pElements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __destructAny( &pDest[nPos], release ); + } + return sizeof(uno_Any); + } + case typelib_TypeClass_ENUM: + return sizeof(int); +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __destructStruct( + (char *)pElements + (nElementSize * nPos), + (typelib_CompoundTypeDescription *)pElementTypeDescr, + release ); + } + sal_Int32 nSize = pElementTypeDescr->nSize; + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return nSize; + } + case typelib_TypeClass_UNION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __destructUnion( + (char *)pElements + (nElementSize * nPos), + pElementTypeDescr, + release ); + } + sal_Int32 nSize = pElementTypeDescr->nSize; + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return nSize; + } + case typelib_TypeClass_SEQUENCE: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + uno_Sequence ** pDest = (uno_Sequence **)pElements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + destructSequence( + &pDest[nPos], + ((typelib_IndirectTypeDescription *)pElementTypeDescr)->pType, + release ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sizeof(uno_Sequence *); + } +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_ARRAY: + OSL_ENSHURE( sal_False, "### unexpected array!" ); + break; +#endif + case typelib_TypeClass_INTERFACE: + { + if (release) + { + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + void * p = ((void **)pElements)[nPos]; + if (p) + (*release)( p ); + } + } + else + { + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + uno_Interface * p = ((uno_Interface **)pElements)[nPos]; + if (p) + (*p->release)( p ); + } + } + return sizeof(void *); + } + } + return 0; +} +//-------------------------------------------------------------------------------------------------- +inline void __destructSequence( + uno_Sequence * pSequence, + typelib_TypeDescriptionReference * pType, + typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + if (! ::osl_decrementInterlockedCount( &pSequence->nRefCount )) + { + if (pSequence->nElements) + { + if (pTypeDescr) + { + __destructElements( + pSequence->elements, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + 0, pSequence->nElements, release ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __destructElements( + pSequence->elements, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + 0, pSequence->nElements, release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + } + ::rtl_freeMemory( pSequence ); + } +} +//-------------------------------------------------------------------------------------------------- +inline void __destructData( + void * pValue, + typelib_TypeDescriptionReference * pType, + typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + switch (pType->eTypeClass) + { + case typelib_TypeClass_STRING: + ::rtl_uString_release( *(rtl_uString **)pValue ); + break; + case typelib_TypeClass_TYPE: + ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference **)pValue ); + break; + case typelib_TypeClass_ANY: + __destructAny( (uno_Any *)pValue, release ); + break; +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (pTypeDescr) + { + __destructStruct( pValue, (typelib_CompoundTypeDescription *)pTypeDescr, release ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __destructStruct( pValue, (typelib_CompoundTypeDescription *)pTypeDescr, release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_UNION: + if (pTypeDescr) + { + __destructUnion( pValue, pTypeDescr, release ); + } + else + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __destructUnion( pValue, pTypeDescr, release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + break; + case typelib_TypeClass_SEQUENCE: + __destructSequence( *(uno_Sequence **)pValue, pType, pTypeDescr, release ); + break; + case typelib_TypeClass_INTERFACE: + __releaseRef( (void **)pValue, release ); + break; + } +} + +} + +#endif diff --git a/cppu/source/uno/eq.hxx b/cppu/source/uno/eq.hxx new file mode 100644 index 000000000000..6deac9cbbd8d --- /dev/null +++ b/cppu/source/uno/eq.hxx @@ -0,0 +1,745 @@ +/************************************************************************* + * + * $RCSfile: eq.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef __EQ_HXX__ +#define __EQ_HXX__ + +#include <math.h> + +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif + +#include "prim.hxx" +#include "destr.hxx" + +namespace cppu +{ + + +//################################################################################################## +//#### equality #################################################################################### +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __unoEqualObject( void * pUnoI1, void * pUnoI2 ) +{ + if (pUnoI1 == pUnoI2) + return sal_True; + if (!pUnoI2 || !pUnoI2) + return sal_False; + + sal_Bool bRet = sal_False; + + void * pArgs[1]; + + const com::sun::star::uno::Type & rXIType = + ::getCppuType( (const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > *)0 ); + pArgs[0] = const_cast< com::sun::star::uno::Type * >( &rXIType ); + uno_Any aRet1, aRet2, aExc; + uno_Any * pExc = &aExc; + + typelib_TypeDescription * pMTqueryInterface = __getQueryInterfaceTypeDescr(); + (*((uno_Interface *)pUnoI1)->pDispatcher)( + (uno_Interface *)pUnoI1, pMTqueryInterface, &aRet1, pArgs, &pExc ); + + OSL_ENSHURE( !pExc, "### Exception occured during queryInterface()!" ); + if (pExc) + { + __destructAny( pExc, 0 ); + } + else + { + if (typelib_TypeClass_INTERFACE == aRet1.pType->eTypeClass) + { + pExc = &aExc; + (*((uno_Interface *)pUnoI2)->pDispatcher)( + (uno_Interface *)pUnoI2, pMTqueryInterface, &aRet2, pArgs, &pExc ); + + OSL_ENSHURE( !pExc, "### Exception occured during queryInterface()!" ); + if (pExc) + { + __destructAny( pExc, 0 ); + } + else + { + if (typelib_TypeClass_INTERFACE == aRet2.pType->eTypeClass) + { + bRet = (*(void **)aRet1.pData == *(void **)aRet2.pData); + } + __destructAny( &aRet2, 0 ); + } + } + __destructAny( &aRet1, 0 ); + } + + typelib_typedescription_release( pMTqueryInterface ); + + return bRet; +} +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __equalObject( + void * pI1, void * pI2, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + if (pI1 == pI2) + return sal_True; + if (queryInterface) + { + sal_Bool bRet = sal_False; + const com::sun::star::uno::Type & rType = + ::getCppuType( (const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > *)0 ); + if (pI1 = (*queryInterface)( pI1, rType.getTypeLibType() )) + { + if (pI2 = (*queryInterface)( pI2, rType.getTypeLibType() )) + { + bRet = (pI1 == pI2); + (*release)( pI2 ); + } + (*release)( pI1 ); + } + return bRet; + } + return __unoEqualObject( pI1, pI2 ); +} + +//================================================================================================== +sal_Bool equalStruct( + void * pDest, void *pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ); +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __equalStruct( + void * pDest, void *pSource, + typelib_CompoundTypeDescription * pTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + if (pTypeDescr->pBaseTypeDescription && + !equalStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, queryInterface, release )) + { + return sal_False; + } + + typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs; + sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; + sal_Int32 nDescr = pTypeDescr->nMembers; + + while (nDescr--) + { + sal_Int32 nOffset = pMemberOffsets[nDescr]; + if (! uno_type_equalData( (char *)pDest + nOffset, + ppTypeRefs[nDescr], + (char *)pSource + nOffset, + ppTypeRefs[nDescr], + queryInterface, release )) + { + return sal_False; + } + } + return sal_True; +} +//================================================================================================== +sal_Bool equalSequence( + uno_Sequence * pDest, uno_Sequence * pSource, + typelib_TypeDescriptionReference * pElementType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ); +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __equalSequence( + uno_Sequence * pDest, uno_Sequence * pSource, + typelib_TypeDescriptionReference * pElementType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + if (pDest == pSource) + return sal_True; + sal_Int32 nElements = pDest->nElements; + if (nElements != pSource->nElements) + return sal_False; + if (! nElements) + return sal_True; + + void * pDestElements = pDest->elements; + void * pSourceElements = pSource->elements; + + switch (pElementType->eTypeClass) + { + case typelib_TypeClass_CHAR: + return (0 == ::rtl_compareMemory( pDestElements, pSourceElements, sizeof(sal_Unicode) * nElements )); + case typelib_TypeClass_BOOLEAN: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if ((((sal_Bool *)pDestElements)[nPos] != sal_False) != + (((sal_Bool *)pSourceElements)[nPos] != sal_False)) + { + return sal_False; + } + } + return sal_True; + } + case typelib_TypeClass_BYTE: + return (0 == ::rtl_compareMemory( pDestElements, pSourceElements, sizeof(sal_Int8) * nElements )); + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + return (0 == ::rtl_compareMemory( pDestElements, pSourceElements, sizeof(sal_Int16) * nElements )); + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + return (0 == ::rtl_compareMemory( pDestElements, pSourceElements, sizeof(sal_Int32) * nElements )); + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + return (0 == ::rtl_compareMemory( pDestElements, pSourceElements, sizeof(sal_Int64) * nElements )); + case typelib_TypeClass_FLOAT: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (((float *)pDestElements)[nPos] != ((float *)pSourceElements)[nPos]) + return sal_False; + } + return sal_True; + } + case typelib_TypeClass_DOUBLE: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (((double *)pDestElements)[nPos] != ((double *)pSourceElements)[nPos]) + return sal_False; + } + return sal_True; + } + case typelib_TypeClass_STRING: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (! ((::rtl::OUString *)pDestElements +nPos)->equals( ((const ::rtl::OUString *)pSourceElements)[nPos] )) + return sal_False; + } + return sal_True; + } + case typelib_TypeClass_TYPE: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (! __type_equals( ((typelib_TypeDescriptionReference **)pDestElements)[nPos], + ((typelib_TypeDescriptionReference **)pSourceElements)[nPos] )) + { + return sal_False; + } + } + return sal_True; + } + case typelib_TypeClass_ANY: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + uno_Any * pDest = (uno_Any *)pDestElements + nPos; + uno_Any * pSource = (uno_Any *)pSourceElements + nPos; + if (! ::uno_type_equalData( pDest->pData, pDest->pType, + pSource->pData, pSource->pType, + queryInterface, release )) + { + return sal_False; + } + } + return sal_True; + } + case typelib_TypeClass_ENUM: + return (0 == ::rtl_compareMemory( pDestElements, pSourceElements, sizeof(int) * nElements )); + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (! __equalStruct( (char *)pDestElements + (nPos * nElementSize), + (char *)pSourceElements + (nPos * nElementSize), + (typelib_CompoundTypeDescription *)pElementTypeDescr, + queryInterface, release )) + { + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sal_False; + } + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sal_True; + } + case typelib_TypeClass_UNION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + sal_Int32 nValueOffset = ((typelib_UnionTypeDescription *)pElementTypeDescr)->nValueOffset; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + char * pDest = (char *)pDestElements + (nPos * nElementSize); + char * pSource = (char *)pSourceElements + (nPos * nElementSize); + typelib_TypeDescriptionReference * pSetType = __unionGetSetType( pDest, pElementTypeDescr ); + sal_Bool bRet = uno_type_equalData( pDest + nValueOffset, pSetType, + pSource + nValueOffset, pSetType, + queryInterface, release ); + ::typelib_typedescriptionreference_release( pSetType ); + if (! bRet) + { + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sal_False; + } + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sal_True; + } + case typelib_TypeClass_SEQUENCE: // sequence of sequence + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + typelib_TypeDescriptionReference * pSeqElementType = + ((typelib_IndirectTypeDescription *)pElementTypeDescr)->pType; + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (! equalSequence( ((uno_Sequence **)pDestElements)[nPos], + ((uno_Sequence **)pSourceElements)[nPos], + pSeqElementType, queryInterface, release )) + { + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sal_False; + } + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + return sal_True; + } + case typelib_TypeClass_INTERFACE: + { + for ( sal_Int32 nPos = nElements; nPos--; ) + { + if (! __equalObject( ((void **)pDestElements)[nPos], ((void **)pSourceElements)[nPos], + queryInterface, release )) + { + return sal_False; + } + } + return sal_True; + } + } + return sal_False; +} +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __equalData( + void * pDest, + typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr, + void * pSource, + typelib_TypeDescriptionReference * pSourceType, typelib_TypeDescription * pSourceTypeDescr, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) +{ + typelib_TypeClass eSourceTypeClass, eDestTypeClass; + while (typelib_TypeClass_ANY == (eDestTypeClass = pDestType->eTypeClass)) + { + pDestTypeDescr = 0; + pDestType = ((uno_Any *)pDest)->pType; + pDest = ((uno_Any *)pDest)->pData; + } + while (typelib_TypeClass_ANY == (eSourceTypeClass = pSourceType->eTypeClass)) + { + pSourceTypeDescr = 0; + pSourceType = ((uno_Any *)pSource)->pType; + pSource = ((uno_Any *)pSource)->pData; + } + + switch (eDestTypeClass) + { + case typelib_TypeClass_VOID: + switch (eSourceTypeClass) + { + case typelib_TypeClass_VOID: + return sal_True; + } + return sal_False; + case typelib_TypeClass_CHAR: + switch (eSourceTypeClass) + { + case typelib_TypeClass_CHAR: + return (*(sal_Unicode *)pDest == *(sal_Unicode *)pSource); + } + return sal_False; + case typelib_TypeClass_BOOLEAN: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BOOLEAN: + return (*(sal_Bool *)pDest == *(sal_Bool *)pSource); + } + return sal_False; + case typelib_TypeClass_BYTE: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_Int8 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_Int8 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_Int8 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_Int8 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_Int8 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_Int8 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_Int8 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(sal_Int8 *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(sal_Int8 *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_SHORT: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_Int16 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_Int16 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_Int16 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_Int16 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_Int16 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_Int16 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_Int16 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(sal_Int16 *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(sal_Int16 *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_UNSIGNED_SHORT: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_uInt16 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_uInt16 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_uInt16 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_uInt16 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_uInt16 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_uInt16 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_uInt16 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(sal_uInt16 *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(sal_uInt16 *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_LONG: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_Int32 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_Int32 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_Int32 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_Int32 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_Int32 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_Int32 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_Int32 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(sal_Int32 *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(sal_Int32 *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_UNSIGNED_LONG: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_uInt32 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_uInt32 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_uInt32 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_uInt32 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_uInt32 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_uInt32 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_uInt32 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(sal_uInt32 *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(sal_uInt32 *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_HYPER: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_Int64 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_Int64 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_Int64 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_Int64 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_Int64 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_Int64 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_Int64 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(sal_Int64 *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(sal_Int64 *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_UNSIGNED_HYPER: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(sal_uInt64 *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(sal_uInt64 *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(sal_uInt64 *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(sal_uInt64 *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(sal_uInt64 *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(sal_uInt64 *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + return (*(sal_uInt64 *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + if (::floor( *(float *)pSource ) != *(float *)pSource || *(float *)pSource < 0) + return sal_False; + return (*(sal_uInt64 *)pDest == (sal_uInt64)*(float *)pSource); + case typelib_TypeClass_DOUBLE: + if (::floor( *(double *)pSource ) != *(double *)pSource || *(double *)pSource < 0) + return sal_False; + return (*(sal_uInt64 *)pDest == (sal_uInt64)*(double *)pSource); + } + return sal_False; + case typelib_TypeClass_FLOAT: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(float *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(float *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(float *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(float *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(float *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(float *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + if (::floor( *(float *)pDest ) != *(float *)pDest || *(float *)pDest < 0) + return sal_False; + return ((sal_uInt64)*(float *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(float *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(float *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_DOUBLE: + switch (eSourceTypeClass) + { + case typelib_TypeClass_BYTE: + return (*(double *)pDest == *(sal_Int8 *)pSource); + case typelib_TypeClass_SHORT: + return (*(double *)pDest == *(sal_Int16 *)pSource); + case typelib_TypeClass_UNSIGNED_SHORT: + return (*(double *)pDest == *(sal_uInt16 *)pSource); + case typelib_TypeClass_LONG: + return (*(double *)pDest == *(sal_Int32 *)pSource); + case typelib_TypeClass_UNSIGNED_LONG: + return (*(double *)pDest == *(sal_uInt32 *)pSource); + case typelib_TypeClass_HYPER: + return (*(double *)pDest == *(sal_Int64 *)pSource); + case typelib_TypeClass_UNSIGNED_HYPER: + if (::floor( *(double *)pDest ) != *(double *)pDest || *(double *)pDest < 0) + return sal_False; + return ((sal_uInt64)*(double *)pDest == *(sal_uInt64 *)pSource); + case typelib_TypeClass_FLOAT: + return (*(double *)pDest == *(float *)pSource); + case typelib_TypeClass_DOUBLE: + return (*(double *)pDest == *(double *)pSource); + } + return sal_False; + case typelib_TypeClass_STRING: + switch (eSourceTypeClass) + { + case typelib_TypeClass_STRING: + return ((::rtl::OUString *)pDest)->equals( *(::rtl::OUString *)pSource ); + } + return sal_False; + case typelib_TypeClass_TYPE: + switch (eSourceTypeClass) + { + case typelib_TypeClass_TYPE: + return __type_equals( *(typelib_TypeDescriptionReference **)pDest, + *(typelib_TypeDescriptionReference **)pSource ); + } + return sal_False; + case typelib_TypeClass_ENUM: + return (__type_equals( pDestType, pSourceType ) && + *(int *)pDest == *(int *)pSource); +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + if (! __type_equals( pDestType, pSourceType )) + return sal_False; + if (pDestTypeDescr) + { + return __equalStruct( + pDest, pSource, + (typelib_CompoundTypeDescription *)pDestTypeDescr, + queryInterface, release ); + } + else + { + TYPELIB_DANGER_GET( &pDestTypeDescr, pDestType ); + sal_Bool bRet = __equalStruct( + pDest, pSource, + (typelib_CompoundTypeDescription *)pDestTypeDescr, + queryInterface, release ); + TYPELIB_DANGER_RELEASE( pDestTypeDescr ); + return bRet; + } + case typelib_TypeClass_UNION: + if (__type_equals( pDestType, pSourceType ) && + *(sal_Int64 *)pDest == *(sal_Int64 *)pSource) // same discriminant + { + sal_Bool bRet; + if (pDestTypeDescr) + { + typelib_TypeDescriptionReference * pSetType = __unionGetSetType( pDest, pDestTypeDescr ); + bRet = uno_type_equalData( + (char *)pDest + ((typelib_UnionTypeDescription *)pDestTypeDescr)->nValueOffset, pSetType, + (char *)pSource + ((typelib_UnionTypeDescription *)pDestTypeDescr)->nValueOffset, pSetType, + queryInterface, release ); + typelib_typedescriptionreference_release( pSetType ); + } + else + { + TYPELIB_DANGER_GET( &pDestTypeDescr, pDestType ); + typelib_TypeDescriptionReference * pSetType = __unionGetSetType( pDest, pDestTypeDescr ); + bRet = uno_type_equalData( + (char *)pDest + ((typelib_UnionTypeDescription *)pDestTypeDescr)->nValueOffset, pSetType, + (char *)pSource + ((typelib_UnionTypeDescription *)pDestTypeDescr)->nValueOffset, pSetType, + queryInterface, release ); + typelib_typedescriptionreference_release( pSetType ); + TYPELIB_DANGER_RELEASE( pDestTypeDescr ); + } + return bRet; + } + return sal_False; + case typelib_TypeClass_SEQUENCE: + if (__type_equals( pDestType, pSourceType )) + { + if (pDestTypeDescr) + { + return __equalSequence( + *(uno_Sequence **)pDest, *(uno_Sequence **)pSource, + ((typelib_IndirectTypeDescription *)pDestTypeDescr)->pType, + queryInterface, release ); + } + else + { + TYPELIB_DANGER_GET( &pDestTypeDescr, pDestType ); + sal_Bool bRet = __equalSequence( + *(uno_Sequence **)pDest, *(uno_Sequence **)pSource, + ((typelib_IndirectTypeDescription *)pDestTypeDescr)->pType, + queryInterface, release ); + TYPELIB_DANGER_RELEASE( pDestTypeDescr ); + return bRet; + } + } + return sal_False; + case typelib_TypeClass_INTERFACE: + if (typelib_TypeClass_INTERFACE == eSourceTypeClass) + return __equalObject( *(void **)pDest, *(void **)pSource, queryInterface, release ); + } + return sal_False; +} + +} + +#endif diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx new file mode 100644 index 000000000000..899909be1d85 --- /dev/null +++ b/cppu/source/uno/lbenv.cxx @@ -0,0 +1,981 @@ +/************************************************************************* + * + * $RCSfile: lbenv.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _OSL_INTERLOCK_H_ +#include <osl/interlck.h> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _OSL_MODULE_H_ +#include <osl/module.h> +#endif +#ifndef _OSL_PROCESS_H_ +#include <osl/process.h> +#endif +#ifndef _RTL_PROCESS_H_ +#include <rtl/process.h> +#endif +#ifndef _RTL_STRING_HXX_ +#include <rtl/string.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif + +#include <stdio.h> +#ifdef SOLARIS +#include <alloca.h> +#else +#include <malloc.h> +#endif +#include <stl/hash_map> +#include <stl/vector> + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _UNO_LBNAMES_H_ +#include <uno/lbnames.h> +#endif +#ifndef _UNO_DISPATCHER_H_ +#include <uno/dispatcher.h> +#endif +#ifndef _UNO_ENVIRONMENT_H_ +#include <uno/environment.h> +#endif + +#include "prim.hxx" +#include "destr.hxx" + +#include <com/sun/star/uno/XInterface.hpp> + + +using namespace std; +using namespace osl; +using namespace rtl; +using namespace cppu; +using namespace com::sun::star::uno; + + +//-------------------------------------------------------------------------------------------------- +inline static sal_Bool td_equals( typelib_InterfaceTypeDescription * pTD1, + typelib_InterfaceTypeDescription * pTD2 ) +{ + return (pTD1 == pTD2 || + (((typelib_TypeDescription *)pTD1)->pTypeName->length == + ((typelib_TypeDescription *)pTD2)->pTypeName->length && + ::rtl_ustr_compare( ((typelib_TypeDescription *)pTD1)->pTypeName->buffer, + ((typelib_TypeDescription *)pTD2)->pTypeName->buffer ) == 0)); +} + +struct ObjectEntry; +//-------------------------------------------------------------------------------------------------- +struct InterfaceEntry +{ + void * pInterface; + uno_freeProxyFunc fpFreeProxy; + typelib_InterfaceTypeDescription * pTypeDescr; + ObjectEntry * pOEntry; + + inline sal_Bool supports( typelib_InterfaceTypeDescription * pTypeDescr_ ) const; +}; +//-------------------------------------------------------------------------------------------------- +struct ObjectEntry +{ + uno_ExtEnvironment * pEnv; + OUString oid; + sal_Int32 nRef; + vector< InterfaceEntry > aInterfaces; + + inline ObjectEntry( uno_ExtEnvironment * pEnv, const OUString & rOId_ ); + + inline void append( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr, + uno_freeProxyFunc fpFreeProxy ); + inline const InterfaceEntry * find( typelib_InterfaceTypeDescription * pTypeDescr ) const; +}; + +//-------------------------------------------------------------------------------------------------- +struct FctPtrHash : public unary_function< const void *, size_t > +{ + size_t operator()( const void * pKey ) const + { return (size_t)pKey; } +}; +//-------------------------------------------------------------------------------------------------- +struct FctOUStringHash : public unary_function< const OUString &, size_t > +{ + size_t operator()( const OUString & rKey ) const + { return rKey.hashCode(); } +}; + +// mapping from environment name to environment +typedef hash_map< OUString, uno_Environment *, FctOUStringHash, equal_to< OUString > > OUString2EnvironmentMap; + +// mapping from ptr to object entry +typedef hash_map< void *, ObjectEntry *, FctPtrHash, equal_to< void * > > Ptr2ObjectMap; +// mapping from oid to object entry +typedef hash_map< OUString, ObjectEntry *, FctOUStringHash, equal_to< OUString > > OId2ObjectMap; + +//================================================================================================== +struct EnvironmentsData +{ + Mutex aMutex; + OUString2EnvironmentMap aName2EnvMap; + + ~EnvironmentsData(); + + inline uno_Environment * getEnvironment( const OUString & rTypeName, void * pContext ); + inline sal_Bool registerEnvironment( uno_Environment * pEnv ); + inline sal_Bool revokeEnvironment( uno_Environment * pEnv ); + inline void getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + const OUString & rEnvTypeName ); +}; +//-------------------------------------------------------------------------------------------------- +static EnvironmentsData & getEnvironmentsData() +{ + static EnvironmentsData * s_p = 0; + if (! s_p) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_p) + { + static EnvironmentsData s_obj; + s_p = &s_obj; + } + } + return *s_p; +} + +//================================================================================================== +struct uno_DefaultEnvironment : public uno_ExtEnvironment +{ + sal_Int32 nRef; + oslModule hModule; + + Mutex aAccess; + Ptr2ObjectMap aPtr2ObjectMap; + OId2ObjectMap aOId2ObjectMap; + + uno_DefaultEnvironment( const OUString & rTypeName_, oslModule hMod_, void * pContext_ ); + ~uno_DefaultEnvironment(); +}; + +//__________________________________________________________________________________________________ +inline ObjectEntry::ObjectEntry( uno_ExtEnvironment * pEnv_, const OUString & rOId_ ) + : pEnv( pEnv_ ) + , oid( rOId_ ) + , nRef( 0 ) +{ + aInterfaces.reserve( 8 ); +} +//__________________________________________________________________________________________________ +inline void ObjectEntry::append( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr, + uno_freeProxyFunc fpFreeProxy ) +{ + InterfaceEntry aNewEntry; + if (! fpFreeProxy) + (*pEnv->acquireInterface)( pEnv, pInterface ); + aNewEntry.pInterface = pInterface; + aNewEntry.fpFreeProxy = fpFreeProxy; + aNewEntry.pOEntry = this; + typelib_typedescription_acquire( (typelib_TypeDescription *)(aNewEntry.pTypeDescr = pTypeDescr) ); + + aInterfaces.push_back( aNewEntry ); + static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap[ pInterface ] = this; +} +//__________________________________________________________________________________________________ +inline sal_Bool InterfaceEntry::supports( typelib_InterfaceTypeDescription * pTypeDescr_ ) const +{ + typelib_InterfaceTypeDescription * pITD = pTypeDescr; + while (pITD) + { + if (td_equals( pITD, pTypeDescr_ )) + return sal_True; + pITD = pITD->pBaseTypeDescription; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline const InterfaceEntry * ObjectEntry::find( typelib_InterfaceTypeDescription * pTypeDescr ) const +{ + // shortcut common case + if (((typelib_TypeDescription *)pTypeDescr)->pTypeName->length == sizeof("com.sun.star.uno.XInterface") && + rtl_ustr_ascii_compare( ((typelib_TypeDescription *)pTypeDescr)->pTypeName->buffer, + "com.sun.star.uno.XInterface" ) == 0) + { + return &aInterfaces[0]; + } + + sal_Int32 nSize = aInterfaces.size(); + for ( sal_Int32 nPos = 0; nPos < nSize; ++nPos ) + { + OSL_ASSERT( aInterfaces[nPos].pOEntry == this ); + if (aInterfaces[nPos].supports( pTypeDescr )) + return &aInterfaces[nPos]; + } + return 0; +} + +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_registerInterface( + uno_ExtEnvironment * pEnv, void ** ppInterface, + rtl_uString * pOId, typelib_InterfaceTypeDescription * pTypeDescr ) +{ + OSL_ENSHURE( pEnv && ppInterface && pOId && pTypeDescr, "### null ptr!" ); + const OUString & rOId = * reinterpret_cast< OUString * >( &pOId ); + + ClearableMutexGuard aGuard( static_cast< uno_DefaultEnvironment * >( pEnv )->aAccess ); + + const OId2ObjectMap::const_iterator iFind( + static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.find( rOId ) ); + if (iFind == static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.end()) + { + ObjectEntry * pOEntry = new ObjectEntry( pEnv, rOId ); + static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap[ rOId ] = pOEntry; + ++pOEntry->nRef; // another register call on object + pOEntry->append( *ppInterface, pTypeDescr, 0 ); + } + else // object entry exists + { + ObjectEntry * pOEntry = (*iFind).second; + ++pOEntry->nRef; // another register call on object + const InterfaceEntry * pIEntry = pOEntry->find( pTypeDescr ); + + if (pIEntry) // type entry exists + { + if (pIEntry->pInterface != *ppInterface) + { + void * pInterface = pIEntry->pInterface; + (*pEnv->acquireInterface)( pEnv, pInterface ); + aGuard.clear(); + (*pEnv->releaseInterface)( pEnv, *ppInterface ); + *ppInterface = pInterface; + } + } + else + { + pOEntry->append( *ppInterface, pTypeDescr, 0 ); + } + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_registerProxyInterface( + uno_ExtEnvironment * pEnv, void ** ppInterface, uno_freeProxyFunc freeProxy, + rtl_uString * pOId, typelib_InterfaceTypeDescription * pTypeDescr ) +{ + OSL_ENSHURE( pEnv && ppInterface && pOId && pTypeDescr, "### null ptr!" ); + const OUString & rOId = * reinterpret_cast< OUString * >( &pOId ); + + ClearableMutexGuard aGuard( static_cast< uno_DefaultEnvironment * >( pEnv )->aAccess ); + + const OId2ObjectMap::const_iterator iFind( + static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.find( rOId ) ); + if (iFind == static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.end()) + { + ObjectEntry * pOEntry = new ObjectEntry( pEnv, rOId ); + static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap[ rOId ] = pOEntry; + ++pOEntry->nRef; // another register call on object + pOEntry->append( *ppInterface, pTypeDescr, freeProxy ); + } + else // object entry exists + { + ObjectEntry * pOEntry = (*iFind).second; + ++pOEntry->nRef; // another register call on object + const InterfaceEntry * pIEntry = pOEntry->find( pTypeDescr ); + + if (pIEntry) // type entry exists + { + if (pIEntry->pInterface != *ppInterface) + { + void * pInterface = pIEntry->pInterface; + (*pEnv->acquireInterface)( pEnv, pInterface ); + --pOEntry->nRef; // manual revoke of proxy to be freed + aGuard.clear(); + (*freeProxy)( pEnv, *ppInterface ); + *ppInterface = pInterface; + } + } + else + { + pOEntry->append( *ppInterface, pTypeDescr, freeProxy ); + } + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_revokeInterface( + uno_ExtEnvironment * pEnv, void * pInterface ) +{ + OSL_ENSHURE( pEnv && pInterface, "### null ptr!" ); + ClearableMutexGuard aGuard( static_cast< uno_DefaultEnvironment * >( pEnv )->aAccess ); + + const Ptr2ObjectMap::const_iterator iFind( + static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.find( pInterface ) ); + OSL_ASSERT( iFind != static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.end() ); + if (! --(*iFind).second->nRef) + { + ObjectEntry * pOEntry = (*iFind).second; + OSL_ASSERT( pEnv == pOEntry->pEnv ); + // cleanup maps + static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.erase( pOEntry->oid ); + sal_Int32 nPos; + for ( nPos = pOEntry->aInterfaces.size(); nPos--; ) + { + static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.erase( + pOEntry->aInterfaces[nPos].pInterface ); + } + + // the last proxy interface of the environment might kill this environment, + // because of releasing its language binding!!! + aGuard.clear(); + + // release interfaces + for ( nPos = pOEntry->aInterfaces.size(); nPos--; ) + { + const InterfaceEntry & rEntry = pOEntry->aInterfaces[nPos]; + typelib_typedescription_release( (typelib_TypeDescription *)rEntry.pTypeDescr ); + if (rEntry.fpFreeProxy) // is proxy or used interface? + (*rEntry.fpFreeProxy)( pEnv, rEntry.pInterface ); + else + (*pEnv->releaseInterface)( pEnv, rEntry.pInterface ); + } + + delete pOEntry; + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_getObjectIdentifier( + uno_ExtEnvironment * pEnv, rtl_uString ** ppOId, void * pInterface ) +{ + OSL_ENSHURE( pEnv && ppOId && pInterface, "### null ptr!" ); + if (*ppOId) + { + rtl_uString_release( *ppOId ); + *ppOId = 0; + } + + ClearableMutexGuard aGuard( static_cast< uno_DefaultEnvironment * >( pEnv )->aAccess ); + + const Ptr2ObjectMap::const_iterator iFind( + static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.find( pInterface ) ); + if (iFind != static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.end()) + { + rtl_uString_acquire( *ppOId = (*iFind).second->oid.pData ); + } + else + { + aGuard.clear(); + (*pEnv->computeObjectIdentifier)( pEnv, ppOId, pInterface ); + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_getRegisteredInterface( + uno_ExtEnvironment * pEnv, void ** ppInterface, + rtl_uString * pOId, typelib_InterfaceTypeDescription * pTypeDescr ) +{ + OSL_ENSHURE( pEnv && ppInterface && pOId && pTypeDescr, "### null ptr!" ); + if (*ppInterface) + { + (*pEnv->releaseInterface)( pEnv, *ppInterface ); + *ppInterface = 0; + } + + const OUString & rOId = * reinterpret_cast< OUString * >( &pOId ); + + MutexGuard aGuard( static_cast< uno_DefaultEnvironment * >( pEnv )->aAccess ); + + const OId2ObjectMap::const_iterator iFind( + static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.find( rOId ) ); + if (iFind != static_cast< uno_DefaultEnvironment * >( pEnv )->aOId2ObjectMap.end()) + { + const InterfaceEntry * pIEntry = (*iFind).second->find( pTypeDescr ); + if (pIEntry) + (*pEnv->acquireInterface)( pEnv, *ppInterface = pIEntry->pInterface ); + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_getRegisteredInterfaces( + uno_ExtEnvironment * pEnv, void *** pppInterfaces, sal_Int32 * pnLen, uno_memAlloc memAlloc ) +{ + OSL_ENSHURE( pEnv && pppInterfaces && pnLen && memAlloc, "### null ptr!" ); + MutexGuard aGuard( static_cast< uno_DefaultEnvironment * >( pEnv )->aAccess ); + + sal_Int32 nLen = static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.size(); + sal_Int32 nPos = 0; + void ** ppInterfaces = (void **)(*memAlloc)( nLen * sizeof(void *) ); + + Ptr2ObjectMap::const_iterator iPos( + static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.begin() ); + while (iPos != static_cast< uno_DefaultEnvironment * >( pEnv )->aPtr2ObjectMap.end()) + { + (*pEnv->acquireInterface)( pEnv, ppInterfaces[nPos++] = (*iPos).first ); + ++iPos; + } + + *pppInterfaces = ppInterfaces; + *pnLen = nLen; +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_acquire( uno_Environment * pEnv ) +{ + osl_incrementInterlockedCount( &((uno_DefaultEnvironment *)pEnv)->nRef ); +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_release( uno_Environment * pEnv ) +{ + MutexGuard aGuard( getEnvironmentsData().aMutex ); + if (! osl_decrementInterlockedCount( &((uno_DefaultEnvironment *)pEnv)->nRef )) + { + getEnvironmentsData().revokeEnvironment( pEnv ); + delete (uno_DefaultEnvironment *)pEnv; + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL defenv_dispose( uno_Environment * pEnv ) +{ +} + +//__________________________________________________________________________________________________ +uno_DefaultEnvironment::uno_DefaultEnvironment( + const OUString & rTypeName_, void * pContext_, oslModule hMod_ ) + : nRef( 0 ) + , hModule( hMod_ ) +{ + ((uno_Environment *)this)->pReserved = 0; + // functions + ((uno_Environment *)this)->acquire = defenv_acquire; + ((uno_Environment *)this)->release = defenv_release; + ((uno_Environment *)this)->dispose = defenv_dispose; + ((uno_Environment *)this)->pExtEnv = this; + // identifier + rtl_uString_acquire( rTypeName_.pData ); + ((uno_Environment *)this)->pTypeName = rTypeName_.pData; + ((uno_Environment *)this)->pContext = pContext_; + + // will be late initialized + ((uno_Environment *)this)->environmentDisposing = 0; + + uno_ExtEnvironment::registerInterface = defenv_registerInterface; + uno_ExtEnvironment::registerProxyInterface = defenv_registerProxyInterface; + uno_ExtEnvironment::revokeInterface = defenv_revokeInterface; + uno_ExtEnvironment::getObjectIdentifier = defenv_getObjectIdentifier; + uno_ExtEnvironment::getRegisteredInterface = defenv_getRegisteredInterface; + uno_ExtEnvironment::getRegisteredInterfaces = defenv_getRegisteredInterfaces; + +} +//__________________________________________________________________________________________________ +uno_DefaultEnvironment::~uno_DefaultEnvironment() +{ + OSL_ENSHURE( aOId2ObjectMap.empty(), "### object entries left!" ); + + if (((uno_Environment *)this)->environmentDisposing) + (*((uno_Environment *)this)->environmentDisposing)( (uno_Environment *)this ); + if (hModule) + osl_unloadModule( hModule ); + + rtl_uString_release( ((uno_Environment *)this)->pTypeName ); +} + +//================================================================================================== +static void writeLine( void * stream, const sal_Char * pLine, const sal_Char * pFilter ) +{ + if (pFilter && *pFilter) + { + // lookup pFilter in pLine + while (*pLine) + { + if (*pLine == *pFilter) + { + sal_Int32 nPos = 1; + while (pLine[nPos] && pFilter[nPos] == pLine[nPos]) + ++nPos; + if (! pFilter[nPos]) + { + if (stream) + { + fprintf( (FILE *)stream, "%s\n", pLine ); + } + else + { + OSL_TRACE( pLine ); + OSL_TRACE( "\n" ); + } + } + } + ++pLine; + } + } + else + { + if (stream) + { + fprintf( (FILE *)stream, "%s\n", pLine ); + } + else + { + OSL_TRACE( pLine ); + OSL_TRACE( "\n" ); + } + } +} +//================================================================================================== +static void writeLine( void * stream, const OUString & rLine, const sal_Char * pFilter ) +{ + OString aLine( OUStringToOString( rLine, RTL_TEXTENCODING_ASCII_US ) ); + writeLine( stream, aLine.getStr(), pFilter ); +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_dumpEnvironment( + void * stream, uno_Environment * pEnv, const sal_Char * pFilter ) +{ + OSL_ENSHURE( pEnv, "### null ptr!" ); + OUStringBuffer buf; + + if (! pEnv->pExtEnv) + { + writeLine( stream, "##############################################################################", pFilter ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("environment: ") ); + buf.append( pEnv->pTypeName ); + writeLine( stream, buf.makeStringAndClear(), pFilter ); + writeLine( stream, "NO INTERFACE INFORMATION AVAILABLE!", pFilter ); + return; + } + + writeLine( stream, "##############################################################################", pFilter ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("environment dump: ") ); + buf.append( pEnv->pTypeName ); + writeLine( stream, buf.makeStringAndClear(), pFilter ); + + MutexGuard aGuard( ((uno_DefaultEnvironment *)pEnv)->aAccess ); + + OId2ObjectMap::const_iterator iPos( ((uno_DefaultEnvironment *)pEnv)->aOId2ObjectMap.begin() ); + while (iPos != ((uno_DefaultEnvironment *)pEnv)->aOId2ObjectMap.end()) + { + ObjectEntry * pOEntry = (*iPos).second; + OSL_ASSERT( (uno_DefaultEnvironment *)pEnv == pOEntry->pEnv ); + + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("+ object entry: nRef=") ); + buf.append( pOEntry->nRef, 10 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; oid=\"") ); + buf.append( pOEntry->oid ); + buf.append( (sal_Unicode)'\"' ); + writeLine( stream, buf.makeStringAndClear(), pFilter ); + + for ( sal_Int32 nPos = pOEntry->aInterfaces.size(); nPos--; ) + { + const InterfaceEntry & rIEntry = pOEntry->aInterfaces[nPos]; + OSL_ASSERT( rIEntry.pOEntry == pOEntry ); + + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" - ") ); + buf.append( ((typelib_TypeDescription *)rIEntry.pTypeDescr)->pTypeName ); + if (rIEntry.fpFreeProxy) + { + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; proxy free=0x") ); + buf.append( (sal_Int64)rIEntry.fpFreeProxy, 16 ); + } + else + { + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; original") ); + } + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("; ptr=0x") ); + buf.append( (sal_Int64)rIEntry.pInterface, 16 ); + writeLine( stream, buf.makeStringAndClear(), pFilter ); + } + ++iPos; + } + writeLine( stream, "##############################################################################", pFilter ); +} +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_dumpEnvironmentByName( + void * stream, rtl_uString * pEnvTypeName, const sal_Char * pFilter ) +{ + uno_Environment * pEnv = 0; + uno_getEnvironment( &pEnv, pEnvTypeName, 0 ); + if (pEnv) + { + uno_dumpEnvironment( stream, pEnv, pFilter ); + (*pEnv->release)( pEnv ); + } + else + { + OUStringBuffer buf( 32 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("environment \"") ); + buf.append( pEnvTypeName ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not exist!") ); + writeLine( stream, buf.makeStringAndClear(), pFilter ); + } +} + +//-------------------------------------------------------------------------------------------------- +inline static const OUString & unoenv_getStaticOIdPart() +{ + static OUString * s_pStaticOidPart = 0; + if (! s_pStaticOidPart) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_pStaticOidPart) + { + OUStringBuffer aRet( 64 ); + aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") ); + // pid + oslProcessInfo info; + info.Size = sizeof(oslProcessInfo); + if (osl_getProcessInfo( 0, osl_Process_IDENTIFIER, &info ) == osl_Process_E_None) + aRet.append( (sal_Int64)info.Ident, 16 ); + else + aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("unknown process id") ); + // good guid + sal_uInt8 ar[16]; + rtl_getGlobalProcessId( ar ); + aRet.append( (sal_Unicode)';' ); + for ( sal_Int32 i = 0; i < 16; ++i ) + aRet.append( (sal_Int32)ar[i], 16 ); + + static OUString s_aStaticOidPart( aRet.makeStringAndClear() ); + s_pStaticOidPart = &s_aStaticOidPart; + } + } + return *s_pStaticOidPart; +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL unoenv_computeObjectIdentifier( + uno_ExtEnvironment * pEnv, rtl_uString ** ppOId, void * pInterface ) +{ + OSL_ENSHURE( pEnv && ppOId && pInterface, "### null ptr!" ); + if (*ppOId) + { + rtl_uString_release( *ppOId ); + *ppOId = 0; + } + + typelib_InterfaceTypeDescription * pTXInterfaceDescr = 0; + const Type & rXIType = ::getCppuType( (const Reference< XInterface > *)0 ); + typelib_TypeDescription * pMTqueryInterface = __getQueryInterfaceTypeDescr(); + + void * pArgs[1]; + pArgs[0] = const_cast< Type * >( &rXIType ); + uno_Any aRet, aExc; + uno_Any * pExc = &aExc; + + (*((uno_Interface *)pInterface)->pDispatcher)( + (uno_Interface *)pInterface, pMTqueryInterface, &aRet, pArgs, &pExc ); + + OSL_ENSHURE( !pExc, "### Exception occured during queryInterface()!" ); + if (pExc) // cleanup exception object + { + __destructAny( pExc, 0 ); + } + else + { + OSL_ENSHURE( aRet.pType->eTypeClass == typelib_TypeClass_INTERFACE, + "### cannot query for XInterface!" ); + if (aRet.pType->eTypeClass == typelib_TypeClass_INTERFACE) + { + // interface + OUStringBuffer oid( 64 ); + oid.append( (sal_Int64)*(void **)aRet.pData, 16 ); + oid.append( (sal_Unicode)';' ); + // environment[context] + oid.append( ((uno_Environment *)pEnv)->pTypeName ); + oid.append( (sal_Unicode)'[' ); + oid.append( (sal_Int64)((uno_Environment *)pEnv)->pContext, 16 ); + // process;good guid + oid.append( unoenv_getStaticOIdPart() ); + OUString aStr( oid.makeStringAndClear() ); + rtl_uString_acquire( *ppOId = aStr.pData ); + } + __destructAny( &aRet, 0 ); + } + + typelib_typedescription_release( pMTqueryInterface ); +} +//================================================================================================== +static void SAL_CALL unoenv_acquireInterface( uno_ExtEnvironment *, void * pUnoI ) +{ + (*((uno_Interface *)pUnoI)->acquire)( (uno_Interface *)pUnoI ); +} +//================================================================================================== +static void SAL_CALL unoenv_releaseInterface( uno_ExtEnvironment *, void * pUnoI ) +{ + (*((uno_Interface *)pUnoI)->release)( (uno_Interface *)pUnoI ); +} + +//__________________________________________________________________________________________________ +EnvironmentsData::~EnvironmentsData() +{ + MutexGuard aGuard( aMutex ); + + OUString2EnvironmentMap::const_iterator iPos( aName2EnvMap.begin() ); +#ifdef CPPU_ALLOW_ASSERTIONS + OSL_ENSHURE( aName2EnvMap.empty(), "### unrevoked environments! living proxies?" ); + while (iPos != aName2EnvMap.end()) + { + ::uno_dumpEnvironment( 0, (*iPos).second, 0 ); + ++iPos; + } + iPos = aName2EnvMap.begin(); +#endif + while (iPos != aName2EnvMap.end()) + { + (*(*iPos).second->dispose)( (*iPos).second ); + ++iPos; + } +} +//__________________________________________________________________________________________________ +inline uno_Environment * EnvironmentsData::getEnvironment( + const OUString & rEnvTypeName, void * pContext ) +{ + uno_Environment * pEnv = 0; + + OUString aKey( OUString::valueOf( (sal_Int32)pContext ) ); + aKey += rEnvTypeName; + + // try to find registered mapping + MutexGuard aGuard( aMutex ); + const OUString2EnvironmentMap::const_iterator iFind( aName2EnvMap.find( aKey ) ); + if (iFind != aName2EnvMap.end()) + { + pEnv = (*iFind).second; + (*pEnv->acquire)( pEnv ); + } + + return pEnv; +} +//__________________________________________________________________________________________________ +inline sal_Bool EnvironmentsData::registerEnvironment( uno_Environment * pEnv ) +{ + OSL_ENSHURE( pEnv, "### null ptr!" ); + OUString aKey( OUString::valueOf( (sal_Int64)pEnv->pContext ) ); + aKey += pEnv->pTypeName; + + // try to find environment + MutexGuard aGuard( aMutex ); + const OUString2EnvironmentMap::const_iterator iFind( aName2EnvMap.find( aKey ) ); + OSL_ENSHURE( iFind == aName2EnvMap.end(), "### environment already registered!" ); + if (iFind == aName2EnvMap.end()) + { + aName2EnvMap[ aKey ] = pEnv; + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +inline sal_Bool EnvironmentsData::revokeEnvironment( uno_Environment * pEnv ) +{ + OSL_ENSHURE( pEnv, "### null ptr!" ); + OUString aKey( OUString::valueOf( (sal_Int64)pEnv->pContext ) ); + aKey += pEnv->pTypeName; + + MutexGuard aGuard( aMutex ); + OSL_ENSHURE( aName2EnvMap.find( aKey ) != aName2EnvMap.end(), "### env reg error!" ); + aName2EnvMap.erase( aKey ); + return sal_True; +} +//__________________________________________________________________________________________________ +inline void EnvironmentsData::getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + const OUString & rEnvTypeName ) +{ + OSL_ENSHURE( pppEnvs && pnLen && memAlloc, "### null ptr!" ); + + uno_Environment ** ppFound; + sal_Int32 nSize = 0; + + { + MutexGuard aGuard( aMutex ); + // max size + ppFound = (uno_Environment **)alloca( sizeof(uno_Environment *) * aName2EnvMap.size() ); + // find matching environment + for ( OUString2EnvironmentMap::const_iterator iPos( aName2EnvMap.begin() ); + iPos != aName2EnvMap.end(); ++iPos ) + { + uno_Environment * pEnv = (*iPos).second; + if (!rEnvTypeName.getLength() || rEnvTypeName.equals( pEnv->pTypeName )) + { + (*pEnv->acquire)( pEnv ); + ppFound[nSize++] = pEnv; + } + } + } + + *pnLen = nSize; + if (nSize) + { + *pppEnvs = (uno_Environment **)(*memAlloc)( sizeof(uno_Environment *) * nSize ); + OSL_ASSERT( *pppEnvs ); + while (nSize--) + { + (*pppEnvs)[nSize] = ppFound[nSize]; + } + } + else + { + *pppEnvs = 0; + } +} + +//-------------------------------------------------------------------------------------------------- +static uno_Environment * initDefaultEnvironment( const OUString & rEnvTypeName, void * pContext ) +{ + uno_Environment * pEnv = 0; + + // create default environment + if (rEnvTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_LB_UNO) )) + { + uno_DefaultEnvironment * pDefEnv = new uno_DefaultEnvironment( rEnvTypeName, pContext, 0 ); + pEnv = (uno_Environment *)pDefEnv; + (*pEnv->acquire)( pEnv ); + pDefEnv->computeObjectIdentifier = unoenv_computeObjectIdentifier; + pDefEnv->acquireInterface = unoenv_acquireInterface; + pDefEnv->releaseInterface = unoenv_releaseInterface; + } + else + { + // late init with some code from matching uno language binding + OUStringBuffer aLibName( 16 ); +#ifdef SAL_UNX + aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM("lib") ); + aLibName.append( rEnvTypeName ); + aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM("_uno.so") ); +#else + aLibName.append( rEnvTypeName ); + aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM("_uno.dll") ); +#endif + OUString aStr( aLibName.makeStringAndClear() ); + // will be unloaded by environment + oslModule hMod = osl_loadModule( aStr.pData, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY ); + if (hMod) + { + OUString aSymbolName( RTL_CONSTASCII_USTRINGPARAM(UNO_INIT_ENVIRONMENT) ); + uno_initEnvironmentFunc fpInit = + (uno_initEnvironmentFunc)osl_getSymbol( hMod, aSymbolName.pData ); + if (fpInit) + { + pEnv = (uno_Environment *)new uno_DefaultEnvironment( rEnvTypeName, pContext, hMod ); + (*pEnv->acquire)( pEnv ); + (*fpInit)( pEnv ); // init of environment + } + else + { + osl_unloadModule( hMod ); + } + } + } + + return pEnv; +} + +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL anonymous_defenv_release( uno_Environment * pEnv ) +{ + if (! osl_decrementInterlockedCount( &((uno_DefaultEnvironment *)pEnv)->nRef )) + delete (uno_DefaultEnvironment *)pEnv; +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_createEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvTypeName, void * pContext ) +{ + OSL_ENSHURE( ppEnv, "### null ptr!" ); + if (*ppEnv) + (*(*ppEnv)->release)( *ppEnv ); + + *ppEnv = initDefaultEnvironment( + * reinterpret_cast< OUString * >( &pEnvTypeName ), pContext ); + (*ppEnv)->release = anonymous_defenv_release; // patch release func +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_getEnvironment( + uno_Environment ** ppEnv, rtl_uString * pEnvTypeName, void * pContext ) +{ + OSL_ENSHURE( ppEnv, "### null ptr!" ); + if (*ppEnv) + (*(*ppEnv)->release)( *ppEnv ); + + const OUString & rEnvTypeName = * reinterpret_cast< OUString * >( &pEnvTypeName ); + + MutexGuard aGuard( getEnvironmentsData().aMutex ); + *ppEnv = getEnvironmentsData().getEnvironment( rEnvTypeName, pContext ); + + if (! *ppEnv) + { + if (*ppEnv = initDefaultEnvironment( rEnvTypeName, pContext )) // register new environment + getEnvironmentsData().registerEnvironment( *ppEnv ); + } +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_getRegisteredEnvironments( + uno_Environment *** pppEnvs, sal_Int32 * pnLen, uno_memAlloc memAlloc, + rtl_uString * pEnvTypeName ) +{ + getEnvironmentsData().getRegisteredEnvironments( + pppEnvs, pnLen, memAlloc, + (pEnvTypeName ? OUString( pEnvTypeName ) : OUString()) ); +} diff --git a/cppu/source/uno/lbmap.cxx b/cppu/source/uno/lbmap.cxx new file mode 100644 index 000000000000..d79a9a9e7755 --- /dev/null +++ b/cppu/source/uno/lbmap.cxx @@ -0,0 +1,657 @@ +/************************************************************************* + * + * $RCSfile: lbmap.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifdef CPPU_ASSERTIONS +#define CPPU_TRACE(x) OSL_TRACE(x) +#else +#define CPPU_TRACE(x) +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef _OSL_MODULE_H_ +#include <osl/module.h> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _OSL_INTERLOCK_H_ +#include <osl/interlck.h> +#endif + +#ifndef _UNO_DISPATCHER_H_ +#include <uno/dispatcher.h> +#endif +#ifndef _UNO_MAPPING_HXX_ +#include <uno/mapping.hxx> +#endif +#ifndef _UNO_ENVIRONMENT_HXX_ +#include <uno/environment.hxx> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif + +#include <com/sun/star/uno/XInterface.hpp> + +#include <stl/hash_map> +#include <stl/set> +#include <stl/algorithm> + + +using namespace std; +using namespace osl; +using namespace rtl; +using namespace com::sun::star::uno; + + +//================================================================================================== +struct MappingEntry +{ + sal_Int32 nRef; + uno_Mapping * pMapping; + uno_freeMappingFunc freeMapping; + OUString aMappingName; + + MappingEntry( uno_Mapping * pMapping_, uno_freeMappingFunc freeMapping_, + const OUString & rMappingName_ ) + : nRef( 1 ) + , pMapping( pMapping_ ) + , freeMapping( freeMapping_ ) + , aMappingName( rMappingName_ ) + {} +}; +//-------------------------------------------------------------------------------------------------- +struct FctOUStringHash : public unary_function< const OUString &, size_t > +{ + size_t operator()( const OUString & rKey ) const + { return (size_t)rKey.hashCode(); } +}; +//-------------------------------------------------------------------------------------------------- +struct FctPtrHash : public unary_function< uno_Mapping *, size_t > +{ + size_t operator()( uno_Mapping * pKey ) const + { return (size_t)pKey; } +}; + +typedef hash_map< OUString, MappingEntry *, FctOUStringHash, equal_to< OUString > > t_OUString2Entry; +typedef hash_map< uno_Mapping *, MappingEntry *, FctPtrHash, equal_to< uno_Mapping * > > t_Mapping2Entry; + +typedef set< uno_getMappingFunc > t_CallbackSet; +typedef set< OUString > t_OUStringSet; + +//================================================================================================== +struct MappingsData +{ + Mutex aMappingsMutex; + t_OUString2Entry aName2Entry; + t_Mapping2Entry aMapping2Entry; + + Mutex aCallbacksMutex; + t_CallbackSet aCallbacks; + + Mutex aNegativeLibsMutex; + t_OUStringSet aNegativeLibs; + ~MappingsData(); +}; +//__________________________________________________________________________________________________ +MappingsData::~MappingsData() +{ +#ifdef CPPU_ASSERTIONS + OSL_ENSHURE( aName2Entry.empty() && aMapping2Entry.empty(), "### unrevoked mappings!" ); + t_OUString2Entry::const_iterator iPos( aName2Entry.begin() ); + while (iPos != aName2Entry.end()) + { + CPPU_TRACE( "\n### unrevoked mapping: " ); + MappingEntry * pEntry = (*iPos).second; + OString aName( OUStringToOString( pEntry->aMappingName, RTL_TEXTENCODING_ASCII_US ) ); + CPPU_TRACE( aName.getStr() ); + ++iPos; + } + OSL_ENSHURE( aCallbacks.empty(), "### callbacks left!" ); + if (aCallbacks.size()) + { + CPPU_TRACE( "\n### " ); + OString aSize( OString::valueOf( (sal_Int32)aCallbacks.size() ) ); + CPPU_TRACE( aSize.getStr() ); + CPPU_TRACE( " unrevoked callbacks" ); + } +#endif +} +//-------------------------------------------------------------------------------------------------- +static MappingsData & getMappingsData() +{ + static MappingsData * s_p = 0; + if (! s_p) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_p) + { + static MappingsData s_obj; + s_p = &s_obj; + } + } + return *s_p; +} + +/** + * This class mediates two different mapping via uno, e.g. form any language to uno, + * then from uno to any other language. + */ +struct uno_Mediate_Mapping : public uno_Mapping +{ + sal_Int32 nRef; + + Environment aFrom; + Environment aTo; + + Mapping aFrom2Uno; + Mapping aUno2To; + + OUString aAddPurpose; + + uno_Mediate_Mapping( const Environment & rFrom_, const Environment & rTo_, + const Mapping & rFrom2Uno_, const Mapping & rUno2To_, + const OUString & rAddPurpose ); +}; +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL mediate_free( uno_Mapping * pMapping ) +{ + delete static_cast< uno_Mediate_Mapping * >( pMapping ); +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL mediate_acquire( uno_Mapping * pMapping ) +{ + if (1 == osl_incrementInterlockedCount( & static_cast< uno_Mediate_Mapping * >( pMapping )->nRef )) + { + uno_registerMapping( &pMapping, mediate_free, + static_cast< uno_Mediate_Mapping * >( pMapping )->aFrom.get(), + static_cast< uno_Mediate_Mapping * >( pMapping )->aTo.get(), + static_cast< uno_Mediate_Mapping * >( pMapping )->aAddPurpose.pData ); + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL mediate_release( uno_Mapping * pMapping ) +{ + if (! osl_decrementInterlockedCount( & static_cast< uno_Mediate_Mapping * >( pMapping )->nRef )) + { + uno_revokeMapping( pMapping ); + } +} +//-------------------------------------------------------------------------------------------------- +static void SAL_CALL mediate_mapInterface( uno_Mapping * pMapping, + void ** ppOut, void * pInterface, + typelib_InterfaceTypeDescription * pInterfaceTypeDescr ) +{ + OSL_ENSHURE( pMapping && ppOut, "### null ptr!" ); + if (pMapping && ppOut) + { + uno_Interface * pUnoI = 0; + + uno_Mapping * pFrom2Uno = static_cast< uno_Mediate_Mapping * >( pMapping )->aFrom2Uno.get(); + uno_Mapping * pUno2To = static_cast< uno_Mediate_Mapping * >( pMapping )->aUno2To.get(); + + (*pFrom2Uno->mapInterface)( pFrom2Uno, (void **)&pUnoI, pInterface, pInterfaceTypeDescr ); + if (pUnoI) + { + (*pUno2To->mapInterface)( pUno2To, ppOut, pUnoI, pInterfaceTypeDescr ); + (*pUnoI->release)( pUnoI ); + } + } +} +//__________________________________________________________________________________________________ +uno_Mediate_Mapping::uno_Mediate_Mapping( const Environment & rFrom_, const Environment & rTo_, + const Mapping & rFrom2Uno_, const Mapping & rUno2To_, + const OUString & rAddPurpose_ ) + : nRef( 1 ) + , aFrom( rFrom_ ) + , aTo( rTo_ ) + , aFrom2Uno( rFrom2Uno_ ) + , aUno2To( rUno2To_ ) + , aAddPurpose( rAddPurpose_ ) +{ + uno_Mapping::acquire = mediate_acquire; + uno_Mapping::release = mediate_release; + uno_Mapping::mapInterface = mediate_mapInterface; +} + +//================================================================================================== +static inline OUString getMappingName( + const Environment & rFrom, const Environment & rTo, const OUString & rAddPurpose ) +{ + OUStringBuffer aKey( 64 ); + aKey.append( rAddPurpose ); + aKey.append( (sal_Unicode)';' ); + aKey.append( rFrom.getTypeName() ); + aKey.append( (sal_Unicode)'[' ); + aKey.append( (sal_Int64)rFrom.get(), 16 ); + aKey.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") ); + aKey.append( rTo.getTypeName() ); + aKey.append( (sal_Unicode)'[' ); + aKey.append( (sal_Int64)rTo.get(), 16 ); + aKey.append( (sal_Unicode)']' ); + return aKey.makeStringAndClear(); +} +//================================================================================================== +static inline OUString getLibName( + const Environment & rFrom, const Environment & rTo, const OUString & rAddPurpose ) +{ + OUStringBuffer aLibName( 16 ); +#ifdef SAL_UNX + aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM("lib") ); + if (rAddPurpose.getLength()) + { + aLibName.append( rAddPurpose ); + aLibName.append( (sal_Unicode)'_' ); + } + aLibName.append( rFrom.getTypeName() ); + aLibName.append( (sal_Unicode)'_' ); + aLibName.append( rTo.getTypeName() ); + aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM(".so") ); +#else + if (rAddPurpose.getLength()) + { + aLibName.append( rAddPurpose ); + aLibName.append( (sal_Unicode)'_' ); + } + aLibName.append( rFrom.getTypeName() ); + aLibName.append( (sal_Unicode)'_' ); + aLibName.append( rTo.getTypeName() ); +#ifndef OS2 + aLibName.appendAscii( RTL_CONSTASCII_STRINGPARAM(".dll") ); +#endif +#endif + return aLibName.makeStringAndClear(); +} + +//-------------------------------------------------------------------------------------------------- +static inline void setNegativeModule( const OUString & rName ) +{ + MappingsData & rData = getMappingsData(); + MutexGuard aGuard( rData.aNegativeLibsMutex ); + rData.aNegativeLibs.insert( rName ); +} +//-------------------------------------------------------------------------------------------------- +static inline oslModule loadModule( const OUString & rName ) +{ + sal_Bool bNeg; + { + MappingsData & rData = getMappingsData(); + MutexGuard aGuard( rData.aNegativeLibsMutex ); + const t_OUStringSet::const_iterator iFind( rData.aNegativeLibs.find( rName ) ); + bNeg = (iFind != rData.aNegativeLibs.end()); + } + + if (! bNeg) + { + oslModule hModule = osl_loadModule( rName.pData, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY ); + if (hModule) + return hModule; + setNegativeModule( rName ); // no load again + } + return 0; +} +//================================================================================================== +static Mapping loadExternalMapping( + const Environment & rFrom, const Environment & rTo, const OUString & rAddPurpose ) +{ + OSL_ASSERT( rFrom.is() && rTo.is() ); + if (rFrom.is() && rTo.is()) + { + // find proper lib + oslModule hModule = 0; + OUString aName; + + if (rFrom.getTypeName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_LB_UNO) )) + hModule = loadModule( aName = getLibName( rTo, rFrom, rAddPurpose ) ); + if (! hModule) + hModule = loadModule( aName = getLibName( rFrom, rTo, rAddPurpose ) ); + if (! hModule) + hModule = loadModule( aName = getLibName( rTo, rFrom, rAddPurpose ) ); + + if (hModule) + { + OUString aSymbolName( RTL_CONSTASCII_USTRINGPARAM(UNO_EXT_GETMAPPING) ); + uno_ext_getMappingFunc fpGetMapFunc = + (uno_ext_getMappingFunc)osl_getSymbol( hModule, aSymbolName.pData ); + if (fpGetMapFunc) + { + Mapping aExt; + (*fpGetMapFunc)( (uno_Mapping **)&aExt, rFrom.get(), rTo.get() ); + if (aExt.is()) + return aExt; + } + osl_unloadModule( hModule ); + setNegativeModule( aName ); + } + } + return Mapping(); +} + +//================================================================================================== +static Mapping getDirectMapping( + const Environment & rFrom, const Environment & rTo, const OUString & rAddPurpose = OUString() ) +{ + OSL_ASSERT( rFrom.is() && rTo.is() ); + if (rFrom.is() && rTo.is()) + { + MappingsData & rData = getMappingsData(); + ClearableMutexGuard aGuard( rData.aMappingsMutex ); + + // try to find registered mapping + const t_OUString2Entry::const_iterator iFind( rData.aName2Entry.find( + getMappingName( rFrom, rTo, rAddPurpose ) ) ); + + if (iFind == rData.aName2Entry.end()) + { + aGuard.clear(); + return loadExternalMapping( rFrom, rTo, rAddPurpose ); + } + else + { + return Mapping( (*iFind).second->pMapping ); + } + } + return Mapping(); +} + +//-------------------------------------------------------------------------------------------------- +static inline Mapping createMediateMapping( + const Environment & rFrom, const Environment & rTo, + const Mapping & rFrom2Uno, const Mapping & rUno2To, + const OUString & rAddPurpose ) +{ + uno_Mapping * pRet = new uno_Mediate_Mapping( + rFrom, rTo, rFrom2Uno, rUno2To, rAddPurpose ); // ref count initially 1 + uno_registerMapping( + &pRet, mediate_free, rFrom.get(), rTo.get(), rAddPurpose.pData ); + Mapping aRet( pRet ); + (*pRet->release)( pRet ); + return aRet; +} +//================================================================================================== +static Mapping getMediateMapping( + const Environment & rFrom, const Environment & rTo, const OUString & rAddPurpose ) +{ + Environment aUno; + Mapping aUno2To; + + // connect to uno + if (rTo.getTypeName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_LB_UNO ) )) // to is uno + { + aUno = rTo; + // no Uno2To mapping necessary + } + else + { + // get registered uno env + OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + uno_getEnvironment( (uno_Environment **)&aUno, aEnvTypeName.pData, 0 ); + + aUno2To = getDirectMapping( aUno, rTo ); + // : uno <-> to + } + + // connect to uno + if (rAddPurpose.getLength()) // insert purpose mapping between new ano_uno <-> uno + { + // create anonymous uno env + Environment aAnUno; + OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + uno_createEnvironment( (uno_Environment **)&aAnUno, aEnvTypeName.pData, 0 ); + + Mapping aAnUno2Uno( getDirectMapping( aAnUno, aUno, rAddPurpose ) ); + if (! aAnUno2Uno.is()) + return Mapping(); + if (aUno2To.is()) // to is not uno + { + // create another mediate mapping + aUno2To = createMediateMapping( aAnUno, rTo, aAnUno2Uno, aUno2To, rAddPurpose ); + // : ano_uno <-> uno <-> to + } + else + { + aUno2To = aAnUno2Uno; + // : ano_uno <-> to (i.e. uno) + } + aUno = aAnUno; + } + + Mapping aFrom2Uno( getDirectMapping( rFrom, aUno ) ); + if (aFrom2Uno.is()) + { + return createMediateMapping( rFrom, rTo, aFrom2Uno, aUno2To, rAddPurpose ); + // : from <-> some uno ... + } + + return Mapping(); +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_getMapping( + uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo, rtl_uString * pAddPurpose ) +{ + OSL_ENSHURE( ppMapping && pFrom && pTo, "### null ptr!" ); + if (*ppMapping) + { + (*(*ppMapping)->release)( *ppMapping ); + *ppMapping = 0; + } + + Mapping aRet; + Environment aFrom( pFrom ), aTo( pTo ); + + OUString aAddPurpose; + if (pAddPurpose) + aAddPurpose = pAddPurpose; + + MappingsData & rData = getMappingsData(); + + // try registered mapping + { + MutexGuard aGuard( rData.aMappingsMutex ); + const t_OUString2Entry::const_iterator iFind( rData.aName2Entry.find( + getMappingName( aFrom, aTo, aAddPurpose ) ) ); + if (iFind != rData.aName2Entry.end()) + aRet = (*iFind).second->pMapping; + } + + if (! aRet.is()) // try callback chain + { + MutexGuard aGuard( rData.aCallbacksMutex ); + for ( t_CallbackSet::const_iterator iPos( rData.aCallbacks.begin() ); + iPos != rData.aCallbacks.end(); ++iPos ) + { + (**iPos)( ppMapping, pFrom, pTo, aAddPurpose.pData ); + if (*ppMapping) + return; + } + } + + if (! aRet.is()) + { + aRet = loadExternalMapping( aFrom, aTo, aAddPurpose ); // direct try + if (! aRet.is()) + aRet = getMediateMapping( aFrom, aTo, aAddPurpose ); // try via uno + } + + if (aRet.is()) + { + (*aRet.get()->acquire)( aRet.get() ); + *ppMapping = aRet.get(); + } +} +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_getMappingByName( + uno_Mapping ** ppMapping, rtl_uString * pFrom, rtl_uString * pTo, rtl_uString * pAddPurpose ) +{ + OSL_ENSHURE( ppMapping && pFrom && pTo, "### null ptr!" ); + if (*ppMapping) + { + (*(*ppMapping)->release)( *ppMapping ); + *ppMapping = 0; + } + + uno_Environment * pEFrom = 0; + uno_getEnvironment( &pEFrom, pFrom, 0 ); + OSL_ENSHURE( pEFrom, "### cannot get source environment!" ); + if (pEFrom) + { + uno_Environment * pETo = 0; + uno_getEnvironment( &pETo, pTo, 0 ); + OSL_ENSHURE( pETo, "### cannot get target environment!" ); + if (pETo) + { + uno_getMapping( ppMapping, pEFrom, pETo, pAddPurpose ); + (*pETo->release)( pETo ); + } + (*pEFrom->release)( pEFrom ); + } +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_registerMapping( + uno_Mapping ** ppMapping, uno_freeMappingFunc freeMapping, + uno_Environment * pFrom, uno_Environment * pTo, rtl_uString * pAddPurpose ) +{ + MappingsData & rData = getMappingsData(); + ClearableMutexGuard aGuard( rData.aMappingsMutex ); + + const t_Mapping2Entry::const_iterator iFind( rData.aMapping2Entry.find( *ppMapping ) ); + if (iFind == rData.aMapping2Entry.end()) + { + OUString aMappingName( + getMappingName( pFrom, pTo, pAddPurpose ? OUString(pAddPurpose) : OUString() ) ); +#ifdef CPPU_ASSERTIONS + CPPU_TRACE( "> inserting new mapping " ); + OString aMappingName8( OUStringToOString( aMappingName, RTL_TEXTENCODING_ASCII_US ) ); + CPPU_TRACE( aMappingName8.getStr() ); + CPPU_TRACE( " <\n" ); +#endif + // count initially 1 + MappingEntry * pEntry = new MappingEntry( *ppMapping, freeMapping, aMappingName ); + rData.aName2Entry[ aMappingName ] = pEntry; + rData.aMapping2Entry[ *ppMapping ] = pEntry; + } + else + { + MappingEntry * pEntry = (*iFind).second; + ++pEntry->nRef; + + if (pEntry->pMapping != *ppMapping) // exchange mapping to be registered + { + (*pEntry->pMapping->acquire)( pEntry->pMapping ); + --pEntry->nRef; // correct count; kill mapping to be registered + aGuard.clear(); + (*freeMapping)( *ppMapping ); + *ppMapping = pEntry->pMapping; + } + } +} +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_revokeMapping( uno_Mapping * pMapping ) +{ + MappingsData & rData = getMappingsData(); + ClearableMutexGuard aGuard( rData.aMappingsMutex ); + + const t_Mapping2Entry::const_iterator iFind( rData.aMapping2Entry.find( pMapping ) ); + OSL_ASSERT( iFind != rData.aMapping2Entry.end() ); + MappingEntry * pEntry = (*iFind).second; + if (! --pEntry->nRef) + { + rData.aMapping2Entry.erase( pEntry->pMapping ); + rData.aName2Entry.erase( pEntry->aMappingName ); + aGuard.clear(); +#ifdef CPPU_ASSERTIONS + CPPU_TRACE( "> revoking mapping " ); + OString aMappingName( OUStringToOString( pEntry->aMappingName, RTL_TEXTENCODING_ASCII_US ) ); + CPPU_TRACE( aMappingName.getStr() ); + CPPU_TRACE( " <\n" ); +#endif + (*pEntry->freeMapping)( pEntry->pMapping ); + delete pEntry; + } +} + +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_registerMappingCallback( uno_getMappingFunc pCallback ) +{ + OSL_ENSHURE( pCallback, "### null ptr!" ); + MappingsData & rData = getMappingsData(); + MutexGuard aGuard( rData.aCallbacksMutex ); + rData.aCallbacks.insert( pCallback ); +} +//################################################################################################## +extern "C" SAL_DLLEXPORT void SAL_CALL uno_revokeMappingCallback( uno_getMappingFunc pCallback ) +{ + OSL_ENSHURE( pCallback, "### null ptr!" ); + MappingsData & rData = getMappingsData(); + MutexGuard aGuard( rData.aCallbacksMutex ); + rData.aCallbacks.erase( pCallback ); +} diff --git a/cppu/source/uno/makefile.mk b/cppu/source/uno/makefile.mk new file mode 100644 index 000000000000..a11b841fd746 --- /dev/null +++ b/cppu/source/uno/makefile.mk @@ -0,0 +1,93 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=cppu +TARGET=cppu_uno + +# --- Settings ----------------------------------------------------- + +.INCLUDE : ..$/..$/util$/makefile.pmk +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/data.obj \ + $(SLO)$/sequence.obj \ + $(SLO)$/any.obj \ + $(SLO)$/lbmap.obj \ + $(SLO)$/lbenv.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmb.obj +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : ..$/..$/util$/target.pmk +.INCLUDE : target.mk diff --git a/cppu/source/uno/prim.hxx b/cppu/source/uno/prim.hxx new file mode 100644 index 000000000000..4f589b4caf2d --- /dev/null +++ b/cppu/source/uno/prim.hxx @@ -0,0 +1,262 @@ +/************************************************************************* + * + * $RCSfile: prim.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef __PRIM_HXX__ +#define __PRIM_HXX__ + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _typelib_TypeClass_H_ +#include <typelib/typeclass.h> +#endif +#ifndef _UNO_SEQUENCE2_H_ +#include <uno/sequence2.h> +#endif +#ifndef _UNO_ANY2_H_ +#include <uno/any2.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif +#ifndef _UNO_MAPPING_H_ +#include <uno/mapping.h> +#endif +#ifndef _UNO_DISPATCHER_H_ +#include <uno/dispatcher.h> +#endif + +#ifndef _OSL_INTERLCK_H +#include <osl/interlck.h> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _RTL_USTRING_HXX +#include <rtl/ustring.hxx> +#endif +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif + +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/uno/XInterface.hpp> + +namespace cppu +{ + +//-------------------------------------------------------------------------------------------------- +inline void * __map( + void * p, + typelib_TypeDescriptionReference * pType, + typelib_TypeDescription * pTypeDescr, + uno_Mapping * mapping ) +{ + void * pRet = 0; + if (p) + { + if (pTypeDescr) + { + (*mapping->mapInterface)( mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr ); + } + else + { + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + (*mapping->mapInterface)( mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + } + return pRet; +} +//-------------------------------------------------------------------------------------------------- +inline void __acquire( void * p, uno_AcquireFunc acquire ) +{ + if (p) + { + if (acquire) + (*acquire)( p ); + else + (*((uno_Interface *)p)->acquire)( (uno_Interface *)p ); + } +} +//-------------------------------------------------------------------------------------------------- +inline void __releaseRef( void ** pRef, uno_ReleaseFunc release ) +{ + if (*pRef) + { + if (release) + (*release)( *pRef ); + else + (*((uno_Interface *)*pRef)->release)( (uno_Interface *)*pRef ); + } +#ifdef DEBUG + *pRef = (void *)0xdeadbeef; +#endif +} + +//-------------------------------------------------------------------------------------------------- +static uno_Sequence * s_pSeq = 0; +static uno_Sequence s_seq; +inline uno_Sequence * __getEmptySequence() +{ + if (! s_pSeq) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! s_pSeq) + { + s_seq.nRefCount = 1; + s_seq.nElements = 0; + s_pSeq = &s_seq; + } + } + ::osl_incrementInterlockedCount( &s_pSeq->nRefCount ); + return s_pSeq; +} +//-------------------------------------------------------------------------------------------------- +static typelib_TypeDescriptionReference * s_pVoidType = 0; +inline typelib_TypeDescriptionReference * __getVoidType() +{ + if (! s_pVoidType) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! s_pVoidType) + { + s_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ); + } + } + ::typelib_typedescriptionreference_acquire( s_pVoidType ); + return s_pVoidType; +} + +//-------------------------------------------------------------------------------------------------- +#ifdef DEBUG +#define __CONSTRUCT_EMPTY_ANY( pAny ) \ +(pAny)->pType = __getVoidType(); \ +(pAny)->pData = (void *)0xdeadbeef; +#else +#define __CONSTRUCT_EMPTY_ANY( pAny ) \ +(pAny)->pType = __getVoidType(); +#endif + +//-------------------------------------------------------------------------------------------------- +#define TYPE_ACQUIRE( pType ) \ + ::osl_incrementInterlockedCount( &(pType)->nRefCount ); + +//-------------------------------------------------------------------------------------------------- +static typelib_TypeDescription * s_pQITD = 0; +inline typelib_TypeDescription * __getQueryInterfaceTypeDescr() +{ + if (! s_pQITD) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! s_pQITD) + { + typelib_InterfaceTypeDescription * pTXInterfaceDescr = 0; + const com::sun::star::uno::Type & rXIType = + ::getCppuType( (const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > *)0 ); + TYPELIB_DANGER_GET( (typelib_TypeDescription **)&pTXInterfaceDescr, rXIType.getTypeLibType() ); + OSL_ASSERT( pTXInterfaceDescr->ppAllMembers ); + ::typelib_typedescriptionreference_getDescription( + &s_pQITD, pTXInterfaceDescr->ppAllMembers[0] ); + TYPELIB_DANGER_RELEASE( (typelib_TypeDescription *)pTXInterfaceDescr ); + } + } + ::typelib_typedescription_acquire( s_pQITD ); + return s_pQITD; +} + +//-------------------------------------------------------------------------------------------------- +inline typelib_TypeDescriptionReference * __unionGetSetType( + void * pUnion, typelib_TypeDescription * pTD ) +{ + typelib_TypeDescriptionReference * pRet; + + sal_Int64 * pDiscr = ((typelib_UnionTypeDescription *)pTD)->pDiscriminants; + sal_Int64 nDiscr = *(sal_Int64 *)pUnion; + for ( sal_Int32 nPos = ((typelib_UnionTypeDescription *)pTD)->nMembers; nPos--; ) + { + if (pDiscr[nPos] == nDiscr) + { + pRet = ((typelib_UnionTypeDescription *)pTD)->ppTypeRefs[nPos]; + break; + } + } + if (nPos >= 0) + { + // default + pRet = ((typelib_UnionTypeDescription *)pTD)->pDefaultTypeRef; + } + typelib_typedescriptionreference_acquire( pRet ); + return pRet; +} +//-------------------------------------------------------------------------------------------------- +inline sal_Bool __type_equals( + typelib_TypeDescriptionReference * pType1, + typelib_TypeDescriptionReference * pType2 ) +{ + return (pType1 == pType2 || + (pType1->eTypeClass == pType2->eTypeClass && + pType1->pTypeName->length == pType2->pTypeName->length && + ::rtl_ustr_compare( pType1->pTypeName->buffer, pType2->pTypeName->buffer ) == 0)); +} + +} + +#endif diff --git a/cppu/source/uno/sequence.cxx b/cppu/source/uno/sequence.cxx new file mode 100644 index 000000000000..8d4576aea3f4 --- /dev/null +++ b/cppu/source/uno/sequence.cxx @@ -0,0 +1,804 @@ +/************************************************************************* + * + * $RCSfile: sequence.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _OSL_INTERLCK_H_ +#include <osl/interlck.h> +#endif + +#ifndef _TYPELIB_TYPEDESCRIPTION_H_ +#include <typelib/typedescription.h> +#endif +#ifndef _UNO_DATA_H_ +#include <uno/data.h> +#endif +#ifndef _UNO_DISPATCHER_H_ +#include <uno/dispatcher.h> +#endif +#ifndef _UNO_SEQUENCE2_H_ +#include <uno/sequence2.h> +#endif + +#include "constr.hxx" +#include "copy.hxx" +#include "destr.hxx" + +using namespace cppu; + +namespace cppu +{ +//-------------------------------------------------------------------------------------------------- +static inline void allocSeq( + uno_Sequence ** ppSeq, sal_Int32 nElementSize, sal_Int32 nElements ) +{ + if (nElements) + { + uno_Sequence * pSeq = (uno_Sequence *) + (*ppSeq + ? ::rtl_reallocateMemory( *ppSeq, SAL_SEQUENCE_HEADER_SIZE + (nElementSize * nElements) ) + : ::rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + (nElementSize * nElements) )); + pSeq->nRefCount = 1; + pSeq->nElements = nElements; + *ppSeq = pSeq; + } +} +//-------------------------------------------------------------------------------------------------- +inline void __defaultConstructElements( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pElementType, + sal_Int32 nStartIndex, sal_Int32 nStopIndex, + sal_Int32 nAlloc = 0 ) // >= 0 means (re)alloc memory for nAlloc elements +{ + switch (pElementType->eTypeClass) + { + case typelib_TypeClass_CHAR: + allocSeq( ppSequence, sizeof(sal_Unicode), nAlloc ); + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(sal_Unicode) * nStartIndex), + sizeof(sal_Unicode) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_BOOLEAN: + allocSeq( ppSequence, sizeof(sal_Bool), nAlloc ); + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(sal_Bool) * nStartIndex), + sizeof(sal_Bool) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_BYTE: + allocSeq( ppSequence, sizeof(sal_Int8), nAlloc ); + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(sal_Int8) * nStartIndex), + sizeof(sal_Int8) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + allocSeq( ppSequence, sizeof(sal_Int16), nAlloc ); + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(sal_Int16) * nStartIndex), + sizeof(sal_Int16) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + allocSeq( ppSequence, sizeof(sal_Int32), nAlloc ); + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(sal_Int32) * nStartIndex), + sizeof(sal_Int32) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + allocSeq( ppSequence, sizeof(sal_Int64), nAlloc ); + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(sal_Int64) * nStartIndex), + sizeof(sal_Int64) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_FLOAT: + { + allocSeq( ppSequence, sizeof(float), nAlloc ); + + float * pElements = (float *)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + pElements[nPos] = 0.0; + } + break; + } + case typelib_TypeClass_DOUBLE: + { + allocSeq( ppSequence, sizeof(double), nAlloc ); + + double * pElements = (double *)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + pElements[nPos] = 0.0; + } + break; + } + case typelib_TypeClass_STRING: + { + allocSeq( ppSequence, sizeof(rtl_uString *), nAlloc ); + + rtl_uString ** pElements = (rtl_uString **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + pElements[nPos] = 0; + RTL_USTRING_NEW( &pElements[nPos] ); + } + break; + } + case typelib_TypeClass_TYPE: + { + allocSeq( ppSequence, sizeof(typelib_TypeDescriptionReference *), nAlloc ); + + typelib_TypeDescriptionReference ** pElements = + (typelib_TypeDescriptionReference **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + pElements[nPos] = __getVoidType(); + } + break; + } + case typelib_TypeClass_ANY: + { + allocSeq( ppSequence, sizeof(uno_Any), nAlloc ); + + uno_Any * pElements = (uno_Any *)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __CONSTRUCT_EMPTY_ANY( &pElements[nPos] ); + } + break; + } + case typelib_TypeClass_ENUM: + { + allocSeq( ppSequence, sizeof(int), nAlloc ); + +// ::rtl_zeroMemory( +// (*ppSequence)->elements + (sizeof(int) * nStartIndex), +// sizeof(int) * (nStopIndex - nStartIndex) ); + + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + int eEnum = ((typelib_EnumTypeDescription *)pElementTypeDescr)->nDefaultEnumValue; + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + + int * pElements = (int *)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + pElements[nPos] = eEnum; + } + break; + } +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + + allocSeq( ppSequence, nElementSize, nAlloc ); + + char * pElements = (*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __defaultConstructStruct( + pElements + (nElementSize * nPos), + (typelib_CompoundTypeDescription *)pElementTypeDescr ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_UNION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + + sal_Int32 nElementSize = pElementTypeDescr->nSize; + + allocSeq( ppSequence, nElementSize, nAlloc ); + + sal_Int32 nValueOffset = ((typelib_UnionTypeDescription *)pElementTypeDescr)->nValueOffset; + sal_Int32 nDefaultDiscr = ((typelib_UnionTypeDescription *)pElementTypeDescr)->nDefaultDiscriminant; + + typelib_TypeDescription * pDefaultTypeDescr = 0; + TYPELIB_DANGER_GET( &pDefaultTypeDescr, ((typelib_UnionTypeDescription *)pElementTypeDescr)->pDefaultTypeRef ); + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + + char * pElements = (*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + char * pMem = pElements + (nElementSize * nPos); + ::uno_constructData( (char *)pMem + nValueOffset, pDefaultTypeDescr ); + *(sal_Int64 *)pMem = nDefaultDiscr; + } + TYPELIB_DANGER_RELEASE( pDefaultTypeDescr ); + break; + } + case typelib_TypeClass_SEQUENCE: + { + allocSeq( ppSequence, sizeof(uno_Sequence *), nAlloc ); + + uno_Sequence ** pElements = (uno_Sequence **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + pElements[nPos] = __getEmptySequence(); + } + break; + } + case typelib_TypeClass_INTERFACE: // either cpp or c-uno interface + allocSeq( ppSequence, sizeof(void *), nAlloc ); + + ::rtl_zeroMemory( + (*ppSequence)->elements + (sizeof(void *) * nStartIndex), + sizeof(void *) * (nStopIndex - nStartIndex) ); + break; + } +} +//-------------------------------------------------------------------------------------------------- +inline void __copyConstructElements( + uno_Sequence ** ppSequence, void * pSourceElements, + typelib_TypeDescriptionReference * pElementType, + sal_Int32 nStartIndex, sal_Int32 nStopIndex, + uno_AcquireFunc acquire, + sal_Int32 nAlloc = 0 ) +{ + switch (pElementType->eTypeClass) + { + case typelib_TypeClass_CHAR: + allocSeq( ppSequence, sizeof(sal_Unicode), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(sal_Unicode) * nStartIndex), + (char *)pSourceElements + (sizeof(sal_Unicode) * nStartIndex), + sizeof(sal_Unicode) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_BOOLEAN: + allocSeq( ppSequence, sizeof(sal_Bool), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(sal_Bool) * nStartIndex), + (char *)pSourceElements + (sizeof(sal_Bool) * nStartIndex), + sizeof(sal_Bool) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_BYTE: + allocSeq( ppSequence, sizeof(sal_Int8), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(sal_Int8) * nStartIndex), + (char *)pSourceElements + (sizeof(sal_Int8) * nStartIndex), + sizeof(sal_Int8) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + allocSeq( ppSequence, sizeof(sal_Int16), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(sal_Int16) * nStartIndex), + (char *)pSourceElements + (sizeof(sal_Int16) * nStartIndex), + sizeof(sal_Int16) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + allocSeq( ppSequence, sizeof(sal_Int32), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(sal_Int32) * nStartIndex), + (char *)pSourceElements + (sizeof(sal_Int32) * nStartIndex), + sizeof(sal_Int32) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + allocSeq( ppSequence, sizeof(sal_Int64), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(sal_Int64) * nStartIndex), + (char *)pSourceElements + (sizeof(sal_Int64) * nStartIndex), + sizeof(sal_Int64) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_FLOAT: + allocSeq( ppSequence, sizeof(float), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(float) * nStartIndex), + (char *)pSourceElements + (sizeof(float) * nStartIndex), + sizeof(float) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_DOUBLE: + allocSeq( ppSequence, sizeof(double), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(double) * nStartIndex), + (char *)pSourceElements + (sizeof(double) * nStartIndex), + sizeof(double) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_ENUM: + allocSeq( ppSequence, sizeof(int), nAlloc ); + ::rtl_copyMemory( + (*ppSequence)->elements + (sizeof(int) * nStartIndex), + (char *)pSourceElements + (sizeof(int) * nStartIndex), + sizeof(int) * (nStopIndex - nStartIndex) ); + break; + case typelib_TypeClass_STRING: + { + allocSeq( ppSequence, sizeof(rtl_uString *), nAlloc ); + + rtl_uString ** pDestElements = (rtl_uString **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + ::rtl_uString_acquire( ((rtl_uString **)pSourceElements)[nPos] ); + pDestElements[nPos] = ((rtl_uString **)pSourceElements)[nPos]; + } + break; + } + case typelib_TypeClass_TYPE: + { + allocSeq( ppSequence, sizeof(typelib_TypeDescriptionReference *), nAlloc ); + + typelib_TypeDescriptionReference ** pDestElements = + (typelib_TypeDescriptionReference **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + TYPE_ACQUIRE( ((typelib_TypeDescriptionReference **)pSourceElements)[nPos] ); + pDestElements[nPos] = ((typelib_TypeDescriptionReference **)pSourceElements)[nPos]; + } + break; + } + case typelib_TypeClass_ANY: + { + allocSeq( ppSequence, sizeof(uno_Any), nAlloc ); + + uno_Any * pDestElements = (uno_Any *)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + uno_Any * pSource = (uno_Any *)pSourceElements + nPos; + __copyConstructAny( + &pDestElements[nPos], + pSource->pData, + pSource->pType, 0, + acquire, 0 ); + } + break; + } +#ifdef CPPU_ASSERTIONS + case typelib_TypeClass_TYPEDEF: + OSL_ENSHURE( sal_False, "### unexpected typedef!" ); + break; +#endif + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + + allocSeq( ppSequence, nElementSize, nAlloc ); + + char * pDestElements = (*ppSequence)->elements; + + typelib_CompoundTypeDescription * pTypeDescr = (typelib_CompoundTypeDescription *)pElementTypeDescr; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + char * pDest = pDestElements + (nElementSize * nPos); + char * pSource = (char *)pSourceElements + (nElementSize * nPos); + + if (pTypeDescr->pBaseTypeDescription) + { + // copy base value + __copyConstructStruct( pDest, pSource, pTypeDescr->pBaseTypeDescription, acquire, 0 ); + } + + // then copy members + typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs; + sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets; + sal_Int32 nDescr = pTypeDescr->nMembers; + + while (nDescr--) + { + ::uno_type_copyData( + pDest + pMemberOffsets[nDescr], + pSource + pMemberOffsets[nDescr], + ppTypeRefs[nDescr], acquire ); + } + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_UNION: + { + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + sal_Int32 nElementSize = pElementTypeDescr->nSize; + + allocSeq( ppSequence, nElementSize, nAlloc ); + + char * pDestElements = (*ppSequence)->elements; + + sal_Int32 nValueOffset = ((typelib_UnionTypeDescription *)pElementTypeDescr)->nValueOffset; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + char * pDest = pDestElements + (nElementSize * nPos); + char * pSource = (char *)pSourceElements + (nElementSize * nPos); + + typelib_TypeDescriptionReference * pSetType = __unionGetSetType( pSource, pElementTypeDescr ); + uno_type_copyData( pDest + nValueOffset, + pSource + nValueOffset, + pSetType, acquire ); + *(sal_Int64 *)pDest = *(sal_Int64 *)pSource; + typelib_typedescriptionreference_release( pSetType ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_SEQUENCE: + { + allocSeq( ppSequence, sizeof(uno_Sequence *), nAlloc ); + + typelib_TypeDescription * pElementTypeDescr = 0; + TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + uno_Sequence ** pDestElements = (uno_Sequence **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __copyConstructSequence( + &pDestElements[nPos], + ((uno_Sequence **)pSourceElements)[nPos], + ((typelib_IndirectTypeDescription *)pElementTypeDescr)->pType, + acquire, 0 ); + } + TYPELIB_DANGER_RELEASE( pElementTypeDescr ); + break; + } + case typelib_TypeClass_INTERFACE: + { + allocSeq( ppSequence, sizeof(void *), nAlloc ); + + void ** pDestElements = (void **)(*ppSequence)->elements; + for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos ) + { + __acquire( pDestElements[nPos] = ((void **)pSourceElements)[nPos], acquire ); + } + break; + } + } +} +//-------------------------------------------------------------------------------------------------- +inline void __reallocSequence( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pElementType, + sal_Int32 nSize, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + uno_Sequence * pSource = *ppSequence; + sal_Int32 nSourceElements = pSource->nElements; + + if (pSource->nRefCount > 1) // split + { + uno_Sequence * pNew = 0; + + sal_Int32 nRest = nSize - nSourceElements; + sal_Int32 nCopy = (nRest > 0 ? nSourceElements : nSize); + + if (nCopy > 0) + { + __copyConstructElements( + &pNew, pSource->elements, pElementType, + 0, nCopy, acquire, + nSize ); // alloc to nSize + } + if (nRest > 0) + { + __defaultConstructElements( + &pNew, pElementType, + nCopy, nSize, + nCopy > 0 ? 0 : nSize ); // alloc to nSize if nCopy <= 0 + } + + // destruct sequence + if (! ::osl_decrementInterlockedCount( &(*ppSequence)->nRefCount )) + { + if ((*ppSequence)->nElements) + { + __destructElements( + (*ppSequence)->elements, pElementType, 0, (*ppSequence)->nElements, release ); + } + ::rtl_freeMemory( *ppSequence ); + } + + *ppSequence = pNew; + } + else + { + if (nSize > nSourceElements) // default construct the rest + { + __defaultConstructElements( + ppSequence, pElementType, + nSourceElements, nSize, + nSize ); // realloc to nSize + } + else // or destruct the rest and realloc mem + { + sal_Int32 nElementSize = __destructElements( + (*ppSequence)->elements, pElementType, + nSize, nSourceElements, release ); + *ppSequence = (uno_Sequence *)::rtl_reallocateMemory( + *ppSequence, SAL_SEQUENCE_HEADER_SIZE + (nSize * nElementSize) ); + (*ppSequence)->nElements = nSize; + } + } +} + +} + +extern "C" +{ +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_construct( + uno_Sequence ** ppSequence, typelib_TypeDescriptionReference * pType, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) +{ + if (len) + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + + typelib_TypeDescriptionReference * pElementType = + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType; + + uno_Sequence * pSequence = 0; + + if (pElements) + { + __copyConstructElements( + &pSequence, pElements, pElementType, + 0, len, acquire, + len ); // alloc to len + } + else + { + __defaultConstructElements( + &pSequence, + pElementType, + 0, len, + len ); // alloc to len + } + + *ppSequence = pSequence; + + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + else + { + *ppSequence = __getEmptySequence(); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_sequence_construct( + uno_Sequence ** ppSequence, typelib_TypeDescription * pTypeDescr, + void * pElements, sal_Int32 len, + uno_AcquireFunc acquire ) +{ + if (len) + { + typelib_TypeDescriptionReference * pElementType = + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType; + + uno_Sequence * pSequence = 0; + + if (pElements) + { + __copyConstructElements( + &pSequence, pElements, pElementType, + 0, len, acquire, + len ); // alloc to len + } + else + { + __defaultConstructElements( + &pSequence, + pElementType, + 0, len, + len ); // alloc to len + } + + *ppSequence = pSequence; + } + else + { + *ppSequence = __getEmptySequence(); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_realloc( + uno_Sequence ** ppSequence, typelib_TypeDescriptionReference * pType, sal_Int32 nSize, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + OSL_ENSHURE( ppSequence, "### null ptr!" ); + OSL_ENSHURE( nSize >= 0, "### new size must be at least 0!" ); + + if (nSize != (*ppSequence)->nElements) + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + __reallocSequence( + ppSequence, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + nSize, acquire, release ); + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_sequence_realloc( + uno_Sequence ** ppSequence, typelib_TypeDescription * pTypeDescr, sal_Int32 nSize, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + OSL_ENSHURE( ppSequence, "### null ptr!" ); + OSL_ENSHURE( nSize >= 0, "### new size must be at least 0!" ); + + if (nSize != (*ppSequence)->nElements) + { + __reallocSequence( + ppSequence, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + nSize, acquire, release ); + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_reference2One( + uno_Sequence ** ppSequence, + typelib_TypeDescriptionReference * pType, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + OSL_ENSHURE( ppSequence, "### null ptr!" ); + uno_Sequence * pSequence = *ppSequence; + if (pSequence->nRefCount > 1) + { + if (pSequence->nElements) + { + typelib_TypeDescription * pTypeDescr = 0; + TYPELIB_DANGER_GET( &pTypeDescr, pType ); + + uno_Sequence * pNew = 0; + __copyConstructElements( + &pNew, pSequence->elements, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + 0, pSequence->nElements, acquire, + pSequence->nElements ); // alloc nElements + + __destructSequence( *ppSequence, pType, pTypeDescr, release ); + *ppSequence = pNew; + + TYPELIB_DANGER_RELEASE( pTypeDescr ); + } + else + { + __destructSequence( *ppSequence, pType, 0, release ); + + uno_Sequence * pNew = (uno_Sequence *)::rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE ); + pNew->nRefCount = 1; + pNew->nElements = 0; + *ppSequence = pNew; + } + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_sequence_reference2One( + uno_Sequence ** ppSequence, + typelib_TypeDescription * pTypeDescr, + uno_AcquireFunc acquire, uno_ReleaseFunc release ) +{ + OSL_ENSHURE( ppSequence, "### null ptr!" ); + uno_Sequence * pSequence = *ppSequence; + if (pSequence->nRefCount > 1) + { + if (pSequence->nElements) + { + uno_Sequence * pNew = 0; + __copyConstructElements( + &pNew, pSequence->elements, + ((typelib_IndirectTypeDescription *)pTypeDescr)->pType, + 0, pSequence->nElements, acquire, + pSequence->nElements ); // alloc nElements + + __destructSequence( *ppSequence, pTypeDescr->pWeakRef, pTypeDescr, release ); + *ppSequence = pNew; + } + else + { + __destructSequence( *ppSequence, pTypeDescr->pWeakRef, pTypeDescr, release ); + + uno_Sequence * pNew = (uno_Sequence *)::rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE ); + pNew->nRefCount = 1; + pNew->nElements = 0; + *ppSequence = pNew; + } + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + typelib_TypeDescription * pTypeDescr, + uno_ReleaseFunc release ) +{ + if (*ppDest != pSource) + { + ::osl_incrementInterlockedCount( &pSource->nRefCount ); + __destructSequence( *ppDest, pTypeDescr->pWeakRef, pTypeDescr, release ); + *ppDest = pSource; + } +} +//################################################################################################## +SAL_DLLEXPORT void SAL_CALL uno_type_sequence_assign( + uno_Sequence ** ppDest, + uno_Sequence * pSource, + typelib_TypeDescriptionReference * pType, + uno_ReleaseFunc release ) +{ + if (*ppDest != pSource) + { + ::osl_incrementInterlockedCount( &pSource->nRefCount ); + __destructSequence( *ppDest, pType, 0, release ); + *ppDest = pSource; + } +} + +} diff --git a/cppu/test/cpputest.idl b/cppu/test/cpputest.idl new file mode 100644 index 000000000000..fab2b36ae7a8 --- /dev/null +++ b/cppu/test/cpputest.idl @@ -0,0 +1,129 @@ +/************************************************************************* + * + * $RCSfile: cpputest.idl,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TEST_CPPUTEST_IDL_ +#define _TEST_CPPUTEST_IDL_ + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/uno/TypeClass.idl> + +module test +{ + +struct Test1 +{ + short nInt16; + double dDouble; + boolean bBool; +}; + +struct Test2 +{ + short nInt16; + Test1 aTest1; +}; + +typedef Test1 TdTest1; + +struct Test3 +{ + byte nInt8; + float nFloat; + double nDouble; + short nInt16; + string aString; + unsigned short nuInt16; + hyper nInt64; + long nInt32; + unsigned hyper nuInt64; + unsigned long nuInt32; + com::sun::star::uno::TypeClass eType; + char wChar; + TdTest1 td; + boolean bBool; + any aAny; +}; + + +struct Base +{ + long n; + short o; +}; + +struct Base1 : Base +{ + short p; +}; + +struct Base2 : Base1 +{ + double p2; +}; + +[ uik(46121273-3462-11d3-87A400A0-24494732), ident("SimpleInterface", 1.0) ] +interface XSimpleInterface : com::sun::star::uno::XInterface +{ + void method(); +}; + +}; //module test + +#endif diff --git a/cppu/test/language_binding.idl b/cppu/test/language_binding.idl new file mode 100644 index 000000000000..ad23f590bf12 --- /dev/null +++ b/cppu/test/language_binding.idl @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: language_binding.idl,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _TEST_LANGUAGE_BINDING_IDL_ +#define _TEST_LANGUAGE_BINDING_IDL_ + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/lang/IllegalArgumentException.idl> + +module test +{ + +enum TestEnum +{ + TEST, + ONE, + TWO, + CHECK, + LOLA, + PALOO, + ZA +}; + +/** + * simple c++ types + */ +struct TestSimple +{ + boolean Bool; + char Char; + byte Byte; + short Short; + unsigned short UShort; + long Long; + unsigned long ULong; + hyper Hyper; + unsigned hyper UHyper; + float Float; + double Double; + test::TestEnum Enum; +}; +/** + * complex c++ types + */ +struct TestElement : test::TestSimple +{ + string String; + com::sun::star::uno::XInterface Interface; + any Any; +}; +struct TestDataElements : test::TestElement +{ + sequence<test::TestElement > Sequence; +}; + +typedef TestDataElements TestData; + +/** + * Monster test interface to test language binding calls. + * + * @author Daniel Boelzle + */ +[ uik(46833373-3462-11d3-87A400A0-24494732), ident("XLBTest", 1.0) ] +interface XLBTestBase : com::sun::star::uno::XInterface +{ + /** + * in parameter test, tests by calls reference also (complex types) + */ + [oneway] void setValues( [in] boolean bBool, [in] char cChar, [in] byte nByte, + [in] short nShort, [in] unsigned short nUShort, + [in] long nLong, [in] unsigned long nULong, + [in] hyper nHyper, [in] unsigned hyper nUHyper, + [in] float fFloat, [in] double fDouble, + [in] test::TestEnum eEnum, [in] string aString, + [in] com::sun::star::uno::XInterface xInterface, [in] any aAny, + [in] sequence<test::TestElement > aSequence, + [in] test::TestData aStruct ); + /** + * inout parameter test + */ + test::TestData setValues2( [inout] boolean bBool, [inout] char cChar, [inout] byte nByte, + [inout] short nShort, [inout] unsigned short nUShort, + [inout] long nLong, [inout] unsigned long nULong, + [inout] hyper nHyper, [inout] unsigned hyper nUHyper, + [inout] float fFloat, [inout] double fDouble, + [inout] test::TestEnum eEnum, [inout] string aString, + [inout] com::sun::star::uno::XInterface xInterface, [inout] any aAny, + [inout] sequence<test::TestElement > aSequence, + [inout] test::TestData aStruct ); + + /** + * out parameter test + */ + test::TestData getValues( [out] boolean bBool, [out] char cChar, [out] byte nByte, + [out] short nShort, [out] unsigned short nUShort, + [out] long nLong, [out] unsigned long nULong, + [out] hyper nHyper, [out] unsigned hyper nUHyper, + [out] float fFloat, [out] double fDouble, + [out] test::TestEnum eEnum, [out] string aString, + [out] com::sun::star::uno::XInterface xInterface, [out] any aAny, + [out] sequence<test::TestElement > aSequence, + [out] test::TestData aStruct ); + + [attribute] boolean Bool; + [attribute] byte Byte; + [attribute] char Char; + [attribute] short Short; + [attribute] unsigned short UShort; + [attribute] long Long; + [attribute] unsigned long ULong; + [attribute] hyper Hyper; + [attribute] unsigned hyper UHyper; + [attribute] float Float; + [attribute] double Double; + [attribute] test::TestEnum Enum; + [attribute] string String; + [attribute] com::sun::star::uno::XInterface Interface; + [attribute] any Any; + [attribute] sequence<test::TestElement > Sequence; + [attribute] test::TestData Struct; +}; + + +/** + * Inherting from monster; adds raiseException(). + * + * @author Daniel Boelzle + */ +[ uik(44C34C20-3478-11d3-87A400A0-24494732), ident("XLanguageBindingTest", 1.0) ] +interface XLanguageBindingTest : test::XLBTestBase +{ + /** + * params are there only for dummy, to test if all temp out params will be released. + */ + test::TestData raiseException( [out] boolean bBool, [out] char cChar, [out] byte nByte, + [out] short nShort, [out] unsigned short nUShort, + [out] long nLong, [out] unsigned long nULong, + [out] hyper nHyper, [out] unsigned hyper nUHyper, + [out] float fFloat, [out] double fDouble, + [out] test::TestEnum eEnum, [out] string aString, + [out] com::sun::star::uno::XInterface xInterface, [out] any aAny, + [out] sequence<test::TestElement > aSequence, + [out] test::TestData aStruct ) + raises( com::sun::star::lang::IllegalArgumentException ); + + /** + * raises runtime exception + */ + [attribute] long RuntimeException; +}; + +}; // test + + +#endif diff --git a/cppu/test/makefile.mk b/cppu/test/makefile.mk new file mode 100644 index 000000000000..ee745c922cba --- /dev/null +++ b/cppu/test/makefile.mk @@ -0,0 +1,153 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=.. + +PRJNAME= testcppu +TARGET= testcppu +LIBTARGET= NO +TARGETTYPE= CUI +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC= TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +UNOUCRDEP= $(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB= $(SOLARBINDIR)$/applicat.rdb +UNOUCROUT= $(OUT)$/inc$/test +INCPRE+= $(OUT)$/inc$/test + +OBJFILES= \ + $(OBJ)$/testcppu.obj \ + $(OBJ)$/test_di.obj + + +APP1TARGET= testcppu +APP1OBJS= $(OBJ)$/test_di.obj \ + $(OBJ)$/testcppu.obj + +APP1STDLIBS+= \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) + +APP1DEF= $(MISC)$/$(APP1TARGET).def + +ALLIDLFILES:= cpputest.idl \ + language_binding.idl + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL : $(BIN)$/testcppu.rdb unoheader ALLTAR +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE : target.mk + +CPPUMAKERFLAGS = -C +.IF "$(COM)" == "MSC" +CPPUMAKERFLAGS = -L +.ENDIF + +TYPES:= -Ttest.XLanguageBindingTest \ + -Ttest.XSimpleInterface \ + -Ttest.Test1 \ + -Ttest.Test2 \ + -Ttest.TdTest1 \ + -Ttest.Test3 \ + -Ttest.Base \ + -Ttest.Base1 \ + -Ttest.Base2 \ + -Tcom.sun.star.lang.XMultiServiceFactory \ + -Tcom.sun.star.lang.XSingleServiceFactory \ + -Tcom.sun.star.lang.XInitialization \ + -Tcom.sun.star.lang.XServiceInfo \ + -Tcom.sun.star.lang.XEventListener \ + -Tcom.sun.star.lang.XTypeProvider \ + -Tcom.sun.star.registry.XSimpleRegistry \ + -Tcom.sun.star.registry.XRegistryKey \ + -Tcom.sun.star.loader.XImplementationLoader \ + -Tcom.sun.star.registry.XImplementationRegistration \ + -Tcom.sun.star.lang.XComponent \ + -Tcom.sun.star.container.XSet \ + -Tcom.sun.star.uno.XReference \ + -Tcom.sun.star.uno.XAdapter \ + -Tcom.sun.star.uno.XAggregation \ + -Tcom.sun.star.uno.XWeak \ + -Tcom.sun.star.reflection.XIdlClassProvider + +$(BIN)$/testcppu.rdb: $(ALLIDLFILES) + +unoidl -I$(PRJ) -I$(SOLARIDLDIR) -Burd -OH$(BIN) $? + +regmerge $@ /UCR $(BIN)$/{$(?:f:s/.idl/.urd/)} + +regmerge $@ / $(UNOUCRRDB) + touch $@ + +unoheader: $(BIN)$/testcppu.rdb + +cppumaker $(CPPUMAKERFLAGS) -BUCR -O$(UNOUCROUT) $(TYPES) $(BIN)$/testcppu.rdb + diff --git a/cppu/test/surrogate.hxx b/cppu/test/surrogate.hxx new file mode 100644 index 000000000000..bb60f491055e --- /dev/null +++ b/cppu/test/surrogate.hxx @@ -0,0 +1,189 @@ +/************************************************************************* + * + * $RCSfile: surrogate.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <uno/dispatcher.h> +#include <uno/mapping.hxx> +#include <uno/environment.h> +#include <uno/data.h> +#include <osl/diagnose.h> +#include <osl/interlck.h> + +#include <com/sun/star/uno/Reference.hxx> + +/* +//================================================================================================== +struct UnoMediator : public uno_Interface +{ + oslInterlockedCount nRef; + uno_Interface * pDest; + + UnoMediator( uno_Interface * pDest ); + ~UnoMediator(); +}; + +//-------------------------------------------------------------------------------------------------- +inline static void SAL_CALL UnoMediator_acquire( uno_Interface * pUnoI ) +{ + osl_incrementInterlockedCount( &((UnoMediator *)pUnoI)->nRef ); +} +//-------------------------------------------------------------------------------------------------- +inline static void SAL_CALL UnoMediator_release( uno_Interface * pUnoI ) +{ + if (! osl_decrementInterlockedCount( &((UnoMediator *)pUnoI)->nRef )) + delete (UnoMediator *)pUnoI; +} +//-------------------------------------------------------------------------------------------------- +inline static void SAL_CALL UnoMediator_dispatch( + uno_Interface * pUnoI, const typelib_TypeDescription * pMemberType, + void * pReturn, void * pArgs[], uno_Any ** ppException ) +{ + (*((UnoMediator *)pUnoI)->pDest->pDispatcher)( + ((UnoMediator *)pUnoI)->pDest, pMemberType, pReturn, pArgs, ppException ); +} + +//__________________________________________________________________________________________________ +UnoMediator::UnoMediator( uno_Interface * pDest_ ) + : nRef( 0 ) + , pDest( pDest_ ) +{ + (*pDest->acquire)( pDest ); + uno_Interface::acquire = UnoMediator_acquire; + uno_Interface::release = UnoMediator_release; + uno_Interface::pDispatcher = UnoMediator_dispatch; +} +//__________________________________________________________________________________________________ +UnoMediator::~UnoMediator() +{ + (*pDest->release)( pDest ); +} +*/ + +//################################################################################################## + +template< class T > +inline sal_Bool makeSurrogate( com::sun::star::uno::Reference< T > & rOut, + const com::sun::star::uno::Reference< T > & rOriginal ) +{ + rOut.clear(); + + typelib_TypeDescription * pTD = 0; + const com::sun::star::uno::Type & rType = ::getCppuType( &rOriginal ); + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + OSL_ENSHURE( pTD, "### cannot get typedescription!" ); + if (pTD) + { + uno_Environment * pCppEnv1 = 0; + uno_Environment * pCppEnv2 = 0; + + ::rtl::OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 ); + uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous + + ::com::sun::star::uno::Mapping aMapping( pCppEnv1, pCppEnv2, ::rtl::OUString::createFromAscii("prot") ); + T * p = (T *)aMapping.mapInterface( rOriginal.get(), (typelib_InterfaceTypeDescription *)pTD ); + if (p) + { + rOut = p; + p->release(); + } + + (*pCppEnv2->release)( pCppEnv2 ); + (*pCppEnv1->release)( pCppEnv1 ); + + TYPELIB_DANGER_RELEASE( pTD ); + } +/* + ::com::sun::star::uno::Mapping aCpp2Uno( CPPU_CURRENT_LANGUAGE_BINDING_NAME, UNO_LB_UNO ); + ::com::sun::star::uno::Mapping aUno2Cpp( UNO_LB_UNO, CPPU_CURRENT_LANGUAGE_BINDING_NAME ); + OSL_ENSHURE( aCpp2Uno.is() && aUno2Cpp.is(), "### cannot get mappings!" ); + if (aCpp2Uno.is() && aUno2Cpp.is()) + { + typelib_TypeDescription * pTD = 0; + const com::sun::star::uno::Type & rType = ::getCppuType( &rOriginal ); + TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); + OSL_ENSHURE( pTD, "### cannot get typedescription!" ); + if (pTD) + { + uno_Interface * pUno = (uno_Interface *)aCpp2Uno.mapInterface( + rOriginal.get(), (typelib_InterfaceTypeDescription *)pTD ); + if (pUno) + { + UnoMediator * pPseudo = new UnoMediator( pUno ); + (*pPseudo->acquire)( pPseudo ); + OSL_ENSHURE( uno_equals( &pUno, &pPseudo, pTD, 0 ), "### interfaces don't belong to same object, but they do!?" ); + (*pUno->release)( pUno ); + + T * pCpp = (T *)aUno2Cpp.mapInterface( + pPseudo, (typelib_InterfaceTypeDescription *)pTD ); + (*pPseudo->release)( pPseudo ); + + if (pCpp) + { + rOut = pCpp; + pCpp->release(); + } + } + TYPELIB_DANGER_RELEASE( pTD ); + } + } +*/ + return rOut.is(); +} diff --git a/cppu/test/test_di.cxx b/cppu/test/test_di.cxx new file mode 100644 index 000000000000..5f8e750fb179 --- /dev/null +++ b/cppu/test/test_di.cxx @@ -0,0 +1,608 @@ +/************************************************************************* + * + * $RCSfile: test_di.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> +#include <osl/time.h> +// +#include <uno/dispatcher.h> +#include <uno/environment.h> +#include <uno/mapping.hxx> +#include <uno/data.h> + +#include <cppuhelper/weak.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppu/macros.hxx> +#include <test/XLanguageBindingTest.hpp> + +#include <cppuhelper/implbase1.hxx> + + +using namespace test; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace osl; +using namespace rtl; + + +//================================================================================================== +sal_Bool equals( const test::TestElement & rData1, const test::TestElement & rData2 ) +{ + OSL_ENSHURE( rData1.Bool == rData2.Bool, "### bool does not match!" ); + OSL_ENSHURE( rData1.Char == rData2.Char, "### char does not match!" ); + OSL_ENSHURE( rData1.Byte == rData2.Byte, "### byte does not match!" ); + OSL_ENSHURE( rData1.Short == rData2.Short, "### short does not match!" ); + OSL_ENSHURE( rData1.UShort == rData2.UShort, "### unsigned short does not match!" ); + OSL_ENSHURE( rData1.Long == rData2.Long, "### long does not match!" ); + OSL_ENSHURE( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); + OSL_ENSHURE( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); + OSL_ENSHURE( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); + OSL_ENSHURE( rData1.Float == rData2.Float, "### float does not match!" ); + OSL_ENSHURE( rData1.Double == rData2.Double, "### double does not match!" ); + OSL_ENSHURE( rData1.Enum == rData2.Enum, "### enum does not match!" ); + OSL_ENSHURE( rData1.String == rData2.String, "### string does not match!" ); + OSL_ENSHURE( rData1.Interface == rData2.Interface, "### interface does not match!" ); + OSL_ENSHURE( rData1.Any == rData2.Any, "### any does not match!" ); + + return (rData1.Bool == rData2.Bool && + rData1.Char == rData2.Char && + rData1.Byte == rData2.Byte && + rData1.Short == rData2.Short && + rData1.UShort == rData2.UShort && + rData1.Long == rData2.Long && + rData1.ULong == rData2.ULong && + rData1.Hyper == rData2.Hyper && + rData1.UHyper == rData2.UHyper && + rData1.Float == rData2.Float && + rData1.Double == rData2.Double && + rData1.Enum == rData2.Enum && + rData1.String == rData2.String && + rData1.Interface == rData2.Interface && + rData1.Any == rData2.Any); +} +//================================================================================================== +sal_Bool equals( const test::TestData & rData1, const test::TestData & rData2 ) +{ + sal_Int32 nLen; + + if ((rData1.Sequence == rData2.Sequence) && + equals( (const test::TestElement &)rData1, (const test::TestElement &)rData2 ) && + (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength()) + { + // once again by hand sequence == + const test::TestElement * pElements1 = rData1.Sequence.getConstArray(); + const test::TestElement * pElements2 = rData2.Sequence.getConstArray(); + for ( ; nLen--; ) + { + if (! equals( pElements1[nLen], pElements2[nLen] )) + { + OSL_ENSHURE( sal_False, "### sequence element did not match!" ); + return sal_False; + } + } + return sal_True; + } + return sal_False; +} +//================================================================================================== +void assign( test::TestElement & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny ) +{ + rData.Bool = bBool; + rData.Char = cChar; + rData.Byte = nByte; + rData.Short = nShort; + rData.UShort = nUShort; + rData.Long = nLong; + rData.ULong = nULong; + rData.Hyper = nHyper; + rData.UHyper = nUHyper; + rData.Float = fFloat; + rData.Double = fDouble; + rData.Enum = eEnum; + rData.String = rStr; + rData.Interface = xTest; + rData.Any = rAny; +} +//================================================================================================== +void assign( test::TestData & rData, + sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const com::sun::star::uno::Sequence< test::TestElement >& rSequence ) +{ + assign( (test::TestElement &)rData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny ); + rData.Sequence = rSequence; +} + +//================================================================================================== +class Test_Impl : public cppu::WeakImplHelper1< XLanguageBindingTest > +{ + test::TestData _aData, _aStructData; + +public: + virtual ~Test_Impl() + { OSL_TRACE( "> scalar Test_Impl dtor <\n" ); } + + // XLBTestBase + virtual void SAL_CALL setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + const test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual test::TestData SAL_CALL setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual test::TestData SAL_CALL getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence< test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL getBool() throw(com::sun::star::uno::RuntimeException) + { return _aData.Bool; } + virtual sal_Int8 SAL_CALL getByte() throw(com::sun::star::uno::RuntimeException) + { return _aData.Byte; } + virtual sal_Unicode SAL_CALL getChar() throw(com::sun::star::uno::RuntimeException) + { return _aData.Char; } + virtual sal_Int16 SAL_CALL getShort() throw(com::sun::star::uno::RuntimeException) + { return _aData.Short; } + virtual sal_uInt16 SAL_CALL getUShort() throw(com::sun::star::uno::RuntimeException) + { return _aData.UShort; } + virtual sal_Int32 SAL_CALL getLong() throw(com::sun::star::uno::RuntimeException) + { return _aData.Long; } + virtual sal_uInt32 SAL_CALL getULong() throw(com::sun::star::uno::RuntimeException) + { return _aData.ULong; } + virtual sal_Int64 SAL_CALL getHyper() throw(com::sun::star::uno::RuntimeException) + { return _aData.Hyper; } + virtual sal_uInt64 SAL_CALL getUHyper() throw(com::sun::star::uno::RuntimeException) + { return _aData.UHyper; } + virtual float SAL_CALL getFloat() throw(com::sun::star::uno::RuntimeException) + { return _aData.Float; } + virtual double SAL_CALL getDouble() throw(com::sun::star::uno::RuntimeException) + { return _aData.Double; } + virtual test::TestEnum SAL_CALL getEnum() throw(com::sun::star::uno::RuntimeException) + { return _aData.Enum; } + virtual rtl::OUString SAL_CALL getString() throw(com::sun::star::uno::RuntimeException) + { return _aData.String; } + virtual com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getInterface( ) throw(com::sun::star::uno::RuntimeException) + { return _aData.Interface; } + virtual com::sun::star::uno::Any SAL_CALL getAny() throw(com::sun::star::uno::RuntimeException) + { return _aData.Any; } + virtual com::sun::star::uno::Sequence< test::TestElement > SAL_CALL getSequence() throw(com::sun::star::uno::RuntimeException) + { return _aData.Sequence; } + virtual test::TestData SAL_CALL getStruct() throw(com::sun::star::uno::RuntimeException) + { return _aStructData; } + + virtual void SAL_CALL setBool( sal_Bool _bool ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Bool = _bool; } + virtual void SAL_CALL setByte( sal_Int8 _byte ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Byte = _byte; } + virtual void SAL_CALL setChar( sal_Unicode _char ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Char = _char; } + virtual void SAL_CALL setShort( sal_Int16 _short ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Short = _short; } + virtual void SAL_CALL setUShort( sal_uInt16 _ushort ) throw(::com::sun::star::uno::RuntimeException) + { _aData.UShort = _ushort; } + virtual void SAL_CALL setLong( sal_Int32 _long ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Long = _long; } + virtual void SAL_CALL setULong( sal_uInt32 _ulong ) throw(::com::sun::star::uno::RuntimeException) + { _aData.ULong = _ulong; } + virtual void SAL_CALL setHyper( sal_Int64 _hyper ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Hyper = _hyper; } + virtual void SAL_CALL setUHyper( sal_uInt64 _uhyper ) throw(::com::sun::star::uno::RuntimeException) + { _aData.UHyper = _uhyper; } + virtual void SAL_CALL setFloat( float _float ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Float = _float; } + virtual void SAL_CALL setDouble( double _double ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Double = _double; } + virtual void SAL_CALL setEnum( test::TestEnum _enum ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Enum = _enum; } + virtual void SAL_CALL setString( const ::rtl::OUString& _string ) throw(::com::sun::star::uno::RuntimeException) + { _aData.String = _string; } + virtual void SAL_CALL setInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _interface ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Interface = _interface; } + virtual void SAL_CALL setAny( const ::com::sun::star::uno::Any& _any ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Any = _any; } + virtual void SAL_CALL setSequence( const ::com::sun::star::uno::Sequence<test::TestElement >& _sequence ) throw(::com::sun::star::uno::RuntimeException) + { _aData.Sequence = _sequence; } + virtual void SAL_CALL setStruct( const test::TestData& _struct ) throw(::com::sun::star::uno::RuntimeException) + { _aStructData = _struct; } + + // XLanguageBindingTest + virtual test::TestData SAL_CALL raiseException( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, sal_Int16& nShort, sal_uInt16& nUShort, sal_Int32& nLong, sal_uInt32& nULong, sal_Int64& nHyper, sal_uInt64& nUHyper, float& fFloat, double& fDouble, test::TestEnum& eEnum, ::rtl::OUString& aString, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInterface, ::com::sun::star::uno::Any& aAny, ::com::sun::star::uno::Sequence<test::TestElement >& aSequence,test::TestData& aStruct ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getRuntimeException() throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRuntimeException( sal_Int32 _runtimeexception ) throw(::com::sun::star::uno::RuntimeException); +}; +//__________________________________________________________________________________________________ +void Test_Impl::setValues( sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte, + sal_Int16 nShort, sal_uInt16 nUShort, + sal_Int32 nLong, sal_uInt32 nULong, + sal_Int64 nHyper, sal_uInt64 nUHyper, + float fFloat, double fDouble, + test::TestEnum eEnum, const ::rtl::OUString& rStr, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + const ::com::sun::star::uno::Any& rAny, + const ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + const test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny, rSequence ); + _aStructData = rStruct; +} +//__________________________________________________________________________________________________ +test::TestData Test_Impl::setValues2( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + assign( _aData, + bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, + eEnum, rStr, xTest, rAny, rSequence ); + _aStructData = rStruct; + return _aStructData; +} +//__________________________________________________________________________________________________ +test::TestData Test_Impl::getValues( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, + sal_Int16& nShort, sal_uInt16& nUShort, + sal_Int32& nLong, sal_uInt32& nULong, + sal_Int64& nHyper, sal_uInt64& nUHyper, + float& fFloat, double& fDouble, + test::TestEnum& eEnum, rtl::OUString& rStr, + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest, + ::com::sun::star::uno::Any& rAny, + ::com::sun::star::uno::Sequence<test::TestElement >& rSequence, + test::TestData& rStruct ) + throw(com::sun::star::uno::RuntimeException) +{ + bBool = _aData.Bool; + cChar = _aData.Char; + nByte = _aData.Byte; + nShort = _aData.Short; + nUShort = _aData.UShort; + nLong = _aData.Long; + nULong = _aData.ULong; + nHyper = _aData.Hyper; + nUHyper = _aData.UHyper; + fFloat = _aData.Float; + fDouble = _aData.Double; + eEnum = _aData.Enum; + rStr = _aData.String; + xTest = _aData.Interface; + rAny = _aData.Any; + rSequence = _aData.Sequence; + rStruct = _aStructData; + return _aStructData; +} + +//================================================================================================== +sal_Bool performTest( const Reference<XLanguageBindingTest > & xLBT ) +{ + OSL_ENSHURE( xLBT.is(), "### no test interface!" ); + if (xLBT.is()) + { + // this data is never ever granted access to by calls other than equals(), assign()! + test::TestData aData; // test against this data + + Reference<XInterface > xI( *new OWeakObject() ); + + assign( (test::TestElement &)aData, + sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, + 0x123456789abcdef0, 0xfedcba9876543210, + (float)17.0815, 3.1415926359, TestEnum_LOLA, + OUString::createFromAscii("dumdidum"), xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + OSL_ENSHURE( aData.Any == xI, "### unexpected any!" ); + OSL_ENSHURE( !(aData.Any != xI), "### unexpected any!" ); + + aData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aData, 1 ); + // aData complete + //================================================================================ + + // this is a manually copy of aData for first setting... + test::TestData aSetData; + + assign( (test::TestElement &)aSetData, + aData.Bool, aData.Char, aData.Byte, aData.Short, aData.UShort, + aData.Long, aData.ULong, aData.Hyper, aData.UHyper, aData.Float, aData.Double, + aData.Enum, aData.String, xI, + Any( &xI, ::getCppuType( (const Reference<XInterface > *)0 ) ) ); + + aSetData.Sequence = Sequence<test::TestElement >( (const test::TestElement *)&aSetData, 1 ); + + xLBT->setValues( + aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short, aSetData.UShort, + aSetData.Long, aSetData.ULong, aSetData.Hyper, aSetData.UHyper, aSetData.Float, aSetData.Double, + aSetData.Enum, aSetData.String, aSetData.Interface, aSetData.Any, aSetData.Sequence, aSetData ); + + { + test::TestData aRet, aRet2; + xLBT->getValues( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) ); + + // set last retrieved values + test::TestData aSV2ret = xLBT->setValues2( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aSV2ret ) && equals( aData, aRet2 ) ); + } + { + test::TestData aRet, aRet2; + test::TestData aGVret = xLBT->getValues( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + + OSL_ASSERT( equals( aData, aRet ) && equals( aData, aRet2 ) && equals( aData, aGVret ) ); + + // set last retrieved values + xLBT->setBool( aRet.Bool ); + xLBT->setChar( aRet.Char ); + xLBT->setByte( aRet.Byte ); + xLBT->setShort( aRet.Short ); + xLBT->setUShort( aRet.UShort ); + xLBT->setLong( aRet.Long ); + xLBT->setULong( aRet.ULong ); + xLBT->setHyper( aRet.Hyper ); + xLBT->setUHyper( aRet.UHyper ); + xLBT->setFloat( aRet.Float ); + xLBT->setDouble( aRet.Double ); + xLBT->setEnum( aRet.Enum ); + xLBT->setString( aRet.String ); + xLBT->setInterface( aRet.Interface ); + xLBT->setAny( aRet.Any ); + xLBT->setSequence( aRet.Sequence ); + xLBT->setStruct( aRet2 ); + } + { + test::TestData aRet, aRet2; + aRet.Hyper = xLBT->getHyper(); + aRet.UHyper = xLBT->getUHyper(); + aRet.Float = xLBT->getFloat(); + aRet.Double = xLBT->getDouble(); + aRet.Byte = xLBT->getByte(); + aRet.Char = xLBT->getChar(); + aRet.Bool = xLBT->getBool(); + aRet.Short = xLBT->getShort(); + aRet.UShort = xLBT->getUShort(); + aRet.Long = xLBT->getLong(); + aRet.ULong = xLBT->getULong(); + aRet.Enum = xLBT->getEnum(); + aRet.String = xLBT->getString(); + aRet.Interface = xLBT->getInterface(); + aRet.Any = xLBT->getAny(); + aRet.Sequence = xLBT->getSequence(); + aRet2 = xLBT->getStruct(); + + return (equals( aData, aRet ) && equals( aData, aRet2 )); + } + } + return sal_False; +} + +//__________________________________________________________________________________________________ +test::TestData Test_Impl::raiseException( sal_Bool& bBool, sal_Unicode& cChar, sal_Int8& nByte, sal_Int16& nShort, sal_uInt16& nUShort, sal_Int32& nLong, sal_uInt32& nULong, sal_Int64& nHyper, sal_uInt64& nUHyper, float& fFloat, double& fDouble, test::TestEnum& eEnum, ::rtl::OUString& aString, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInterface, ::com::sun::star::uno::Any& aAny, ::com::sun::star::uno::Sequence< test::TestElement >& aSequence, test::TestData& aStruct ) + throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + IllegalArgumentException aExc; + aExc.ArgumentPosition = 5; + aExc.Message = OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." ); + aExc.Context = getInterface(); + throw aExc; + return test::TestData(); +} +//__________________________________________________________________________________________________ +sal_Int32 Test_Impl::getRuntimeException() throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." ); + aExc.Context = getInterface(); + throw aExc; + return 0; +} +//__________________________________________________________________________________________________ +void Test_Impl::setRuntimeException( sal_Int32 _runtimeexception ) throw(::com::sun::star::uno::RuntimeException) +{ + RuntimeException aExc; + aExc.Message = OUString::createFromAscii( "dum dum dum ich tanz im kreis herum..." ); + aExc.Context = getInterface(); + throw aExc; +} +//================================================================================================== +sal_Bool raiseException( const Reference< XLanguageBindingTest > & xLBT ) +{ + sal_Int32 nCount = 0; + try + { + try + { + try + { + test::TestData aRet, aRet2; + xLBT->raiseException( + aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort, + aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float, aRet.Double, + aRet.Enum, aRet.String, aRet.Interface, aRet.Any, aRet.Sequence, aRet2 ); + } + catch (IllegalArgumentException aExc) + { + ++nCount; + OSL_ENSHURE( aExc.ArgumentPosition == 5 && + aExc.Context == xLBT->getInterface() && + aExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + "### unexpected exception content!" ); + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->getRuntimeException(); + } + } + catch (const RuntimeException & rExc) + { + ++nCount; + OSL_ENSHURE( rExc.Context == xLBT->getInterface() && + rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + "### unexpected exception content!" ); + + /** it is certain, that the RuntimeException testing will fail, if no */ + xLBT->setRuntimeException( 0xcafebabe ); + } + } + catch (Exception & rExc) + { + ++nCount; + OSL_ENSHURE( rExc.Context == xLBT->getInterface() && + rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") ), + "### unexpected exception content!" ); + return (nCount == 3 && + rExc.Context == xLBT->getInterface() && + rExc.Message.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dum dum dum ich tanz im kreis herum...") )); + } + return sal_False; +} + +//================================================================================================== +void test_di(void) +{ + Reference<XLanguageBindingTest > xOriginal( (XLanguageBindingTest *)new Test_Impl() ); + Reference<XLanguageBindingTest > xLBT; + + uno_Environment * pCppEnv1 = 0; + uno_Environment * pCppEnv2 = 0; + + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCppEnv1, aCppEnvTypeName.pData, 0 ); + uno_createEnvironment( &pCppEnv2, aCppEnvTypeName.pData, 0 ); // anonymous + + Mapping aMapping( pCppEnv1, pCppEnv2, OUString::createFromAscii("prot") ); + aMapping.mapInterface( (void **)&xLBT, xOriginal.get(), ::getCppuType( &xOriginal ) ); + OSL_ENSHURE( aMapping.is(), "### cannot get mapping!" ); + + (*pCppEnv2->release)( pCppEnv2 ); + (*pCppEnv1->release)( pCppEnv1 ); + + OSL_ASSERT( xLBT.is() ); + + if (xLBT.is() && performTest( xLBT )) + { + if (raiseException( xLBT )) + { + printf( "> dynamic invocation test succeeded!\n" ); + return; + } + } + printf( "> dynamic invocation test failed!\n" ); +} diff --git a/cppu/test/testcppu.cxx b/cppu/test/testcppu.cxx new file mode 100644 index 000000000000..d08b29214b5a --- /dev/null +++ b/cppu/test/testcppu.cxx @@ -0,0 +1,886 @@ +/************************************************************************* + * + * $RCSfile: testcppu.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <uno/environment.h> +#include <uno/mapping.hxx> + +#include <uno/dispatcher.h> +#include <rtl/alloc.h> + +#include <cppuhelper/queryinterface.hxx> +#include <com/sun/star/uno/Exception.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/Uik.hpp> +#include <rtl/ustring.hxx> +#include <osl/diagnose.h> +#include <osl/interlck.h> + + +#include <test/Test1.hpp> +#include <test/Test2.hpp> +#include <test/TdTest1.hpp> +#include <test/Test3.hpp> +#include <test/Base.hpp> +#include <test/Base1.hpp> +#include <test/Base2.hpp> + +#include <cppuhelper/servicefactory.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <test/XSimpleInterface.hpp> +#include <test/XLanguageBindingTest.hpp> + +using namespace test; +using namespace rtl; +using namespace osl; + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace test; + + +sal_Int32 getSize( const Type & rT ) +{ + sal_Int32 nSize; + typelib_TypeDescription * pTD = 0; + typelib_typedescriptionreference_getDescription( &pTD, rT.getTypeLibType() ); + nSize = pTD->nSize; + typelib_typedescription_release( pTD ); + return nSize; +} +/* + * main. + */ +void testCppu() +{ + { + // test the size of types + OSL_ENSHURE( sizeof( Uik ) == getSize( getCppuType( (Uik *)0) ), + "bad sizeof uik" ); + OSL_ENSHURE( sizeof( Test1 ) == getSize( getCppuType( (Test1*)0).getTypeLibType() ), + "bad sizeof test1" ); +// OSL_ENSHURE( sizeof( TdTest1 ) == getSize( get_test_TdTest1_Type().getTypeLibType() ), +// "bad sizeof TypedefTest1" ); + OSL_ENSHURE( sizeof( Test2 ) == getSize( getCppuType( (Test2*)0).getTypeLibType() ), + "bad sizeof test2" ); + +/* find the error +sal_Int32 nPos; +nPos = (sal_Int32)&((Test3 *)0)->nInt8; +nPos = (sal_Int32)&((Test3 *)0)->nFloat; +nPos = (sal_Int32)&((Test3 *)0)->nuInt8; +nPos = (sal_Int32)&((Test3 *)0)->nDouble; +nPos = (sal_Int32)&((Test3 *)0)->nInt16; +nPos = (sal_Int32)&((Test3 *)0)->aString; +nPos = (sal_Int32)&((Test3 *)0)->nuInt16; +nPos = (sal_Int32)&((Test3 *)0)->nInt64; +nPos = (sal_Int32)&((Test3 *)0)->nInt32; +nPos = (sal_Int32)&((Test3 *)0)->nuInt64; +nPos = (sal_Int32)&((Test3 *)0)->nuInt32; +nPos = (sal_Int32)&((Test3 *)0)->eType; +nPos = (sal_Int32)&((Test3 *)0)->wChar; +nPos = (sal_Int32)&((Test3 *)0)->td; +nPos = (sal_Int32)&((Test3 *)0)->bBool; +nPos = (sal_Int32)&((Test3 *)0)->aAny; +*/ + OSL_ENSHURE( sizeof( Test3 ) == getSize( getCppuType( (Test3*)0).getTypeLibType() ), + "bad sizeof test3" ); + } + + { + // test the default constructor + Test1 a1; + a1.nInt16 = 4; + a1.dDouble = 3.6; + a1.bBool = sal_True; + uno_type_constructData( &a1, getCppuType( (Test1*)0).getTypeLibType() ); + OSL_ASSERT( a1.nInt16 == 0 && a1.dDouble == 0.0 && a1.bBool == sal_False); + + Test2 a2; + a2.nInt16 = 2; + a2.aTest1.nInt16 = 4; + a2.aTest1.dDouble = 3.6; + a2.aTest1.dDouble = sal_True; + uno_type_constructData( &a2, getCppuType( (Test2*)0).getTypeLibType() ); + OSL_ASSERT( a2.nInt16 == 0 && a2.aTest1.nInt16 == 0 && a2.aTest1.dDouble == 0.0 && a2.aTest1.bBool == sal_False); + + Test3 * pa3 = (Test3 *)new char[ sizeof( Test3 ) ]; + Test3 & a3 = *pa3; + a3.nInt8 = 2; + a3.nFloat = (float)2; + a3.nDouble = 2; + a3.nInt16 = 2; + a3.nuInt16 = 2; + a3.nInt64 = 2; + a3.nInt32 = 2; + a3.nuInt64 = 2; + a3.nuInt32 = 2; + a3.eType = TypeClass_STRUCT; + a3.wChar = L'g'; + a3.td.nInt16 = 2; + a3.td.dDouble = 2; + a3.bBool = sal_True; + uno_type_constructData( &a3, getCppuType( (Test3*)0).getTypeLibType() ); + OSL_ASSERT( a3.nInt8 == 0 && a3.nFloat == (float)0 + && a3.nDouble == 0 && a3.nInt16 == 0 && a3.aString == OUString() + && a3.nuInt16 == 0 && a3.nInt64 == 0 && a3.nInt32 == 0 + && a3.nuInt64 == 0 && a3.nuInt32 == 0 && a3.eType == TypeClass_VOID + && a3.wChar == L'\0' && a3.td.nInt16 == 0 && a3.td.dDouble == 0 + && a3.bBool == sal_False ); + OSL_ASSERT( a3.aAny.getValueType() == getCppuVoidType() ); + delete pa3; + } + + { + // test the destructor + long a1[ sizeof( Test1 ) / sizeof(long) +1 ]; + uno_type_constructData( &a1, getCppuType( (Test1*)0).getTypeLibType() ); + uno_type_destructData( &a1, getCppuType( (Test1*)0).getTypeLibType(), cpp_release ); + + long a2[ sizeof( Test2 ) / sizeof(long) +1 ]; + uno_type_constructData( &a2, getCppuType( (Test2*)0).getTypeLibType() ); + uno_type_destructData( &a2, getCppuType( (Test2*)0).getTypeLibType(), cpp_release ); + + long a3[ sizeof( Test3 ) / sizeof(long) +1 ]; + uno_type_constructData( &a3, getCppuType( (Test3*)0).getTypeLibType() ); + OUString aTestString( RTL_CONSTASCII_USTRINGPARAM("test") ); + ((Test3*)a3)->aString = aTestString; + uno_type_destructData( &a3, getCppuType( (Test3*)0).getTypeLibType(), cpp_release ); + OSL_ASSERT( aTestString.pData->refCount == 1 ); + } + + { + // test the copy constructor + Test1 a1; + a1.nInt16 = 4; + a1.dDouble = 3.6; + a1.bBool = sal_True; + char sz1[sizeof( Test1 )]; + uno_type_copyData( sz1, &a1, getCppuType( (Test1*)0).getTypeLibType(), cpp_acquire ); + OSL_ASSERT( ((Test1*)sz1)->nInt16 == 4 && ((Test1*)sz1)->dDouble == 3.6 && ((Test1*)sz1)->bBool == sal_True); + + Test2 a2; + a2.nInt16 = 2; + a2.aTest1.nInt16 = 4; + a2.aTest1.dDouble = 3.6; + a2.aTest1.bBool = sal_True; + char sz2[sizeof( Test2 )]; + uno_type_copyData( sz2, &a2, getCppuType( (Test2*)0).getTypeLibType(), cpp_acquire ); + OSL_ASSERT( ((Test2*)sz2)->nInt16 == 2 ); + OSL_ASSERT(((Test2*)sz2)->aTest1.nInt16 == 4 ); + OSL_ASSERT( ((Test2*)sz2)->aTest1.dDouble == 3.6 ); + OSL_ASSERT(((Test2*)sz2)->aTest1.bBool == sal_True); + + Test3 a3; + a3.nInt8 = 2; + a3.nFloat = (float)2; + a3.nDouble = 2; + a3.nInt16 = 2; + a3.aString = OUString::createFromAscii("2"); + a3.nuInt16 = 2; + a3.nInt64 = 2; + a3.nInt32 = 2; + a3.nuInt64 = 2; + a3.nuInt32 = 2; + a3.eType = TypeClass_STRUCT; + a3.wChar = L'2'; + a3.td.nInt16 = 2; + a3.td.dDouble = 2; + a3.bBool = sal_True; + a3.aAny = makeAny( (sal_Int32)2 ); + char sz3[sizeof( Test3 )]; + uno_type_copyData( sz3, &a3, getCppuType( (Test3*)0).getTypeLibType(), cpp_acquire ); + OSL_ASSERT( ((Test3*)sz3)->nInt8 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nFloat == (float)2 ); + OSL_ASSERT( ((Test3*)sz3)->nDouble == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nInt16 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->aString == OUString::createFromAscii("2") ); + OSL_ASSERT( ((Test3*)sz3)->nuInt16 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nInt64 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nInt32 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nuInt64 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->nuInt32 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->eType == TypeClass_STRUCT ); + OSL_ASSERT( ((Test3*)sz3)->wChar == L'2' ); + OSL_ASSERT( ((Test3*)sz3)->td.nInt16 == 2 ); + OSL_ASSERT( ((Test3*)sz3)->td.dDouble == 2 ); + OSL_ASSERT( ((Test3*)sz3)->bBool == sal_True ); + OSL_ASSERT( ((Test3*)sz3)->aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)((Test3*)sz3)->aAny.getValue() == 2 ); + ((Test3 *)sz3)->~Test3(); + } + + { + sal_Bool bAssignable; + // test assignment + Test1 a1; + a1.nInt16 = 4; + a1.dDouble = 3.6; + a1.bBool = sal_True; + Test1 sz1; + bAssignable = uno_type_assignData( + &sz1, getCppuType( (Test1*)0).getTypeLibType(), + &a1, getCppuType( (Test1*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( bAssignable ); + OSL_ASSERT( sz1.nInt16 == 4 && sz1.dDouble == 3.6 && sz1.bBool == sal_True); + + Test2 a2; + a2.nInt16 = 2; + a2.aTest1.nInt16 = 4; + a2.aTest1.dDouble = 3.6; + a2.aTest1.bBool = sal_True; + Test2 sz2; + bAssignable = uno_type_assignData( + &sz2, getCppuType( (Test2*)0).getTypeLibType(), + &a2, getCppuType( (Test2*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( bAssignable ); + OSL_ASSERT( sz2.nInt16 == 2 && sz2.aTest1.nInt16 == 4 + && sz2.aTest1.dDouble == 3.6 && sz2.aTest1.bBool == sal_True); + + Test3 a3; + Test3 sz3; + a3.nInt8 = 2; + a3.nFloat = (float)2; + a3.nDouble = 2; + a3.nInt16 = 2; + a3.aString = OUString::createFromAscii("2"); + a3.nuInt16 = 2; + a3.nInt64 = 2; + a3.nInt32 = 2; + a3.nuInt64 = 2; + a3.nuInt32 = 2; + a3.eType = TypeClass_STRUCT; + a3.wChar = L'2'; + a3.td.nInt16 = 2; + a3.td.dDouble = 2; + a3.bBool = sal_True; + a3.aAny = makeAny( (sal_Int32)2 ); + bAssignable = uno_type_assignData( + &sz3, getCppuType( (Test3*)0).getTypeLibType(), + &a3, getCppuType( (Test3*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( bAssignable ); + OSL_ASSERT( sz3.nInt8 == 2 ); + OSL_ASSERT( sz3.nFloat == (float)2 ); + OSL_ASSERT( sz3.nDouble == 2 ); + OSL_ASSERT( sz3.nInt16 == 2 ); + OSL_ASSERT( sz3.aString == OUString::createFromAscii("2") ); + OSL_ASSERT( sz3.nuInt16 == 2 ); + OSL_ASSERT( sz3.nInt64 == 2 ); + OSL_ASSERT( sz3.nInt32 == 2 ); + OSL_ASSERT( sz3.nuInt64 == 2 ); + OSL_ASSERT( sz3.nuInt32 == 2 ); + OSL_ASSERT( sz3.eType == TypeClass_STRUCT ); + OSL_ASSERT( sz3.wChar == L'2' ); + OSL_ASSERT( sz3.td.nInt16 == 2 ); + OSL_ASSERT( sz3.td.dDouble == 2 ); + OSL_ASSERT( sz3.bBool == sal_True ); + OSL_ASSERT( sz3.aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)sz3.aAny.getValue() == 2 ); + + // test not assigneable values + bAssignable = uno_type_assignData( + &a1, getCppuType( (Test1*)0).getTypeLibType(), + &a2, getCppuType( (Test2*)0).getTypeLibType(), + cpp_queryInterface, cpp_acquire, cpp_release ); + OSL_ASSERT( !bAssignable ); + } + + { + // test any + Any aAny = makeAny( (sal_Int8)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int8 *)0 ) ); + OSL_ASSERT( *(sal_Int8*)aAny.getValue() == 2 ); + aAny = makeAny( (float)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (float *)0 ) ); + OSL_ASSERT( *(float*)aAny.getValue() == (float)2 ); + aAny = makeAny( (sal_Int8)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int8 *)0 ) ); + OSL_ASSERT( *(sal_Int8*)aAny.getValue() == 2 ); + aAny = makeAny( (double)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (double *)0 ) ); + OSL_ASSERT( *(double*)aAny.getValue() == (double)2 ); + aAny = makeAny( (sal_Int16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + aAny = makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (OUString *)0 ) ); + OSL_ASSERT( *(OUString*)aAny.getValue() == OUString::createFromAscii("test") ); + aAny = makeAny( (sal_uInt16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + sal_Int64 aInt64; + sal_setInt64( &aInt64, 2, 0 ); + aAny = makeAny( aInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int64 *)0 ) ); + sal_uInt32 lowInt; + sal_Int32 highInt; + sal_getInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &highInt ); + OSL_ASSERT( lowInt == 2 && highInt == 0 ); + aAny = makeAny( (sal_Int32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)aAny.getValue() == 2 ); + sal_uInt64 auInt64; + sal_setUInt64( &auInt64, 2, 0 ); + aAny = makeAny( auInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt64 *)0 ) ); + sal_uInt32 uhighInt; + sal_getUInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &uhighInt ); + OSL_ASSERT( lowInt == 2 && uhighInt == 0 ); + aAny = makeAny( (sal_uInt32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt32 *)0 ) ); + OSL_ASSERT( *(sal_uInt32*)aAny.getValue() == 2 ); + aAny = makeAny( TypeClass_STRUCT ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (TypeClass *)0 ) ); + OSL_ASSERT( *(TypeClass*)aAny.getValue() == TypeClass_STRUCT ); + sal_Unicode c = L'2'; + aAny.setValue( &c, getCppuCharType() ); + OSL_ASSERT( aAny.getValueType() == getCppuCharType() ); + OSL_ASSERT( *(sal_Unicode*)aAny.getValue() == L'2' ); + sal_Bool b = sal_True; + aAny.setValue( &b, getCppuBooleanType() ); + OSL_ASSERT( aAny.getValueType() == getCppuBooleanType() ); + OSL_ASSERT( *(sal_Bool*)aAny.getValue() == sal_True ); + } + + { + // test: operator <<=( any, value ) + Any aAny; + aAny <<= (sal_Int8)2; + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int8 *)0 ) ); + OSL_ASSERT( *(sal_Int8*)aAny.getValue() == 2 ); + aAny <<=( (float)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (float *)0 ) ); + OSL_ASSERT( *(float*)aAny.getValue() == (float)2 ); +// aAny <<=( (sal_uInt8)2 ); +// OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt8 *)0 ) ); +// OSL_ASSERT( *(sal_uInt8*)aAny.getValue() == 2 ); + aAny <<=( (double)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (double *)0 ) ); + OSL_ASSERT( *(double*)aAny.getValue() == (double)2 ); + aAny <<=( (sal_Int16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + aAny <<=( OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (OUString *)0 ) ); + OSL_ASSERT( *(OUString*)aAny.getValue() == OUString::createFromAscii("test") ); + aAny <<=( (sal_uInt16)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt16 *)0 ) ); + OSL_ASSERT( *(sal_Int16*)aAny.getValue() == 2 ); + sal_Int64 aInt64; + sal_setInt64( &aInt64, 2, 0 ); + aAny <<=( aInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int64 *)0 ) ); + sal_uInt32 lowInt; + sal_Int32 highInt; + sal_getInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &highInt ); + OSL_ASSERT( lowInt == 2 && highInt == 0 ); + aAny <<=( (sal_Int32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_Int32 *)0 ) ); + OSL_ASSERT( *(sal_Int32*)aAny.getValue() == 2 ); + sal_uInt64 auInt64; + sal_setUInt64( &auInt64, 2, 0 ); + aAny <<=( auInt64 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt64 *)0 ) ); + sal_uInt32 uhighInt; + sal_getUInt64( *(sal_Int64*)aAny.getValue(), &lowInt, &uhighInt ); + OSL_ASSERT( lowInt == 2 && uhighInt == 0 ); + aAny <<=( (sal_uInt32)2 ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (sal_uInt32 *)0 ) ); + OSL_ASSERT( *(sal_uInt32*)aAny.getValue() == 2 ); + aAny <<=( TypeClass_STRUCT ); + OSL_ASSERT( aAny.getValueType() == getCppuType( (TypeClass *)0 ) ); + OSL_ASSERT( *(TypeClass*)aAny.getValue() == TypeClass_STRUCT ); + } + + { + // test: operator >>=( any, value ) + Test3 a3; + makeAny( (sal_Int8)2) >>= a3.nInt8; + OSL_ASSERT( (makeAny( (sal_Int8)2) >>= a3.nInt8) && a3.nInt8 == 2 ); + OSL_ASSERT( (makeAny( (float)2) >>= a3.nFloat) && a3.nFloat ==(float)2 ); + OSL_ASSERT( (makeAny( (double)2) >>= a3.nDouble) && a3.nDouble == 2 ); + OSL_ASSERT( (makeAny( (sal_Int16)2) >>= a3.nInt16) && a3.nInt16 == 2 ); + OSL_ASSERT( (makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("2") )) >>= a3.aString) && + a3.aString == OUString::createFromAscii("2") ); + OSL_ASSERT( (makeAny( (sal_uInt16)2) >>= a3.nuInt16) && a3.nuInt16 == 2 ); + sal_Int64 aInt64; + sal_uInt32 lowInt; + sal_Int32 highInt; + sal_setInt64( &aInt64, 2, 0 ); + OSL_ASSERT( makeAny( aInt64 ) >>= a3.nInt64 ); + sal_getInt64( a3.nInt64, &lowInt, &highInt ); + OSL_ASSERT( lowInt == 2 ); + OSL_ASSERT( (makeAny( (sal_Int32)2) >>= a3.nInt32) && a3.nInt32 == 2 ); + sal_uInt64 auInt64; + sal_uInt32 uhighInt; + sal_setUInt64( &auInt64, 2, 0 ); + OSL_ASSERT( makeAny( auInt64 ) >>= a3.nuInt64 ); + sal_getUInt64( a3.nuInt64, &lowInt, &uhighInt ); + OSL_ASSERT( lowInt == 2 ); + OSL_ASSERT( (makeAny( (sal_uInt32)2) >>= a3.nuInt32) && a3.nuInt32 == 2 ); + OSL_ASSERT( (makeAny( TypeClass_STRUCT) >>= a3.eType) && a3.eType == TypeClass_STRUCT ); + //OSL_ASSERT( (makeAny( L'2' ) >>= a3.wChar) && a3.nInt8 ==L'2'; + OSL_ASSERT( (makeAny( (sal_Int16)2) >>= a3.td.nInt16) && a3.nInt16 == 2 ); + OSL_ASSERT( (makeAny( (double)2) >>= a3.td.dDouble) && a3.nDouble == 2 ); + //OSL_ASSERT( (makeAny( (sal_True)2) >>= a3.bBool) && a3.nInt8 ==sal_True; + + // Only one negative test, the implementation has only one if to test this + OSL_ASSERT( (makeAny( (float)2) >>= a3.nFloat) && a3.nFloat ==(float)2 ); + } + + { + // test: Sequence + Sequence< Test1 > aTestSeq; + OSL_ASSERT( aTestSeq.getLength() == 0 ); + sal_Int32 szInt32[2] = { 1, 2 }; + Sequence< sal_Int32 > aInt32Seq( szInt32, 2 ); + OSL_ASSERT( aInt32Seq.getLength() == 2 ); + OSL_ASSERT( aInt32Seq[0] == 1 && aInt32Seq[1] == 2 ); + OSL_ASSERT( aInt32Seq.getArray()[0] == 1 && aInt32Seq.getArray()[1] == 2 ); + Sequence< sal_Int32 > aNextInt32Seq( aInt32Seq ); + OSL_ASSERT( aNextInt32Seq[0] == 1 && aNextInt32Seq[1] == 2 ); + aInt32Seq[0] = 45; + OSL_ASSERT( aInt32Seq[0] == 45 && aInt32Seq[1] == 2 ); + OSL_ASSERT( aNextInt32Seq[0] == 1 && aNextInt32Seq[1] == 2 ); + sal_Int32 * pArray = aNextInt32Seq.getArray(); + OSL_ASSERT( pArray[0] == 1 && pArray[1] == 2 ); + Sequence< double > aDoubleSeq( 5 ); + OSL_ASSERT( aDoubleSeq[4] == 0.0 ); + Sequence< OUString > aStringSeq( 5 ); + OSL_ASSERT( aStringSeq[4] == OUString() ); + } + sal_Int32 szInt32[2] = { 1, 2 }; + Sequence<sal_Int32 > aInt32Seq( szInt32, 2 ); + Sequence<sal_Int32 > aNextInt32Seq( aInt32Seq ); + aNextInt32Seq.realloc( 1 ); // split of sequence + const sal_Int32 * pArray = aNextInt32Seq.getConstArray(); + OSL_ASSERT( pArray[0] == 1 ); + aInt32Seq.realloc( 1 ); // reallocate mem + pArray = aInt32Seq.getConstArray(); + OSL_ASSERT( pArray[0] == 1 ); +} + +class TestInterface : public XInterface +{ +public: + // XInterface + void SAL_CALL acquire() { osl_incrementInterlockedCount( &nRefCount ); } + void SAL_CALL release() + { + if( !osl_decrementInterlockedCount( &nRefCount ) ) + delete this; + } + Any SAL_CALL queryInterface( const Type & rType ) + { + return cppu::queryInterface( rType, static_cast< XInterface* >( this ) ); + } + + TestInterface() : nRefCount( 0 ) {} + + sal_Int32 nRefCount; +}; + +struct SimpleInterface : public TestInterface, public XSimpleInterface +{ + void SAL_CALL acquire() { TestInterface::acquire(); } + void SAL_CALL release() { TestInterface::release(); } + Any SAL_CALL queryInterface( const Type & rType ) + { + Any aRet( cppu::queryInterface( rType, static_cast< XSimpleInterface * >( this ) ) ); + return (aRet.hasValue() ? aRet : TestInterface::queryInterface( rType )); + } + virtual void SAL_CALL method() throw(::com::sun::star::uno::RuntimeException) + {} +}; + +static sal_Bool s_aAssignableFromTab[11][11] = +{ + /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */ +/* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, +/* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, +/* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, +/* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, +/* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, +/* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0 }, +/* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1 } +}; +template < class T > +static void test_assignSimple( const T & rVal, /*const*/ Any /*&*/ rAny ) +{ + typelib_TypeDescription * pTD = 0; + ::getCppuType( &rVal ).getDescription( &pTD ); + sal_Bool bTable = s_aAssignableFromTab[pTD->eTypeClass-1][rAny.getValueTypeClass()-1]; + OSL_ASSERT( + (bTable!=sal_False) == + (typelib_typedescriptionreference_isAssignableFrom( + pTD->pWeakRef, rAny.getValueTypeRef() )!=sal_False) ); + T t; + OSL_ASSERT( (bTable!=sal_False) == ((rAny >>= t)!=sal_False) ); + if (bTable) + OSL_ASSERT( t == rVal ); + typelib_typedescription_release( pTD ); +} +template < class T > +static void test_simple_assignment( const T & rVal ) +{ + // bool + sal_Bool tr = sal_True; + typelib_TypeDescription * pBoolTD = 0; + ::getCppuBooleanType().getDescription( &pBoolTD ); + Any a( &tr, pBoolTD ); + test_assignSimple( rVal, a ); + OSL_ASSERT( typelib_typedescriptionreference_isAssignableFrom( pBoolTD->pWeakRef, a.getValueTypeRef() ) ); + typelib_typedescription_release( pBoolTD ); + OSL_ASSERT( *(sal_Bool *)a.getValue() ); + // char + sal_Unicode ch = 'a'; + typelib_TypeDescription * pCharTD = 0; + ::getCppuCharType().getDescription( &pCharTD ); + a.setValue( &ch, pCharTD ); + test_assignSimple( rVal, a ); + OSL_ASSERT( typelib_typedescriptionreference_isAssignableFrom( pCharTD->pWeakRef, a.getValueTypeRef() ) ); + typelib_typedescription_release( pCharTD ); + OSL_ASSERT( *(sal_Unicode *)a.getValue() == 'a' ); + + // rest by template + a <<= (sal_Int8)5; + test_assignSimple( rVal, a ); + a <<= (sal_Int16)5; + test_assignSimple( rVal, a ); + a <<= (sal_uInt16)5; + test_assignSimple( rVal, a ); + a <<= (sal_Int32)5; + test_assignSimple( rVal, a ); + a <<= (sal_uInt32)5; + test_assignSimple( rVal, a ); + a <<= (sal_Int64)5; + test_assignSimple( rVal, a ); + a <<= (sal_uInt64)5; + test_assignSimple( rVal, a ); + a <<= (float)5; + test_assignSimple( rVal, a ); + a <<= (double)5; + test_assignSimple( rVal, a ); +} +static void testAssignment() +{ + // simple types + test_simple_assignment( (sal_Int8)5 ); + test_simple_assignment( (sal_Int16)5 ); + test_simple_assignment( (sal_uInt16)5 ); + test_simple_assignment( (sal_Int32)5 ); + test_simple_assignment( (sal_uInt32)5 ); + test_simple_assignment( (sal_Int64)5 ); + test_simple_assignment( (sal_uInt64)5 ); + test_simple_assignment( (float)5 ); + test_simple_assignment( (double)5 ); + // some complex things + Any a; + TestSimple ts; + TestElement te; // derived from simple + a <<= ts; + OSL_ASSERT( !(a >>= te) ); + OSL_ASSERT( a >>= ts ); + a <<= te; + OSL_ASSERT( (a >>= te) && (a >>= ts) ); + // interface + Reference< XSimpleInterface > xOriginal( new SimpleInterface() ); + a <<= xOriginal; + Reference< XInterface > x; + OSL_ASSERT( (a >>= x) && (a == xOriginal) && (xOriginal == x) && (x == xOriginal) ); + // sequence + Sequence< TestElement > aSeq( 5 ); + Sequence< TestElement > aSeq2( 3 ); + aSeq[1].Byte = 17; + a <<= aSeq; + OSL_ASSERT( a >>= aSeq2 ); + OSL_ASSERT( aSeq2[1].Byte == 17 ); + aSeq2[1].Byte = 20; + OSL_ASSERT( aSeq != aSeq2 ); + OSL_ASSERT( a != aSeq2 ); + a <<= aSeq2; + OSL_ASSERT( a >>= aSeq ); + OSL_ASSERT( a == aSeq ); + OSL_ASSERT( !(a != aSeq) ); + OSL_ASSERT( aSeq == aSeq2 ); + OSL_ASSERT( aSeq[1].Byte == 20 ); +} + +void test_interface() +{ + { + // test: Interface + Reference< XInterface > xIFace; + OSL_ASSERT( !xIFace.is() ); + xIFace.clear(); // do nothing + } +} + +void test_inheritance() +{ + OSL_ASSERT( sizeof( Base ) == getSize( getCppuType( (Base *)0).getTypeLibType() ) ); + OSL_ASSERT( sizeof( Base1 ) == getSize( getCppuType( (Base1 *)0).getTypeLibType() ) ); + OSL_ASSERT( sizeof( Base2 ) == getSize( getCppuType( (Base2 *)0).getTypeLibType() ) ); +} + +sal_Int32 nCallback_1; +sal_Int32 nCallback; +void SAL_CALL typedescription_Callback_1 +( + void * pContext, + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName +) +{ + OSL_ENSHURE( pContext == (void *)1, "### unexpected context!" ); + if( *ppRet ) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } + + OUString aTypeName( pTypeName ); + if( -1 != aTypeName.indexOf( OUString::createFromAscii("1_") ) ) + { + nCallback_1++; + OUString aName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") ); + OUString empty; + typelib_CompoundMember_Init aMember = { typelib_TypeClass_UNSIGNED_SHORT, + aName.pData, + empty.pData }; + typelib_typedescription_new( + ppRet, + typelib_TypeClass_STRUCT, pTypeName, 0, + 1, + &aMember + ); + } +} + +void SAL_CALL typedescription_Callback +( + void * pContext, + typelib_TypeDescription ** ppRet, + rtl_uString * pTypeName +) +{ + OSL_ENSHURE( pContext == (void *)0, "### unexpected context!" ); + if( *ppRet ) + { + typelib_typedescription_release( *ppRet ); + *ppRet = 0; + } + + OUString aTypeName( pTypeName ); + if( -1 != aTypeName.indexOf( OUString::createFromAscii("cachetest") ) ) + { + nCallback++; + aTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM("1_") ) + aTypeName; + OUString empty; + typelib_CompoundMember_Init aMember = { typelib_TypeClass_STRUCT, + aTypeName.pData, + empty.pData }; + typelib_typedescription_new( + ppRet, + typelib_TypeClass_STRUCT, pTypeName, 0, + 1, + &aMember + ); + } +} + +void test_cache() +{ + typelib_typedescription_registerCallback( (void *)1, typedescription_Callback_1 ); + typelib_typedescription_registerCallback( 0, typedescription_Callback ); + + for( sal_Int32 i = 0; i < 300; i++ ) + { + typelib_TypeDescription * pTD = 0; + OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("cachetest") ); + aTypeName = aTypeName + OUString::valueOf( i ); + typelib_typedescription_getByName( &pTD, aTypeName.pData ); + typelib_typedescription_release( pTD ); + } + OSL_ASSERT( nCallback_1 == 300 ); + OSL_ASSERT( nCallback == 300 ); + // The cache size is 200 so the description "cachetest200" is in the cache + typelib_TypeDescription * pTD = 0; + OUString aName200( RTL_CONSTASCII_USTRINGPARAM("cachetest200") ); + typelib_typedescription_getByName( &pTD, aName200.pData ); + OSL_ASSERT( nCallback_1 == 300 ); + OSL_ASSERT( nCallback == 300 ); + // The cache size is 200 so the description "cachetest199" is not in the cache + // "1_cachetest199" is loaded too. + OUString aName199( RTL_CONSTASCII_USTRINGPARAM("cachetest199") ); + typelib_typedescription_getByName( &pTD, aName199.pData ); + typelib_typedescription_release( pTD ); + OSL_ASSERT( nCallback_1 == 301 ); + OSL_ASSERT( nCallback == 301 ); + + typelib_typedescription_revokeCallback( (void *)1, typedescription_Callback_1 ); + typelib_typedescription_revokeCallback( 0, typedescription_Callback ); +} + +static OUString s_aAddPurpose; + +static void SAL_CALL getMappingCallback( + uno_Mapping ** ppMapping, + uno_Environment * pFrom, uno_Environment * pTo, rtl_uString * pAddPurpose ) +{ + s_aAddPurpose = pAddPurpose; +} +static void testMappingCallback() +{ + uno_registerMappingCallback( getMappingCallback ); + OSL_ASSERT( ! s_aAddPurpose.getLength() ); + Mapping aTest( + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + uno_revokeMappingCallback( getMappingCallback ); + OSL_ASSERT( s_aAddPurpose.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("test") ) ); + s_aAddPurpose = OUString(); + Mapping aTest2( + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), + OUString( RTL_CONSTASCII_USTRINGPARAM("test") ) ); + OSL_ASSERT( ! s_aAddPurpose.getLength() ); +} + +static void testEnvironment(void) +{ + uno_Environment * pEnv = 0; + void ** ppInterfaces = 0; + sal_Int32 nLen; + + OUString aUnoEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + uno_getEnvironment( &pEnv, aUnoEnvTypeName.pData, 0 ); + (*pEnv->pExtEnv->getRegisteredInterfaces)( pEnv->pExtEnv, &ppInterfaces, &nLen, rtl_allocateMemory ); + while (nLen--) + { + uno_Interface * pUnoI = (uno_Interface *)ppInterfaces[nLen]; + (*pUnoI->release)( pUnoI ); + } + rtl_freeMemory( ppInterfaces ); + + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pEnv, aCppEnvTypeName.pData, 0 ); + (*pEnv->pExtEnv->getRegisteredInterfaces)( pEnv->pExtEnv, &ppInterfaces, &nLen, rtl_allocateMemory ); + while (nLen--) + { + uno_Interface * pUnoI = (uno_Interface *)ppInterfaces[nLen]; + (*pUnoI->release)( pUnoI ); + } + rtl_freeMemory( ppInterfaces ); + (*pEnv->release)( pEnv ); +} + +#ifdef SOLARIS +extern "C" void ChangeGlobalInit(); +#endif + +/* + * main. + */ +int SAL_CALL main(int argc, char **argv) +{ +#ifdef SOLARIS + ChangeGlobalInit(); +#endif + typelib_setCacheSize( 200 ); +#ifdef SAL_W32 + Reference< XMultiServiceFactory > xMgr( cppu::createRegistryServiceFactory( + OUString( RTL_CONSTASCII_USTRINGPARAM("testcppu.rdb") ) ) ); +#endif + testEnvironment(); + testMappingCallback(); + + // perform test + void test_di(void); + test_di(); + void test_performance(void); + testAssignment(); + testCppu(); +// test_cache(); // cache test not possible if types are loaded dynamically... + test_interface(); + test_inheritance(); + + // shutdown +#ifdef SAL_W32 + Reference< XComponent > xComp( xMgr, UNO_QUERY ); + OSL_ENSHURE( xComp.is(), "### serivce manager has to implement XComponent!" ); + xComp->dispose(); + xMgr.clear(); +#endif + typelib_setCacheSize( 0 ); + testEnvironment(); + + return 0; +} diff --git a/cppu/test/testthreadpool.cxx b/cppu/test/testthreadpool.cxx new file mode 100644 index 000000000000..2f2f84499599 --- /dev/null +++ b/cppu/test/testthreadpool.cxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * $RCSfile: testthreadpool.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:25:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <osl/diagnose.h> + +#include <rtl/uuid.h> + +#include <uno/threadpool.h> + +#include <vos/thread.hxx> + +#define TEST_ENSURE OSL_ENSHURE + +using namespace ::vos; + + +class OThread1 : public OThread +{ +public: + OThread1( sal_uInt8 *pCallerUuid ); + virtual void run(); + +public: + sal_uInt8 *m_pCallerUuid; + sal_Int8 *m_pThreadIdentifier; + sal_Int32 m_nThreadIdentifierLength; + + void *m_pThreadData; +}; + +OThread1::OThread1( sal_uInt8 *pCallerUuid ) : + m_pCallerUuid( pCallerUuid ), + m_pThreadData( (void*) 1 ), + m_pThreadIdentifier( 0 ), + m_nThreadIdentifierLength( 0 ) +{ + +} + +void OThread1::run() +{ + + uno_threadpool_Ticket *pTicket = uno_threadpool_createTicket( m_pCallerUuid ); + + uno_threadIdent_retrieve( &m_pThreadIdentifier , &m_nThreadIdentifierLength ); + + uno_threadpool_waitOnTicket( pTicket , &m_pThreadData ); + + uno_threadIdent_revoke(); +} + + +void SAL_CALL doIt( void *pThreadData ) +{ + *( sal_Int32 *) pThreadData = 2; +} + +void testthreadpool() +{ + printf( "Testing threadpool ..." ); + fflush( stdout ); + + sal_uInt8 pCallerUuid1[16]; + sal_uInt8 pCallerUuid2[16]; + rtl_createUuid( pCallerUuid1, 0 , sal_True ); + rtl_createUuid( pCallerUuid2, 0 , sal_True ); + + //------------ + // Test reply + //------------ + { + OThread1 thread1( pCallerUuid1 ); + + thread1.create(); + + // do a busy wait + while( ! thread1.m_pThreadIdentifier && ! thread1.m_nThreadIdentifierLength ); + + void *pThreadData = (void*)0xdeadbabe; + uno_threadpool_reply( thread1.m_pThreadIdentifier , + thread1.m_nThreadIdentifierLength, + pThreadData ); + + // do a busy wait + while( (void*)1 == thread1.m_pThreadData ); + + TEST_ENSURE( pThreadData == thread1.m_pThreadData, "uno_threadpool_reply error" ); + } + + //--------------- + // Test request + //--------------- + { + OThread1 thread1( pCallerUuid1 ); + + thread1.create(); + + // do a busy wait + while( ! thread1.m_pThreadIdentifier && ! thread1.m_nThreadIdentifierLength ); + + // do a request + sal_Int32 i = 1; + uno_threadpool_request( thread1.m_pThreadIdentifier , + thread1.m_nThreadIdentifierLength, + &i, + doIt, + sal_False); + + // do a busy wait + while( 1 == i ); + TEST_ENSURE( 2 == i, "uno_threadpool_request error" ); + + // get it out of the pool + void *pThreadData = (void*)0xdeadbabe; + uno_threadpool_reply( thread1.m_pThreadIdentifier , + thread1.m_nThreadIdentifierLength, + pThreadData ); + + // do a busy wait + while( pThreadData != thread1.m_pThreadData ); + + } + + //--------------- + // Test dispose threads + //--------------- + { + OThread1 thread1( pCallerUuid1 ); + OThread1 thread2( pCallerUuid2 ); + + thread1.create(); + thread2.create(); + + // do a busy wait + while( ! thread1.m_pThreadIdentifier && ! thread1.m_nThreadIdentifierLength && + ! thread2.m_pThreadIdentifier && ! thread2.m_nThreadIdentifierLength ); + + // dispose the first + uno_threadpool_disposeThreads( pCallerUuid1 ); + + while( (void*)1 == thread1.m_pThreadData ); + TEST_ENSURE( (void*)0 == thread1.m_pThreadData, "disposing threads failed" ); + + TimeValue value = {1,0}; + osl_waitThread( &value ); + TEST_ENSURE( (void*)1 == thread2.m_pThreadData, "wrong thread disposed !" ); + + // test, if new threads are directly disposed + OThread1 thread3( pCallerUuid1 ); + thread3.create(); + + while( (void*)1 == thread3.m_pThreadData ); + TEST_ENSURE( (void*)0 == thread3.m_pThreadData , + "new threads entering threadpool are not disposed" ); + + uno_threadpool_reply( thread2.m_pThreadIdentifier , + thread2.m_nThreadIdentifierLength, + (void*)0x2 ); + + while( (void*)1 == thread2.m_pThreadData ); + TEST_ENSURE( (void*)2 == thread2.m_pThreadData , "reply does not work correctly" ); + + uno_threadpool_stopDisposeThreads( pCallerUuid1 ); + } + printf( "Done\n" ); +} diff --git a/cppu/util/makefile.mk b/cppu/util/makefile.mk new file mode 100644 index 000000000000..027f1ed04401 --- /dev/null +++ b/cppu/util/makefile.mk @@ -0,0 +1,120 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=.. + +PRJNAME=cppu +TARGET=cppu +USE_DEFFILE=TRUE +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE + +# --- Settings ----------------------------------------------------- +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +.INCLUDE : ..$/version.mk + +# --- Files -------------------------------------------------------- + +SHL1LIBS= \ + $(SLB)$/cppu_typelib.lib \ + $(SLB)$/cppu_uno.lib \ + $(SLB)$/cppu_threadpool.lib + +SHL1TARGET= $(CPPU_TARGET)$(CPPU_MAJOR) + +SHL1STDLIBS= $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET) +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +DOCPPFILES= \ + $(INC)$/typelib$/uik.h \ + $(INC)$/typelib$/typeclass.h \ + $(INC)$/typelib$/typedescription.h \ + $(INC)$/typelib$/typedescription.hxx \ + $(INC)$/uno$/any2.h \ + $(INC)$/uno$/sequence2.h \ + $(INC)$/uno$/data.h \ + $(INC)$/uno$/environment.h \ + $(INC)$/uno$/environment.hxx \ + $(INC)$/uno$/mapping.h \ + $(INC)$/uno$/mapping.hxx \ + $(INC)$/uno$/dispatcher.h \ + $(INC)$/uno$/threadpool.h \ + $(INC)$/com$/sun$/star$/uno$/genfunc.h \ + $(INC)$/com$/sun$/star$/uno$/Reference.h\ + $(INC)$/com$/sun$/star$/uno$/Type.h \ + $(INC)$/com$/sun$/star$/uno$/Any.h \ + $(INC)$/com$/sun$/star$/uno$/Sequence.h + +docpp: $(DOCPPFILES) + +doc++ -H -m -f -u -d $(OUT)$/doc$/$(PRJNAME) $(DOCPPFILES) diff --git a/cppu/util/makefile.pmk b/cppu/util/makefile.pmk new file mode 100644 index 000000000000..a6963ff4dc68 --- /dev/null +++ b/cppu/util/makefile.pmk @@ -0,0 +1,63 @@ +#************************************************************************* +# +# $RCSfile: makefile.pmk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE diff --git a/cppu/util/target.pmk b/cppu/util/target.pmk new file mode 100644 index 000000000000..78aa9757958f --- /dev/null +++ b/cppu/util/target.pmk @@ -0,0 +1,96 @@ +#************************************************************************* +# +# $RCSfile: target.pmk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:25:54 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +.IF "$(debug)" == "" + +# switch on aggressive opt + +# msvc++ +.IF "$(COM)" == "MSC" +CFLAGS += /O2gityb2 /Gs +.ENDIF + +# sunpro 5 +.IF "$(COM)" == "C50" +CFLAGS += -O5 -xO5 +.ENDIF + +# gcc +.IF "$(COM)" == "GCC" +CFLAGS += -O +.ENDIF + +.ELSE + +# msvc++: no inlining +.IF "$(COM)" == "MSC" +CFLAGS += /Ob0 +.ENDIF + +.IF "$(cppu_assert)" != "" +CFLAGS += -DCPPU_ASSERTIONS +.ENDIF + +.ENDIF + +.IF "$(cppu_no_leak)" == "" +CFLAGS += -DCPPU_LEAK_STATIC_DATA +.ENDIF |