1*bae3752eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bae3752eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bae3752eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bae3752eSAndrew Rist * distributed with this work for additional information 6*bae3752eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bae3752eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bae3752eSAndrew Rist * "License"); you may not use this file except in compliance 9*bae3752eSAndrew Rist * with the License. You may obtain a copy of the License at 10*bae3752eSAndrew Rist * 11*bae3752eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*bae3752eSAndrew Rist * 13*bae3752eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bae3752eSAndrew Rist * software distributed under the License is distributed on an 15*bae3752eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bae3752eSAndrew Rist * KIND, either express or implied. See the License for the 17*bae3752eSAndrew Rist * specific language governing permissions and limitations 18*bae3752eSAndrew Rist * under the License. 19*bae3752eSAndrew Rist * 20*bae3752eSAndrew Rist *************************************************************/ 21*bae3752eSAndrew Rist 22*bae3752eSAndrew Rist 23cdf0e10cSrcweir #ifndef _UNTOOLS_UCBLOCKBYTES_HXX 24cdf0e10cSrcweir #define _UNTOOLS_UCBLOCKBYTES_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 27cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 28cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 30cdf0e10cSrcweir #include "unotools/unotoolsdllapi.h" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <vos/thread.hxx> 33cdf0e10cSrcweir #include <vos/conditn.hxx> 34cdf0e10cSrcweir #include <vos/mutex.hxx> 35cdf0e10cSrcweir #include <tools/stream.hxx> 36cdf0e10cSrcweir #include <tools/link.hxx> 37cdf0e10cSrcweir #include <tools/errcode.hxx> 38cdf0e10cSrcweir #include <tools/datetime.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace com 41cdf0e10cSrcweir { 42cdf0e10cSrcweir namespace sun 43cdf0e10cSrcweir { 44cdf0e10cSrcweir namespace star 45cdf0e10cSrcweir { 46cdf0e10cSrcweir namespace task 47cdf0e10cSrcweir { 48cdf0e10cSrcweir class XInteractionHandler; 49cdf0e10cSrcweir } 50cdf0e10cSrcweir namespace io 51cdf0e10cSrcweir { 52cdf0e10cSrcweir class XStream; 53cdf0e10cSrcweir class XInputStream; 54cdf0e10cSrcweir class XOutputStream; 55cdf0e10cSrcweir class XSeekable; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir namespace ucb 58cdf0e10cSrcweir { 59cdf0e10cSrcweir class XContent; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir namespace beans 62cdf0e10cSrcweir { 63cdf0e10cSrcweir struct PropertyValue; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir } 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir namespace utl 70cdf0e10cSrcweir { 71cdf0e10cSrcweir SV_DECL_REF( UcbLockBytes ) 72cdf0e10cSrcweir 73cdf0e10cSrcweir class UcbLockBytesHandler : public SvRefBase 74cdf0e10cSrcweir { 75cdf0e10cSrcweir sal_Bool m_bActive; 76cdf0e10cSrcweir public: 77cdf0e10cSrcweir enum LoadHandlerItem 78cdf0e10cSrcweir { 79cdf0e10cSrcweir DATA_AVAILABLE, 80cdf0e10cSrcweir DONE, 81cdf0e10cSrcweir CANCEL 82cdf0e10cSrcweir }; 83cdf0e10cSrcweir UcbLockBytesHandler()84cdf0e10cSrcweir UcbLockBytesHandler() 85cdf0e10cSrcweir : m_bActive( sal_True ) 86cdf0e10cSrcweir {} 87cdf0e10cSrcweir 88cdf0e10cSrcweir virtual void Handle( LoadHandlerItem nWhich, UcbLockBytesRef xLockBytes ) = 0; Activate(sal_Bool bActivate=sal_True)89cdf0e10cSrcweir void Activate( sal_Bool bActivate = sal_True ) { m_bActive = bActivate; } IsActive() const90cdf0e10cSrcweir sal_Bool IsActive() const { return m_bActive; } 91cdf0e10cSrcweir }; 92cdf0e10cSrcweir 93cdf0e10cSrcweir SV_DECL_IMPL_REF( UcbLockBytesHandler ) 94cdf0e10cSrcweir 95cdf0e10cSrcweir #define NS_UNO ::com::sun::star::uno 96cdf0e10cSrcweir #define NS_IO ::com::sun::star::io 97cdf0e10cSrcweir #define NS_UCB ::com::sun::star::ucb 98cdf0e10cSrcweir #define NS_BEANS ::com::sun::star::beans 99cdf0e10cSrcweir #define NS_TASK ::com::sun::star::task 100cdf0e10cSrcweir 101cdf0e10cSrcweir class UNOTOOLS_DLLPUBLIC UcbLockBytes : public virtual SvLockBytes 102cdf0e10cSrcweir { 103cdf0e10cSrcweir vos::OCondition m_aInitialized; 104cdf0e10cSrcweir vos::OCondition m_aTerminated; 105cdf0e10cSrcweir vos::OMutex m_aMutex; 106cdf0e10cSrcweir 107cdf0e10cSrcweir String m_aContentType; 108cdf0e10cSrcweir String m_aRealURL; 109cdf0e10cSrcweir DateTime m_aExpireDate; 110cdf0e10cSrcweir 111cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XInputStream > m_xInputStream; 112cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XOutputStream > m_xOutputStream; 113cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XSeekable > m_xSeekable; 114cdf0e10cSrcweir void* m_pCommandThread; // is alive only for compatibility reasons 115cdf0e10cSrcweir UcbLockBytesHandlerRef m_xHandler; 116cdf0e10cSrcweir 117cdf0e10cSrcweir sal_uInt32 m_nRead; 118cdf0e10cSrcweir sal_uInt32 m_nSize; 119cdf0e10cSrcweir ErrCode m_nError; 120cdf0e10cSrcweir 121cdf0e10cSrcweir sal_Bool m_bTerminated : 1; 122cdf0e10cSrcweir sal_Bool m_bDontClose : 1; 123cdf0e10cSrcweir sal_Bool m_bStreamValid : 1; 124cdf0e10cSrcweir 125cdf0e10cSrcweir DECL_LINK( DataAvailHdl, void * ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir UcbLockBytes( UcbLockBytesHandler* pHandler=NULL ); 128cdf0e10cSrcweir protected: 129cdf0e10cSrcweir virtual ~UcbLockBytes (void); 130cdf0e10cSrcweir 131cdf0e10cSrcweir public: 132cdf0e10cSrcweir // properties: Referer, PostMimeType 133cdf0e10cSrcweir static UcbLockBytesRef CreateLockBytes( const NS_UNO::Reference < NS_UCB::XContent >& xContent, 134cdf0e10cSrcweir const ::rtl::OUString& rReferer, 135cdf0e10cSrcweir const ::rtl::OUString& rMediaType, 136cdf0e10cSrcweir const NS_UNO::Reference < NS_IO::XInputStream >& xPostData, 137cdf0e10cSrcweir const NS_UNO::Reference < NS_TASK::XInteractionHandler >& xInter, 138cdf0e10cSrcweir UcbLockBytesHandler* pHandler=0 ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir static UcbLockBytesRef CreateLockBytes( const NS_UNO::Reference < NS_UCB::XContent >& xContent, 141cdf0e10cSrcweir const NS_UNO::Sequence < NS_BEANS::PropertyValue >& rProps, 142cdf0e10cSrcweir StreamMode eMode, 143cdf0e10cSrcweir const NS_UNO::Reference < NS_TASK::XInteractionHandler >& xInter, 144cdf0e10cSrcweir UcbLockBytesHandler* pHandler=0 ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir static UcbLockBytesRef CreateInputLockBytes( const NS_UNO::Reference < NS_IO::XInputStream >& xContent ); 147cdf0e10cSrcweir static UcbLockBytesRef CreateLockBytes( const NS_UNO::Reference < NS_IO::XStream >& xContent ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir // SvLockBytes 150cdf0e10cSrcweir virtual void SetSynchronMode (sal_Bool bSynchron); 151cdf0e10cSrcweir virtual ErrCode ReadAt ( sal_uLong nPos, void *pBuffer, sal_uLong nCount, sal_uLong *pRead) const; 152cdf0e10cSrcweir virtual ErrCode WriteAt ( sal_uLong, const void*, sal_uLong, sal_uLong *pWritten); 153cdf0e10cSrcweir virtual ErrCode Flush (void) const; 154cdf0e10cSrcweir virtual ErrCode SetSize (sal_uLong); 155cdf0e10cSrcweir virtual ErrCode Stat ( SvLockBytesStat *pStat, SvLockBytesStatFlag) const; 156cdf0e10cSrcweir SetError(ErrCode nError)157cdf0e10cSrcweir void SetError( ErrCode nError ) 158cdf0e10cSrcweir { m_nError = nError; } 159cdf0e10cSrcweir GetError() const160cdf0e10cSrcweir ErrCode GetError() const 161cdf0e10cSrcweir { return m_nError; } 162cdf0e10cSrcweir 163cdf0e10cSrcweir void Cancel(); // is alive only for compatibility reasons 164cdf0e10cSrcweir 165cdf0e10cSrcweir // the following properties are available when and after the first DataAvailable callback has been executed 166cdf0e10cSrcweir String GetContentType() const; 167cdf0e10cSrcweir String GetRealURL() const; 168cdf0e10cSrcweir DateTime GetExpireDate() const; 169cdf0e10cSrcweir 170cdf0e10cSrcweir // calling this method delegates the responsibility to call closeinput to the caller! 171cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XInputStream > getInputStream(); 172cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XStream > getStream(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir #if _SOLAR__PRIVATE 175cdf0e10cSrcweir sal_Bool setInputStream_Impl( const NS_UNO::Reference < NS_IO::XInputStream > &rxInputStream, 176cdf0e10cSrcweir sal_Bool bSetXSeekable = sal_True ); 177cdf0e10cSrcweir sal_Bool setStream_Impl( const NS_UNO::Reference < NS_IO::XStream > &rxStream ); 178cdf0e10cSrcweir void terminate_Impl (void); 179cdf0e10cSrcweir getInputStream_Impl() const180cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XInputStream > getInputStream_Impl() const 181cdf0e10cSrcweir { 182cdf0e10cSrcweir vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); 183cdf0e10cSrcweir return m_xInputStream; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir getOutputStream_Impl() const186cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XOutputStream > getOutputStream_Impl() const 187cdf0e10cSrcweir { 188cdf0e10cSrcweir vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); 189cdf0e10cSrcweir return m_xOutputStream; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir getSeekable_Impl() const192cdf0e10cSrcweir NS_UNO::Reference < NS_IO::XSeekable > getSeekable_Impl() const 193cdf0e10cSrcweir { 194cdf0e10cSrcweir vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); 195cdf0e10cSrcweir return m_xSeekable; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir hasInputStream_Impl() const198cdf0e10cSrcweir sal_Bool hasInputStream_Impl() const 199cdf0e10cSrcweir { 200cdf0e10cSrcweir vos::OGuard aGuard( SAL_CONST_CAST(UcbLockBytes*, this)->m_aMutex ); 201cdf0e10cSrcweir return m_xInputStream.is(); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir setDontClose_Impl()204cdf0e10cSrcweir void setDontClose_Impl() 205cdf0e10cSrcweir { m_bDontClose = sal_True; } 206cdf0e10cSrcweir SetContentType_Impl(const String & rType)207cdf0e10cSrcweir void SetContentType_Impl( const String& rType ) { m_aContentType = rType; } SetRealURL_Impl(const String & rURL)208cdf0e10cSrcweir void SetRealURL_Impl( const String& rURL ) { m_aRealURL = rURL; } SetExpireDate_Impl(const DateTime & rDateTime)209cdf0e10cSrcweir void SetExpireDate_Impl( const DateTime& rDateTime ) { m_aExpireDate = rDateTime; } 210cdf0e10cSrcweir void SetStreamValid_Impl(); 211cdf0e10cSrcweir #endif 212cdf0e10cSrcweir }; 213cdf0e10cSrcweir 214cdf0e10cSrcweir SV_IMPL_REF( UcbLockBytes ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir #endif 219