2000-09-18 09:29:57 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* $RCSfile: testserver.cxx,v $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-01-29 07:41:28 -06:00
|
|
|
* $Revision: 1.13 $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-01-29 07:41:28 -06:00
|
|
|
* last change: $Author: rt $ $Date: 2008-01-29 14:41:28 $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2005-09-07 16:52:59 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 10:03:57 -05:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_bridges.hxx"
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-03-14 02:31:19 -06:00
|
|
|
#ifndef _OSL_TIME_H_
|
|
|
|
#include <osl/time.h>
|
|
|
|
#endif
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <osl/mutex.hxx>
|
|
|
|
#include <osl/conditn.h>
|
|
|
|
|
2001-03-16 02:42:20 -06:00
|
|
|
#include <osl/thread.hxx>
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
#include <cppuhelper/servicefactory.hxx>
|
|
|
|
#include <cppuhelper/implbase1.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/connection/XAcceptor.hpp>
|
|
|
|
#include <com/sun/star/connection/XConnection.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/bridge/XInstanceProvider.hpp>
|
|
|
|
#include <com/sun/star/bridge/XBridgeFactory.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include <test/XTestFactory.hpp>
|
|
|
|
|
|
|
|
#include <cppuhelper/weak.hxx>
|
|
|
|
|
|
|
|
using namespace ::test;
|
|
|
|
using namespace ::rtl;
|
2001-03-16 02:42:20 -06:00
|
|
|
using namespace ::osl;
|
2000-09-18 09:29:57 -05:00
|
|
|
using namespace ::cppu;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::bridge;
|
|
|
|
using namespace ::com::sun::star::connection;
|
|
|
|
#include "testcomp.h"
|
|
|
|
#ifdef SAL_W32
|
|
|
|
#include <conio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********
|
|
|
|
*
|
|
|
|
********/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyThread :
|
2001-03-16 02:42:20 -06:00
|
|
|
public Thread
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyThread( const Reference< XAcceptor > &r ,
|
|
|
|
const Reference< XBridgeFactory > &rFactory,
|
|
|
|
const Reference< XMultiServiceFactory > &rSMgr,
|
|
|
|
const OUString &sConnectionDescription,
|
|
|
|
const OUString &sProtocol,
|
|
|
|
sal_Bool bReverse,
|
|
|
|
sal_Bool bLatency ) :
|
|
|
|
m_rAcceptor( r ),
|
|
|
|
m_rBridgeFactory ( rFactory ),
|
2008-01-29 07:41:28 -06:00
|
|
|
m_rSMgr( rSMgr ),
|
2000-09-18 09:29:57 -05:00
|
|
|
m_sConnectionDescription( sConnectionDescription ),
|
|
|
|
m_sProtocol( sProtocol ),
|
|
|
|
m_bReverse( bReverse ),
|
2008-01-29 07:41:28 -06:00
|
|
|
m_bLatency( bLatency )
|
2000-09-18 09:29:57 -05:00
|
|
|
{}
|
|
|
|
virtual void SAL_CALL run();
|
|
|
|
|
|
|
|
void latencyTest( const Reference< XConnection > &r );
|
|
|
|
|
|
|
|
private:
|
|
|
|
Reference < XAcceptor > m_rAcceptor;
|
|
|
|
Reference < XBridgeFactory > m_rBridgeFactory;
|
|
|
|
Reference < XMultiServiceFactory > m_rSMgr;
|
|
|
|
OUString m_sConnectionDescription;
|
|
|
|
OUString m_sProtocol;
|
|
|
|
sal_Bool m_bReverse;
|
|
|
|
sal_Bool m_bLatency;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void MyThread::latencyTest( const Reference< XConnection > &r )
|
|
|
|
{
|
|
|
|
Sequence < sal_Int8 > s;
|
|
|
|
while( 12 == r->read( s , 12 ) )
|
|
|
|
{
|
|
|
|
r->read( s , 188 );
|
|
|
|
s = Sequence < sal_Int8 >(60);
|
|
|
|
r->write( s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyThread::run()
|
|
|
|
{
|
|
|
|
|
|
|
|
while ( sal_True )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference < XConnection > rConnection =
|
|
|
|
m_rAcceptor->accept( m_sConnectionDescription );
|
|
|
|
|
|
|
|
if( ! rConnection.is() )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( m_bLatency )
|
|
|
|
{
|
|
|
|
latencyTest( rConnection );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
Reference < XBridge > rBridge =
|
|
|
|
m_rBridgeFactory->createBridge(
|
|
|
|
OUString() ,
|
|
|
|
m_sProtocol,
|
|
|
|
rConnection ,
|
|
|
|
(XInstanceProvider * ) new OInstanceProvider(m_rSMgr) );
|
|
|
|
|
|
|
|
|
|
|
|
if( m_bReverse )
|
|
|
|
{
|
|
|
|
printf( "doing reverse callme test (test is ok, when on each line a +- appears\n" );
|
|
|
|
Reference < XInterface > r = rBridge->getInstance(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("blubber" )));
|
|
|
|
Reference < XTestFactory > rFactory( r , UNO_QUERY );
|
|
|
|
Reference < XCallMe > rCallMe = rFactory->createCallMe();
|
|
|
|
|
|
|
|
for( sal_Int32 i = 0 ; i < 1 ; i ++ )
|
|
|
|
{
|
|
|
|
rCallMe->callOneway(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("my test string")) , 2 );
|
|
|
|
}
|
|
|
|
printf( "all oneway are send\n" );
|
|
|
|
rCallMe->call( OUString::createFromAscii( "reverse call me test finished" ) , 0 );
|
|
|
|
printf( "revers callme test finished\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( Exception & e )
|
|
|
|
{
|
|
|
|
printf( "Exception was thrown by acceptor \n" );
|
|
|
|
OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
|
|
|
|
printf( "%s\n" , o.getStr() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
|
|
|
printf( "Exception was thrown by acceptor thread\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-18 04:09:22 -05:00
|
|
|
int main( int argc, char *argv[] )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
// testserver();
|
|
|
|
|
|
|
|
if( argc < 2 )
|
|
|
|
{
|
|
|
|
printf( "usage : testserver [-r] connectionstring\n"
|
|
|
|
" -r does a reverse test (server calls client)\n" );
|
2003-03-18 12:07:19 -06:00
|
|
|
return 0;
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString sConnectionString;
|
|
|
|
OUString sProtocol;
|
|
|
|
sal_Bool bReverse = sal_False;
|
|
|
|
sal_Bool bLatency = sal_False;
|
|
|
|
|
|
|
|
parseCommandLine( argv , &sConnectionString , &sProtocol , &bLatency , &bReverse );
|
|
|
|
|
|
|
|
{
|
|
|
|
Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM( "server.rdb" ) ) );
|
|
|
|
|
|
|
|
Reference < XBridgeFactory > rBridgeFactory ( createComponent(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
|
2003-04-23 10:33:18 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION )),
|
2000-09-18 09:29:57 -05:00
|
|
|
rSMgr ),
|
|
|
|
UNO_QUERY );
|
|
|
|
|
|
|
|
|
|
|
|
createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
|
2003-04-23 10:33:18 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION)),
|
2000-09-18 09:29:57 -05:00
|
|
|
rSMgr );
|
|
|
|
|
|
|
|
|
|
|
|
Reference < XAcceptor > rAcceptor(
|
|
|
|
createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")),
|
2003-04-23 10:33:18 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION)),
|
2000-09-18 09:29:57 -05:00
|
|
|
rSMgr ) ,
|
|
|
|
UNO_QUERY );
|
|
|
|
|
|
|
|
MyThread thread( rAcceptor ,
|
|
|
|
rBridgeFactory,
|
|
|
|
rSMgr,
|
|
|
|
sConnectionString,
|
|
|
|
sProtocol,
|
|
|
|
bReverse,
|
|
|
|
bLatency);
|
|
|
|
thread.create();
|
|
|
|
|
|
|
|
#ifdef SAL_W32
|
|
|
|
_getch();
|
|
|
|
#elif SOLARIS
|
|
|
|
getchar();
|
|
|
|
#elif LINUX
|
|
|
|
TimeValue value={360,0};
|
|
|
|
osl_waitThread( &value );
|
|
|
|
#endif
|
|
|
|
printf( "Closing...\n" );
|
|
|
|
|
|
|
|
rAcceptor->stopAccepting();
|
|
|
|
thread.join();
|
|
|
|
|
|
|
|
printf( "Closed\n" );
|
|
|
|
|
|
|
|
Reference < XComponent > rComp2( rBridgeFactory , UNO_QUERY );
|
|
|
|
rComp2->dispose();
|
|
|
|
Reference < XComponent > rComp( rSMgr, UNO_QUERY );
|
|
|
|
rComp->dispose();
|
|
|
|
}
|
2002-04-18 04:09:22 -05:00
|
|
|
return 0;
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|