xref: /AOO41X/main/package/source/xstor/oseekinstream.cxx (revision a38728232e8c39f9058a1a2aa8ee4e6db7b8ca34)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_package.hxx"
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <osl/diagnose.h>
29 
30 #include "oseekinstream.hxx"
31 #include "owriteablestream.hxx"
32 
33 using namespace ::com::sun::star;
34 
OInputSeekStream(OWriteStream_Impl & pImpl,uno::Reference<io::XInputStream> xStream,const uno::Sequence<beans::PropertyValue> & aProps,sal_Int32 nStorageType)35 OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
36                                     uno::Reference < io::XInputStream > xStream,
37                                     const uno::Sequence< beans::PropertyValue >& aProps,
38                                     sal_Int32 nStorageType )
39 : OInputCompStream( pImpl, xStream, aProps, nStorageType )
40 {
41     if ( m_xStream.is() )
42     {
43         m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
44         OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
45     }
46 }
47 
OInputSeekStream(uno::Reference<io::XInputStream> xStream,const uno::Sequence<beans::PropertyValue> & aProps,sal_Int32 nStorageType)48 OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
49                                     const uno::Sequence< beans::PropertyValue >& aProps,
50                                     sal_Int32 nStorageType )
51 : OInputCompStream( xStream, aProps, nStorageType )
52 {
53     if ( m_xStream.is() )
54     {
55         m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
56         OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
57     }
58 }
59 
~OInputSeekStream()60 OInputSeekStream::~OInputSeekStream()
61 {
62 }
63 
getTypes()64 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
65         throw ( uno::RuntimeException )
66 {
67     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
68 
69     if ( pTypeCollection == NULL )
70     {
71         ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
72 
73         if ( pTypeCollection == NULL )
74         {
75             static ::cppu::OTypeCollection aTypeCollection(
76                     ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
77                     OInputCompStream::getTypes() );
78 
79             pTypeCollection = &aTypeCollection ;
80         }
81     }
82 
83     return pTypeCollection->getTypes() ;
84 }
85 
queryInterface(const uno::Type & rType)86 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
87         throw( uno::RuntimeException )
88 {
89     // Attention:
90     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
91 
92     uno::Any aReturn( ::cppu::queryInterface( rType,
93                                         static_cast< io::XSeekable* >( this ) ) );
94 
95     if ( aReturn.hasValue() == sal_True )
96     {
97         return aReturn ;
98     }
99 
100     return OInputCompStream::queryInterface( rType ) ;
101 }
102 
acquire()103 void SAL_CALL OInputSeekStream::acquire()
104         throw()
105 {
106     OInputCompStream::acquire();
107 }
108 
release()109 void SAL_CALL OInputSeekStream::release()
110         throw()
111 {
112     OInputCompStream::release();
113 }
114 
115 
seek(sal_Int64 location)116 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
117         throw ( lang::IllegalArgumentException,
118                 io::IOException,
119                 uno::RuntimeException )
120 {
121     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
122     if ( m_bDisposed )
123     {
124         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
125         throw lang::DisposedException();
126     }
127 
128     if ( !m_xSeekable.is() )
129     {
130         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
131         throw uno::RuntimeException();
132     }
133 
134     m_xSeekable->seek( location );
135 }
136 
getPosition()137 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
138         throw ( io::IOException,
139                 uno::RuntimeException)
140 {
141     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
142     if ( m_bDisposed )
143     {
144         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
145         throw lang::DisposedException();
146     }
147 
148     if ( !m_xSeekable.is() )
149     {
150         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
151         throw uno::RuntimeException();
152     }
153 
154     return m_xSeekable->getPosition();
155 }
156 
getLength()157 sal_Int64 SAL_CALL OInputSeekStream::getLength()
158         throw ( io::IOException,
159                 uno::RuntimeException )
160 {
161     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
162     if ( m_bDisposed )
163     {
164         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
165         throw lang::DisposedException();
166     }
167 
168     if ( !m_xSeekable.is() )
169     {
170         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
171         throw uno::RuntimeException();
172     }
173 
174     return m_xSeekable->getLength();
175 }
176 
177