1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <osl/mutex.hxx>
23 #include <osl/thread.hxx>
25 #include <cppuhelper/servicefactory.hxx>
27 #include <com/sun/star/bridge/XBridgeFactory.hpp>
28 #include <com/sun/star/connection/XAcceptor.hpp>
29 #include <com/sun/star/connection/XConnector.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
33 #include <cppuhelper/weak.hxx>
35 #include <test/XTestFactory.hpp>
38 using namespace ::test
;
39 using namespace ::rtl
;
40 using namespace ::cppu
;
41 using namespace ::osl
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::bridge
;
45 using namespace ::com::sun::star::connection
;
52 #include "osl/mutex.h"
62 MyThread( const Reference
< XAcceptor
> &r
,
63 const Reference
< XBridgeFactory
> &rFactory
,
64 const OUString
&sConnectionDescription
) :
66 m_rBridgeFactory ( rFactory
),
67 m_sConnectionDescription( sConnectionDescription
)
69 virtual void SAL_CALL
run();
72 Reference
< XAcceptor
> m_rAcceptor
;
73 Reference
< XBridgeFactory
> m_rBridgeFactory
;
74 OUString m_sConnectionDescription
;
86 Reference
< XConnection
> rConnection
=
87 m_rAcceptor
->accept( m_sConnectionDescription
);
89 if( ! rConnection
.is() )
94 Reference
< XBridge
> rBridge
=
95 m_rBridgeFactory
->createBridge(
99 (XInstanceProvider
* ) new OInstanceProvider
);
105 printf( "Exception was thrown by acceptor thread\n" );
112 int main( int argc
, char *argv
[] )
116 printf( "usage : testsamprocess host:port\n" );
121 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
122 OUString( "client.rdb" ) );
124 Reference
< XConnector
> rConnector(
125 createComponent( OUString("com.sun.star.connection.Connector"),
126 OUString( "connector.uno" SAL_DLLEXTENSION
),
130 Reference
< XAcceptor
> rAcceptor(
131 createComponent( OUString("com.sun.star.connection.Acceptor"),
132 OUString( "acceptor.uno" SAL_DLLEXTENSION
),
136 // just ensure that it is registered
137 // createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
138 // OUString( "iiopbrdg" SAL_DLLEXTENSION),
141 Reference
< XBridgeFactory
> rFactory(
142 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
143 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
148 MyThread
threadAcceptor( rAcceptor
, rFactory
, OUString::createFromAscii( argv
[1] ) );
150 threadAcceptor
.create();
151 TimeValue value
={2,0};
152 osl_waitThread( &value
);
156 Reference
< XConnection
> rConnection
=
157 rConnector
->connect( OUString::createFromAscii( argv
[1] ) );
159 printf( "%s\n" , OUStringToOString( rConnection
->getDescription(),
160 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
165 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
166 OUString("bla blub"),
169 Reference
< XInstanceProvider
> () );
171 Reference
< XInterface
> rInitialObject
172 = rBridge
->getInstance( OUString("bla") );
174 if( rInitialObject
.is() )
176 printf( "got the remote object\n" );
177 testRemote( rInitialObject
);
179 printf( "Closing...\n" );
180 TimeValue timeValue
={2,0};
181 osl_waitThread( &timeValue
);
184 Reference
< XBridge
> rBridge
= rFactory
->getBridge(
185 OUString("bla blub") );
186 OSL_ASSERT( ! rBridge
.is() );
191 printf( "Login failed, got an Exception !\n" );
194 rAcceptor
->stopAccepting();
195 threadAcceptor
.join();
197 Reference
< XComponent
> rComp( rFactory
, UNO_QUERY
);
201 rComp
= Reference
< XComponent
> ( rSMgr
, UNO_QUERY
);
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */