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