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 ::cppu
;
40 using namespace ::osl
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::bridge
;
44 using namespace ::com::sun::star::connection
;
51 #include "osl/mutex.h"
61 MyThread( const Reference
< XAcceptor
> &r
,
62 const Reference
< XBridgeFactory
> &rFactory
,
63 const OUString
&sConnectionDescription
) :
65 m_rBridgeFactory ( rFactory
),
66 m_sConnectionDescription( sConnectionDescription
)
68 virtual void SAL_CALL
run();
71 Reference
< XAcceptor
> m_rAcceptor
;
72 Reference
< XBridgeFactory
> m_rBridgeFactory
;
73 OUString m_sConnectionDescription
;
85 Reference
< XConnection
> rConnection
=
86 m_rAcceptor
->accept( m_sConnectionDescription
);
88 if( ! rConnection
.is() )
93 Reference
< XBridge
> rBridge
=
94 m_rBridgeFactory
->createBridge(
98 (XInstanceProvider
* ) new OInstanceProvider
);
104 printf( "Exception was thrown by acceptor thread\n" );
111 int main( int argc
, char *argv
[] )
115 printf( "usage : testsamprocess host:port\n" );
120 Reference
< XMultiServiceFactory
> rSMgr
= createRegistryServiceFactory(
121 OUString( "client.rdb" ) );
123 Reference
< XConnector
> rConnector(
124 createComponent( OUString("com.sun.star.connection.Connector"),
125 OUString( "connector.uno" SAL_DLLEXTENSION
),
129 Reference
< XAcceptor
> rAcceptor(
130 createComponent( OUString("com.sun.star.connection.Acceptor"),
131 OUString( "acceptor.uno" SAL_DLLEXTENSION
),
135 // just ensure that it is registered
136 // createComponent( OUString("com.sun.star.bridge.Bridge.iiop"),
137 // OUString( "iiopbrdg" SAL_DLLEXTENSION),
140 Reference
< XBridgeFactory
> rFactory(
141 createComponent( OUString("com.sun.star.bridge.BridgeFactory"),
142 OUString( "bridgefac.uno" SAL_DLLEXTENSION
),
147 MyThread
threadAcceptor( rAcceptor
, rFactory
, OUString::createFromAscii( argv
[1] ) );
149 threadAcceptor
.create();
150 TimeValue value
={2,0};
151 osl_waitThread( &value
);
155 Reference
< XConnection
> rConnection
=
156 rConnector
->connect( OUString::createFromAscii( argv
[1] ) );
158 printf( "%s\n" , OUStringToOString( rConnection
->getDescription(),
159 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
164 Reference
< XBridge
> rBridge
= rFactory
->createBridge(
165 OUString("bla blub"),
168 Reference
< XInstanceProvider
> () );
170 Reference
< XInterface
> rInitialObject
171 = rBridge
->getInstance( OUString("bla") );
173 if( rInitialObject
.is() )
175 printf( "got the remote object\n" );
176 testRemote( rInitialObject
);
178 printf( "Closing...\n" );
179 TimeValue timeValue
={2,0};
180 osl_waitThread( &timeValue
);
183 Reference
< XBridge
> rBridge
= rFactory
->getBridge(
184 OUString("bla blub") );
185 OSL_ASSERT( ! rBridge
.is() );
190 printf( "Login failed, got an Exception !\n" );
193 rAcceptor
->stopAccepting();
194 threadAcceptor
.join();
196 Reference
< XComponent
> rComp( rFactory
, UNO_QUERY
);
200 rComp
= Reference
< XComponent
> ( rSMgr
, UNO_QUERY
);
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */