23#include <com/sun/star/io/IOException.hpp>
24#include <com/sun/star/io/NotConnectedException.hpp>
25#include <com/sun/star/io/XActiveDataSource.hpp>
26#include <com/sun/star/io/XActiveDataSink.hpp>
27#include <com/sun/star/io/XActiveDataControl.hpp>
28#include <com/sun/star/io/XConnectable.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/uno/XComponentContext.hpp>
35#include <osl/thread.h>
48 class Pump :
public WeakImplHelper<
49 XActiveDataSource, XActiveDataSink, XActiveDataControl, XConnectable, XServiceInfo >
62 static void static_run(
void* pObject );
67 void fireTerminated();
68 void fireError(
const Any &a );
72 virtual ~Pump()
override;
85 virtual void SAL_CALL
start()
override;
86 virtual void SAL_CALL terminate()
override;
117void Pump::fireError(
const Any & exception )
122 while( iter.hasMoreElements() )
126 iter.next()->error( exception );
130 SAL_WARN(
"io.streams",
"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners" << e);
135void Pump::fireClose()
153 while( iter.hasMoreElements() )
157 iter.next()->closed( );
161 SAL_WARN(
"io.streams",
"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners" << e);
166void Pump::fireStarted()
171 while( iter.hasMoreElements() )
175 iter.next()->started( );
179 SAL_WARN(
"io.streams",
"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners" << e);
184void Pump::fireTerminated()
189 while( iter.hasMoreElements() )
193 iter.next()->terminated();
197 SAL_WARN(
"io.streams",
"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners" << e);
222 rInput->closeInput();
233 rOutput->closeOutput();
242void Pump::static_run(
void* pObject )
244 osl_setThreadName(
"io_stm::Pump::run()");
246 static_cast<Pump*
>(
pObject)->release();
259 std::unique_lock aGuard(
m_aMutex );
266 throw NotConnectedException(
"no input stream set", getXWeak() );
269 while( rInput->readSomeBytes( aData, 65536 ) )
273 throw NotConnectedException(
"no output stream set", getXWeak() );
275 rOutput->writeBytes( aData );
281 fireError(
Any( e ) );
285 fireError(
Any( e ) );
287 catch (
const Exception & e )
289 fireError(
Any( e ) );
295 catch (
const css::uno::Exception &e )
299 SAL_WARN(
"io.streams",
"com.sun.star.comp.stoc.Pump: unexpected exception during calling listeners" << e);
310 std::unique_lock aGuard(
m_aMutex );
317 std::unique_lock aGuard(
m_aMutex );
324 std::unique_lock aGuard(
m_aMutex );
331 std::unique_lock aGuard(
m_aMutex );
342 std::unique_lock aGuard(
m_aMutex );
343 m_cnt.addInterface( aGuard, xListener );
349 std::unique_lock aGuard(
m_aMutex );
350 m_cnt.removeInterface( aGuard, xListener );
356 std::unique_lock aGuard(
m_aMutex );
357 m_aThread = osl_createSuspendedThread(Pump::static_run,
this);
361 "Pump::start Couldn't create worker thread",
372void Pump::terminate()
391 std::unique_lock aGuard(
m_aMutex );
395 xConnect->setSuccessor(
this );
402 std::unique_lock aGuard(
m_aMutex );
413 std::unique_lock aGuard(
m_aMutex );
417 xConnect->setPredecessor(
this );
423 std::unique_lock aGuard(
m_aMutex );
428OUString Pump::getImplementationName()
430 return "com.sun.star.comp.io.Pump";
434sal_Bool Pump::supportsService(
const OUString& ServiceName)
442 return {
"com.sun.star.io.Pump" };
447extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
449 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
451 return cppu::acquire(
new io_stm::Pump());
EmbeddedObjectRef * pObject
#define SAL_WARN(area, stream)
def run(arg=None, arg2=-1)
constexpr OUStringLiteral aData
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool getOutputStream(ProgramOptions const &options, OString const &extension, std::ostream **ppOutputStream, OString &targetSourceFileName, OString &tmpSourceFileName)
comphelper::OInterfaceContainerHelper4< XStreamListener > m_cnt
Reference< XConnectable > m_xPred
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * io_Pump_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Reference< XInputStream > m_xInput
Reference< XOutputStream > m_xOutput
Reference< XConnectable > m_xSucc