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