Branch data 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 : : #ifndef _UNTOOLS_UCBLOCKBYTES_HXX
20 : : #define _UNTOOLS_UCBLOCKBYTES_HXX
21 : :
22 : : #include <com/sun/star/uno/Reference.hxx>
23 : : #include <com/sun/star/uno/Sequence.hxx>
24 : : #include <com/sun/star/ucb/XContent.hpp>
25 : : #include <com/sun/star/beans/PropertyValue.hpp>
26 : : #include "unotools/unotoolsdllapi.h"
27 : :
28 : : #include <osl/thread.hxx>
29 : : #include <osl/conditn.hxx>
30 : : #include <osl/mutex.hxx>
31 : : #include <tools/stream.hxx>
32 : : #include <tools/link.hxx>
33 : : #include <tools/errcode.hxx>
34 : : #include <tools/datetime.hxx>
35 : :
36 : : namespace com
37 : : {
38 : : namespace sun
39 : : {
40 : : namespace star
41 : : {
42 : : namespace task
43 : : {
44 : : class XInteractionHandler;
45 : : }
46 : : namespace io
47 : : {
48 : : class XStream;
49 : : class XInputStream;
50 : : class XOutputStream;
51 : : class XSeekable;
52 : : }
53 : : namespace ucb
54 : : {
55 : : class XContent;
56 : : }
57 : : namespace beans
58 : : {
59 : : struct PropertyValue;
60 : : }
61 : : }
62 : : }
63 : : }
64 : :
65 : : namespace utl
66 : : {
67 : 207848 : SV_DECL_REF( UcbLockBytes )
68 : :
69 [ # # ]: 0 : class UcbLockBytesHandler : public SvRefBase
70 : : {
71 : : sal_Bool m_bActive;
72 : : public:
73 : : enum LoadHandlerItem
74 : : {
75 : : DATA_AVAILABLE,
76 : : DONE,
77 : : CANCEL
78 : : };
79 : :
80 : : UcbLockBytesHandler()
81 : : : m_bActive( sal_True )
82 : : {}
83 : :
84 : : virtual void Handle( LoadHandlerItem nWhich, UcbLockBytesRef xLockBytes ) = 0;
85 : : void Activate( sal_Bool bActivate = sal_True ) { m_bActive = bActivate; }
86 : : sal_Bool IsActive() const { return m_bActive; }
87 : : };
88 : :
89 [ - + ][ - + ]: 116554 : SV_DECL_IMPL_REF( UcbLockBytesHandler )
[ - + ]
90 : :
91 : : class UNOTOOLS_DLLPUBLIC UcbLockBytes : public virtual SvLockBytes
92 : : {
93 : : osl::Condition m_aInitialized;
94 : : osl::Condition m_aTerminated;
95 : : osl::Mutex m_aMutex;
96 : :
97 : : String m_aContentType;
98 : : String m_aRealURL;
99 : : DateTime m_aExpireDate;
100 : :
101 : : ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInputStream;
102 : : ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > m_xOutputStream;
103 : : ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable;
104 : : void* m_pCommandThread; // is alive only for compatibility reasons
105 : : UcbLockBytesHandlerRef m_xHandler;
106 : :
107 : : sal_uInt32 m_nRead;
108 : : sal_uInt32 m_nSize;
109 : : ErrCode m_nError;
110 : :
111 : : sal_Bool m_bTerminated : 1;
112 : : sal_Bool m_bDontClose : 1;
113 : : sal_Bool m_bStreamValid : 1;
114 : :
115 : : DECL_LINK( DataAvailHdl, void * );
116 : :
117 : : UcbLockBytes( UcbLockBytesHandler* pHandler=NULL );
118 : : protected:
119 : : virtual ~UcbLockBytes (void);
120 : :
121 : : public:
122 : : // properties: Referer, PostMimeType
123 : : static UcbLockBytesRef CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XContent >& xContent,
124 : : const ::rtl::OUString& rReferer,
125 : : const ::rtl::OUString& rMediaType,
126 : : const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xPostData,
127 : : const ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler >& xInter,
128 : : UcbLockBytesHandler* pHandler=0 );
129 : :
130 : : static UcbLockBytesRef CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XContent >& xContent,
131 : : const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& rProps,
132 : : StreamMode eMode,
133 : : const ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler >& xInter,
134 : : UcbLockBytesHandler* pHandler=0 );
135 : :
136 : : static UcbLockBytesRef CreateInputLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xContent );
137 : : static UcbLockBytesRef CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xContent );
138 : :
139 : : // SvLockBytes
140 : : virtual void SetSynchronMode (sal_Bool bSynchron);
141 : : virtual ErrCode ReadAt ( sal_uLong nPos, void *pBuffer, sal_uLong nCount, sal_uLong *pRead) const;
142 : : virtual ErrCode WriteAt ( sal_uLong, const void*, sal_uLong, sal_uLong *pWritten);
143 : : virtual ErrCode Flush (void) const;
144 : : virtual ErrCode SetSize (sal_uLong);
145 : : virtual ErrCode Stat ( SvLockBytesStat *pStat, SvLockBytesStatFlag) const;
146 : :
147 : 2202 : void SetError( ErrCode nError )
148 : 2202 : { m_nError = nError; }
149 : :
150 : 56598 : ErrCode GetError() const
151 : 56598 : { return m_nError; }
152 : :
153 : : void Cancel(); // is alive only for compatibility reasons
154 : :
155 : : // the following properties are available when and after the first DataAvailable callback has been executed
156 : : String GetContentType() const;
157 : : String GetRealURL() const;
158 : : DateTime GetExpireDate() const;
159 : :
160 : : // calling this method delegates the responsibility to call closeinput to the caller!
161 : : ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream();
162 : :
163 : : #if _SOLAR__PRIVATE
164 : : sal_Bool setInputStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > &rxInputStream,
165 : : sal_Bool bSetXSeekable = sal_True );
166 : : sal_Bool setStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > &rxStream );
167 : : void terminate_Impl (void);
168 : :
169 : 87619 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream_Impl() const
170 : : {
171 [ + - ]: 87619 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
172 [ + - ]: 87619 : return m_xInputStream;
173 : : }
174 : :
175 : 30058 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > getOutputStream_Impl() const
176 : : {
177 [ + - ]: 30058 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
178 [ + - ]: 30058 : return m_xOutputStream;
179 : : }
180 : :
181 : 96567 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > getSeekable_Impl() const
182 : : {
183 [ + - ]: 96567 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
184 [ + - ]: 96567 : return m_xSeekable;
185 : : }
186 : :
187 : 0 : sal_Bool hasInputStream_Impl() const
188 : : {
189 [ # # ]: 0 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
190 [ # # ]: 0 : return m_xInputStream.is();
191 : : }
192 : :
193 : 10615 : void setDontClose_Impl()
194 : 10615 : { m_bDontClose = sal_True; }
195 : :
196 : 0 : void SetContentType_Impl( const String& rType ) { m_aContentType = rType; }
197 : 0 : void SetRealURL_Impl( const String& rURL ) { m_aRealURL = rURL; }
198 : 0 : void SetExpireDate_Impl( const DateTime& rDateTime ) { m_aExpireDate = rDateTime; }
199 : : void SetStreamValid_Impl();
200 : : #endif
201 : : };
202 : :
203 [ + + ][ - + ]: 231984 : SV_IMPL_REF( UcbLockBytes );
[ + - ][ + - ]
204 : :
205 : : }
206 : :
207 : : #endif
208 : :
209 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|