fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / unotools / streamwrap.hxx
blob097b3dee94e300da29244d053aa7d4233a841ff6
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 .
19 #include "unotools/unotoolsdllapi.h"
21 #ifndef _UTL_STREAM_WRAPPER_HXX_
22 #define _UTL_STREAM_WRAPPER_HXX_
23 #include <osl/mutex.hxx>
24 #include <com/sun/star/io/XOutputStream.hpp>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/io/XSeekable.hpp>
27 #include <com/sun/star/io/XTruncate.hpp>
28 #include <com/sun/star/io/XStream.hpp>
29 #include <cppuhelper/implbase3.hxx>
30 #include <cppuhelper/implbase1.hxx>
32 class SvStream;
34 namespace utl
36 namespace stario = ::com::sun::star::io;
37 namespace staruno = ::com::sun::star::uno;
39 //==================================================================
40 //= OInputStreamWrapper
41 //==================================================================
42 typedef ::cppu::WeakImplHelper1 < stario::XInputStream
43 > InputStreamWrapper_Base;
44 // needed for some compilers
45 /// helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XInputStream</type>
46 class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public InputStreamWrapper_Base
48 protected:
49 ::osl::Mutex m_aMutex;
50 SvStream* m_pSvStream;
51 sal_Bool m_bSvStreamOwner : 1;
52 OInputStreamWrapper()
53 { m_pSvStream = 0; m_bSvStreamOwner = sal_False; }
54 void SetStream(SvStream* _pStream, sal_Bool bOwner )
55 { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; }
57 public:
58 OInputStreamWrapper(SvStream& _rStream);
59 OInputStreamWrapper(SvStream* pStream, sal_Bool bOwner=sal_False);
60 virtual ~OInputStreamWrapper();
62 // stario::XInputStream
63 virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
64 virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
65 virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
66 virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException);
67 virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException);
69 protected:
70 /// throws a NotConnectedException if the object is not connected anymore
71 void checkConnected() const;
72 /// throws an exception according to the error flag of m_pSvStream
73 void checkError() const;
76 //==================================================================
77 //= OSeekableInputStreamWrapper
78 //==================================================================
79 typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable
80 > OSeekableInputStreamWrapper_Base;
81 /** helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XInputStream</type>
82 which is seekable (i.e. supports the <type scope="com.sun.star.io">XSeekable</type> interface).
84 class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper : public ::cppu::ImplInheritanceHelper1 < OInputStreamWrapper, com::sun::star::io::XSeekable >
86 protected:
87 OSeekableInputStreamWrapper() {}
88 public:
89 OSeekableInputStreamWrapper(SvStream& _rStream);
90 OSeekableInputStreamWrapper(SvStream* _pStream, sal_Bool _bOwner = sal_False);
92 // XSeekable
93 virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
94 virtual sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
95 virtual sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
98 //==================================================================
99 //= OOutputStreamWrapper
100 //==================================================================
101 typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base;
102 // needed for some compilers
103 class OOutputStreamWrapper : public OutputStreamWrapper_Base
105 public:
106 UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream& _rStream);
108 protected:
109 virtual ~OOutputStreamWrapper();
111 // stario::XOutputStream
112 virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
113 virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
114 virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
116 /// throws an exception according to the error flag of m_pSvStream
117 void checkError() const;
119 // TODO: thread safety!
120 SvStream& rStream;
123 //==================================================================
124 //= OSeekableOutputStreamWrapper
125 //==================================================================
126 typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable
127 > OSeekableOutputStreamWrapper_Base;
128 /** helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XOutputStream</type>
129 which is seekable (i.e. supports the <type scope="com.sun.star.io">XSeekable</type> interface).
131 class OSeekableOutputStreamWrapper
132 :public OOutputStreamWrapper
133 ,public OSeekableOutputStreamWrapper_Base
135 public:
136 UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper(SvStream& _rStream);
138 private:
139 virtual ~OSeekableOutputStreamWrapper();
141 // disambiguate XInterface
142 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
143 virtual void SAL_CALL acquire( ) throw ();
144 virtual void SAL_CALL release( ) throw ();
146 // XSeekable
147 virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
148 virtual sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
149 virtual sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
152 class UNOTOOLS_DLLPUBLIC OStreamWrapper : public ::cppu::ImplInheritanceHelper3 < OSeekableInputStreamWrapper, com::sun::star::io::XStream, com::sun::star::io::XOutputStream, com::sun::star::io::XTruncate >
154 public:
155 OStreamWrapper(SvStream& _rStream);
157 // stario::XStream
158 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException);
159 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException);
161 // stario::XOutputStream
162 virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
163 virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
164 virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
165 virtual void SAL_CALL truncate() throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
169 // namespace utl
171 #endif // _UTL_STREAM_WRAPPER_HXX_
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */