update credits
[LibreOffice.git] / bridges / test / testserver.cxx
blob8aefdfd909b1eeecded167489ab75840afcdd943
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <string.h>
21 #include <osl/time.h>
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;
53 #include "testcomp.h"
54 #ifdef SAL_W32
55 #include <conio.h>
56 #endif
58 /*********
60 ********/
64 class MyThread :
65 public Thread
67 public:
68 MyThread( const Reference< XAcceptor > &r ,
69 const Reference< XBridgeFactory > &rFactory,
70 const Reference< XMultiServiceFactory > &rSMgr,
71 const OUString &sConnectionDescription,
72 const OUString &sProtocol,
73 sal_Bool bReverse,
74 sal_Bool bLatency ) :
75 m_rAcceptor( r ),
76 m_rBridgeFactory ( rFactory ),
77 m_rSMgr( rSMgr ),
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 );
87 private:
88 Reference < XAcceptor > m_rAcceptor;
89 Reference < XBridgeFactory > m_rBridgeFactory;
90 Reference < XMultiServiceFactory > m_rSMgr;
91 OUString m_sConnectionDescription;
92 OUString m_sProtocol;
93 sal_Bool m_bReverse;
94 sal_Bool m_bLatency;
98 void MyThread::latencyTest( const Reference< XConnection > &r )
100 Sequence < sal_Int8 > s;
101 while( 12 == r->read( s , 12 ) )
103 r->read( s , 188 );
104 s = Sequence < sal_Int8 >(60);
105 r->write( s );
109 void MyThread::run()
112 while ( true )
116 Reference < XConnection > rConnection =
117 m_rAcceptor->accept( m_sConnectionDescription );
119 if( ! rConnection.is() )
121 break;
123 if( m_bLatency )
125 latencyTest( rConnection );
127 else
130 Reference < XBridge > rBridge =
131 m_rBridgeFactory->createBridge(
132 OUString() ,
133 m_sProtocol,
134 rConnection ,
135 (XInstanceProvider * ) new OInstanceProvider(m_rSMgr) );
138 if( m_bReverse )
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 ++ )
148 rCallMe->callOneway(
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() );
162 break;
164 catch ( ... )
166 printf( "Exception was thrown by acceptor thread\n" );
167 break;
173 int main( int argc, char *argv[] )
175 // testserver();
177 if( argc < 2 )
179 printf( "usage : testserver [-r] connectionstring\n"
180 " -r does a reverse test (server calls client)\n" );
181 return 0;
184 OUString sConnectionString;
185 OUString sProtocol;
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 ),
198 rSMgr ),
199 UNO_QUERY );
202 createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
203 OUString( "remotebridge.uno" SAL_DLLEXTENSION),
204 rSMgr );
207 Reference < XAcceptor > rAcceptor(
208 createComponent( OUString("com.sun.star.connection.Acceptor"),
209 OUString( "acceptor.uno" SAL_DLLEXTENSION),
210 rSMgr ) ,
211 UNO_QUERY );
213 MyThread thread( rAcceptor ,
214 rBridgeFactory,
215 rSMgr,
216 sConnectionString,
217 sProtocol,
218 bReverse,
219 bLatency);
220 thread.create();
222 #ifdef SAL_W32
223 _getch();
224 #elif SOLARIS
225 getchar();
226 #elif LINUX
227 TimeValue value={360,0};
228 osl_waitThread( &value );
229 #endif
230 printf( "Closing...\n" );
232 rAcceptor->stopAccepting();
233 thread.join();
235 printf( "Closed\n" );
237 Reference < XComponent > rComp2( rBridgeFactory , UNO_QUERY );
238 rComp2->dispose();
239 Reference < XComponent > rComp( rSMgr, UNO_QUERY );
240 rComp->dispose();
242 return 0;
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */