1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_bridges.hxx" 30*cdf0e10cSrcweir #include <osl/time.h> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <osl/mutex.hxx> 33*cdf0e10cSrcweir #include <osl/thread.h> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <com/sun/star/connection/XConnector.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeFactory.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <com/sun/star/text/XTextDocument.hpp> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <test/XTestFactory.hpp> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir using namespace ::test; 58*cdf0e10cSrcweir using namespace ::rtl; 59*cdf0e10cSrcweir using namespace ::cppu; 60*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 61*cdf0e10cSrcweir using namespace ::com::sun::star::io; 62*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 63*cdf0e10cSrcweir using namespace ::com::sun::star::bridge; 64*cdf0e10cSrcweir using namespace ::com::sun::star::registry; 65*cdf0e10cSrcweir using namespace ::com::sun::star::connection; 66*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 67*cdf0e10cSrcweir using namespace ::com::sun::star::text; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #include "testcomp.h" 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir #ifdef SAL_W32 72*cdf0e10cSrcweir #include <conio.h> 73*cdf0e10cSrcweir #endif 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void mygetchar() 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir #ifdef SAL_W32 79*cdf0e10cSrcweir _getch(); 80*cdf0e10cSrcweir #else 81*cdf0e10cSrcweir getchar(); 82*cdf0e10cSrcweir #endif 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir void testPipe( const Reference < XMultiServiceFactory > & rSmgr ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir Reference < XOutputStream > rOut( 89*cdf0e10cSrcweir rSmgr->createInstance( OUString::createFromAscii( "com.sun.star.io.Pipe" ) ), 90*cdf0e10cSrcweir UNO_QUERY ); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir OSL_ASSERT( rOut.is() ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir Sequence < sal_Int8 > seq( 10 ); 96*cdf0e10cSrcweir seq.getArray()[0] = 42; 97*cdf0e10cSrcweir rOut->writeBytes( seq ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir Sequence < sal_Int8 > seq; 103*cdf0e10cSrcweir Reference < XInputStream > rIn( rOut , UNO_QUERY ); 104*cdf0e10cSrcweir if( ! ( rIn->available() == 10) ) 105*cdf0e10cSrcweir printf( "wrong bytes available\n" ); 106*cdf0e10cSrcweir if( ! ( rIn->readBytes( seq , 10 ) == 10 ) ) 107*cdf0e10cSrcweir printf( "wrong bytes read\n" ); 108*cdf0e10cSrcweir if( ! ( 42 == seq.getArray()[0] ) ) 109*cdf0e10cSrcweir printf( "wrong element in sequence\n" ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // OSL_ASSERT( 0 ); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir #include<stdio.h> 115*cdf0e10cSrcweir #include<string.h> 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void testWriter( const Reference < XComponent > & rCmp ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir Reference< XTextDocument > rTextDoc( rCmp , UNO_QUERY ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir Reference< XText > rText = rTextDoc->getText(); 123*cdf0e10cSrcweir Reference< XTextCursor > rCursor = rText->createTextCursor(); 124*cdf0e10cSrcweir Reference< XTextRange > rRange ( rCursor , UNO_QUERY ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir char pcText[1024]; 127*cdf0e10cSrcweir pcText[0] = 0; 128*cdf0e10cSrcweir printf( "pleast type any text\n" ); 129*cdf0e10cSrcweir while( sal_True ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir scanf( "%s" , pcText ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if( !strcmp( pcText , "end" ) ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir break; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if ( strlen( pcText ) < sizeof(pcText)-1 ) 139*cdf0e10cSrcweir strcat( pcText , " " ); // #100211# - checked 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir rText->insertString( rRange , OUString::createFromAscii( pcText ) , sal_False ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir void testDocument( const Reference < XMultiServiceFactory > & rSmgr ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir Reference < XComponentLoader > rLoader( 148*cdf0e10cSrcweir rSmgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop" ))), 149*cdf0e10cSrcweir UNO_QUERY ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir OSL_ASSERT( rLoader.is() ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir sal_Char *urls[] = { 154*cdf0e10cSrcweir "private:factory/swriter", 155*cdf0e10cSrcweir "private:factory/scalc", 156*cdf0e10cSrcweir "private:factory/sdraw", 157*cdf0e10cSrcweir "http://www.heise.de", 158*cdf0e10cSrcweir "file://h|/remote_interfaces.sdw" 159*cdf0e10cSrcweir }; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir sal_Char *docu[]= { 162*cdf0e10cSrcweir "a new writer document ...\n", 163*cdf0e10cSrcweir "a new calc document ...\n", 164*cdf0e10cSrcweir "a new draw document ...\n", 165*cdf0e10cSrcweir "www.heise.de\n", 166*cdf0e10cSrcweir "the remote_interfaces.sdw doc\n" 167*cdf0e10cSrcweir }; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir sal_Int32 i; 170*cdf0e10cSrcweir for( i = 0 ; i < 1 ; i ++ ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir printf( "press any key to open %s\n" , docu[i] ); 173*cdf0e10cSrcweir mygetchar(); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir Reference< XComponent > rComponent = 176*cdf0e10cSrcweir rLoader->loadComponentFromURL( 177*cdf0e10cSrcweir OUString::createFromAscii( urls[i] ) , 178*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("_blank")), 179*cdf0e10cSrcweir 0 , 180*cdf0e10cSrcweir Sequence < ::com::sun::star::beans::PropertyValue >() ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir testWriter( rComponent ); 183*cdf0e10cSrcweir printf( "press any key to close the document\n" ); 184*cdf0e10cSrcweir mygetchar(); 185*cdf0e10cSrcweir rComponent->dispose(); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir void doSomething( const Reference < XInterface > &r ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir Reference < XNamingService > rName( r, UNO_QUERY ); 193*cdf0e10cSrcweir if( rName.is() ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir printf( "got the remote naming service !\n" ); 196*cdf0e10cSrcweir Reference < XInterface > rXsmgr = rName->getRegisteredObject( 197*cdf0e10cSrcweir OUString::createFromAscii( "StarOffice.ServiceManager" ) ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir Reference < XMultiServiceFactory > rSmgr( rXsmgr , UNO_QUERY ); 200*cdf0e10cSrcweir if( rSmgr.is() ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir printf( "got the remote service manager !\n" ); 203*cdf0e10cSrcweir testPipe( rSmgr ); 204*cdf0e10cSrcweir testDocument( rSmgr ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir int main( int argc, char *argv[] ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir if( argc < 2 ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir printf( "usage : testclient host:port" ); 215*cdf0e10cSrcweir return 0; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir OUString sConnectionString; 219*cdf0e10cSrcweir OUString sProtocol; 220*cdf0e10cSrcweir sal_Bool bLatency = sal_False; 221*cdf0e10cSrcweir sal_Bool bReverse = sal_False; 222*cdf0e10cSrcweir parseCommandLine( argv , &sConnectionString , &sProtocol , &bLatency , &bReverse ); 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory( 225*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) ); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // just ensure that it is registered 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir Reference < XConnector > rConnector( 230*cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")), 231*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)), 232*cdf0e10cSrcweir rSMgr ), 233*cdf0e10cSrcweir UNO_QUERY ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")), 236*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("remotebridge.uno" SAL_DLLEXTENSION)), 237*cdf0e10cSrcweir rSMgr ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir Reference < XBridgeFactory > rFactory( 240*cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")), 241*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)), 242*cdf0e10cSrcweir rSMgr ), 243*cdf0e10cSrcweir UNO_QUERY ); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir try 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir if( rFactory.is() && rConnector.is() ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir Reference < XConnection > rConnection = 250*cdf0e10cSrcweir rConnector->connect( sConnectionString ); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir Reference < XBridge > rBridge = rFactory->createBridge( 253*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")), 254*cdf0e10cSrcweir sProtocol, 255*cdf0e10cSrcweir rConnection, 256*cdf0e10cSrcweir Reference < XInstanceProvider > () ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir Reference < XInterface > rInitialObject 259*cdf0e10cSrcweir = rBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("NamingService")) ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if( rInitialObject.is() ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir printf( "got the remote object\n" ); 264*cdf0e10cSrcweir doSomething( rInitialObject ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir TimeValue value={2,0}; 267*cdf0e10cSrcweir osl_waitThread( &value ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir catch (... ) { 271*cdf0e10cSrcweir printf( "Exception thrown\n" ); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir Reference < XComponent > rComp( rSMgr , UNO_QUERY ); 275*cdf0e10cSrcweir rComp->dispose(); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir //_getch(); 278*cdf0e10cSrcweir return 0; 279*cdf0e10cSrcweir } 280