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