bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / streaming / seqoutputstreamserv.cxx
blobf1ef3c6ebb4829804ed60c57a161463b414f355e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/config.h>
22 #include "comphelper_module.hxx"
23 #include "comphelper_services.hxx"
25 #include <boost/noncopyable.hpp>
26 #include <osl/mutex.hxx>
27 #include <cppuhelper/factory.hxx>
28 #include <cppuhelper/implementationentry.hxx>
29 #include <cppuhelper/implbase2.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <comphelper/seqstream.hxx>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/io/XSequenceOutputStream.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
36 using namespace ::com::sun::star;
39 namespace {
41 class SequenceOutputStreamService:
42 public cppu::WeakImplHelper2<lang::XServiceInfo, io::XSequenceOutputStream>,
43 private boost::noncopyable
45 public:
46 explicit SequenceOutputStreamService();
48 // ::com::sun::star::lang::XServiceInfo:
49 virtual OUString SAL_CALL getImplementationName() throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
50 virtual sal_Bool SAL_CALL supportsService( const OUString & ServiceName ) throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
51 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
53 // XServiceInfo - static versions (used for component registration)
54 static OUString SAL_CALL getImplementationName_static();
55 static uno::Sequence< OUString > SAL_CALL getSupportedServiceNames_static();
56 static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& );
58 // ::com::sun::star::io::XOutputStream:
59 virtual void SAL_CALL writeBytes( const uno::Sequence< ::sal_Int8 > & aData ) throw ( io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
60 virtual void SAL_CALL flush() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException, std::exception ) SAL_OVERRIDE;
61 virtual void SAL_CALL closeOutput() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException, std::exception ) SAL_OVERRIDE;
63 // ::com::sun::star::io::XSequenceOutputStream:
64 virtual uno::Sequence< ::sal_Int8 > SAL_CALL getWrittenBytes( ) throw ( io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
66 private:
67 virtual ~SequenceOutputStreamService() {};
70 ::osl::Mutex m_aMutex;
71 uno::Reference< io::XOutputStream > m_xOutputStream;
72 uno::Sequence< ::sal_Int8 > m_aSequence;
74 SequenceOutputStreamService::SequenceOutputStreamService()
76 m_xOutputStream.set( static_cast < ::cppu::OWeakObject* >( new ::comphelper::OSequenceOutputStream( m_aSequence ) ), uno::UNO_QUERY_THROW );
79 // com.sun.star.uno.XServiceInfo:
80 OUString SAL_CALL SequenceOutputStreamService::getImplementationName() throw ( uno::RuntimeException, std::exception )
82 return getImplementationName_static();
85 OUString SAL_CALL SequenceOutputStreamService::getImplementationName_static()
87 return OUString("com.sun.star.comp.SequenceOutputStreamService");
90 sal_Bool SAL_CALL SequenceOutputStreamService::supportsService( OUString const & serviceName ) throw ( uno::RuntimeException, std::exception )
92 return cppu::supportsService(this, serviceName);
95 uno::Sequence< OUString > SAL_CALL SequenceOutputStreamService::getSupportedServiceNames() throw ( uno::RuntimeException, std::exception )
97 return getSupportedServiceNames_static();
100 uno::Sequence< OUString > SAL_CALL SequenceOutputStreamService::getSupportedServiceNames_static()
102 uno::Sequence< OUString > s( 1 );
103 s[0] = "com.sun.star.io.SequenceOutputStream";
104 return s;
107 uno::Reference< uno::XInterface > SAL_CALL SequenceOutputStreamService::Create(
108 SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >& )
110 return static_cast< ::cppu::OWeakObject * >( new SequenceOutputStreamService());
113 // ::com::sun::star::io::XOutputStream:
114 void SAL_CALL SequenceOutputStreamService::writeBytes( const uno::Sequence< ::sal_Int8 > & aData ) throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException, std::exception )
116 ::osl::MutexGuard aGuard( m_aMutex );
117 if ( !m_xOutputStream.is() )
118 throw io::NotConnectedException();
120 m_xOutputStream->writeBytes( aData );
121 m_aSequence = aData;
124 void SAL_CALL SequenceOutputStreamService::flush() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException, std::exception )
126 ::osl::MutexGuard aGuard( m_aMutex );
127 if ( !m_xOutputStream.is() )
128 throw io::NotConnectedException();
130 m_xOutputStream->flush();
133 void SAL_CALL SequenceOutputStreamService::closeOutput() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException, std::exception )
135 ::osl::MutexGuard aGuard( m_aMutex );
136 if ( !m_xOutputStream.is() )
137 throw io::NotConnectedException();
139 m_xOutputStream->closeOutput();
140 m_xOutputStream = uno::Reference< io::XOutputStream >();
143 // ::com::sun::star::io::XSequenceOutputStream:
144 uno::Sequence< ::sal_Int8 > SAL_CALL SequenceOutputStreamService::getWrittenBytes() throw ( io::NotConnectedException, io::IOException, uno::RuntimeException, std::exception)
146 ::osl::MutexGuard aGuard( m_aMutex );
147 if ( !m_xOutputStream.is() )
148 throw io::NotConnectedException();
150 m_xOutputStream->flush();
151 return m_aSequence;
154 } // anonymous namespace
156 void createRegistryInfo_SequenceOutputStream()
158 static ::comphelper::module::OAutoRegistration< SequenceOutputStreamService > aAutoRegistration;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */