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