Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / package / source / xstor / oseekinstream.cxx
blob2e8527b5fbdf408b75085fe7a591f040c105dc70
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 .
20 #include <com/sun/star/lang/DisposedException.hpp>
21 #include <cppuhelper/typeprovider.hxx>
22 #include <cppuhelper/queryinterface.hxx>
23 #include <osl/diagnose.h>
25 #include "oseekinstream.hxx"
26 #include "owriteablestream.hxx"
28 using namespace ::com::sun::star;
30 OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
31 uno::Reference < io::XInputStream > const & xStream,
32 const uno::Sequence< beans::PropertyValue >& aProps,
33 sal_Int32 nStorageType )
34 : OInputCompStream( pImpl, xStream, aProps, nStorageType )
36 m_xSeekable.set( m_xStream, uno::UNO_QUERY );
37 OSL_ENSURE( m_xSeekable.is(), "No seeking support!" );
40 OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > const & xStream,
41 const uno::Sequence< beans::PropertyValue >& aProps,
42 sal_Int32 nStorageType )
43 : OInputCompStream( xStream, aProps, nStorageType )
45 m_xSeekable.set( m_xStream, uno::UNO_QUERY );
46 OSL_ENSURE( m_xSeekable.is(), "No seeking support!" );
49 OInputSeekStream::~OInputSeekStream()
53 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
55 static ::cppu::OTypeCollection* pTypeCollection = nullptr ;
57 if ( pTypeCollection == nullptr )
59 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() ) ;
61 if ( pTypeCollection == nullptr )
63 static ::cppu::OTypeCollection aTypeCollection(
64 cppu::UnoType<io::XSeekable>::get(),
65 OInputCompStream::getTypes() );
67 pTypeCollection = &aTypeCollection ;
71 return pTypeCollection->getTypes() ;
74 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
76 // Attention:
77 // Don't use mutex or guard in this method!!! Is a method of XInterface.
79 uno::Any aReturn( ::cppu::queryInterface( rType,
80 static_cast< io::XSeekable* >( this ) ) );
82 if ( aReturn.hasValue() )
84 return aReturn ;
87 return OInputCompStream::queryInterface( rType ) ;
90 void SAL_CALL OInputSeekStream::acquire()
91 throw()
93 OInputCompStream::acquire();
96 void SAL_CALL OInputSeekStream::release()
97 throw()
99 OInputCompStream::release();
102 void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
104 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
105 if ( m_bDisposed )
107 SAL_INFO("package.xstor", "Disposed!");
108 throw lang::DisposedException();
111 if ( !m_xSeekable.is() )
113 SAL_INFO("package.xstor", "No seekable!");
114 throw uno::RuntimeException();
117 m_xSeekable->seek( location );
120 sal_Int64 SAL_CALL OInputSeekStream::getPosition()
122 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
123 if ( m_bDisposed )
125 SAL_INFO("package.xstor", "Disposed!");
126 throw lang::DisposedException();
129 if ( !m_xSeekable.is() )
131 SAL_INFO("package.xstor", "No seekable!");
132 throw uno::RuntimeException();
135 return m_xSeekable->getPosition();
138 sal_Int64 SAL_CALL OInputSeekStream::getLength()
140 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
141 if ( m_bDisposed )
143 SAL_INFO("package.xstor", "Disposed!");
144 throw lang::DisposedException();
147 if ( !m_xSeekable.is() )
149 SAL_INFO("package.xstor", "No seekable!");
150 throw uno::RuntimeException();
153 return m_xSeekable->getLength();
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */