1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_UNOTOOLS_UCBLOCKBYTES_HXX
20 #define INCLUDED_UNOTOOLS_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>
27 #include <osl/thread.hxx>
28 #include <osl/conditn.hxx>
29 #include <osl/mutex.hxx>
30 #include <rtl/ustring.hxx>
31 #include <tools/stream.hxx>
32 #include <tools/link.hxx>
33 #include <tools/errcode.hxx>
34 #include <tools/datetime.hxx>
44 class XInteractionHandler
;
68 typedef tools::SvRef
<UcbLockBytes
> UcbLockBytesRef
;
70 class UcbLockBytesHandler
: public SvRefBase
78 void Activate( bool bActivate
= true ) { m_bActive
= bActivate
; }
79 bool IsActive() const { return m_bActive
; }
82 typedef tools::SvRef
<UcbLockBytesHandler
> UcbLockBytesHandlerRef
;
84 class UcbLockBytes
: public virtual SvLockBytes
86 osl::Condition m_aInitialized
;
87 osl::Condition m_aTerminated
;
90 OUString m_aContentType
;
92 DateTime m_aExpireDate
;
94 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> m_xInputStream
;
95 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
> m_xOutputStream
;
96 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XSeekable
> m_xSeekable
;
97 void* m_pCommandThread
; // is alive only for compatibility reasons
98 UcbLockBytesHandlerRef m_xHandler
;
106 DECL_STATIC_LINK( UcbLockBytes
, DataAvailHdl
, void * );
108 UcbLockBytes( UcbLockBytesHandler
* pHandler
);
110 virtual ~UcbLockBytes();
113 // properties: Referer, PostMimeType
114 static UcbLockBytesRef
CreateLockBytes( const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& xContent
,
115 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rProps
,
117 const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionHandler
>& xInter
,
118 UcbLockBytesHandler
* pHandler
=0 );
120 static UcbLockBytesRef
CreateInputLockBytes( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xContent
);
121 static UcbLockBytesRef
CreateLockBytes( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xContent
);
124 virtual void SetSynchronMode (bool bSynchron
) SAL_OVERRIDE
;
125 virtual ErrCode
ReadAt(sal_uInt64 nPos
, void *pBuffer
, sal_uLong nCount
, sal_uLong
*pRead
) const SAL_OVERRIDE
;
126 virtual ErrCode
WriteAt(sal_uInt64
, const void*, sal_uLong
, sal_uLong
*pWritten
) SAL_OVERRIDE
;
127 virtual ErrCode
Flush() const SAL_OVERRIDE
;
128 virtual ErrCode
SetSize(sal_uInt64
) SAL_OVERRIDE
;
129 virtual ErrCode
Stat ( SvLockBytesStat
*pStat
, SvLockBytesStatFlag
) const SAL_OVERRIDE
;
131 void SetError( ErrCode nError
)
132 { m_nError
= nError
; }
134 ErrCode
GetError() const
137 // the following properties are available when and after the first DataAvailable callback has been executed
138 OUString
GetContentType() const;
139 OUString
GetRealURL() const;
140 DateTime
GetExpireDate() const;
142 // calling this method delegates the responsibility to call closeinput to the caller!
143 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> getInputStream();
145 bool setInputStream_Impl( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> &rxInputStream
,
146 bool bSetXSeekable
= true );
147 bool setStream_Impl( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
> &rxStream
);
148 void terminate_Impl();
150 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> getInputStream_Impl() const
152 osl::MutexGuard
aGuard( (const_cast< UcbLockBytes
* >(this))->m_aMutex
);
153 return m_xInputStream
;
156 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
> getOutputStream_Impl() const
158 osl::MutexGuard
aGuard( (const_cast< UcbLockBytes
* >(this))->m_aMutex
);
159 return m_xOutputStream
;
162 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XSeekable
> getSeekable_Impl() const
164 osl::MutexGuard
aGuard( (const_cast< UcbLockBytes
* >(this))->m_aMutex
);
168 bool hasInputStream_Impl() const
170 osl::MutexGuard
aGuard( (const_cast< UcbLockBytes
* >(this))->m_aMutex
);
171 return m_xInputStream
.is();
174 void setDontClose_Impl()
175 { m_bDontClose
= true; }
177 void SetContentType_Impl( const OUString
& rType
) { m_aContentType
= rType
; }
178 void SetRealURL_Impl( const OUString
& rURL
) { m_aRealURL
= rURL
; }
179 void SetExpireDate_Impl( const DateTime
& rDateTime
) { m_aExpireDate
= rDateTime
; }
180 void SetStreamValid_Impl();
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */