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