Line data Source code
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>
21 : #include <cppuhelper/typeprovider.hxx>
22 : #include <osl/diagnose.h>
23 :
24 : #include "oseekinstream.hxx"
25 : #include "owriteablestream.hxx"
26 :
27 : using namespace ::com::sun::star;
28 :
29 0 : OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl,
30 : uno::Reference < io::XInputStream > xStream,
31 : const uno::Sequence< beans::PropertyValue >& aProps,
32 : sal_Int32 nStorageType )
33 0 : : OInputCompStream( pImpl, xStream, aProps, nStorageType )
34 : {
35 0 : if ( m_xStream.is() )
36 : {
37 0 : m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
38 : OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
39 : }
40 0 : }
41 :
42 0 : OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream,
43 : const uno::Sequence< beans::PropertyValue >& aProps,
44 : sal_Int32 nStorageType )
45 0 : : OInputCompStream( xStream, aProps, nStorageType )
46 : {
47 0 : if ( m_xStream.is() )
48 : {
49 0 : m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY );
50 : OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" );
51 : }
52 0 : }
53 :
54 0 : OInputSeekStream::~OInputSeekStream()
55 : {
56 0 : }
57 :
58 0 : uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
59 : throw ( uno::RuntimeException, std::exception )
60 : {
61 : static ::cppu::OTypeCollection* pTypeCollection = NULL ;
62 :
63 0 : if ( pTypeCollection == NULL )
64 : {
65 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ;
66 :
67 0 : if ( pTypeCollection == NULL )
68 : {
69 : static ::cppu::OTypeCollection aTypeCollection(
70 0 : ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ),
71 0 : OInputCompStream::getTypes() );
72 :
73 0 : pTypeCollection = &aTypeCollection ;
74 0 : }
75 : }
76 :
77 0 : return pTypeCollection->getTypes() ;
78 : }
79 :
80 0 : uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
81 : throw( uno::RuntimeException, std::exception )
82 : {
83 : // Attention:
84 : // Don't use mutex or guard in this method!!! Is a method of XInterface.
85 :
86 : uno::Any aReturn( ::cppu::queryInterface( rType,
87 0 : static_cast< io::XSeekable* >( this ) ) );
88 :
89 0 : if ( aReturn.hasValue() )
90 : {
91 0 : return aReturn ;
92 : }
93 :
94 0 : return OInputCompStream::queryInterface( rType ) ;
95 : }
96 :
97 0 : void SAL_CALL OInputSeekStream::acquire()
98 : throw()
99 : {
100 0 : OInputCompStream::acquire();
101 0 : }
102 :
103 0 : void SAL_CALL OInputSeekStream::release()
104 : throw()
105 : {
106 0 : OInputCompStream::release();
107 0 : }
108 :
109 0 : void SAL_CALL OInputSeekStream::seek( sal_Int64 location )
110 : throw ( lang::IllegalArgumentException,
111 : io::IOException,
112 : uno::RuntimeException, std::exception )
113 : {
114 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
115 0 : if ( m_bDisposed )
116 : {
117 0 : ::package::StaticAddLog( OSL_LOG_PREFIX "Disposed!" );
118 0 : throw lang::DisposedException();
119 : }
120 :
121 0 : if ( !m_xSeekable.is() )
122 : {
123 0 : ::package::StaticAddLog( OSL_LOG_PREFIX "No seekable!" );
124 0 : throw uno::RuntimeException();
125 : }
126 :
127 0 : m_xSeekable->seek( location );
128 0 : }
129 :
130 0 : sal_Int64 SAL_CALL OInputSeekStream::getPosition()
131 : throw ( io::IOException,
132 : uno::RuntimeException, std::exception)
133 : {
134 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
135 0 : if ( m_bDisposed )
136 : {
137 0 : ::package::StaticAddLog( OSL_LOG_PREFIX "Disposed!" );
138 0 : throw lang::DisposedException();
139 : }
140 :
141 0 : if ( !m_xSeekable.is() )
142 : {
143 0 : ::package::StaticAddLog( OSL_LOG_PREFIX "No seekable!" );
144 0 : throw uno::RuntimeException();
145 : }
146 :
147 0 : return m_xSeekable->getPosition();
148 : }
149 :
150 0 : sal_Int64 SAL_CALL OInputSeekStream::getLength()
151 : throw ( io::IOException,
152 : uno::RuntimeException, std::exception )
153 : {
154 0 : ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
155 0 : if ( m_bDisposed )
156 : {
157 0 : ::package::StaticAddLog( OSL_LOG_PREFIX "Disposed!" );
158 0 : throw lang::DisposedException();
159 : }
160 :
161 0 : if ( !m_xSeekable.is() )
162 : {
163 0 : ::package::StaticAddLog( OSL_LOG_PREFIX "No seekable!" );
164 0 : throw uno::RuntimeException();
165 : }
166 :
167 0 : return m_xSeekable->getLength();
168 : }
169 :
170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|