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: testsameprocess.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"
33 #if OSL_DEBUG_LEVEL == 0
40 #include <osl/mutex.hxx>
41 #include <osl/thread.hxx>
43 #include <cppuhelper/servicefactory.hxx>
45 #include <com/sun/star/bridge/XBridgeFactory.hpp>
46 #include <com/sun/star/connection/XAcceptor.hpp>
47 #include <com/sun/star/connection/XConnector.hpp>
49 #include <com/sun/star/lang/XComponent.hpp>
51 #include <cppuhelper/weak.hxx>
53 #include <test/XTestFactory.hpp>
56 using namespace ::test
;
57 using namespace ::rtl
;
58 using namespace ::cppu
;
59 using namespace ::osl
;
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::bridge
;
63 using namespace ::com::sun::star::connection
;
70 #include "osl/mutex.h"
80 MyThread( const Reference
< XAcceptor
> &r
,
81 const Reference
< XBridgeFactory
> &rFactory
,
82 const OUString
&sConnectionDescription
) :
84 m_rBridgeFactory ( rFactory
),
85 m_sConnectionDescription( sConnectionDescription
)
87 virtual void SAL_CALL
run();
90 Reference
< XAcceptor
> m_rAcceptor
;
91 Reference
< XBridgeFactory
> m_rBridgeFactory
;
92 OUString m_sConnectionDescription
;
104 Reference
< XConnection
> rConnection
=
105 m_rAcceptor
->accept( m_sConnectionDescription
);
107 if( ! rConnection
.is() )
112 Reference
< XBridge
> rBridge
=
113 m_rBridgeFactory
->createBridge(
115 OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")) ,
117 (XInstanceProvider
* ) new OInstanceProvider
);
123 printf( "Exception was thrown by acceptor thread\n" );
130 int main( int argc
, char *argv
[] )
134 printf( "usage : testsamprocess host:port\n" );
139 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
140 OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) );
142 Reference
< XConnector
> rConnector(
143 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")),
144 OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION
)),
148 Reference
< XAcceptor
> rAcceptor(
149 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")),
150 OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION
)),
154 // just ensure that it is registered
155 // createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
156 // OUString( RTL_CONSTASCII_USTRINGPARAM("iiopbrdg" SAL_DLLEXTENSION)),
159 Reference
< XBridgeFactory
> rFactory(
160 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
161 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION
)),
166 MyThread
threadAcceptor( rAcceptor
, rFactory
, OUString::createFromAscii( argv
[1] ) );
168 threadAcceptor
.create();
169 TimeValue value
={2,0};
170 osl_waitThread( &value
);
174 Reference
< XConnection
> rConnection
=
175 rConnector
->connect( OUString::createFromAscii( argv
[1] ) );
177 printf( "%s\n" , OUStringToOString( rConnection
->getDescription(),
178 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
183 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
184 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")),
185 OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")),
187 Reference
< XInstanceProvider
> () );
189 Reference
< XInterface
> rInitialObject
190 = rBridge
->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("bla")) );
192 if( rInitialObject
.is() )
194 printf( "got the remote object\n" );
195 testRemote( rInitialObject
);
197 printf( "Closing...\n" );
198 TimeValue timeValue
={2,0};
199 osl_waitThread( &timeValue
);
202 Reference
< XBridge
> rBridge
= rFactory
->getBridge(
203 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) );
204 assert( ! rBridge
.is() );
209 printf( "Login failed, got an Exception !\n" );
212 rAcceptor
->stopAccepting();
213 threadAcceptor
.join();
215 Reference
< XComponent
> rComp( rFactory
, UNO_QUERY
);
219 rComp
= Reference
< XComponent
> ( rSMgr
, UNO_QUERY
);