2000-09-18 09:29:57 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* $RCSfile: testsameprocess.cxx,v $
|
|
|
|
* $Revision: 1.13 $
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
2008-04-11 05:23:35 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 09:29:57 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 10:03:43 -05:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_bridges.hxx"
|
2003-04-15 10:29:58 -05:00
|
|
|
#if OSL_DEBUG_LEVEL == 0
|
2008-01-29 07:41:15 -06:00
|
|
|
#undef NDEBUG
|
2003-04-15 10:29:58 -05:00
|
|
|
#define NDEBUG
|
|
|
|
#endif
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <assert.h>
|
2001-03-14 02:31:19 -06:00
|
|
|
#include <osl/time.h>
|
|
|
|
|
2000-09-18 09:29:57 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2001-03-16 02:42:20 -06:00
|
|
|
#include <osl/thread.hxx>
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
#include <cppuhelper/servicefactory.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/bridge/XBridgeFactory.hpp>
|
|
|
|
#include <com/sun/star/connection/XAcceptor.hpp>
|
|
|
|
#include <com/sun/star/connection/XConnector.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
|
|
|
|
#include <cppuhelper/weak.hxx>
|
|
|
|
|
|
|
|
#include <test/XTestFactory.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ::test;
|
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::cppu;
|
2001-03-16 02:42:20 -06:00
|
|
|
using namespace ::osl;
|
2000-09-18 09:29:57 -05:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::bridge;
|
|
|
|
using namespace ::com::sun::star::connection;
|
|
|
|
|
|
|
|
#ifdef SAL_W32
|
|
|
|
#include <conio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "testcomp.h"
|
|
|
|
#include "osl/mutex.h"
|
|
|
|
|
|
|
|
/*********
|
|
|
|
*
|
|
|
|
********/
|
|
|
|
|
|
|
|
class MyThread :
|
2001-03-16 02:42:20 -06:00
|
|
|
public Thread
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyThread( const Reference< XAcceptor > &r ,
|
|
|
|
const Reference< XBridgeFactory > &rFactory,
|
|
|
|
const OUString &sConnectionDescription) :
|
|
|
|
m_rAcceptor( r ),
|
|
|
|
m_rBridgeFactory ( rFactory ),
|
|
|
|
m_sConnectionDescription( sConnectionDescription )
|
|
|
|
{}
|
|
|
|
virtual void SAL_CALL run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Reference < XAcceptor > m_rAcceptor;
|
|
|
|
Reference < XBridgeFactory > m_rBridgeFactory;
|
|
|
|
OUString m_sConnectionDescription;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MyThread::run()
|
|
|
|
{
|
|
|
|
|
|
|
|
while ( sal_True )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference < XConnection > rConnection =
|
|
|
|
m_rAcceptor->accept( m_sConnectionDescription );
|
|
|
|
|
|
|
|
if( ! rConnection.is() )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference < XBridge > rBridge =
|
|
|
|
m_rBridgeFactory->createBridge(
|
|
|
|
OUString() ,
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")) ,
|
|
|
|
rConnection ,
|
|
|
|
(XInstanceProvider * ) new OInstanceProvider );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
|
|
|
printf( "Exception was thrown by acceptor thread\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-18 04:09:22 -05:00
|
|
|
int main( int argc, char *argv[] )
|
2000-09-18 09:29:57 -05:00
|
|
|
{
|
|
|
|
if( argc < 2 )
|
|
|
|
{
|
|
|
|
printf( "usage : testsamprocess host:port\n" );
|
2003-03-18 12:07:19 -06:00
|
|
|
return 0;
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Reference< XMultiServiceFactory > rSMgr = createRegistryServiceFactory(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM( "client.rdb" ) ) );
|
|
|
|
|
|
|
|
Reference < XConnector > rConnector(
|
|
|
|
createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector")),
|
2003-04-23 10:45:38 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("connector.uno" SAL_DLLEXTENSION)),
|
2000-09-18 09:29:57 -05:00
|
|
|
rSMgr ),
|
|
|
|
UNO_QUERY );
|
|
|
|
|
|
|
|
Reference < XAcceptor > rAcceptor(
|
|
|
|
createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor")),
|
2003-04-23 10:45:38 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("acceptor.uno" SAL_DLLEXTENSION)),
|
2000-09-18 09:29:57 -05:00
|
|
|
rSMgr ),
|
|
|
|
UNO_QUERY );
|
|
|
|
|
|
|
|
// just ensure that it is registered
|
2003-04-23 10:45:38 -05:00
|
|
|
// createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.Bridge.iiop")),
|
|
|
|
// OUString( RTL_CONSTASCII_USTRINGPARAM("iiopbrdg" SAL_DLLEXTENSION)),
|
|
|
|
// rSMgr );
|
2000-09-18 09:29:57 -05:00
|
|
|
|
|
|
|
Reference < XBridgeFactory > rFactory(
|
|
|
|
createComponent( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory")),
|
2003-04-23 10:45:38 -05:00
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("bridgefac.uno" SAL_DLLEXTENSION)),
|
2000-09-18 09:29:57 -05:00
|
|
|
rSMgr ),
|
|
|
|
UNO_QUERY );
|
|
|
|
|
|
|
|
|
|
|
|
MyThread threadAcceptor( rAcceptor , rFactory , OUString::createFromAscii( argv[1] ) );
|
|
|
|
|
|
|
|
threadAcceptor.create();
|
|
|
|
TimeValue value={2,0};
|
|
|
|
osl_waitThread( &value );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference < XConnection > rConnection =
|
|
|
|
rConnector->connect( OUString::createFromAscii( argv[1] ) );
|
|
|
|
|
|
|
|
printf( "%s\n" , OUStringToOString( rConnection->getDescription(),
|
|
|
|
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
|
|
|
|
|
|
|
|
if( rFactory.is() )
|
|
|
|
{
|
|
|
|
|
|
|
|
Reference < XBridge > rBridge = rFactory->createBridge(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")),
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("iiop")),
|
|
|
|
rConnection,
|
|
|
|
Reference < XInstanceProvider > () );
|
|
|
|
|
|
|
|
Reference < XInterface > rInitialObject
|
|
|
|
= rBridge->getInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("bla")) );
|
|
|
|
|
|
|
|
if( rInitialObject.is() )
|
|
|
|
{
|
|
|
|
printf( "got the remote object\n" );
|
|
|
|
testRemote( rInitialObject );
|
|
|
|
}
|
|
|
|
printf( "Closing...\n" );
|
2008-01-29 07:41:15 -06:00
|
|
|
TimeValue timeValue={2,0};
|
|
|
|
osl_waitThread( &timeValue );
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Reference < XBridge > rBridge = rFactory->getBridge(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM("bla blub")) );
|
|
|
|
assert( ! rBridge.is() );
|
|
|
|
|
|
|
|
}
|
|
|
|
catch( Exception & )
|
|
|
|
{
|
|
|
|
printf( "Login failed, got an Exception !\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
rAcceptor->stopAccepting();
|
|
|
|
threadAcceptor.join();
|
|
|
|
|
|
|
|
Reference < XComponent > rComp( rFactory , UNO_QUERY );
|
|
|
|
rComp->dispose();
|
|
|
|
|
|
|
|
|
|
|
|
rComp = Reference < XComponent > ( rSMgr , UNO_QUERY );
|
|
|
|
rComp->dispose();
|
|
|
|
}
|
2002-04-18 04:09:22 -05:00
|
|
|
return 0;
|
2000-09-18 09:29:57 -05:00
|
|
|
}
|