xref: /aoo41x/main/io/source/stm/opump.cxx (revision 3716f815)
1*3716f815SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3716f815SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3716f815SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3716f815SAndrew Rist  * distributed with this work for additional information
6*3716f815SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3716f815SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3716f815SAndrew Rist  * "License"); you may not use this file except in compliance
9*3716f815SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3716f815SAndrew Rist  *
11*3716f815SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3716f815SAndrew Rist  *
13*3716f815SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3716f815SAndrew Rist  * software distributed under the License is distributed on an
15*3716f815SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3716f815SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3716f815SAndrew Rist  * specific language governing permissions and limitations
18*3716f815SAndrew Rist  * under the License.
19*3716f815SAndrew Rist  *
20*3716f815SAndrew Rist  *************************************************************/
21*3716f815SAndrew Rist 
22*3716f815SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_io.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/diagnose.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
32cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
33cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataControl.hpp>
34cdf0e10cSrcweir #include <com/sun/star/io/XConnectable.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
38cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <uno/dispatcher.h>
41cdf0e10cSrcweir #include <uno/mapping.hxx>
42cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
43cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
44cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
45cdf0e10cSrcweir #include <osl/mutex.hxx>
46cdf0e10cSrcweir #include <osl/thread.h>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir using namespace osl;
50cdf0e10cSrcweir using namespace std;
51cdf0e10cSrcweir using namespace rtl;
52cdf0e10cSrcweir using namespace cppu;
53cdf0e10cSrcweir using namespace com::sun::star::uno;
54cdf0e10cSrcweir using namespace com::sun::star::lang;
55cdf0e10cSrcweir using namespace com::sun::star::registry;
56cdf0e10cSrcweir using namespace com::sun::star::io;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "factreg.hxx"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace io_stm {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	class Pump : public WeakImplHelper5<
63cdf0e10cSrcweir 		  XActiveDataSource, XActiveDataSink, XActiveDataControl, XConnectable, XServiceInfo >
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		Mutex									m_aMutex;
66cdf0e10cSrcweir 		oslThread								m_aThread;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 		Reference< XConnectable >				m_xPred;
69cdf0e10cSrcweir 		Reference< XConnectable >				m_xSucc;
70cdf0e10cSrcweir 		Reference< XInputStream >				m_xInput;
71cdf0e10cSrcweir 		Reference< XOutputStream >				m_xOutput;
72cdf0e10cSrcweir         OInterfaceContainerHelper               m_cnt;
73cdf0e10cSrcweir         sal_Bool                                m_closeFired;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 		void run();
76cdf0e10cSrcweir 		static void static_run( void* pObject );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         void close();
79cdf0e10cSrcweir 		void fireClose();
80cdf0e10cSrcweir 		void fireStarted();
81cdf0e10cSrcweir 		void fireTerminated();
82cdf0e10cSrcweir 		void fireError( const Any &a );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	public:
85cdf0e10cSrcweir 		Pump();
86cdf0e10cSrcweir 		virtual ~Pump();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		// XActiveDataSource
89cdf0e10cSrcweir 		virtual void SAL_CALL setOutputStream( const Reference< ::com::sun::star::io::XOutputStream >& xOutput ) throw();
90cdf0e10cSrcweir 		virtual Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream() throw();
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		// XActiveDataSink
93cdf0e10cSrcweir 		virtual void SAL_CALL setInputStream( const Reference< ::com::sun::star::io::XInputStream >& xStream ) throw();
94cdf0e10cSrcweir 		virtual Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream() throw();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		// XActiveDataControl
97cdf0e10cSrcweir 		virtual void SAL_CALL addListener( const Reference< ::com::sun::star::io::XStreamListener >& xListener ) throw();
98cdf0e10cSrcweir 		virtual void SAL_CALL removeListener( const Reference< ::com::sun::star::io::XStreamListener >& xListener ) throw();
99cdf0e10cSrcweir 		virtual void SAL_CALL start() throw( RuntimeException );
100cdf0e10cSrcweir 		virtual void SAL_CALL terminate() throw();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		// XConnectable
103cdf0e10cSrcweir 		virtual void SAL_CALL setPredecessor( const Reference< ::com::sun::star::io::XConnectable >& xPred ) throw();
104cdf0e10cSrcweir 		virtual Reference< ::com::sun::star::io::XConnectable > SAL_CALL getPredecessor() throw();
105cdf0e10cSrcweir 		virtual void SAL_CALL setSuccessor( const Reference< ::com::sun::star::io::XConnectable >& xSucc ) throw();
106cdf0e10cSrcweir 		virtual Reference< ::com::sun::star::io::XConnectable > SAL_CALL getSuccessor() throw();
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	public: // XServiceInfo
109cdf0e10cSrcweir 		virtual OUString    SAL_CALL getImplementationName() throw(  );
110cdf0e10cSrcweir 		virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw(  );
111cdf0e10cSrcweir 		virtual sal_Bool     SAL_CALL supportsService(const OUString& ServiceName) throw(  );
112cdf0e10cSrcweir 	};
113cdf0e10cSrcweir 
Pump()114cdf0e10cSrcweir Pump::Pump() : m_aThread( 0 ),
115cdf0e10cSrcweir                m_cnt( m_aMutex ),
116cdf0e10cSrcweir                m_closeFired( sal_False )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
~Pump()121cdf0e10cSrcweir Pump::~Pump()
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	// exit gracefully
124cdf0e10cSrcweir     if( m_aThread )
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         osl_joinWithThread( m_aThread );
127cdf0e10cSrcweir         osl_destroyThread( m_aThread );
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
fireError(const Any & exception)132cdf0e10cSrcweir void Pump::fireError( const  Any & exception )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     OInterfaceIteratorHelper iter( m_cnt );
135cdf0e10cSrcweir     while( iter.hasMoreElements() )
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         try
138cdf0e10cSrcweir 		{
139cdf0e10cSrcweir 			static_cast< XStreamListener * > ( iter.next() )->error( exception );
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 		catch ( RuntimeException &e )
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			OString sMessage = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
144cdf0e10cSrcweir 			OSL_ENSURE( !"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners", sMessage.getStr() );
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
fireClose()149cdf0e10cSrcweir void Pump::fireClose()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     sal_Bool bFire = sal_False;
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         MutexGuard guard( m_aMutex );
154cdf0e10cSrcweir         if( ! m_closeFired  )
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             m_closeFired = sal_True;
157cdf0e10cSrcweir             bFire = sal_True;
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     if( bFire )
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         OInterfaceIteratorHelper iter( m_cnt );
164cdf0e10cSrcweir         while( iter.hasMoreElements() )
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir             try
167cdf0e10cSrcweir             {
168cdf0e10cSrcweir                 static_cast< XStreamListener * > ( iter.next() )->closed( );
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir             catch ( RuntimeException &e )
171cdf0e10cSrcweir             {
172cdf0e10cSrcweir                 OString sMessage = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
173cdf0e10cSrcweir                 OSL_ENSURE( !"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners", sMessage.getStr() );
174cdf0e10cSrcweir             }
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
fireStarted()179cdf0e10cSrcweir void Pump::fireStarted()
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     OInterfaceIteratorHelper iter( m_cnt );
182cdf0e10cSrcweir     while( iter.hasMoreElements() )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         try
185cdf0e10cSrcweir 		{
186cdf0e10cSrcweir 			static_cast< XStreamListener * > ( iter.next() )->started( );
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 		catch ( RuntimeException &e )
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir 			OString sMessage = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
191cdf0e10cSrcweir 			OSL_ENSURE( !"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners", sMessage.getStr() );
192cdf0e10cSrcweir 		}
193cdf0e10cSrcweir 	}
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
fireTerminated()196cdf0e10cSrcweir void Pump::fireTerminated()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     OInterfaceIteratorHelper iter( m_cnt );
199cdf0e10cSrcweir     while( iter.hasMoreElements() )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         try
202cdf0e10cSrcweir 		{
203cdf0e10cSrcweir 			static_cast< XStreamListener * > ( iter.next() )->terminated();
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 		catch ( RuntimeException &e )
206cdf0e10cSrcweir 		{
207cdf0e10cSrcweir 			OString sMessage = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
208cdf0e10cSrcweir 			OSL_ENSURE( !"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners", sMessage.getStr() );
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 	}
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
close()215cdf0e10cSrcweir void Pump::close()
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	// close streams and release references
218cdf0e10cSrcweir     Reference< XInputStream > rInput;
219cdf0e10cSrcweir     Reference< XOutputStream > rOutput;
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         MutexGuard guard( m_aMutex );
222cdf0e10cSrcweir         rInput = m_xInput;
223cdf0e10cSrcweir 		m_xInput.clear();
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         rOutput = m_xOutput;
226cdf0e10cSrcweir         m_xOutput.clear();
227cdf0e10cSrcweir         m_xSucc.clear();
228cdf0e10cSrcweir         m_xPred.clear();
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 	if( rInput.is() )
231cdf0e10cSrcweir 	{
232cdf0e10cSrcweir 		try
233cdf0e10cSrcweir 		{
234cdf0e10cSrcweir 			rInput->closeInput();
235cdf0e10cSrcweir 		}
236cdf0e10cSrcweir 		catch( Exception & )
237cdf0e10cSrcweir 		{
238cdf0e10cSrcweir 			// go down calm
239cdf0e10cSrcweir 		}
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir 	if( rOutput.is() )
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		try
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			rOutput->closeOutput();
246cdf0e10cSrcweir 		}
247cdf0e10cSrcweir 		catch( Exception & )
248cdf0e10cSrcweir 		{
249cdf0e10cSrcweir 			// go down calm
250cdf0e10cSrcweir 		}
251cdf0e10cSrcweir 	}
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
static_run(void * pObject)254cdf0e10cSrcweir void Pump::static_run( void* pObject )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	((Pump*)pObject)->run();
257cdf0e10cSrcweir 	((Pump*)pObject)->release();
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
run()260cdf0e10cSrcweir void Pump::run()
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	try
263cdf0e10cSrcweir 	{
264cdf0e10cSrcweir         fireStarted();
265cdf0e10cSrcweir 		try
266cdf0e10cSrcweir 		{
267cdf0e10cSrcweir             Reference< XInputStream > rInput;
268cdf0e10cSrcweir             Reference< XOutputStream > rOutput;
269cdf0e10cSrcweir             {
270cdf0e10cSrcweir                 Guard< Mutex > aGuard( m_aMutex );
271cdf0e10cSrcweir                 rInput = m_xInput;
272cdf0e10cSrcweir                 rOutput = m_xOutput;
273cdf0e10cSrcweir             }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 			if( ! rInput.is() )
276cdf0e10cSrcweir 			{
277cdf0e10cSrcweir 				NotConnectedException exception(
278cdf0e10cSrcweir 					OUString::createFromAscii( "no input stream set" ) , Reference<XInterface>((OWeakObject*)this) );
279cdf0e10cSrcweir 				throw exception;
280cdf0e10cSrcweir 			}
281cdf0e10cSrcweir 			Sequence< sal_Int8 > aData;
282cdf0e10cSrcweir 			while( rInput->readSomeBytes( aData, 65536 ) )
283cdf0e10cSrcweir 			{
284cdf0e10cSrcweir 				if( ! rOutput.is() )
285cdf0e10cSrcweir 				{
286cdf0e10cSrcweir 					NotConnectedException exception(
287cdf0e10cSrcweir 						OUString::createFromAscii( "no output stream set" ) , Reference<XInterface>( (OWeakObject*)this) );
288cdf0e10cSrcweir 					throw exception;
289cdf0e10cSrcweir 				}
290cdf0e10cSrcweir 				rOutput->writeBytes( aData );
291cdf0e10cSrcweir 				osl_yieldThread();
292cdf0e10cSrcweir 			}
293cdf0e10cSrcweir 		}
294cdf0e10cSrcweir 		catch ( IOException & e )
295cdf0e10cSrcweir 		{
296cdf0e10cSrcweir 			fireError( makeAny( e ) );
297cdf0e10cSrcweir 		}
298cdf0e10cSrcweir 		catch ( RuntimeException & e )
299cdf0e10cSrcweir 		{
300cdf0e10cSrcweir 			fireError( makeAny( e ) );
301cdf0e10cSrcweir 		}
302cdf0e10cSrcweir 		catch ( Exception & e )
303cdf0e10cSrcweir 		{
304cdf0e10cSrcweir 			fireError( makeAny( e ) );
305cdf0e10cSrcweir 		}
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 		close();
308cdf0e10cSrcweir         fireClose();
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir 	catch ( com::sun::star::uno::Exception &e )
311cdf0e10cSrcweir 	{
312cdf0e10cSrcweir 		// we are the last on the stack.
313cdf0e10cSrcweir 		// this is to avoid crashing the program, when e.g. a bridge crashes
314cdf0e10cSrcweir 		OString sMessage = OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US );
315cdf0e10cSrcweir 		OSL_ENSURE( !"com.sun.star.comp.stoc.Pump: unexpected exception", sMessage.getStr() );
316cdf0e10cSrcweir 	}
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir // ------------------------------------------------------------
320cdf0e10cSrcweir 
321cdf0e10cSrcweir /*
322cdf0e10cSrcweir  * XConnectable
323cdf0e10cSrcweir  */
324cdf0e10cSrcweir 
setPredecessor(const Reference<XConnectable> & xPred)325cdf0e10cSrcweir void Pump::setPredecessor( const Reference< XConnectable >& xPred ) throw()
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
328cdf0e10cSrcweir 	m_xPred = xPred;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir // ------------------------------------------------------------
332cdf0e10cSrcweir 
getPredecessor()333cdf0e10cSrcweir Reference< XConnectable > Pump::getPredecessor() throw()
334cdf0e10cSrcweir {
335cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
336cdf0e10cSrcweir 	return m_xPred;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir // ------------------------------------------------------------
340cdf0e10cSrcweir 
setSuccessor(const Reference<XConnectable> & xSucc)341cdf0e10cSrcweir void Pump::setSuccessor( const Reference< XConnectable >& xSucc ) throw()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
344cdf0e10cSrcweir 	m_xSucc = xSucc;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir // ------------------------------------------------------------
348cdf0e10cSrcweir 
getSuccessor()349cdf0e10cSrcweir Reference< XConnectable > Pump::getSuccessor() throw()
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
352cdf0e10cSrcweir 	return m_xSucc;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir // -----------------------------------------------------------------
356cdf0e10cSrcweir 
357cdf0e10cSrcweir /*
358cdf0e10cSrcweir  * XActiveDataControl
359cdf0e10cSrcweir  */
360cdf0e10cSrcweir 
addListener(const Reference<XStreamListener> & xListener)361cdf0e10cSrcweir void Pump::addListener( const Reference< XStreamListener >& xListener ) throw()
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     m_cnt.addInterface( xListener );
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir // ------------------------------------------------------------
367cdf0e10cSrcweir 
removeListener(const Reference<XStreamListener> & xListener)368cdf0e10cSrcweir void Pump::removeListener( const Reference< XStreamListener >& xListener ) throw()
369cdf0e10cSrcweir {
370cdf0e10cSrcweir     m_cnt.removeInterface( xListener );
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir // ------------------------------------------------------------
374cdf0e10cSrcweir 
start()375cdf0e10cSrcweir void Pump::start() throw( RuntimeException )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
378cdf0e10cSrcweir 	m_aThread = osl_createSuspendedThread((oslWorkerFunction)Pump::static_run,this);
379cdf0e10cSrcweir     if( m_aThread )
380cdf0e10cSrcweir     {
381cdf0e10cSrcweir         // will be released by OPump::static_run
382cdf0e10cSrcweir         acquire();
383cdf0e10cSrcweir         osl_resumeThread( m_aThread );
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir     else
386cdf0e10cSrcweir     {
387cdf0e10cSrcweir         throw RuntimeException(
388cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Pump::start Couldn't create worker thread" )),
389cdf0e10cSrcweir             *this);
390cdf0e10cSrcweir     }
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir // ------------------------------------------------------------
394cdf0e10cSrcweir 
terminate()395cdf0e10cSrcweir void Pump::terminate() throw()
396cdf0e10cSrcweir {
397cdf0e10cSrcweir 	close();
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	// wait for the worker to die
400cdf0e10cSrcweir     if( m_aThread )
401cdf0e10cSrcweir         osl_joinWithThread( m_aThread );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     fireTerminated();
404cdf0e10cSrcweir     fireClose();
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir // ------------------------------------------------------------
408cdf0e10cSrcweir 
409cdf0e10cSrcweir /*
410cdf0e10cSrcweir  * XActiveDataSink
411cdf0e10cSrcweir  */
412cdf0e10cSrcweir 
setInputStream(const Reference<XInputStream> & xStream)413cdf0e10cSrcweir void Pump::setInputStream( const Reference< XInputStream >& xStream ) throw()
414cdf0e10cSrcweir {
415cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
416cdf0e10cSrcweir 	m_xInput = xStream;
417cdf0e10cSrcweir 	Reference< XConnectable > xConnect( xStream, UNO_QUERY );
418cdf0e10cSrcweir 	if( xConnect.is() )
419cdf0e10cSrcweir 		xConnect->setSuccessor( this );
420cdf0e10cSrcweir 	// data transfer starts in XActiveDataControl::start
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir // ------------------------------------------------------------
424cdf0e10cSrcweir 
getInputStream()425cdf0e10cSrcweir Reference< XInputStream > Pump::getInputStream() throw()
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
428cdf0e10cSrcweir 	return m_xInput;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir // ------------------------------------------------------------
432cdf0e10cSrcweir 
433cdf0e10cSrcweir /*
434cdf0e10cSrcweir  * XActiveDataSource
435cdf0e10cSrcweir  */
436cdf0e10cSrcweir 
setOutputStream(const Reference<XOutputStream> & xOut)437cdf0e10cSrcweir void Pump::setOutputStream( const Reference< XOutputStream >& xOut ) throw()
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
440cdf0e10cSrcweir 	m_xOutput = xOut;
441cdf0e10cSrcweir 	Reference< XConnectable > xConnect( xOut, UNO_QUERY );
442cdf0e10cSrcweir 	if( xConnect.is() )
443cdf0e10cSrcweir 		xConnect->setPredecessor( this );
444cdf0e10cSrcweir 	// data transfer starts in XActiveDataControl::start
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir // ------------------------------------------------------------
448cdf0e10cSrcweir 
getOutputStream()449cdf0e10cSrcweir Reference< XOutputStream > Pump::getOutputStream() throw()
450cdf0e10cSrcweir {
451cdf0e10cSrcweir 	Guard< Mutex > aGuard( m_aMutex );
452cdf0e10cSrcweir 	return m_xOutput;
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 
456cdf0e10cSrcweir // XServiceInfo
getImplementationName()457cdf0e10cSrcweir OUString Pump::getImplementationName() throw(  )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     return OPumpImpl_getImplementationName();
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)463cdf0e10cSrcweir sal_Bool Pump::supportsService(const OUString& ServiceName) throw(  )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
466cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
469cdf0e10cSrcweir         if( pArray[i] == ServiceName )
470cdf0e10cSrcweir             return sal_True;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir     return sal_False;
473cdf0e10cSrcweir }
474cdf0e10cSrcweir 
475cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames(void)476cdf0e10cSrcweir Sequence< OUString > Pump::getSupportedServiceNames(void) throw(  )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir     return OPumpImpl_getSupportedServiceNames();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 
OPumpImpl_CreateInstance(const Reference<XComponentContext> &)482cdf0e10cSrcweir Reference< XInterface > SAL_CALL OPumpImpl_CreateInstance( const Reference< XComponentContext > & ) throw (Exception)
483cdf0e10cSrcweir {
484cdf0e10cSrcweir 	return Reference< XInterface >( *new Pump );
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
OPumpImpl_getImplementationName()487cdf0e10cSrcweir OUString OPumpImpl_getImplementationName()
488cdf0e10cSrcweir {
489cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.Pump") );
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
OPumpImpl_getSupportedServiceNames(void)492cdf0e10cSrcweir Sequence<OUString> OPumpImpl_getSupportedServiceNames(void)
493cdf0e10cSrcweir {
494cdf0e10cSrcweir 	OUString s( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.Pump" ) );
495cdf0e10cSrcweir 	Sequence< OUString > seq( &s , 1 );
496cdf0e10cSrcweir 	return seq;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501