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