1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_bridges.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "com/sun/star/bridge/UnoUrlResolver.hpp" 32*cdf0e10cSrcweir #include "com/sun/star/bridge/XUnoUrlResolver.hpp" 33*cdf0e10cSrcweir #include "com/sun/star/lang/XMain.hpp" 34*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 35*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp" 36*cdf0e10cSrcweir #include "com/sun/star/registry/InvalidRegistryException.hpp" 37*cdf0e10cSrcweir #include "com/sun/star/registry/XRegistryKey.hpp" 38*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx" 39*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp" 40*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 41*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 42*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx" 43*cdf0e10cSrcweir #include "com/sun/star/uno/Type.hxx" 44*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 45*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp" 46*cdf0e10cSrcweir #include "cppuhelper/factory.hxx" 47*cdf0e10cSrcweir #include "cppuhelper/implbase3.hxx" 48*cdf0e10cSrcweir #include "cppuhelper/weak.hxx" 49*cdf0e10cSrcweir #include "osl/conditn.hxx" 50*cdf0e10cSrcweir #include "osl/interlck.h" 51*cdf0e10cSrcweir #include "rtl/string.h" 52*cdf0e10cSrcweir #include "rtl/ustring.hxx" 53*cdf0e10cSrcweir #include "sal/types.h" 54*cdf0e10cSrcweir #include "test/javauno/acquire/XBase.hpp" 55*cdf0e10cSrcweir #include "test/javauno/acquire/XDerived.hpp" 56*cdf0e10cSrcweir #include "test/javauno/acquire/XTest.hpp" 57*cdf0e10cSrcweir #include "uno/environment.h" 58*cdf0e10cSrcweir #include "uno/lbnames.h" 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include <iostream> 61*cdf0e10cSrcweir #include <cstdlib> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir namespace css = com::sun::star; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir namespace { 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir class WaitCondition { 68*cdf0e10cSrcweir public: 69*cdf0e10cSrcweir WaitCondition() {} 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir ~WaitCondition(); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir osl::Condition & get() { return m_condition; } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir private: 76*cdf0e10cSrcweir WaitCondition(WaitCondition &); // not implemented 77*cdf0e10cSrcweir void operator =(WaitCondition); // not implemented 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir osl::Condition m_condition; 80*cdf0e10cSrcweir }; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir WaitCondition::~WaitCondition() { 85*cdf0e10cSrcweir std::cout << "waiting for condition\n"; 86*cdf0e10cSrcweir if (m_condition.wait() != osl::Condition::result_ok) { 87*cdf0e10cSrcweir throw "osl::Condition::wait failed"; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir namespace { 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir class Interface: public css::uno::XInterface { 94*cdf0e10cSrcweir public: 95*cdf0e10cSrcweir explicit Interface(osl::Condition & condition): 96*cdf0e10cSrcweir m_condition(condition), m_refCount(0) {} 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) 99*cdf0e10cSrcweir throw (css::uno::RuntimeException); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw () 102*cdf0e10cSrcweir { osl_incrementInterlockedCount(&m_refCount); } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir virtual void SAL_CALL release() throw (); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir protected: 107*cdf0e10cSrcweir virtual ~Interface() { m_condition.set(); } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir private: 110*cdf0e10cSrcweir Interface(Interface &); // not implemented 111*cdf0e10cSrcweir void operator =(Interface); // not implemented 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir osl::Condition & m_condition; 114*cdf0e10cSrcweir oslInterlockedCount m_refCount; 115*cdf0e10cSrcweir }; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir css::uno::Any Interface::queryInterface(css::uno::Type const & type) 120*cdf0e10cSrcweir throw (css::uno::RuntimeException) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return type.getTypeName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( 123*cdf0e10cSrcweir "com.sun.star.uno.XInterface")) 124*cdf0e10cSrcweir ? css::uno::makeAny(css::uno::Reference< css::uno::XInterface >(this)) 125*cdf0e10cSrcweir : css::uno::Any(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir void Interface::release() throw () { 129*cdf0e10cSrcweir if (osl_decrementInterlockedCount(&m_refCount) == 0) { 130*cdf0e10cSrcweir delete this; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir namespace { 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir class Base: public Interface, public test::javauno::acquire::XBase { 137*cdf0e10cSrcweir public: 138*cdf0e10cSrcweir explicit Base(osl::Condition & condition): Interface(condition) {} 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) 141*cdf0e10cSrcweir throw (css::uno::RuntimeException); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw () { Interface::acquire(); } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir virtual void SAL_CALL release() throw () { Interface::release(); } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir protected: 148*cdf0e10cSrcweir virtual ~Base() {} 149*cdf0e10cSrcweir }; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir css::uno::Any Base::queryInterface(css::uno::Type const & type) 154*cdf0e10cSrcweir throw (css::uno::RuntimeException) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return type.getTypeName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( 157*cdf0e10cSrcweir "test.javauno.acquire.XBase")) 158*cdf0e10cSrcweir ? css::uno::makeAny( 159*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XBase >(this)) 160*cdf0e10cSrcweir : Interface::queryInterface(type); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir namespace { 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir class Derived: public Base, public test::javauno::acquire::XDerived { 166*cdf0e10cSrcweir public: 167*cdf0e10cSrcweir explicit Derived(osl::Condition & condition): Base(condition) {} 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) 170*cdf0e10cSrcweir throw (css::uno::RuntimeException); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw () { Base::acquire(); } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir virtual void SAL_CALL release() throw () { Base::release(); } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir private: 177*cdf0e10cSrcweir virtual ~Derived() {} 178*cdf0e10cSrcweir }; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir css::uno::Any Derived::queryInterface(css::uno::Type const & type) 183*cdf0e10cSrcweir throw (css::uno::RuntimeException) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return (type.getTypeName().equalsAsciiL( 186*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("test.javauno.acquire.XDerived"))) 187*cdf0e10cSrcweir ? css::uno::makeAny( 188*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived >(this)) 189*cdf0e10cSrcweir : Interface::queryInterface(type); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir namespace { 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir class Service: public cppu::WeakImplHelper3< 195*cdf0e10cSrcweir css::lang::XServiceInfo, css::lang::XMain, test::javauno::acquire::XTest > 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir public: 198*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName() 199*cdf0e10cSrcweir throw (css::uno::RuntimeException) 200*cdf0e10cSrcweir { return getImplementationName_static(); } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName) 203*cdf0e10cSrcweir throw (css::uno::RuntimeException); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir virtual css::uno::Sequence< rtl::OUString > SAL_CALL 206*cdf0e10cSrcweir getSupportedServiceNames() throw (css::uno::RuntimeException) 207*cdf0e10cSrcweir { return getSupportedServiceNames_static(); } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL 210*cdf0e10cSrcweir run(css::uno::Sequence< rtl::OUString > const & arguments) 211*cdf0e10cSrcweir throw (css::uno::RuntimeException); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir virtual void SAL_CALL setInterfaceToInterface( 214*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > const & obj) 215*cdf0e10cSrcweir throw (css::uno::RuntimeException) 216*cdf0e10cSrcweir { m_interface = obj; } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir virtual void SAL_CALL setBaseToInterface( 219*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XBase > const & obj) 220*cdf0e10cSrcweir throw (css::uno::RuntimeException) 221*cdf0e10cSrcweir { m_interface = obj; } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir virtual void SAL_CALL setDerivedToInterface( 224*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > const & obj) 225*cdf0e10cSrcweir throw (css::uno::RuntimeException) 226*cdf0e10cSrcweir { m_interface = obj; } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > 229*cdf0e10cSrcweir SAL_CALL getInterfaceFromInterface() throw (css::uno::RuntimeException) 230*cdf0e10cSrcweir { return m_interface; } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir virtual void SAL_CALL clearInterface() throw (css::uno::RuntimeException) 233*cdf0e10cSrcweir { m_interface.clear(); } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir virtual void SAL_CALL setBaseToBase( 236*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XBase > const & obj) 237*cdf0e10cSrcweir throw (css::uno::RuntimeException) 238*cdf0e10cSrcweir { m_base = obj; } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir virtual void SAL_CALL setDerivedToBase( 241*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > const & obj) 242*cdf0e10cSrcweir throw (css::uno::RuntimeException) 243*cdf0e10cSrcweir { m_base = obj.get(); } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > 246*cdf0e10cSrcweir SAL_CALL getInterfaceFromBase() throw (css::uno::RuntimeException) 247*cdf0e10cSrcweir { return m_base; } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir virtual css::uno::Reference< test::javauno::acquire::XBase > 250*cdf0e10cSrcweir SAL_CALL getBaseFromBase() throw (css::uno::RuntimeException) 251*cdf0e10cSrcweir { return m_base; } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir virtual void SAL_CALL clearBase() throw (css::uno::RuntimeException) 254*cdf0e10cSrcweir { m_base.clear(); } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir virtual void SAL_CALL setDerivedToDerived( 257*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > const & obj) 258*cdf0e10cSrcweir throw (css::uno::RuntimeException) 259*cdf0e10cSrcweir { m_derived = obj; } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > 262*cdf0e10cSrcweir SAL_CALL getInterfaceFromDerived() throw (css::uno::RuntimeException) 263*cdf0e10cSrcweir { return m_derived; } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir virtual css::uno::Reference< test::javauno::acquire::XBase > 266*cdf0e10cSrcweir SAL_CALL getBaseFromDerived() throw (css::uno::RuntimeException) 267*cdf0e10cSrcweir { return m_derived.get(); } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir virtual css::uno::Reference< test::javauno::acquire::XDerived > 270*cdf0e10cSrcweir SAL_CALL getDerivedFromDerived() throw (css::uno::RuntimeException) 271*cdf0e10cSrcweir { return m_derived; } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir virtual void SAL_CALL clearDerived() throw (css::uno::RuntimeException) 274*cdf0e10cSrcweir { m_derived.clear(); } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > 277*cdf0e10cSrcweir SAL_CALL roundTripInterfaceToInterface( 278*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > const & obj) 279*cdf0e10cSrcweir throw (css::uno::RuntimeException) 280*cdf0e10cSrcweir { return obj; } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > 283*cdf0e10cSrcweir SAL_CALL roundTripBaseToInterface( 284*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XBase > const & obj) 285*cdf0e10cSrcweir throw (css::uno::RuntimeException) 286*cdf0e10cSrcweir { return obj; } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > 289*cdf0e10cSrcweir SAL_CALL roundTripDerivedToInterface( 290*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > const & obj) 291*cdf0e10cSrcweir throw (css::uno::RuntimeException) 292*cdf0e10cSrcweir { return obj; } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir virtual css::uno::Reference< test::javauno::acquire::XBase > 295*cdf0e10cSrcweir SAL_CALL roundTripBaseToBase( 296*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XBase > const & obj) 297*cdf0e10cSrcweir throw (css::uno::RuntimeException) 298*cdf0e10cSrcweir { return obj; } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir virtual css::uno::Reference< test::javauno::acquire::XBase > 301*cdf0e10cSrcweir SAL_CALL roundTripDerivedToBase( 302*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > const & obj) 303*cdf0e10cSrcweir throw (css::uno::RuntimeException) 304*cdf0e10cSrcweir { return obj.get(); } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir virtual css::uno::Reference< test::javauno::acquire::XDerived > 307*cdf0e10cSrcweir SAL_CALL roundTripDerivedToDerived( 308*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > const & obj) 309*cdf0e10cSrcweir throw (css::uno::RuntimeException) 310*cdf0e10cSrcweir { return obj; } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir static rtl::OUString getImplementationName_static(); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir static css::uno::Sequence< rtl::OUString > 315*cdf0e10cSrcweir getSupportedServiceNames_static(); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir static css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( 318*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context) 319*cdf0e10cSrcweir throw (css::uno::Exception); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir private: 322*cdf0e10cSrcweir explicit Service( 323*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context): 324*cdf0e10cSrcweir m_context(context) {} 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_context; 327*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > m_interface; 328*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XBase > m_base; 329*cdf0e10cSrcweir css::uno::Reference< test::javauno::acquire::XDerived > m_derived; 330*cdf0e10cSrcweir }; 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir sal_Bool Service::supportsService(rtl::OUString const & serviceName) 335*cdf0e10cSrcweir throw (css::uno::RuntimeException) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > names( 338*cdf0e10cSrcweir getSupportedServiceNames_static()); 339*cdf0e10cSrcweir for (sal_Int32 i = 0; i< names.getLength(); ++i) { 340*cdf0e10cSrcweir if (names[i] == serviceName) { 341*cdf0e10cSrcweir return true; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir return false; 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir namespace { 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir template< typename T > void assertNotNull(css::uno::Reference< T > const & ref) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir if (!ref.is()) { 352*cdf0e10cSrcweir std::cerr << "assertNotNull failed\n"; 353*cdf0e10cSrcweir std::abort(); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir sal_Int32 Service::run(css::uno::Sequence< rtl::OUString > const & arguments) 360*cdf0e10cSrcweir throw (css::uno::RuntimeException) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir // - arguments[0] must be the UNO URL to connect to: 363*cdf0e10cSrcweir css::uno::Reference< XTest > test( 364*cdf0e10cSrcweir css::bridge::UnoUrlResolver::create(m_context)->resolve(arguments[0]), 365*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir WaitCondition c; 369*cdf0e10cSrcweir test->setInterfaceToInterface(new Interface(c.get())); 370*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromInterface()); 371*cdf0e10cSrcweir test->clearInterface(); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir WaitCondition c; 375*cdf0e10cSrcweir test->setInterfaceToInterface( 376*cdf0e10cSrcweir static_cast< Interface * >(new Base(c.get()))); 377*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromInterface()); 378*cdf0e10cSrcweir test->clearInterface(); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir WaitCondition c; 382*cdf0e10cSrcweir test->setInterfaceToInterface( 383*cdf0e10cSrcweir static_cast< Interface * >(new Derived(c.get()))); 384*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromInterface()); 385*cdf0e10cSrcweir test->clearInterface(); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir WaitCondition c; 390*cdf0e10cSrcweir test->setBaseToInterface(new Base(c.get())); 391*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromInterface()); 392*cdf0e10cSrcweir test->clearInterface(); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir WaitCondition c; 396*cdf0e10cSrcweir test->setBaseToInterface(static_cast< Base * >(new Derived(c.get()))); 397*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromInterface()); 398*cdf0e10cSrcweir test->clearInterface(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir WaitCondition c; 403*cdf0e10cSrcweir test->setDerivedToInterface(new Derived(c.get())); 404*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromInterface()); 405*cdf0e10cSrcweir test->clearInterface(); 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir WaitCondition c; 410*cdf0e10cSrcweir test->setBaseToBase(new Base(c.get())); 411*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromBase()); 412*cdf0e10cSrcweir assertNotNull(test->getBaseFromBase()); 413*cdf0e10cSrcweir test->clearBase(); 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir WaitCondition c; 417*cdf0e10cSrcweir test->setBaseToBase(static_cast< Base * >(new Derived(c.get()))); 418*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromBase()); 419*cdf0e10cSrcweir assertNotNull(test->getBaseFromBase()); 420*cdf0e10cSrcweir test->clearBase(); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir WaitCondition c; 425*cdf0e10cSrcweir test->setDerivedToBase(new Derived(c.get())); 426*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromBase()); 427*cdf0e10cSrcweir assertNotNull(test->getBaseFromBase()); 428*cdf0e10cSrcweir test->clearBase(); 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir WaitCondition c; 433*cdf0e10cSrcweir test->setDerivedToDerived(new Derived(c.get())); 434*cdf0e10cSrcweir assertNotNull(test->getInterfaceFromDerived()); 435*cdf0e10cSrcweir assertNotNull(test->getBaseFromDerived()); 436*cdf0e10cSrcweir assertNotNull(test->getDerivedFromDerived()); 437*cdf0e10cSrcweir test->clearDerived(); 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir WaitCondition c; 442*cdf0e10cSrcweir assertNotNull( 443*cdf0e10cSrcweir test->roundTripInterfaceToInterface(new Interface(c.get()))); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir WaitCondition c; 447*cdf0e10cSrcweir assertNotNull(test->roundTripInterfaceToInterface( 448*cdf0e10cSrcweir static_cast< Interface * >(new Base(c.get())))); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir WaitCondition c; 452*cdf0e10cSrcweir assertNotNull(test->roundTripInterfaceToInterface( 453*cdf0e10cSrcweir static_cast< Interface * >(new Derived(c.get())))); 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir WaitCondition c; 458*cdf0e10cSrcweir assertNotNull(test->roundTripBaseToInterface(new Base(c.get()))); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir WaitCondition c; 462*cdf0e10cSrcweir assertNotNull(test->roundTripBaseToInterface( 463*cdf0e10cSrcweir static_cast< Base * >(new Derived(c.get())))); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir WaitCondition c; 468*cdf0e10cSrcweir assertNotNull(test->roundTripDerivedToInterface(new Derived(c.get()))); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir WaitCondition c; 473*cdf0e10cSrcweir assertNotNull(test->roundTripBaseToBase(new Base(c.get()))); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir WaitCondition c; 477*cdf0e10cSrcweir assertNotNull(test->roundTripBaseToBase( 478*cdf0e10cSrcweir static_cast< Base * >(new Derived(c.get())))); 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir WaitCondition c; 483*cdf0e10cSrcweir assertNotNull(test->roundTripDerivedToBase(new Derived(c.get()))); 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir WaitCondition c; 488*cdf0e10cSrcweir assertNotNull(test->roundTripDerivedToDerived(new Derived(c.get()))); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir std::cout << "Client and server both cleanly terminate now: Success\n"; 492*cdf0e10cSrcweir return 0; 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir rtl::OUString Service::getImplementationName_static() { 496*cdf0e10cSrcweir return rtl::OUString::createFromAscii( 497*cdf0e10cSrcweir "com.sun.star.test.bridges.testacquire.impl"); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Service::getSupportedServiceNames_static() { 501*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > names(1); 502*cdf0e10cSrcweir names[0] = rtl::OUString::createFromAscii( 503*cdf0e10cSrcweir "com.sun.star.test.bridges.testacquire"); 504*cdf0e10cSrcweir return names; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > Service::createInstance( 508*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context) 509*cdf0e10cSrcweir throw (css::uno::Exception) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir return static_cast< cppu::OWeakObject * >(new Service(context)); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment( 515*cdf0e10cSrcweir char const ** envTypeName, uno_Environment **) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir if (envTypeName != 0) { 518*cdf0e10cSrcweir *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(char const * implName, 523*cdf0e10cSrcweir void * serviceManager, void *) { 524*cdf0e10cSrcweir void * p = 0; 525*cdf0e10cSrcweir if (serviceManager != 0) { 526*cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleComponentFactory > f; 527*cdf0e10cSrcweir if (Service::getImplementationName_static().equalsAscii(implName)) { 528*cdf0e10cSrcweir f = cppu::createSingleComponentFactory( 529*cdf0e10cSrcweir &Service::createInstance, 530*cdf0e10cSrcweir Service::getImplementationName_static(), 531*cdf0e10cSrcweir Service::getSupportedServiceNames_static()); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir if (f.is()) { 534*cdf0e10cSrcweir f->acquire(); 535*cdf0e10cSrcweir p = f.get(); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir return p; 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir namespace { 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir bool writeInfo(void * registryKey, rtl::OUString const & implementationName, 544*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > const & serviceNames) { 545*cdf0e10cSrcweir rtl::OUString keyName(rtl::OUString::createFromAscii("/")); 546*cdf0e10cSrcweir keyName += implementationName; 547*cdf0e10cSrcweir keyName += rtl::OUString::createFromAscii("/UNO/SERVICES"); 548*cdf0e10cSrcweir css::uno::Reference< css::registry::XRegistryKey > key; 549*cdf0e10cSrcweir try { 550*cdf0e10cSrcweir key = static_cast< css::registry::XRegistryKey * >(registryKey)-> 551*cdf0e10cSrcweir createKey(keyName); 552*cdf0e10cSrcweir } catch (css::registry::InvalidRegistryException &) {} 553*cdf0e10cSrcweir if (!key.is()) { 554*cdf0e10cSrcweir return false; 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir bool success = true; 557*cdf0e10cSrcweir for (sal_Int32 i = 0; i < serviceNames.getLength(); ++i) { 558*cdf0e10cSrcweir try { 559*cdf0e10cSrcweir key->createKey(serviceNames[i]); 560*cdf0e10cSrcweir } catch (css::registry::InvalidRegistryException &) { 561*cdf0e10cSrcweir success = false; 562*cdf0e10cSrcweir break; 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir return success; 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir extern "C" sal_Bool SAL_CALL component_writeInfo(void *, void * registryKey) { 571*cdf0e10cSrcweir return registryKey 572*cdf0e10cSrcweir && writeInfo(registryKey, Service::getImplementationName_static(), 573*cdf0e10cSrcweir Service::getSupportedServiceNames_static()); 574*cdf0e10cSrcweir } 575