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: testserver.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"
36 #include <osl/mutex.hxx>
37 #include <osl/conditn.h>
39 #include <osl/thread.hxx>
41 #include <cppuhelper/servicefactory.hxx>
42 #include <cppuhelper/implbase1.hxx>
44 #include <com/sun/star/connection/XAcceptor.hpp>
45 #include <com/sun/star/connection/XConnection.hpp>
47 #include <com/sun/star/bridge/XInstanceProvider.hpp>
48 #include <com/sun/star/bridge/XBridgeFactory.hpp>
50 #include <com/sun/star/lang/XComponent.hpp>
51 #include <com/sun/star/lang/XInitialization.hpp>
54 #include <test/XTestFactory.hpp>
56 #include <cppuhelper/weak.hxx>
58 using namespace ::test
;
59 using namespace ::rtl
;
60 using namespace ::osl
;
61 using namespace ::cppu
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::lang
;
64 using namespace ::com::sun::star::bridge
;
65 using namespace ::com::sun::star::connection
;
81 MyThread( const Reference
< XAcceptor
> &r
,
82 const Reference
< XBridgeFactory
> &rFactory
,
83 const Reference
< XMultiServiceFactory
> &rSMgr
,
84 const OUString
&sConnectionDescription
,
85 const OUString
&sProtocol
,
89 m_rBridgeFactory ( rFactory
),
91 m_sConnectionDescription( sConnectionDescription
),
92 m_sProtocol( sProtocol
),
93 m_bReverse( bReverse
),
94 m_bLatency( bLatency
)
96 virtual void SAL_CALL
run();
98 void latencyTest( const Reference
< XConnection
> &r
);
101 Reference
< XAcceptor
> m_rAcceptor
;
102 Reference
< XBridgeFactory
> m_rBridgeFactory
;
103 Reference
< XMultiServiceFactory
> m_rSMgr
;
104 OUString m_sConnectionDescription
;
105 OUString m_sProtocol
;
111 void MyThread::latencyTest( const Reference
< XConnection
> &r
)
113 Sequence
< sal_Int8
> s
;
114 while( 12 == r
->read( s
, 12 ) )
117 s
= Sequence
< sal_Int8
>(60);
129 Reference
< XConnection
> rConnection
=
130 m_rAcceptor
->accept( m_sConnectionDescription
);
132 if( ! rConnection
.is() )
138 latencyTest( rConnection
);
143 Reference
< XBridge
> rBridge
=
144 m_rBridgeFactory
->createBridge(
148 (XInstanceProvider
* ) new OInstanceProvider(m_rSMgr
) );
153 printf( "doing reverse callme test (test is ok, when on each line a +- appears\n" );
154 Reference
< XInterface
> r
= rBridge
->getInstance(
155 OUString( RTL_CONSTASCII_USTRINGPARAM("blubber" )));
156 Reference
< XTestFactory
> rFactory( r
, UNO_QUERY
);
157 Reference
< XCallMe
> rCallMe
= rFactory
->createCallMe();
159 for( sal_Int32 i
= 0 ; i
< 1 ; i
++ )
162 OUString( RTL_CONSTASCII_USTRINGPARAM("my test string")) , 2 );
164 printf( "all oneway are send\n" );
165 rCallMe
->call( OUString::createFromAscii( "reverse call me test finished" ) , 0 );
166 printf( "revers callme test finished\n" );
170 catch ( Exception
& e
)
172 printf( "Exception was thrown by acceptor \n" );
173 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
174 printf( "%s\n" , o
.getStr() );
179 printf( "Exception was thrown by acceptor thread\n" );
186 int main( int argc
, char *argv
[] )
192 printf( "usage : testserver [-r] connectionstring\n"
193 " -r does a reverse test (server calls client)\n" );
197 OUString sConnectionString
;
199 sal_Bool bReverse
= sal_False
;
200 sal_Bool bLatency
= sal_False
;
202 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
205 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
206 OUString( RTL_CONSTASCII_USTRINGPARAM( "server.rdb" ) ) );
208 Reference
< XBridgeFactory
> rBridgeFactory ( createComponent(
209 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
210 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION
)),
215 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
216 OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION
)),
220 Reference
< XAcceptor
> rAcceptor(
221 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")),
222 OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION
)),
226 MyThread
thread( rAcceptor
,
240 TimeValue value
={360,0};
241 osl_waitThread( &value
);
243 printf( "Closing...\n" );
245 rAcceptor
->stopAccepting();
248 printf( "Closed\n" );
250 Reference
< XComponent
> rComp2( rBridgeFactory
, UNO_QUERY
);
252 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);