1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testnativethreadpoolclient.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
34 #include "test/javauno/nativethreadpool/XRelay.hpp"
35 #include "test/javauno/nativethreadpool/XSource.hpp"
37 #include "com/sun/star/bridge/UnoUrlResolver.hpp"
38 #include "com/sun/star/bridge/XUnoUrlResolver.hpp"
39 #include "com/sun/star/connection/ConnectionSetupException.hpp"
40 #include "com/sun/star/connection/NoConnectException.hpp"
41 #include "com/sun/star/lang/IllegalArgumentException.hpp"
42 #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
43 #include "com/sun/star/lang/XMain.hpp"
44 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
45 #include "com/sun/star/uno/Exception.hpp"
46 #include "com/sun/star/uno/Reference.hxx"
47 #include "com/sun/star/uno/RuntimeException.hpp"
48 #include "com/sun/star/uno/Sequence.hxx"
49 #include "com/sun/star/uno/XComponentContext.hpp"
50 #include "com/sun/star/uno/XInterface.hpp"
51 #include "cppuhelper/factory.hxx"
52 #include "cppuhelper/implbase2.hxx"
53 #include "cppuhelper/implementationentry.hxx"
54 #include "cppuhelper/weak.hxx"
55 #include "osl/thread.hxx"
56 #include "rtl/ustring.hxx"
57 #include "sal/types.h"
58 #include "uno/lbnames.h"
62 namespace css
= com::sun::star
;
66 class Client
: public cppu::WeakImplHelper2
<
67 css::lang::XMain
, test::javauno::nativethreadpool::XSource
>
71 css::uno::Reference
< css::uno::XComponentContext
> const & theContext
):
72 context(theContext
) {}
77 virtual sal_Int32 SAL_CALL
run(css::uno::Sequence
< rtl::OUString
> const &)
78 throw (css::uno::RuntimeException
);
80 virtual sal_Int64 SAL_CALL
get() throw (css::uno::RuntimeException
);
82 css::uno::Reference
< css::uno::XComponentContext
> context
;
86 sal_Int32
Client::run(css::uno::Sequence
< rtl::OUString
> const &)
87 throw (css::uno::RuntimeException
)
89 css::uno::Reference
< css::lang::XMultiComponentFactory
> factory(
90 context
->getServiceManager());
92 throw new css::uno::RuntimeException(
93 rtl::OUString::createFromAscii(
94 "no component context service manager"),
95 static_cast< cppu::OWeakObject
* >(this));
97 css::uno::Reference
< test::javauno::nativethreadpool::XRelay
> relay
;
99 relay
= css::uno::Reference
< test::javauno::nativethreadpool::XRelay
>(
100 factory
->createInstanceWithContext(
101 rtl::OUString::createFromAscii(
102 "test.javauno.nativethreadpool.Relay"),
104 css::uno::UNO_QUERY_THROW
);
105 } catch (css::uno::RuntimeException
&) {
107 } catch (css::uno::Exception
& e
) {
108 throw css::lang::WrappedTargetRuntimeException(
109 rtl::OUString::createFromAscii(
110 "creating test.javauno.nativethreadpool.Relay service"),
111 static_cast< cppu::OWeakObject
* >(this), css::uno::makeAny(e
));
114 if (!data
.setData(reinterpret_cast< void * >(12345))) {
115 throw new css::uno::RuntimeException(
116 rtl::OUString::createFromAscii("osl::ThreadData::setData failed"),
117 static_cast< cppu::OWeakObject
* >(this));
119 css::uno::Reference
< test::javauno::nativethreadpool::XSource
> source
;
122 = css::uno::Reference
< test::javauno::nativethreadpool::XSource
>(
123 css::bridge::UnoUrlResolver::create(context
)->resolve(
124 rtl::OUString::createFromAscii(
125 "uno:socket,host=localhost,port=3830;urp;test")),
126 css::uno::UNO_QUERY_THROW
);
127 } catch (css::connection::NoConnectException
& e
) {
128 throw css::lang::WrappedTargetRuntimeException(
129 rtl::OUString::createFromAscii(
130 "com.sun.star.uno.UnoUrlResolver.resolve"),
131 static_cast< cppu::OWeakObject
* >(this), css::uno::makeAny(e
));
132 } catch (css::connection::ConnectionSetupException
& e
) {
133 throw css::lang::WrappedTargetRuntimeException(
134 rtl::OUString::createFromAscii(
135 "com.sun.star.uno.UnoUrlResolver.resolve"),
136 static_cast< cppu::OWeakObject
* >(this), css::uno::makeAny(e
));
137 } catch (css::lang::IllegalArgumentException
& e
) {
138 throw css::lang::WrappedTargetRuntimeException(
139 rtl::OUString::createFromAscii(
140 "com.sun.star.uno.UnoUrlResolver.resolve"),
141 static_cast< cppu::OWeakObject
* >(this), css::uno::makeAny(e
));
143 bool success
= source
->get() == 12345;
144 std::cout
<< "success? " << (success
? "yes" : "no") << '\n';
145 return success
? 0 : 1;
148 sal_Int64
Client::get() throw (css::uno::RuntimeException
) {
149 return static_cast< sal_Int64
>(reinterpret_cast< sal_IntPtr
>(data
.getData()));
152 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
create(
153 css::uno::Reference
< css::uno::XComponentContext
> const & context
)
154 SAL_THROW((css::uno::Exception
))
156 return static_cast< cppu::OWeakObject
* >(new Client(context
));
159 rtl::OUString SAL_CALL
getImplementationName() {
160 return rtl::OUString::createFromAscii(
161 "test.javauno.nativethreadpool.client");
164 css::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames() {
165 return css::uno::Sequence
< rtl::OUString
>();
168 cppu::ImplementationEntry entries
[] = {
169 { &create
, &getImplementationName
, &getSupportedServiceNames
,
170 &cppu::createSingleComponentFactory
, 0, 0 },
176 extern "C" void * SAL_CALL
component_getFactory(
177 char const * implName
, void * serviceManager
, void * registryKey
)
179 return cppu::component_getFactoryHelper(
180 implName
, serviceManager
, registryKey
, entries
);
183 extern "C" void SAL_CALL
component_getImplementationEnvironment(
184 char const ** envTypeName
, uno_Environment
**)
186 *envTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;