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 <osl/time.h> 31 32 #include <osl/mutex.hxx> 33 #include <osl/thread.hxx> 34 35 #include <cppuhelper/servicefactory.hxx> 36 37 #include <com/sun/star/bridge/XBridgeFactory.hpp> 38 #include <com/sun/star/connection/XAcceptor.hpp> 39 #include <com/sun/star/connection/XConnector.hpp> 40 41 #include <com/sun/star/lang/XComponent.hpp> 42 43 #include <cppuhelper/weak.hxx> 44 45 #include <test/XTestFactory.hpp> 46 47 48 using namespace ::test; 49 using namespace ::rtl; 50 using namespace ::cppu; 51 using namespace ::osl; 52 using namespace ::com::sun::star::uno; 53 using namespace ::com::sun::star::lang; 54 using namespace ::com::sun::star::bridge; 55 using namespace ::com::sun::star::connection; 56 57 #ifdef SAL_W32 58 #include <conio.h> 59 #endif 60 61 #include "testcomp.h" 62 #include "osl/mutex.h" 63 64 /********* 65 * 66 ********/ 67 68 class MyThread : 69 public Thread 70 { 71 public: 72 MyThread( const Reference< XAcceptor > &r , 73 const Reference< XBridgeFactory > &rFactory, 74 const OUString &sConnectionDescription) : 75 m_rAcceptor( r ), 76 m_rBridgeFactory ( rFactory ), 77 m_sConnectionDescription( sConnectionDescription ) 78 {} 79 virtual void SAL_CALL run(); 80 81 private: 82 Reference < XAcceptor > m_rAcceptor; 83 Reference < XBridgeFactory > m_rBridgeFactory; 84 OUString m_sConnectionDescription; 85 }; 86 87 88 89 void MyThread::run() 90 { 91 92 while ( sal_True ) 93 { 94 try 95 { 96 Reference < XConnection > rConnection = 97 m_rAcceptor->accept( m_sConnectionDescription ); 98 99 if( ! rConnection.is() ) 100 { 101 break; 102 } 103 104 Reference < XBridge > rBridge = 105 m_rBridgeFactory->createBridge( 106 OUString() , 107 OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")) , 108 rConnection , 109 (XInstanceProvider * ) new OInstanceProvider ); 110 111 112 } 113 catch ( ... ) 114 { 115 printf( "Exception was thrown by acceptor thread\n" ); 116 break; 117 } 118 } 119 } 120 121 122 int main( int argc, char *argv[] ) 123 { 124 if( argc < 2 ) 125 { 126 printf( "usage : testsamprocess host:port\n" ); 127 return 0; 128 } 129 130 { 131 Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory( 132 OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) ); 133 134 Reference < XConnector > rConnector( 135 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")), 136 OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)), 137 rSMgr ), 138 UNO_QUERY ); 139 140 Reference < XAcceptor > rAcceptor( 141 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")), 142 OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION)), 143 rSMgr ), 144 UNO_QUERY ); 145 146 // just ensure that it is registered 147 // createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")), 148 // OUString( RTL_CONSTASCII_USTRINGPARAM("iiopbrdg" SAL_DLLEXTENSION)), 149 // rSMgr ); 150 151 Reference < XBridgeFactory > rFactory( 152 createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")), 153 OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)), 154 rSMgr ), 155 UNO_QUERY ); 156 157 158 MyThread threadAcceptor( rAcceptor , rFactory , OUString::createFromAscii( argv[1] ) ); 159 160 threadAcceptor.create(); 161 TimeValue value={2,0}; 162 osl_waitThread( &value ); 163 164 try 165 { 166 Reference < XConnection > rConnection = 167 rConnector->connect( OUString::createFromAscii( argv[1] ) ); 168 169 printf( "%s\n" , OUStringToOString( rConnection->getDescription(), 170 RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 171 172 if( rFactory.is() ) 173 { 174 175 Reference < XBridge > rBridge = rFactory->createBridge( 176 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")), 177 OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")), 178 rConnection, 179 Reference < XInstanceProvider > () ); 180 181 Reference < XInterface > rInitialObject 182 = rBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("bla")) ); 183 184 if( rInitialObject.is() ) 185 { 186 printf( "got the remote object\n" ); 187 testRemote( rInitialObject ); 188 } 189 printf( "Closing...\n" ); 190 TimeValue timeValue={2,0}; 191 osl_waitThread( &timeValue ); 192 } 193 194 Reference < XBridge > rBridge = rFactory->getBridge( 195 OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) ); 196 OSL_ASSERT( ! rBridge.is() ); 197 198 } 199 catch( Exception & ) 200 { 201 printf( "Login failed, got an Exception !\n" ); 202 } 203 204 rAcceptor->stopAccepting(); 205 threadAcceptor.join(); 206 207 Reference < XComponent > rComp( rFactory , UNO_QUERY ); 208 rComp->dispose(); 209 210 211 rComp = Reference < XComponent > ( rSMgr , UNO_QUERY ); 212 rComp->dispose(); 213 } 214 return 0; 215 } 216