xref: /trunk/main/unotools/source/ucbhelper/XTempFile.hxx (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
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 _XTEMPFILE_HXX_
24 #define _XTEMPFILE_HXX_
25 
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include <com/sun/star/io/XOutputStream.hpp>
28 #include <com/sun/star/io/XSeekable.hpp>
29 #include <com/sun/star/io/XStream.hpp>
30 #include <com/sun/star/io/XTempFile.hpp>
31 #include <com/sun/star/io/XTruncate.hpp>
32 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <cppuhelper/implbase5.hxx>
35 #ifndef _CPPUHELPER_PROPERTYSETMIXIN_HXX_
36 #include <cppuhelper/propertysetmixin.hxx>
37 #endif
38 #include <osl/mutex.hxx>
39 
40 class SvStream;
41 namespace utl { class TempFile; }
42 
43 typedef  ::cppu::WeakImplHelper5<   ::com::sun::star::io::XTempFile
44                                     ,   ::com::sun::star::io::XInputStream
45                                                 ,   ::com::sun::star::io::XOutputStream
46                                                 ,   ::com::sun::star::io::XTruncate
47                                                 ,   ::com::sun::star::lang::XServiceInfo
48                                                 >
49                                     OTempFileBase;
50 
51 class OTempFileService :
52     public OTempFileBase,
53     public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile >
54 {
55 protected:
56     ::utl::TempFile*    mpTempFile;
57     ::osl::Mutex        maMutex;
58     SvStream*           mpStream;
59     sal_Bool            mbRemoveFile;
60     sal_Bool            mbInClosed;
61     sal_Bool            mbOutClosed;
62 
63     sal_Int64           mnCachedPos;
64     sal_Bool            mbHasCachedPos;
65 
66     void checkError () const;
67     void checkConnected ();
68 
69 public:
70     OTempFileService (::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);
71 
72     //Methods
73     //  XInterface
74     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType )
75         throw (::com::sun::star::uno::RuntimeException);
76     virtual void SAL_CALL acquire(  )
77         throw ();
78     virtual void SAL_CALL release(  )
79         throw ();
80     //  XTypeProvider
81     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  )
82         throw (::com::sun::star::uno::RuntimeException);
83     virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getImplementationId(  )
84         throw (::com::sun::star::uno::RuntimeException);
85 
86     //  XTempFile
87     virtual ::sal_Bool SAL_CALL getRemoveFile()
88         throw (::com::sun::star::uno::RuntimeException);
89     virtual void SAL_CALL setRemoveFile( ::sal_Bool _removefile )
90         throw (::com::sun::star::uno::RuntimeException);
91     virtual ::rtl::OUString SAL_CALL getUri()
92         throw (::com::sun::star::uno::RuntimeException);
93     virtual ::rtl::OUString SAL_CALL getResourceName()
94         throw (::com::sun::star::uno::RuntimeException);
95 
96     // XInputStream
97     virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
98         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
99     virtual ::sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
100         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
101     virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip )
102         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
103     virtual ::sal_Int32 SAL_CALL available(  )
104         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
105     virtual void SAL_CALL closeInput(  )
106         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
107     // XOutputStream
108     virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData )
109         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
110     virtual void SAL_CALL flush(  )
111         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
112     virtual void SAL_CALL closeOutput(  )
113         throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
114     // XSeekable
115     virtual void SAL_CALL seek( sal_Int64 location )
116         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
117     virtual sal_Int64 SAL_CALL getPosition(  )
118         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
119     virtual sal_Int64 SAL_CALL getLength(  )
120         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
121     // XStream
122     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(  )
123         throw (::com::sun::star::uno::RuntimeException);
124     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  )
125         throw (::com::sun::star::uno::RuntimeException);
126     // XTruncate
127     virtual void SAL_CALL truncate()
128         throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
129     // XServiceInfo
130     virtual ::rtl::OUString SAL_CALL getImplementationName()
131         throw (::com::sun::star::uno::RuntimeException);
132     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
133         throw (::com::sun::star::uno::RuntimeException);
134     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
135         throw (::com::sun::star::uno::RuntimeException);
136 
137     //::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL XTempFile_createInstance( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);
138     static ::rtl::OUString getImplementationName_Static ();
139     static ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames_Static();
140 
141 private:
142     OTempFileService( OTempFileService & );
143     virtual ~OTempFileService ();
144 
145 };
146 #endif
147