xref: /trunk/main/package/source/xstor/oseekinstream.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_package.hxx"
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #include <cppuhelper/typeprovider.hxx>
32 #include <osl/diagnose.h>
33 
34 #include "oseekinstream.hxx"
35 #include "owriteablestream.hxx"
36 
37 using namespace ::com::sun::star;
38 
39 OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
40                                     uno::Reference < io::XInputStream > xStream,
41                                     const uno::Sequence< beans::PropertyValue >& aProps,
42                                     sal_Int32 nStorageType )
43 : OInputCompStream( pImpl, xStream, aProps, nStorageType )
44 {
45     if ( m_xStream.is() )
46     {
47         m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
48         OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
49     }
50 }
51 
52 OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
53                                     const uno::Sequence< beans::PropertyValue >& aProps,
54                                     sal_Int32 nStorageType )
55 : OInputCompStream( xStream, aProps, nStorageType )
56 {
57     if ( m_xStream.is() )
58     {
59         m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
60         OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
61     }
62 }
63 
64 OInputSeekStream::~OInputSeekStream()
65 {
66 }
67 
68 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
69         throw ( uno::RuntimeException )
70 {
71     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
72 
73     if ( pTypeCollection == NULL )
74     {
75         ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
76 
77         if ( pTypeCollection == NULL )
78         {
79             static ::cppu::OTypeCollection aTypeCollection(
80                     ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
81                     OInputCompStream::getTypes() );
82 
83             pTypeCollection = &aTypeCollection ;
84         }
85     }
86 
87     return pTypeCollection->getTypes() ;
88 }
89 
90 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
91         throw( uno::RuntimeException )
92 {
93     // Attention:
94     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
95 
96     uno::Any aReturn( ::cppu::queryInterface( rType,
97                                         static_cast< io::XSeekable* >( this ) ) );
98 
99     if ( aReturn.hasValue() == sal_True )
100     {
101         return aReturn ;
102     }
103 
104     return OInputCompStream::queryInterface( rType ) ;
105 }
106 
107 void SAL_CALL OInputSeekStream::acquire()
108         throw()
109 {
110     OInputCompStream::acquire();
111 }
112 
113 void SAL_CALL OInputSeekStream::release()
114         throw()
115 {
116     OInputCompStream::release();
117 }
118 
119 
120 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
121         throw ( lang::IllegalArgumentException,
122                 io::IOException,
123                 uno::RuntimeException )
124 {
125     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
126     if ( m_bDisposed )
127     {
128         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
129         throw lang::DisposedException();
130     }
131 
132     if ( !m_xSeekable.is() )
133     {
134         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
135         throw uno::RuntimeException();
136     }
137 
138     m_xSeekable->seek( location );
139 }
140 
141 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
142         throw ( io::IOException,
143                 uno::RuntimeException)
144 {
145     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
146     if ( m_bDisposed )
147     {
148         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
149         throw lang::DisposedException();
150     }
151 
152     if ( !m_xSeekable.is() )
153     {
154         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
155         throw uno::RuntimeException();
156     }
157 
158     return m_xSeekable->getPosition();
159 }
160 
161 sal_Int64 SAL_CALL OInputSeekStream::getLength()
162         throw ( io::IOException,
163                 uno::RuntimeException )
164 {
165     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
166     if ( m_bDisposed )
167     {
168         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) );
169         throw lang::DisposedException();
170     }
171 
172     if ( !m_xSeekable.is() )
173     {
174         ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) );
175         throw uno::RuntimeException();
176     }
177 
178     return m_xSeekable->getLength();
179 }
180 
181