1*61dff127SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*61dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*61dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*61dff127SAndrew Rist * distributed with this work for additional information 6*61dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*61dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*61dff127SAndrew Rist * "License"); you may not use this file except in compliance 9*61dff127SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*61dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*61dff127SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*61dff127SAndrew Rist * software distributed under the License is distributed on an 15*61dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*61dff127SAndrew Rist * KIND, either express or implied. See the License for the 17*61dff127SAndrew Rist * specific language governing permissions and limitations 18*61dff127SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*61dff127SAndrew Rist *************************************************************/ 21*61dff127SAndrew Rist 22*61dff127SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_bridges.hxx" 26cdf0e10cSrcweir #include <string.h> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <osl/time.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <osl/mutex.hxx> 31cdf0e10cSrcweir #include <osl/module.h> 32cdf0e10cSrcweir #include <osl/thread.h> 33cdf0e10cSrcweir #include <osl/conditn.h> 34cdf0e10cSrcweir #include <osl/diagnose.h> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <uno/mapping.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <com/sun/star/connection/XConnector.hpp> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeFactory.hpp> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 45cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 46cdf0e10cSrcweir #include <com/sun/star/lang/XMain.hpp> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include <com/sun/star/test/performance/XPerformanceTest.hpp> 49cdf0e10cSrcweir 50cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 51cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 52cdf0e10cSrcweir 53cdf0e10cSrcweir #include <test/XTestFactory.hpp> 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir using namespace ::test; 57cdf0e10cSrcweir using namespace ::rtl; 58cdf0e10cSrcweir using namespace ::cppu; 59cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60cdf0e10cSrcweir using namespace ::com::sun::star::lang; 61cdf0e10cSrcweir using namespace ::com::sun::star::bridge; 62cdf0e10cSrcweir using namespace ::com::sun::star::registry; 63cdf0e10cSrcweir using namespace ::com::sun::star::connection; 64cdf0e10cSrcweir using namespace ::com::sun::star::test::performance; 65cdf0e10cSrcweir 66cdf0e10cSrcweir #include "testcomp.h" 67cdf0e10cSrcweir 68cdf0e10cSrcweir 69cdf0e10cSrcweir void doPerformanceTest( const Reference < XPerformanceTest > & /* xBench */) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir printf( "not implemented\n" ); 72cdf0e10cSrcweir // sal_Int32 i,nLoop = 2000; 73cdf0e10cSrcweir // sal_Int32 tStart, tEnd , tEnd2; 74cdf0e10cSrcweir // //------------------------------------ 75cdf0e10cSrcweir // // oneway calls 76cdf0e10cSrcweir // i = nLoop; 77cdf0e10cSrcweir // tStart = GetTickCount(); 78cdf0e10cSrcweir // while (i--) 79cdf0e10cSrcweir // xBench->async(); 80cdf0e10cSrcweir // tEnd = GetTickCount(); 81cdf0e10cSrcweir // xBench->sync(); 82cdf0e10cSrcweir // tEnd2 = GetTickCount(); 83cdf0e10cSrcweir // printf( "%d %d %d\n" , nLoop, tEnd - tStart , tEnd2 -tStart ); 84cdf0e10cSrcweir // // synchron calls 85cdf0e10cSrcweir // i = nLoop; 86cdf0e10cSrcweir // tStart = GetTickCount(); 87cdf0e10cSrcweir // while (i--) 88cdf0e10cSrcweir // xBench->sync(); 89cdf0e10cSrcweir // tEnd = GetTickCount(); 90cdf0e10cSrcweir // printf( "%d %d \n" , nLoop, tEnd - tStart ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir void testLatency( const Reference < XConnection > &r , sal_Bool /* bReply */) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir sal_Int32 nLoop = 10000; 97cdf0e10cSrcweir TimeValue aStartTime, aEndTime; 98cdf0e10cSrcweir osl_getSystemTime( &aStartTime ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir sal_Int32 i; 101cdf0e10cSrcweir for( i = 0 ; i < nLoop ; i++ ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir Sequence< sal_Int8 > s1( 200 ); 104cdf0e10cSrcweir r->write( s1 ); 105cdf0e10cSrcweir r->read( s1 , 12 ); 106cdf0e10cSrcweir r->read( s1 , 48 ); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir osl_getSystemTime( &aEndTime ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir double fStart = (double)aStartTime.Seconds + ((double)aStartTime.Nanosec / 1000000000.0); 111cdf0e10cSrcweir double fEnd = (double)aEndTime.Seconds + ((double)aEndTime.Nanosec / 1000000000.0); 112cdf0e10cSrcweir 113cdf0e10cSrcweir printf( "System latency per call : %g\n" , (( fEnd-fStart )/2.) / ((double)(nLoop)) ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir int main( int argc, char *argv[] ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir if( argc < 2 ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir printf( 121cdf0e10cSrcweir "usage : testclient [-r] connectionstring\n" 122cdf0e10cSrcweir " -r reverse call me test (server calls client)" 123cdf0e10cSrcweir ); 124cdf0e10cSrcweir return 0; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir OUString sConnectionString; 128cdf0e10cSrcweir OUString sProtocol; 129cdf0e10cSrcweir sal_Bool bLatency = sal_False; 130cdf0e10cSrcweir sal_Bool bReverse = sal_False; 131cdf0e10cSrcweir 132cdf0e10cSrcweir parseCommandLine( argv , &sConnectionString , &sProtocol , &bLatency , &bReverse ); 133cdf0e10cSrcweir 134cdf0e10cSrcweir { 135cdf0e10cSrcweir Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory( 136cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("client.rdb")) ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir Reference < XConnector > rConnector( 140cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")), 141cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)), 142cdf0e10cSrcweir rSMgr ), 143cdf0e10cSrcweir UNO_QUERY ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir 146cdf0e10cSrcweir try 147cdf0e10cSrcweir { 148cdf0e10cSrcweir Reference < XConnection > rConnection = 149cdf0e10cSrcweir rConnector->connect( sConnectionString ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir printf( "%s\n" , OUStringToOString( rConnection->getDescription(), 152cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir 155cdf0e10cSrcweir if( bLatency ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir testLatency( rConnection , sal_False ); 158cdf0e10cSrcweir testLatency( rConnection , sal_True ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir else 161cdf0e10cSrcweir { 162cdf0e10cSrcweir // just ensure that it is registered 163cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")), 164cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION)), 165cdf0e10cSrcweir rSMgr ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir Reference < XBridgeFactory > rFactory( 168cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")), 169cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)), 170cdf0e10cSrcweir rSMgr ), 171cdf0e10cSrcweir UNO_QUERY ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir if( rFactory.is() ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir 176cdf0e10cSrcweir Reference < XBridge > rBridge = rFactory->createBridge( 177cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")), 178cdf0e10cSrcweir sProtocol, 179cdf0e10cSrcweir rConnection, 180cdf0e10cSrcweir new OInstanceProvider ); 181cdf0e10cSrcweir { 182cdf0e10cSrcweir // test the factory 183cdf0e10cSrcweir Reference < XBridge > rBridge2 = rFactory->getBridge( OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) ); 184cdf0e10cSrcweir OSL_ASSERT( rBridge2.is() ); 185cdf0e10cSrcweir OSL_ASSERT( rBridge2->getDescription() == rBridge->getDescription( ) ); 186cdf0e10cSrcweir OSL_ASSERT( rBridge2->getName() == rBridge->getName() ); 187cdf0e10cSrcweir OSL_ASSERT( rBridge2 == rBridge ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir 191cdf0e10cSrcweir Reference < XInterface > rInitialObject = rBridge->getInstance( 192cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bridges-testobject")) ); 193cdf0e10cSrcweir 194cdf0e10cSrcweir if( rInitialObject.is() ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir printf( "got the remote object\n" ); 197cdf0e10cSrcweir if( ! bReverse ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir // Reference < XComponent > rPerfTest( rInitialObject , UNO_QUERY ); 200cdf0e10cSrcweir // if( rPerfTest.is() ) 201cdf0e10cSrcweir // { 202cdf0e10cSrcweir // // doPerformanceTest( rPerfTest ); 203cdf0e10cSrcweir // } 204cdf0e10cSrcweir // else 205cdf0e10cSrcweir // { 206cdf0e10cSrcweir testRemote( rInitialObject ); 207cdf0e10cSrcweir // } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir } 210cdf0e10cSrcweir // Reference < XComponent > rComp( rBridge , UNO_QUERY ); 211cdf0e10cSrcweir // rComp->dispose(); 212cdf0e10cSrcweir 213cdf0e10cSrcweir rInitialObject = Reference < XInterface > (); 214cdf0e10cSrcweir printf( "Waiting...\n" ); 215cdf0e10cSrcweir TimeValue value={bReverse ?1000 :2,0}; 216cdf0e10cSrcweir osl_waitThread( &value ); 217cdf0e10cSrcweir printf( "Closing...\n" ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir Reference < XBridge > rBridge = rFactory->getBridge( OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) ); 221cdf0e10cSrcweir // OSL_ASSERT( ! rBridge.is() ); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir } 225cdf0e10cSrcweir catch( DisposedException & e ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ); 228cdf0e10cSrcweir printf( "A remote object reference became invalid\n%s\n" , o.pData->buffer ); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir catch( Exception &e ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir OString o = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ); 233cdf0e10cSrcweir printf( "Login failed, got an Exception !\n%s\n" , o.pData->buffer ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir 237cdf0e10cSrcweir Reference < XComponent > rComp( rSMgr , UNO_QUERY ); 238cdf0e10cSrcweir rComp->dispose(); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir printf( "Closed\n" ); 241cdf0e10cSrcweir return 0; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244