161dff127SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 361dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 461dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file 561dff127SAndrew Rist * distributed with this work for additional information 661dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file 761dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the 861dff127SAndrew Rist * "License"); you may not use this file except in compliance 961dff127SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1161dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1361dff127SAndrew Rist * Unless required by applicable law or agreed to in writing, 1461dff127SAndrew Rist * software distributed under the License is distributed on an 1561dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1661dff127SAndrew Rist * KIND, either express or implied. See the License for the 1761dff127SAndrew Rist * specific language governing permissions and limitations 1861dff127SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2061dff127SAndrew Rist *************************************************************/ 2161dff127SAndrew Rist 2261dff127SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_bridges.hxx" 26cdf0e10cSrcweir #include <osl/time.h> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include <osl/thread.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeFactory.hpp> 34cdf0e10cSrcweir #include <com/sun/star/connection/XAcceptor.hpp> 35cdf0e10cSrcweir #include <com/sun/star/connection/XConnector.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include <test/XTestFactory.hpp> 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::test; 45cdf0e10cSrcweir using namespace ::rtl; 46cdf0e10cSrcweir using namespace ::cppu; 47cdf0e10cSrcweir using namespace ::osl; 48cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49cdf0e10cSrcweir using namespace ::com::sun::star::lang; 50cdf0e10cSrcweir using namespace ::com::sun::star::bridge; 51cdf0e10cSrcweir using namespace ::com::sun::star::connection; 52cdf0e10cSrcweir 53cdf0e10cSrcweir #ifdef SAL_W32 54cdf0e10cSrcweir #include <conio.h> 55cdf0e10cSrcweir #endif 56cdf0e10cSrcweir 57cdf0e10cSrcweir #include "testcomp.h" 58cdf0e10cSrcweir #include "osl/mutex.h" 59cdf0e10cSrcweir 60cdf0e10cSrcweir /********* 61cdf0e10cSrcweir * 62cdf0e10cSrcweir ********/ 63cdf0e10cSrcweir 64cdf0e10cSrcweir class MyThread : 65cdf0e10cSrcweir public Thread 66cdf0e10cSrcweir { 67cdf0e10cSrcweir public: 68cdf0e10cSrcweir MyThread( const Reference< XAcceptor > &r , 69cdf0e10cSrcweir const Reference< XBridgeFactory > &rFactory, 70cdf0e10cSrcweir const OUString &sConnectionDescription) : 71cdf0e10cSrcweir m_rAcceptor( r ), 72cdf0e10cSrcweir m_rBridgeFactory ( rFactory ), 73cdf0e10cSrcweir m_sConnectionDescription( sConnectionDescription ) 74cdf0e10cSrcweir {} 75cdf0e10cSrcweir virtual void SAL_CALL run(); 76cdf0e10cSrcweir 77cdf0e10cSrcweir private: 78cdf0e10cSrcweir Reference < XAcceptor > m_rAcceptor; 79cdf0e10cSrcweir Reference < XBridgeFactory > m_rBridgeFactory; 80cdf0e10cSrcweir OUString m_sConnectionDescription; 81cdf0e10cSrcweir }; 82cdf0e10cSrcweir 83cdf0e10cSrcweir 84cdf0e10cSrcweir 85cdf0e10cSrcweir void MyThread::run() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir 88cdf0e10cSrcweir while ( sal_True ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir try 91cdf0e10cSrcweir { 92cdf0e10cSrcweir Reference < XConnection > rConnection = 93cdf0e10cSrcweir m_rAcceptor->accept( m_sConnectionDescription ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir if( ! rConnection.is() ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir break; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir Reference < XBridge > rBridge = 101cdf0e10cSrcweir m_rBridgeFactory->createBridge( 102cdf0e10cSrcweir OUString() , 103cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")) , 104cdf0e10cSrcweir rConnection , 105cdf0e10cSrcweir (XInstanceProvider * ) new OInstanceProvider ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir 108cdf0e10cSrcweir } 109cdf0e10cSrcweir catch ( ... ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir printf( "Exception was thrown by acceptor thread\n" ); 112cdf0e10cSrcweir break; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir 118cdf0e10cSrcweir int main( int argc, char *argv[] ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if( argc < 2 ) 121cdf0e10cSrcweir { 122*e405e85bSDamjan Jovanovic printf( "usage : testsameprocess host:port\n" ); 123cdf0e10cSrcweir return 0; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir { 127cdf0e10cSrcweir Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory( 128cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) ); 129cdf0e10cSrcweir 130cdf0e10cSrcweir Reference < XConnector > rConnector( 131cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")), 132cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)), 133cdf0e10cSrcweir rSMgr ), 134cdf0e10cSrcweir UNO_QUERY ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir Reference < XAcceptor > rAcceptor( 137cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")), 138cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION)), 139cdf0e10cSrcweir rSMgr ), 140cdf0e10cSrcweir UNO_QUERY ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir // just ensure that it is registered 143cdf0e10cSrcweir // createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")), 144cdf0e10cSrcweir // OUString( RTL_CONSTASCII_USTRINGPARAM("iiopbrdg" SAL_DLLEXTENSION)), 145cdf0e10cSrcweir // rSMgr ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir Reference < XBridgeFactory > rFactory( 148cdf0e10cSrcweir createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")), 149cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)), 150cdf0e10cSrcweir rSMgr ), 151cdf0e10cSrcweir UNO_QUERY ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir 154cdf0e10cSrcweir MyThread threadAcceptor( rAcceptor , rFactory , OUString::createFromAscii( argv[1] ) ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir threadAcceptor.create(); 157cdf0e10cSrcweir TimeValue value={2,0}; 158cdf0e10cSrcweir osl_waitThread( &value ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir try 161cdf0e10cSrcweir { 162cdf0e10cSrcweir Reference < XConnection > rConnection = 163cdf0e10cSrcweir rConnector->connect( OUString::createFromAscii( argv[1] ) ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir printf( "%s\n" , OUStringToOString( rConnection->getDescription(), 166cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir if( rFactory.is() ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir 171cdf0e10cSrcweir Reference < XBridge > rBridge = rFactory->createBridge( 172cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")), 173cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")), 174cdf0e10cSrcweir rConnection, 175cdf0e10cSrcweir Reference < XInstanceProvider > () ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir Reference < XInterface > rInitialObject 178cdf0e10cSrcweir = rBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("bla")) ); 179cdf0e10cSrcweir 180cdf0e10cSrcweir if( rInitialObject.is() ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir printf( "got the remote object\n" ); 183cdf0e10cSrcweir testRemote( rInitialObject ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir printf( "Closing...\n" ); 186cdf0e10cSrcweir TimeValue timeValue={2,0}; 187cdf0e10cSrcweir osl_waitThread( &timeValue ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir Reference < XBridge > rBridge = rFactory->getBridge( 191cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) ); 192cdf0e10cSrcweir OSL_ASSERT( ! rBridge.is() ); 193cdf0e10cSrcweir 194cdf0e10cSrcweir } 195cdf0e10cSrcweir catch( Exception & ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir printf( "Login failed, got an Exception !\n" ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir rAcceptor->stopAccepting(); 201cdf0e10cSrcweir threadAcceptor.join(); 202cdf0e10cSrcweir 203cdf0e10cSrcweir Reference < XComponent > rComp( rFactory , UNO_QUERY ); 204cdf0e10cSrcweir rComp->dispose(); 205cdf0e10cSrcweir 206cdf0e10cSrcweir 207cdf0e10cSrcweir rComp = Reference < XComponent > ( rSMgr , UNO_QUERY ); 208cdf0e10cSrcweir rComp->dispose(); 209cdf0e10cSrcweir } 210cdf0e10cSrcweir return 0; 211cdf0e10cSrcweir } 212