1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _XTEMPFILE_HXX_
28 #define _XTEMPFILE_HXX_
29 
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/io/XSeekable.hpp>
33 #include <com/sun/star/io/XStream.hpp>
34 #include <com/sun/star/io/XTempFile.hpp>
35 #include <com/sun/star/io/XTruncate.hpp>
36 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <cppuhelper/implbase5.hxx>
40 #ifndef _CPPUHELPER_PROPERTYSETMIXIN_HXX_
41 #include <cppuhelper/propertysetmixin.hxx>
42 #endif
43 #include <osl/mutex.hxx>
44 
45 class SvStream;
46 namespace utl { class TempFile; }
47 
48 typedef	 ::cppu::WeakImplHelper5<	::com::sun::star::io::XTempFile
49 									,	::com::sun::star::io::XInputStream
50 				  								,	::com::sun::star::io::XOutputStream
51 				  								,	::com::sun::star::io::XTruncate
52 				  								,	::com::sun::star::lang::XServiceInfo
53 				  								>
54 									OTempFileBase;
55 
56 class OTempFileService :
57 	public OTempFileBase,
58 	public ::cppu::PropertySetMixin< ::com::sun::star::io::XTempFile >
59 {
60 protected:
61 	::utl::TempFile* 	mpTempFile;
62 	::osl::Mutex		maMutex;
63 	SvStream* 			mpStream;
64 	sal_Bool			mbRemoveFile;
65 	sal_Bool			mbInClosed;
66 	sal_Bool			mbOutClosed;
67 
68 	sal_Int64			mnCachedPos;
69 	sal_Bool			mbHasCachedPos;
70 
71 	void checkError () const;
72 	void checkConnected ();
73 
74 public:
75 	OTempFileService (::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);
76 
77 	//Methods
78 	//	XInterface
79 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType )
80 		throw (::com::sun::star::uno::RuntimeException);
81 	virtual void SAL_CALL acquire(  )
82 		throw ();
83 	virtual void SAL_CALL release(  )
84 		throw ();
85 	//	XTypeProvider
86 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  )
87 		throw (::com::sun::star::uno::RuntimeException);
88 	virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getImplementationId(  )
89 		throw (::com::sun::star::uno::RuntimeException);
90 
91 	//	XTempFile
92 	virtual ::sal_Bool SAL_CALL getRemoveFile()
93 		throw (::com::sun::star::uno::RuntimeException);
94 	virtual void SAL_CALL setRemoveFile( ::sal_Bool _removefile )
95 		throw (::com::sun::star::uno::RuntimeException);
96 	virtual ::rtl::OUString SAL_CALL getUri()
97 		throw (::com::sun::star::uno::RuntimeException);
98 	virtual ::rtl::OUString SAL_CALL getResourceName()
99 		throw (::com::sun::star::uno::RuntimeException);
100 
101     // XInputStream
102     virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
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 readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
105 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
106     virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip )
107 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
108     virtual ::sal_Int32 SAL_CALL available(  )
109 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
110     virtual void SAL_CALL closeInput(  )
111 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
112 	// XOutputStream
113 	virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData )
114 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
115     virtual void SAL_CALL flush(  )
116 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
117     virtual void SAL_CALL closeOutput(  )
118 		throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
119 	// XSeekable
120     virtual void SAL_CALL seek( sal_Int64 location )
121 		throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
122     virtual sal_Int64 SAL_CALL getPosition(  )
123 		throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
124     virtual sal_Int64 SAL_CALL getLength(  )
125 		throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
126 	// XStream
127     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream(  )
128 		throw (::com::sun::star::uno::RuntimeException);
129     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream(  )
130 		throw (::com::sun::star::uno::RuntimeException);
131 	// XTruncate
132     virtual void SAL_CALL truncate()
133 		throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
134 	// XServiceInfo
135     virtual ::rtl::OUString SAL_CALL getImplementationName()
136 		throw (::com::sun::star::uno::RuntimeException);
137 	virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
138 		throw (::com::sun::star::uno::RuntimeException);
139     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
140 		throw (::com::sun::star::uno::RuntimeException);
141 
142 	//::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);
143 	static ::rtl::OUString getImplementationName_Static ();
144 	static ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames_Static();
145 
146 	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 );
147 
148 private:
149 	OTempFileService( OTempFileService & );
150 	virtual ~OTempFileService ();
151 
152 };
153 #endif
154