bump product version to 4.1.6.2
[LibreOffice.git] / include / unotools / ucblockbytes.hxx
blobcf5d98b935837ca1dbe510f0389dc4d74d18ca78
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 .
19 #ifndef _UNTOOLS_UCBLOCKBYTES_HXX
20 #define _UNTOOLS_UCBLOCKBYTES_HXX
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"
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>
36 namespace com
38 namespace sun
40 namespace star
42 namespace task
44 class XInteractionHandler;
46 namespace io
48 class XStream;
49 class XInputStream;
50 class XOutputStream;
51 class XSeekable;
53 namespace ucb
55 class XContent;
57 namespace beans
59 struct PropertyValue;
65 namespace utl
67 SV_DECL_REF( UcbLockBytes )
69 class UcbLockBytesHandler : public SvRefBase
71 sal_Bool m_bActive;
72 public:
73 enum LoadHandlerItem
75 DATA_AVAILABLE,
76 DONE,
77 CANCEL
80 UcbLockBytesHandler()
81 : m_bActive( sal_True )
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; }
89 SV_DECL_IMPL_REF( UcbLockBytesHandler )
91 class UNOTOOLS_DLLPUBLIC UcbLockBytes : public virtual SvLockBytes
93 osl::Condition m_aInitialized;
94 osl::Condition m_aTerminated;
95 osl::Mutex m_aMutex;
97 String m_aContentType;
98 String m_aRealURL;
99 DateTime m_aExpireDate;
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;
107 sal_uInt32 m_nRead;
108 sal_uInt32 m_nSize;
109 ErrCode m_nError;
111 sal_Bool m_bTerminated : 1;
112 sal_Bool m_bDontClose : 1;
113 sal_Bool m_bStreamValid : 1;
115 DECL_LINK( DataAvailHdl, void * );
117 UcbLockBytes( UcbLockBytesHandler* pHandler=NULL );
118 protected:
119 virtual ~UcbLockBytes (void);
121 public:
122 // properties: Referer, PostMimeType
123 static UcbLockBytesRef CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XContent >& xContent,
124 const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& rProps,
125 StreamMode eMode,
126 const ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler >& xInter,
127 UcbLockBytesHandler* pHandler=0 );
129 static UcbLockBytesRef CreateInputLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xContent );
130 static UcbLockBytesRef CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xContent );
132 // SvLockBytes
133 virtual void SetSynchronMode (sal_Bool bSynchron);
134 virtual ErrCode ReadAt ( sal_uLong nPos, void *pBuffer, sal_uLong nCount, sal_uLong *pRead) const;
135 virtual ErrCode WriteAt ( sal_uLong, const void*, sal_uLong, sal_uLong *pWritten);
136 virtual ErrCode Flush (void) const;
137 virtual ErrCode SetSize (sal_uLong);
138 virtual ErrCode Stat ( SvLockBytesStat *pStat, SvLockBytesStatFlag) const;
140 void SetError( ErrCode nError )
141 { m_nError = nError; }
143 ErrCode GetError() const
144 { return m_nError; }
146 // the following properties are available when and after the first DataAvailable callback has been executed
147 String GetContentType() const;
148 String GetRealURL() const;
149 DateTime GetExpireDate() const;
151 // calling this method delegates the responsibility to call closeinput to the caller!
152 ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream();
154 sal_Bool setInputStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > &rxInputStream,
155 sal_Bool bSetXSeekable = sal_True );
156 sal_Bool setStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > &rxStream );
157 void terminate_Impl (void);
159 ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream_Impl() const
161 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
162 return m_xInputStream;
165 ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > getOutputStream_Impl() const
167 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
168 return m_xOutputStream;
171 ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > getSeekable_Impl() const
173 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
174 return m_xSeekable;
177 sal_Bool hasInputStream_Impl() const
179 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
180 return m_xInputStream.is();
183 void setDontClose_Impl()
184 { m_bDontClose = sal_True; }
186 void SetContentType_Impl( const String& rType ) { m_aContentType = rType; }
187 void SetRealURL_Impl( const String& rURL ) { m_aRealURL = rURL; }
188 void SetExpireDate_Impl( const DateTime& rDateTime ) { m_aExpireDate = rDateTime; }
189 void SetStreamValid_Impl();
192 SV_IMPL_REF( UcbLockBytes );
196 #endif
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */