xref: /trunk/main/package/source/xstor/oseekinstream.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
66     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
67 
68     if ( pTypeCollection == NULL )
69     {
70         ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
71 
72         if ( pTypeCollection == NULL )
73         {
74             static ::cppu::OTypeCollection aTypeCollection(
75                     ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
76                     OInputCompStream::getTypes() );
77 
78             pTypeCollection = &aTypeCollection ;
79         }
80     }
81 
82     return pTypeCollection->getTypes() ;
83 }
84 
queryInterface(const uno::Type & rType)85 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
86 {
87     // Attention:
88     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
89 
90     uno::Any aReturn( ::cppu::queryInterface( rType,
91                                         static_cast< io::XSeekable* >( this ) ) );
92 
93     if ( aReturn.hasValue() == sal_True )
94     {
95         return aReturn ;
96     }
97 
98     return OInputCompStream::queryInterface( rType ) ;
99 }
100 
acquire()101 void SAL_CALL OInputSeekStream::acquire()
102         throw()
103 {
104     OInputCompStream::acquire();
105 }
106 
release()107 void SAL_CALL OInputSeekStream::release()
108         throw()
109 {
110     OInputCompStream::release();
111 }
112 
113 
seek(sal_Int64 location)114 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
115 {
116     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
117     if ( m_bDisposed )
118     {
119         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
120         throw lang::DisposedException();
121     }
122 
123     if ( !m_xSeekable.is() )
124     {
125         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
126         throw uno::RuntimeException();
127     }
128 
129     m_xSeekable->seek( location );
130 }
131 
getPosition()132 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
133 {
134     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
135     if ( m_bDisposed )
136     {
137         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
138         throw lang::DisposedException();
139     }
140 
141     if ( !m_xSeekable.is() )
142     {
143         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
144         throw uno::RuntimeException();
145     }
146 
147     return m_xSeekable->getPosition();
148 }
149 
getLength()150 sal_Int64 SAL_CALL OInputSeekStream::getLength()
151 {
152     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
153     if ( m_bDisposed )
154     {
155         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
156         throw lang::DisposedException();
157     }
158 
159     if ( !m_xSeekable.is() )
160     {
161         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
162         throw uno::RuntimeException();
163     }
164 
165     return m_xSeekable->getLength();
166 }
167