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 INCLUDED_UNOTOOLS_UCBLOCKBYTES_HXX
20 : #define INCLUDED_UNOTOOLS_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 <rtl/ustring.hxx>
32 : #include <tools/stream.hxx>
33 : #include <tools/link.hxx>
34 : #include <tools/errcode.hxx>
35 : #include <tools/datetime.hxx>
36 :
37 : namespace com
38 : {
39 : namespace sun
40 : {
41 : namespace star
42 : {
43 : namespace task
44 : {
45 : class XInteractionHandler;
46 : }
47 : namespace io
48 : {
49 : class XStream;
50 : class XInputStream;
51 : class XOutputStream;
52 : class XSeekable;
53 : }
54 : namespace ucb
55 : {
56 : class XContent;
57 : }
58 : namespace beans
59 : {
60 : struct PropertyValue;
61 : }
62 : }
63 : }
64 : }
65 :
66 : namespace utl
67 : {
68 : class UcbLockBytes;
69 : typedef tools::SvRef<UcbLockBytes> UcbLockBytesRef;
70 :
71 : class UcbLockBytesHandler : public SvRefBase
72 : {
73 : bool m_bActive;
74 : public:
75 : enum LoadHandlerItem
76 : {
77 : DATA_AVAILABLE,
78 : DONE,
79 : CANCEL
80 : };
81 :
82 : UcbLockBytesHandler()
83 : : m_bActive( true )
84 : {}
85 :
86 : virtual void Handle( LoadHandlerItem nWhich, UcbLockBytesRef xLockBytes ) = 0;
87 : void Activate( bool bActivate = true ) { m_bActive = bActivate; }
88 : bool IsActive() const { return m_bActive; }
89 : };
90 :
91 : typedef tools::SvRef<UcbLockBytesHandler> UcbLockBytesHandlerRef;
92 :
93 : class UNOTOOLS_DLLPUBLIC UcbLockBytes : public virtual SvLockBytes
94 : {
95 : osl::Condition m_aInitialized;
96 : osl::Condition m_aTerminated;
97 : osl::Mutex m_aMutex;
98 :
99 : OUString m_aContentType;
100 : OUString m_aRealURL;
101 : DateTime m_aExpireDate;
102 :
103 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInputStream;
104 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > m_xOutputStream;
105 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable;
106 : void* m_pCommandThread; // is alive only for compatibility reasons
107 : UcbLockBytesHandlerRef m_xHandler;
108 :
109 : ErrCode m_nError;
110 :
111 : bool m_bTerminated;
112 : bool m_bDontClose;
113 : bool m_bStreamValid;
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 ::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 );
128 :
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 );
131 :
132 : // SvLockBytes
133 : virtual void SetSynchronMode (bool bSynchron) SAL_OVERRIDE;
134 : virtual ErrCode ReadAt(sal_uInt64 nPos, void *pBuffer, sal_uLong nCount, sal_uLong *pRead) const SAL_OVERRIDE;
135 : virtual ErrCode WriteAt(sal_uInt64, const void*, sal_uLong, sal_uLong *pWritten) SAL_OVERRIDE;
136 : virtual ErrCode Flush() const SAL_OVERRIDE;
137 : virtual ErrCode SetSize(sal_uInt64) SAL_OVERRIDE;
138 : virtual ErrCode Stat ( SvLockBytesStat *pStat, SvLockBytesStatFlag) const SAL_OVERRIDE;
139 :
140 0 : void SetError( ErrCode nError )
141 0 : { m_nError = nError; }
142 :
143 0 : ErrCode GetError() const
144 0 : { return m_nError; }
145 :
146 : // the following properties are available when and after the first DataAvailable callback has been executed
147 : OUString GetContentType() const;
148 : OUString GetRealURL() const;
149 : DateTime GetExpireDate() const;
150 :
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();
153 :
154 : bool setInputStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > &rxInputStream,
155 : bool bSetXSeekable = true );
156 : bool setStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > &rxStream );
157 : void terminate_Impl (void);
158 :
159 0 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream_Impl() const
160 : {
161 0 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
162 0 : return m_xInputStream;
163 : }
164 :
165 0 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > getOutputStream_Impl() const
166 : {
167 0 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
168 0 : return m_xOutputStream;
169 : }
170 :
171 0 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > getSeekable_Impl() const
172 : {
173 0 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
174 0 : return m_xSeekable;
175 : }
176 :
177 0 : bool hasInputStream_Impl() const
178 : {
179 0 : osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
180 0 : return m_xInputStream.is();
181 : }
182 :
183 0 : void setDontClose_Impl()
184 0 : { m_bDontClose = true; }
185 :
186 0 : void SetContentType_Impl( const OUString& rType ) { m_aContentType = rType; }
187 0 : void SetRealURL_Impl( const OUString& rURL ) { m_aRealURL = rURL; }
188 0 : void SetExpireDate_Impl( const DateTime& rDateTime ) { m_aExpireDate = rDateTime; }
189 : void SetStreamValid_Impl();
190 : };
191 :
192 : }
193 :
194 : #endif
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|