LibreOffice Module package (master) 1
oseekinstream.cxx
Go to the documentation of this file.
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
20#include <com/sun/star/lang/DisposedException.hpp>
23#include <osl/diagnose.h>
24#include <sal/log.hxx>
25
26#include "oseekinstream.hxx"
27#include "owriteablestream.hxx"
28
29using namespace ::com::sun::star;
30
32 uno::Reference < io::XInputStream > const & xStream,
33 const uno::Sequence< beans::PropertyValue >& aProps,
34 sal_Int32 nStorageType )
35: OInputCompStream( pImpl, xStream, aProps, nStorageType )
36{
37 m_xSeekable.set( m_xStream, uno::UNO_QUERY );
38 OSL_ENSURE( m_xSeekable.is(), "No seeking support!" );
39}
40
41OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > const & xStream,
42 const uno::Sequence< beans::PropertyValue >& aProps,
43 sal_Int32 nStorageType )
44: OInputCompStream( xStream, aProps, nStorageType )
45{
46 m_xSeekable.set( m_xStream, uno::UNO_QUERY );
47 OSL_ENSURE( m_xSeekable.is(), "No seeking support!" );
48}
49
51{
52}
53
54uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
55{
57 OInputCompStream::getTypes());
58
59 return aTypeCollection.getTypes();
60}
61
63{
64 // Attention:
65 // Don't use mutex or guard in this method!!! Is a method of XInterface.
66
67 uno::Any aReturn( ::cppu::queryInterface( rType,
68 static_cast< io::XSeekable* >( this ) ) );
69
70 if ( aReturn.hasValue() )
71 {
72 return aReturn ;
73 }
74
75 return OInputCompStream::queryInterface( rType ) ;
76}
77
79 noexcept
80{
81 OInputCompStream::acquire();
82}
83
85 noexcept
86{
87 OInputCompStream::release();
88}
89
90void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
91{
92 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
93 if ( m_bDisposed )
94 {
95 SAL_INFO("package.xstor", "Disposed!");
96 throw lang::DisposedException();
97 }
98
99 if ( !m_xSeekable.is() )
100 {
101 SAL_INFO("package.xstor", "No seekable!");
102 throw uno::RuntimeException();
103 }
104
105 m_xSeekable->seek( location );
106}
107
109{
110 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
111 if ( m_bDisposed )
112 {
113 SAL_INFO("package.xstor", "Disposed!");
114 throw lang::DisposedException();
115 }
116
117 if ( !m_xSeekable.is() )
118 {
119 SAL_INFO("package.xstor", "No seekable!");
120 throw uno::RuntimeException();
121 }
122
123 return m_xSeekable->getPosition();
124}
125
126sal_Int64 SAL_CALL OInputSeekStream::getLength()
127{
128 ::osl::MutexGuard aGuard( m_xMutex->GetMutex() );
129 if ( m_bDisposed )
130 {
131 SAL_INFO("package.xstor", "Disposed!");
132 throw lang::DisposedException();
133 }
134
135 if ( !m_xSeekable.is() )
136 {
137 SAL_INFO("package.xstor", "No seekable!");
138 throw uno::RuntimeException();
139 }
140
141 return m_xSeekable->getLength();
142}
143
144/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XInputStream > xStream
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
rtl::Reference< comphelper::RefCountedMutex > m_xMutex
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL acquire() noexcept override
OInputSeekStream(OWriteStream_Impl &pImpl, css::uno::Reference< css::io::XInputStream > const &xStream, const css::uno::Sequence< css::beans::PropertyValue > &aProps, sal_Int32 nStorageType)
virtual void SAL_CALL seek(sal_Int64 location) override
virtual sal_Int64 SAL_CALL getLength() override
css::uno::Reference< css::io::XSeekable > m_xSeekable
virtual ~OInputSeekStream() override
virtual void SAL_CALL release() noexcept override
virtual sal_Int64 SAL_CALL getPosition() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
uno::Reference< io::XSeekable > m_xSeekable
#define SAL_INFO(area, stream)
bool hasValue()