1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/diagnose.h>
22 #include <osl/interlck.h>
24 #include <cppuhelper/factory.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
28 #include <com/sun/star/registry/XRegistryKey.hpp>
30 #include <com/sun/star/test/performance/XPerformanceTest.hpp>
34 using namespace com::sun::star::uno
;
35 using namespace com::sun::star::lang
;
36 using namespace com::sun::star::registry
;
37 using namespace com::sun::star::test::performance
;
39 using ::rtl::OUString
;
41 #define SERVICENAME "com.sun.star.test.performance.PerformanceTestObject"
42 #define IMPLNAME "com.sun.star.comp.performance.PerformanceTestObject"
44 namespace benchmark_object
47 //--------------------------------------------------------------------------------------------------
48 inline static Sequence
< OUString
> getSupportedServiceNames()
50 OUString
aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME
) );
51 return Sequence
< OUString
>( &aName
, 1 );
54 //==================================================================================================
57 , public XPerformanceTest
59 OUString _aDummyString
;
61 Sequence
< Reference
< XInterface
> > _aDummySequence
;
62 ComplexTypes _aDummyStruct
;
63 RuntimeException _aDummyRE
;
71 ServiceImpl( const Reference
< XMultiServiceFactory
> & xMgr
)
76 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& aType
) throw(::com::sun::star::uno::RuntimeException
)
78 // execution time remains appr. constant any time
80 if (aType
== ::getCppuType( (const Reference
< XInterface
> *)0 ))
82 void * p
= (XInterface
*)(XPerformanceTest
*)this;
83 aRet
.setValue( &p
, ::getCppuType( (const Reference
< XInterface
> *)0 ) );
85 if (aType
== ::getCppuType( (const Reference
< XPerformanceTest
> *)0 ))
87 void * p
= (XPerformanceTest
*)this;
88 aRet
.setValue( &p
, ::getCppuType( (const Reference
< XPerformanceTest
> *)0 ) );
90 if (! aRet
.hasValue())
92 void * p
= (XPerformanceTest
*)this;
93 Any
aDummy( &p
, ::getCppuType( (const Reference
< XPerformanceTest
> *)0 ) );
97 virtual void SAL_CALL
acquire() throw()
98 { osl_atomic_increment( &_nRef
); }
99 virtual void SAL_CALL
release() throw()
100 { if (! osl_atomic_decrement( &_nRef
)) delete this; }
103 virtual OUString SAL_CALL
getImplementationName() throw (RuntimeException
);
104 virtual sal_Bool SAL_CALL
supportsService( const OUString
& rServiceName
) throw (RuntimeException
);
105 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (RuntimeException
);
108 virtual sal_Int32 SAL_CALL
getLong_attr() throw(::com::sun::star::uno::RuntimeException
)
110 virtual void SAL_CALL
setLong_attr( sal_Int32 _attributelong
) throw(::com::sun::star::uno::RuntimeException
)
112 virtual sal_Int64 SAL_CALL
getHyper_attr() throw(::com::sun::star::uno::RuntimeException
)
114 virtual void SAL_CALL
setHyper_attr( sal_Int64 _attributehyper
) throw(::com::sun::star::uno::RuntimeException
)
116 virtual float SAL_CALL
getFloat_attr() throw(::com::sun::star::uno::RuntimeException
)
118 virtual void SAL_CALL
setFloat_attr( float _attributefloat
) throw(::com::sun::star::uno::RuntimeException
)
120 virtual double SAL_CALL
getDouble_attr() throw(::com::sun::star::uno::RuntimeException
)
122 virtual void SAL_CALL
setDouble_attr( double _attributedouble
) throw(::com::sun::star::uno::RuntimeException
)
124 virtual OUString SAL_CALL
getString_attr() throw(::com::sun::star::uno::RuntimeException
)
125 { return _aDummyString
; }
126 virtual void SAL_CALL
setString_attr( const ::rtl::OUString
& _attributestring
) throw(::com::sun::star::uno::RuntimeException
)
128 virtual Reference
< XInterface
> SAL_CALL
getInterface_attr() throw(::com::sun::star::uno::RuntimeException
)
129 { return Reference
< XInterface
>(); }
130 virtual void SAL_CALL
setInterface_attr( const Reference
< XInterface
>& _attributeinterface
) throw(::com::sun::star::uno::RuntimeException
)
132 virtual Any SAL_CALL
getAny_attr() throw(::com::sun::star::uno::RuntimeException
)
133 { return _aDummyAny
; }
134 virtual void SAL_CALL
setAny_attr( const Any
& _attributeany
) throw(::com::sun::star::uno::RuntimeException
)
136 virtual Sequence
< Reference
< XInterface
> > SAL_CALL
getSequence_attr() throw(::com::sun::star::uno::RuntimeException
)
137 { return _aDummySequence
; }
138 virtual void SAL_CALL
setSequence_attr( const Sequence
< Reference
< XInterface
> >& _attributesequence
) throw(::com::sun::star::uno::RuntimeException
)
140 virtual ComplexTypes SAL_CALL
getStruct_attr() throw(::com::sun::star::uno::RuntimeException
)
141 { return _aDummyStruct
; }
142 virtual void SAL_CALL
setStruct_attr( const ::com::sun::star::test::performance::ComplexTypes
& _attributestruct
) throw(::com::sun::star::uno::RuntimeException
)
146 virtual sal_Int32 SAL_CALL
getLong() throw(::com::sun::star::uno::RuntimeException
)
148 virtual void SAL_CALL
setLong( sal_Int32 _long
) throw(::com::sun::star::uno::RuntimeException
)
150 virtual sal_Int64 SAL_CALL
getHyper() throw(::com::sun::star::uno::RuntimeException
)
152 virtual void SAL_CALL
setHyper( sal_Int64 _hyper
) throw(::com::sun::star::uno::RuntimeException
)
154 virtual float SAL_CALL
getFloat() throw(::com::sun::star::uno::RuntimeException
)
156 virtual void SAL_CALL
setFloat( float _float
) throw(::com::sun::star::uno::RuntimeException
)
158 virtual double SAL_CALL
getDouble() throw(::com::sun::star::uno::RuntimeException
)
160 virtual void SAL_CALL
setDouble( double _double
) throw(::com::sun::star::uno::RuntimeException
)
162 virtual OUString SAL_CALL
getString() throw(::com::sun::star::uno::RuntimeException
)
163 { return _aDummyString
; }
164 virtual void SAL_CALL
setString( const ::rtl::OUString
& _string
) throw(::com::sun::star::uno::RuntimeException
)
166 virtual Reference
< XInterface
> SAL_CALL
getInterface() throw(::com::sun::star::uno::RuntimeException
)
167 { return Reference
< XInterface
>(); }
168 virtual void SAL_CALL
setInterface( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _interface
) throw(::com::sun::star::uno::RuntimeException
)
170 virtual Any SAL_CALL
getAny() throw(::com::sun::star::uno::RuntimeException
)
171 { return _aDummyAny
; }
172 virtual void SAL_CALL
setAny( const ::com::sun::star::uno::Any
& _any
) throw(::com::sun::star::uno::RuntimeException
)
174 virtual Sequence
< Reference
< XInterface
> > SAL_CALL
getSequence() throw(::com::sun::star::uno::RuntimeException
)
175 { return _aDummySequence
; }
176 virtual void SAL_CALL
setSequence( const Sequence
< Reference
< XInterface
> >& _sequence
) throw(::com::sun::star::uno::RuntimeException
)
178 virtual ComplexTypes SAL_CALL
getStruct() throw(::com::sun::star::uno::RuntimeException
)
179 { return _aDummyStruct
; }
180 virtual void SAL_CALL
setStruct( const ::com::sun::star::test::performance::ComplexTypes
& c
) throw(::com::sun::star::uno::RuntimeException
)
183 virtual void SAL_CALL
async() throw(::com::sun::star::uno::RuntimeException
)
185 virtual void SAL_CALL
sync() throw(::com::sun::star::uno::RuntimeException
)
187 virtual ComplexTypes SAL_CALL
complex_in( const ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
189 virtual ComplexTypes SAL_CALL
complex_inout( ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
191 virtual void SAL_CALL
complex_oneway( const ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
193 virtual void SAL_CALL
complex_noreturn( const ::com::sun::star::test::performance::ComplexTypes
& aVal
) throw(::com::sun::star::uno::RuntimeException
)
195 virtual Reference
< XPerformanceTest
> SAL_CALL
createObject() throw(::com::sun::star::uno::RuntimeException
)
196 { return new ServiceImpl(); }
197 virtual void SAL_CALL
raiseRuntimeException( ) throw(::com::sun::star::uno::RuntimeException
)
201 //##################################################################################################
204 //__________________________________________________________________________________________________
205 OUString
ServiceImpl::getImplementationName()
206 throw (RuntimeException
)
208 return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME
) );
210 //__________________________________________________________________________________________________
211 sal_Bool
ServiceImpl::supportsService( const OUString
& rServiceName
)
212 throw (RuntimeException
)
214 const Sequence
< OUString
> & rSNL
= getSupportedServiceNames();
215 const OUString
* pArray
= rSNL
.getConstArray();
216 for ( sal_Int32 nPos
= rSNL
.getLength(); nPos
--; )
218 if (pArray
[nPos
] == rServiceName
)
223 //__________________________________________________________________________________________________
224 Sequence
< OUString
> ServiceImpl::getSupportedServiceNames()
225 throw (RuntimeException
)
227 return benchmark_object::getSupportedServiceNames();
232 //==================================================================================================
233 static Reference
< XInterface
> SAL_CALL
ServiceImpl_create( const Reference
< XMultiServiceFactory
> & xSMgr
)
235 return Reference
< XInterface
>( (XPerformanceTest
*)new ServiceImpl( xSMgr
) );
241 //##################################################################################################
242 //##################################################################################################
243 //##################################################################################################
248 sal_Bool SAL_CALL
component_writeInfo(
249 void * pServiceManager
, void * pRegistryKey
)
255 Reference
< XRegistryKey
> xNewKey(
256 reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey(
257 OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME
"/UNO/SERVICES") ) ) );
258 xNewKey
->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME
) ) );
262 catch (InvalidRegistryException
&)
264 OSL_FAIL( "### InvalidRegistryException!" );
269 //==================================================================================================
270 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory(
271 const sal_Char
* pImplName
, void * pServiceManager
, void * pRegistryKey
)
275 if (pServiceManager
&& rtl_str_compare( pImplName
, IMPLNAME
) == 0)
277 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
278 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
279 OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME
) ),
280 benchmark_object::ServiceImpl_create
,
281 benchmark_object::getSupportedServiceNames() ) );
286 pRet
= xFactory
.get();
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */