1*61dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*61dff127SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*61dff127SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*61dff127SAndrew Rist  * distributed with this work for additional information
6*61dff127SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*61dff127SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*61dff127SAndrew Rist  * "License"); you may not use this file except in compliance
9*61dff127SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*61dff127SAndrew Rist  *
11*61dff127SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*61dff127SAndrew Rist  *
13*61dff127SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*61dff127SAndrew Rist  * software distributed under the License is distributed on an
15*61dff127SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61dff127SAndrew Rist  * KIND, either express or implied.  See the License for the
17*61dff127SAndrew Rist  * specific language governing permissions and limitations
18*61dff127SAndrew Rist  * under the License.
19*61dff127SAndrew Rist  *
20*61dff127SAndrew Rist  *************************************************************/
21*61dff127SAndrew Rist 
22*61dff127SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "test/javauno/nativethreadpool/XSource.hpp"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "com/sun/star/bridge/UnoUrlResolver.hpp"
30cdf0e10cSrcweir #include "com/sun/star/bridge/XUnoUrlResolver.hpp"
31cdf0e10cSrcweir #include "com/sun/star/connection/ConnectionSetupException.hpp"
32cdf0e10cSrcweir #include "com/sun/star/connection/NoConnectException.hpp"
33cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
34cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
35cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
36cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
37cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
38cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
39cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
40cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
41cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
42cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
43cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
44cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
45cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
46cdf0e10cSrcweir #include "rtl/ustring.hxx"
47cdf0e10cSrcweir #include "sal/types.h"
48cdf0e10cSrcweir #include "uno/lbnames.h"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir namespace css = com::sun::star;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class Server:
55cdf0e10cSrcweir     public cppu::WeakImplHelper1< test::javauno::nativethreadpool::XSource >
56cdf0e10cSrcweir {
57cdf0e10cSrcweir public:
Server(css::uno::Reference<css::uno::XComponentContext> const & theContext)58cdf0e10cSrcweir     explicit Server(
59cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & theContext):
60cdf0e10cSrcweir         context(theContext) {}
61cdf0e10cSrcweir 
62cdf0e10cSrcweir private:
~Server()63cdf0e10cSrcweir     virtual ~Server() {}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL get() throw (css::uno::RuntimeException);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > context;
68cdf0e10cSrcweir };
69cdf0e10cSrcweir 
get()70cdf0e10cSrcweir sal_Int32 Server::get() throw (css::uno::RuntimeException) {
71cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiComponentFactory > factory(
72cdf0e10cSrcweir         context->getServiceManager());
73cdf0e10cSrcweir     if (!factory.is()) {
74cdf0e10cSrcweir         throw new css::uno::RuntimeException(
75cdf0e10cSrcweir             rtl::OUString::createFromAscii(
76cdf0e10cSrcweir                 "no component context service manager"),
77cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this));
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     css::uno::Reference< test::javauno::nativethreadpool::XSource > source;
80cdf0e10cSrcweir     try {
81cdf0e10cSrcweir         // Use "127.0.0.1" instead of "localhost", see #i32281#:
82cdf0e10cSrcweir         source
83cdf0e10cSrcweir             = css::uno::Reference< test::javauno::nativethreadpool::XSource >(
84cdf0e10cSrcweir                 css::bridge::UnoUrlResolver::create(context)->resolve(
85cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
86cdf0e10cSrcweir                         "uno:socket,host=127.0.0.1,port=3831;urp;test")),
87cdf0e10cSrcweir                 css::uno::UNO_QUERY_THROW);
88cdf0e10cSrcweir     } catch (css::connection::NoConnectException & e) {
89cdf0e10cSrcweir         throw css::lang::WrappedTargetRuntimeException(
90cdf0e10cSrcweir             rtl::OUString::createFromAscii(
91cdf0e10cSrcweir                 "com.sun.star.uno.UnoUrlResolver.resolve"),
92cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
93cdf0e10cSrcweir     } catch (css::connection::ConnectionSetupException & e) {
94cdf0e10cSrcweir         throw css::lang::WrappedTargetRuntimeException(
95cdf0e10cSrcweir             rtl::OUString::createFromAscii(
96cdf0e10cSrcweir                 "com.sun.star.uno.UnoUrlResolver.resolve"),
97cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
98cdf0e10cSrcweir     } catch (css::lang::IllegalArgumentException & e) {
99cdf0e10cSrcweir         throw css::lang::WrappedTargetRuntimeException(
100cdf0e10cSrcweir             rtl::OUString::createFromAscii(
101cdf0e10cSrcweir                 "com.sun.star.uno.UnoUrlResolver.resolve"),
102cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir     return source->get();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
create(css::uno::Reference<css::uno::XComponentContext> const & context)107cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL create(
108cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context)
109cdf0e10cSrcweir     SAL_THROW((css::uno::Exception))
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     return static_cast< cppu::OWeakObject * >(new Server(context));
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
getImplementationName()114cdf0e10cSrcweir rtl::OUString SAL_CALL getImplementationName() {
115cdf0e10cSrcweir     return rtl::OUString::createFromAscii(
116cdf0e10cSrcweir         "test.javauno.nativethreadpool.server");
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
getSupportedServiceNames()119cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() {
120cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir cppu::ImplementationEntry entries[] = {
124cdf0e10cSrcweir     { &create, &getImplementationName, &getSupportedServiceNames,
125cdf0e10cSrcweir       &cppu::createSingleComponentFactory, 0, 0 },
126cdf0e10cSrcweir     { 0, 0, 0, 0, 0, 0 }
127cdf0e10cSrcweir };
128cdf0e10cSrcweir 
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
component_getFactory(char const * implName,void * serviceManager,void * registryKey)131cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(
132cdf0e10cSrcweir     char const * implName, void * serviceManager, void * registryKey)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     return cppu::component_getFactoryHelper(
135cdf0e10cSrcweir         implName, serviceManager, registryKey, entries);
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
component_getImplementationEnvironment(char const ** envTypeName,uno_Environment **)138cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
139cdf0e10cSrcweir     char const ** envTypeName, uno_Environment **)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
142cdf0e10cSrcweir }
143