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 ::osl
;
47 using namespace ::cppu
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::lang
;
50 using namespace ::com::sun::star::bridge
;
51 using namespace ::com::sun::star::connection
;
67 MyThread( const Reference
< XAcceptor
> &r
,
68 const Reference
< XBridgeFactory
> &rFactory
,
69 const Reference
< XMultiServiceFactory
> &rSMgr
,
70 const OUString
&sConnectionDescription
,
71 const OUString
&sProtocol
,
75 m_rBridgeFactory ( rFactory
),
77 m_sConnectionDescription( sConnectionDescription
),
78 m_sProtocol( sProtocol
),
79 m_bReverse( bReverse
),
80 m_bLatency( bLatency
)
82 virtual void SAL_CALL
run();
84 void latencyTest( const Reference
< XConnection
> &r
);
87 Reference
< XAcceptor
> m_rAcceptor
;
88 Reference
< XBridgeFactory
> m_rBridgeFactory
;
89 Reference
< XMultiServiceFactory
> m_rSMgr
;
90 OUString m_sConnectionDescription
;
97 void MyThread::latencyTest( const Reference
< XConnection
> &r
)
99 Sequence
< sal_Int8
> s
;
100 while( 12 == r
->read( s
, 12 ) )
103 s
= Sequence
< sal_Int8
>(60);
115 Reference
< XConnection
> rConnection
=
116 m_rAcceptor
->accept( m_sConnectionDescription
);
118 if( ! rConnection
.is() )
124 latencyTest( rConnection
);
129 Reference
< XBridge
> rBridge
=
130 m_rBridgeFactory
->createBridge(
134 (XInstanceProvider
* ) new OInstanceProvider(m_rSMgr
) );
139 printf( "doing reverse callme test (test is ok, when on each line a +- appears\n" );
140 Reference
< XInterface
> r
= rBridge
->getInstance(
141 OUString("blubber" ));
142 Reference
< XTestFactory
> rFactory( r
, UNO_QUERY
);
143 Reference
< XCallMe
> rCallMe
= rFactory
->createCallMe();
145 for( sal_Int32 i
= 0 ; i
< 1 ; i
++ )
148 OUString("my test string") , 2 );
150 printf( "all oneway are send\n" );
151 rCallMe
->call( OUString( "reverse call me test finished" ) , 0 );
152 printf( "revers callme test finished\n" );
156 catch ( Exception
& e
)
158 printf( "Exception was thrown by acceptor \n" );
159 OString o
= OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
);
160 printf( "%s\n" , o
.getStr() );
165 printf( "Exception was thrown by acceptor thread\n" );
172 int main( int argc
, char *argv
[] )
178 printf( "usage : testserver [-r] connectionstring\n"
179 " -r does a reverse test (server calls client)\n" );
183 OUString sConnectionString
;
185 sal_Bool bReverse
= sal_False
;
186 sal_Bool bLatency
= sal_False
;
188 parseCommandLine( argv
, &sConnectionString
, &sProtocol
, &bLatency
, &bReverse
);
191 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
192 OUString( "server.rdb" ) );
194 Reference
< XBridgeFactory
> rBridgeFactory ( createComponent(
195 OUString("com.sun.star.bridge.BridgeFactory"),
196 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
201 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
202 OUString( "remotebridge.uno" SAL_DLLEXTENSION
),
206 Reference
< XAcceptor
> rAcceptor(
207 createComponent( OUString("com.sun.star.connection.Acceptor"),
208 OUString( "acceptor.uno" SAL_DLLEXTENSION
),
212 MyThread
thread( rAcceptor
,
226 TimeValue value
={360,0};
227 osl_waitThread( &value
);
229 printf( "Closing...\n" );
231 rAcceptor
->stopAccepting();
234 printf( "Closed\n" );
236 Reference
< XComponent
> rComp2( rBridgeFactory
, UNO_QUERY
);
238 Reference
< XComponent
> rComp( rSMgr
, UNO_QUERY
);
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */