Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include <unotools/unotoolsdllapi.h>
20 :
21 : #ifndef INCLUDED_UNOTOOLS_STREAMWRAP_HXX
22 : #define INCLUDED_UNOTOOLS_STREAMWRAP_HXX
23 :
24 : #include <osl/mutex.hxx>
25 : #include <com/sun/star/io/XOutputStream.hpp>
26 : #include <com/sun/star/io/XInputStream.hpp>
27 : #include <com/sun/star/io/XSeekable.hpp>
28 : #include <com/sun/star/io/XTruncate.hpp>
29 : #include <com/sun/star/io/XStream.hpp>
30 : #include <cppuhelper/implbase3.hxx>
31 : #include <cppuhelper/implbase1.hxx>
32 :
33 : class SvStream;
34 :
35 : namespace utl
36 : {
37 :
38 : //= OInputStreamWrapper
39 :
40 : typedef ::cppu::WeakImplHelper1 < css::io::XInputStream
41 : > InputStreamWrapper_Base;
42 : // needed for some compilers
43 : /// helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
44 : class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public InputStreamWrapper_Base
45 : {
46 : protected:
47 : ::osl::Mutex m_aMutex;
48 : SvStream* m_pSvStream;
49 : bool m_bSvStreamOwner : 1;
50 2368 : OInputStreamWrapper()
51 2368 : { m_pSvStream = 0; m_bSvStreamOwner = false; }
52 2368 : void SetStream(SvStream* _pStream, bool bOwner )
53 2368 : { m_pSvStream = _pStream; m_bSvStreamOwner = bOwner; }
54 :
55 : public:
56 : OInputStreamWrapper(SvStream& _rStream);
57 : OInputStreamWrapper(SvStream* pStream, bool bOwner=false);
58 : virtual ~OInputStreamWrapper();
59 :
60 : // css::io::XInputStream
61 : virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
62 : virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 : virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 : virtual sal_Int32 SAL_CALL available() throw(css::io::NotConnectedException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
65 : virtual void SAL_CALL closeInput() throw(css::io::NotConnectedException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
66 :
67 : protected:
68 : /// throws a NotConnectedException if the object is not connected anymore
69 : void checkConnected() const;
70 : /// throws an exception according to the error flag of m_pSvStream
71 : void checkError() const;
72 : };
73 :
74 : //= OSeekableInputStreamWrapper
75 :
76 : typedef ::cppu::ImplHelper1 < css::io::XSeekable
77 : > OSeekableInputStreamWrapper_Base;
78 : /** helper class for wrapping an SvStream into an com.sun.star.io::XInputStream
79 : which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
80 : */
81 3590 : class UNOTOOLS_DLLPUBLIC OSeekableInputStreamWrapper : public ::cppu::ImplInheritanceHelper1 < OInputStreamWrapper, css::io::XSeekable >
82 : {
83 : protected:
84 1142 : OSeekableInputStreamWrapper() {}
85 : public:
86 : OSeekableInputStreamWrapper(SvStream& _rStream);
87 : OSeekableInputStreamWrapper(SvStream* _pStream, bool _bOwner = false);
88 :
89 : // XSeekable
90 : virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (css::lang::IllegalArgumentException, css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
91 : virtual sal_Int64 SAL_CALL getPosition( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
92 : virtual sal_Int64 SAL_CALL getLength( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 : };
94 :
95 : //= OOutputStreamWrapper
96 :
97 : typedef ::cppu::WeakImplHelper1<css::io::XOutputStream> OutputStreamWrapper_Base;
98 : // needed for some compilers
99 : class OOutputStreamWrapper : public OutputStreamWrapper_Base
100 : {
101 : public:
102 : UNOTOOLS_DLLPUBLIC OOutputStreamWrapper(SvStream& _rStream);
103 :
104 : protected:
105 : virtual ~OOutputStreamWrapper();
106 :
107 : // css::io::XOutputStream
108 : virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
109 : virtual void SAL_CALL flush() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 : virtual void SAL_CALL closeOutput() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
111 :
112 : /// throws an exception according to the error flag of m_pSvStream
113 : void checkError() const;
114 :
115 : // TODO: thread safety!
116 : SvStream& rStream;
117 : };
118 :
119 : //= OSeekableOutputStreamWrapper
120 :
121 : typedef ::cppu::ImplHelper1 < css::io::XSeekable
122 : > OSeekableOutputStreamWrapper_Base;
123 : /** helper class for wrapping an SvStream into an com.sun.star.io::XOutputStream
124 : which is seekable (i.e. supports the com.sun.star.io::XSeekable interface).
125 : */
126 : class OSeekableOutputStreamWrapper
127 : :public OOutputStreamWrapper
128 : ,public OSeekableOutputStreamWrapper_Base
129 : {
130 : public:
131 : UNOTOOLS_DLLPUBLIC OSeekableOutputStreamWrapper(SvStream& _rStream);
132 :
133 : private:
134 : virtual ~OSeekableOutputStreamWrapper();
135 :
136 : // disambiguate XInterface
137 : virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 : virtual void SAL_CALL acquire( ) throw () SAL_OVERRIDE;
139 : virtual void SAL_CALL release( ) throw () SAL_OVERRIDE;
140 :
141 : // XSeekable
142 : virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (css::lang::IllegalArgumentException, css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 : virtual sal_Int64 SAL_CALL getPosition( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 : virtual sal_Int64 SAL_CALL getLength( ) throw (css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 : };
146 :
147 2284 : class UNOTOOLS_DLLPUBLIC OStreamWrapper : public ::cppu::ImplInheritanceHelper3 < OSeekableInputStreamWrapper, css::io::XStream, css::io::XOutputStream, css::io::XTruncate >
148 : {
149 : public:
150 : OStreamWrapper(SvStream& _rStream);
151 :
152 : // css::io::XStream
153 : virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 : virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 :
156 : // css::io::XOutputStream
157 : virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 >& aData) throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 : virtual void SAL_CALL flush() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 : virtual void SAL_CALL closeOutput() throw(css::io::NotConnectedException, css::io::BufferSizeExceededException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 : virtual void SAL_CALL truncate() throw(css::io::IOException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 : };
162 :
163 : }
164 : // namespace utl
165 :
166 : #endif // INCLUDED_UNOTOOLS_STREAMWRAP_HXX
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|