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