1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <osl/mutex.hxx>
24 #include <osl/conditn.h>
26 #include <osl/thread.hxx>
28 #include <cppuhelper/servicefactory.hxx>
29 #include <cppuhelper/implbase1.hxx>
31 #include <com/sun/star/connection/XAcceptor.hpp>
32 #include <com/sun/star/connection/XConnection.hpp>
34 #include <com/sun/star/bridge/XInstanceProvider.hpp>
35 #include <com/sun/star/bridge/XBridgeFactory.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
41 #include <test/XTestFactory.hpp>
43 #include <cppuhelper/weak.hxx>
45 using namespace ::test
;
46 using namespace ::rtl
;
47 using namespace ::osl
;
48 using namespace ::cppu
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::bridge
;
52 using namespace ::com::sun::star::connection
;
68 MyThread( const Reference
< XAcceptor
> &r
,
69 const Reference
< XBridgeFactory
> &rFactory
,
70 const Reference
< XMultiServiceFactory
> &rSMgr
,
71 const OUString
&sConnectionDescription
,
72 const OUString
&sProtocol
,
76 m_rBridgeFactory ( rFactory
),
78 m_sConnectionDescription( sConnectionDescription
),
79 m_sProtocol( sProtocol
),
80 m_bReverse( bReverse
),
81 m_bLatency( bLatency
)
83 virtual void SAL_CALL
run();
85 void latencyTest( const Reference
< XConnection
> &r
);
88 Reference
< XAcceptor
> m_rAcceptor
;
89 Reference
< XBridgeFactory
> m_rBridgeFactory
;
90 Reference
< XMultiServiceFactory
> m_rSMgr
;
91 OUString m_sConnectionDescription
;
98 void MyThread::latencyTest( const Reference
< XConnection
> &r
)
100 Sequence
< sal_Int8
> s
;
101 while( 12 == r
->read( s
, 12 ) )
104 s
= Sequence
< sal_Int8
>(60);
116 Reference
< XConnection
> rConnection
=
117 m_rAcceptor
->accept( m_sConnectionDescription
);
119 if( ! rConnection
.is() )
125 latencyTest( rConnection
);
130 Reference
< XBridge
> rBridge
=
131 m_rBridgeFactory
->createBridge(
135 (XInstanceProvider
* ) new OInstanceProvider(m_rSMgr
) );
140 printf( "doing reverse callme test (test is ok, when on each line a +- appears\n" );
141 Reference
< XInterface
> r
= rBridge
->getInstance(
142 OUString("blubber" ));
143 Reference
< XTestFactory
> rFactory( r
, UNO_QUERY
);
144 Reference
< XCallMe
> rCallMe
= rFactory
->createCallMe();
146 for( sal_Int32 i
= 0 ; i
< 1 ; i
++ )
149 OUString("my test string") , 2 );
151 printf( "all oneway are send\n" );
152 rCallMe
->call( OUString( "reverse call me test finished" ) , 0 );
153 printf( "revers callme test finished\n" );
157 catch ( Exception
& e
)
159 printf( "Exception was thrown by acceptor \n" );
160 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
161 printf( "%s\n" , o
.getStr() );
166 printf( "Exception was thrown by acceptor thread\n" );
173 int main( int argc
, char *argv
[] )
179 printf( "usage : testserver [-r] connectionstring\n"
180 " -r does a reverse test (server calls client)\n" );
184 OUString sConnectionString
;
186 sal_Bool bReverse
= sal_False
;
187 sal_Bool bLatency
= sal_False
;
189 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
192 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
193 OUString( "server.rdb" ) );
195 Reference
< XBridgeFactory
> rBridgeFactory ( createComponent(
196 OUString("com.sun.star.bridge.BridgeFactory"),
197 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
202 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
203 OUString( "remotebridge.uno" SAL_DLLEXTENSION
),
207 Reference
< XAcceptor
> rAcceptor(
208 createComponent( OUString("com.sun.star.connection.Acceptor"),
209 OUString( "acceptor.uno" SAL_DLLEXTENSION
),
213 MyThread
thread( rAcceptor
,
227 TimeValue value
={360,0};
228 osl_waitThread( &value
);
230 printf( "Closing...\n" );
232 rAcceptor
->stopAccepting();
235 printf( "Closed\n" );
237 Reference
< XComponent
> rComp2( rBridgeFactory
, UNO_QUERY
);
239 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */