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 "test/javauno/nativethreadpool/XRelay.hpp" 32*cdf0e10cSrcweir #include "test/javauno/nativethreadpool/XSource.hpp" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "com/sun/star/bridge/UnoUrlResolver.hpp" 35*cdf0e10cSrcweir #include "com/sun/star/bridge/XUnoUrlResolver.hpp" 36*cdf0e10cSrcweir #include "com/sun/star/connection/ConnectionSetupException.hpp" 37*cdf0e10cSrcweir #include "com/sun/star/connection/NoConnectException.hpp" 38*cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp" 39*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" 40*cdf0e10cSrcweir #include "com/sun/star/lang/XMain.hpp" 41*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp" 42*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp" 43*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 44*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 45*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx" 46*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 47*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp" 48*cdf0e10cSrcweir #include "cppuhelper/factory.hxx" 49*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 50*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 51*cdf0e10cSrcweir #include "cppuhelper/weak.hxx" 52*cdf0e10cSrcweir #include "osl/thread.hxx" 53*cdf0e10cSrcweir #include "rtl/ustring.hxx" 54*cdf0e10cSrcweir #include "sal/types.h" 55*cdf0e10cSrcweir #include "uno/lbnames.h" 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <iostream> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir namespace css = com::sun::star; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir namespace { 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir class Client: public cppu::WeakImplHelper2< 64*cdf0e10cSrcweir css::lang::XMain, test::javauno::nativethreadpool::XSource > 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir public: 67*cdf0e10cSrcweir explicit Client( 68*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & theContext): 69*cdf0e10cSrcweir context(theContext) {} 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir private: 72*cdf0e10cSrcweir virtual ~Client() {} 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL run(css::uno::Sequence< rtl::OUString > const &) 75*cdf0e10cSrcweir throw (css::uno::RuntimeException); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL get() throw (css::uno::RuntimeException); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > context; 80*cdf0e10cSrcweir osl::ThreadData data; 81*cdf0e10cSrcweir }; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir sal_Int32 Client::run(css::uno::Sequence< rtl::OUString > const &) 84*cdf0e10cSrcweir throw (css::uno::RuntimeException) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiComponentFactory > factory( 87*cdf0e10cSrcweir context->getServiceManager()); 88*cdf0e10cSrcweir if (!factory.is()) { 89*cdf0e10cSrcweir throw new css::uno::RuntimeException( 90*cdf0e10cSrcweir rtl::OUString::createFromAscii( 91*cdf0e10cSrcweir "no component context service manager"), 92*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this)); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir css::uno::Reference< test::javauno::nativethreadpool::XRelay > relay; 95*cdf0e10cSrcweir try { 96*cdf0e10cSrcweir relay = css::uno::Reference< test::javauno::nativethreadpool::XRelay >( 97*cdf0e10cSrcweir factory->createInstanceWithContext( 98*cdf0e10cSrcweir rtl::OUString::createFromAscii( 99*cdf0e10cSrcweir "test.javauno.nativethreadpool.Relay"), 100*cdf0e10cSrcweir context), 101*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 102*cdf0e10cSrcweir } catch (css::uno::RuntimeException &) { 103*cdf0e10cSrcweir throw; 104*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 105*cdf0e10cSrcweir throw css::lang::WrappedTargetRuntimeException( 106*cdf0e10cSrcweir rtl::OUString::createFromAscii( 107*cdf0e10cSrcweir "creating test.javauno.nativethreadpool.Relay service"), 108*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e)); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir relay->start(this); 111*cdf0e10cSrcweir if (!data.setData(reinterpret_cast< void * >(12345))) { 112*cdf0e10cSrcweir throw new css::uno::RuntimeException( 113*cdf0e10cSrcweir rtl::OUString::createFromAscii("osl::ThreadData::setData failed"), 114*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this)); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir css::uno::Reference< test::javauno::nativethreadpool::XSource > source; 117*cdf0e10cSrcweir try { 118*cdf0e10cSrcweir source 119*cdf0e10cSrcweir = css::uno::Reference< test::javauno::nativethreadpool::XSource >( 120*cdf0e10cSrcweir css::bridge::UnoUrlResolver::create(context)->resolve( 121*cdf0e10cSrcweir rtl::OUString::createFromAscii( 122*cdf0e10cSrcweir "uno:socket,host=localhost,port=3830;urp;test")), 123*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 124*cdf0e10cSrcweir } catch (css::connection::NoConnectException & e) { 125*cdf0e10cSrcweir throw css::lang::WrappedTargetRuntimeException( 126*cdf0e10cSrcweir rtl::OUString::createFromAscii( 127*cdf0e10cSrcweir "com.sun.star.uno.UnoUrlResolver.resolve"), 128*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e)); 129*cdf0e10cSrcweir } catch (css::connection::ConnectionSetupException & e) { 130*cdf0e10cSrcweir throw css::lang::WrappedTargetRuntimeException( 131*cdf0e10cSrcweir rtl::OUString::createFromAscii( 132*cdf0e10cSrcweir "com.sun.star.uno.UnoUrlResolver.resolve"), 133*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e)); 134*cdf0e10cSrcweir } catch (css::lang::IllegalArgumentException & e) { 135*cdf0e10cSrcweir throw css::lang::WrappedTargetRuntimeException( 136*cdf0e10cSrcweir rtl::OUString::createFromAscii( 137*cdf0e10cSrcweir "com.sun.star.uno.UnoUrlResolver.resolve"), 138*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e)); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir bool success = source->get() == 12345; 141*cdf0e10cSrcweir std::cout << "success? " << (success ? "yes" : "no") << '\n'; 142*cdf0e10cSrcweir return success ? 0 : 1; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir sal_Int32 Client::get() throw (css::uno::RuntimeException) { 146*cdf0e10cSrcweir return reinterpret_cast< sal_Int32 >(data.getData()); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL create( 150*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context) 151*cdf0e10cSrcweir SAL_THROW((css::uno::Exception)) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir return static_cast< cppu::OWeakObject * >(new Client(context)); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir rtl::OUString SAL_CALL getImplementationName() { 157*cdf0e10cSrcweir return rtl::OUString::createFromAscii( 158*cdf0e10cSrcweir "test.javauno.nativethreadpool.client"); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() { 162*cdf0e10cSrcweir return css::uno::Sequence< rtl::OUString >(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir cppu::ImplementationEntry entries[] = { 166*cdf0e10cSrcweir { &create, &getImplementationName, &getSupportedServiceNames, 167*cdf0e10cSrcweir &cppu::createSingleComponentFactory, 0, 0 }, 168*cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } 169*cdf0e10cSrcweir }; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory( 174*cdf0e10cSrcweir char const * implName, void * serviceManager, void * registryKey) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir return cppu::component_getFactoryHelper( 177*cdf0e10cSrcweir implName, serviceManager, registryKey, entries); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment( 181*cdf0e10cSrcweir char const ** envTypeName, uno_Environment **) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 184*cdf0e10cSrcweir } 185