1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filrec.cxx,v $
10 * $Revision: 1.3.22.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
36 namespace fileaccess
{
38 void ReconnectingFile::disconnect()
41 m_bDisconnect
= sal_True
;
44 sal_Bool
ReconnectingFile::reconnect()
46 sal_Bool bResult
= sal_False
;
50 if ( m_aFile
.open( m_nFlags
) == ::osl::FileBase::E_None
51 || m_aFile
.open( OpenFlag_Read
) == ::osl::FileBase::E_None
)
53 m_bDisconnect
= sal_False
;
61 ::osl::FileBase::RC
ReconnectingFile::open( sal_uInt32 uFlags
)
63 ::osl::FileBase::RC nResult
= m_aFile
.open( uFlags
);
64 if ( nResult
== ::osl::FileBase::E_None
)
66 if ( uFlags
& OpenFlag_Create
)
67 m_nFlags
= (uFlags
& ( ~OpenFlag_Create
)) | OpenFlag_Write
;
71 m_bFlagsSet
= sal_True
;
77 ::osl::FileBase::RC
ReconnectingFile::close()
80 m_bFlagsSet
= sal_False
;
81 m_bDisconnect
= sal_False
;
83 return m_aFile
.close();
86 ::osl::FileBase::RC
ReconnectingFile::setPos( sal_uInt32 uHow
, sal_Int64 uPos
)
88 ::osl::FileBase::RC nRes
= ::osl::FileBase::E_NETWORK
;
90 if ( uHow
== Pos_Absolut
&& uPos
> 0 )
95 nRes
= m_aFile
.setPos( uHow
, uPos
);
99 // E_INVAL error code means in this case that
100 // the file handler is invalid
101 nRes
= m_aFile
.setPos( uHow
, uPos
);
102 if ( ( nRes
== ::osl::FileBase::E_NETWORK
103 || nRes
== ::osl::FileBase::E_INVAL
)
105 nRes
= m_aFile
.setPos( uHow
, uPos
);
110 if ( !m_bDisconnect
)
111 nRes
= m_aFile
.setPos( uHow
, uPos
);
117 ::osl::FileBase::RC
ReconnectingFile::getPos( sal_uInt64
& uPos
)
120 return ::osl::FileBase::E_NETWORK
;
122 return m_aFile
.getPos( uPos
);
125 ::osl::FileBase::RC
ReconnectingFile::setSize( sal_uInt64 uSize
)
127 ::osl::FileBase::RC nRes
= ::osl::FileBase::E_NETWORK
;
134 nRes
= m_aFile
.setSize( uSize
);
138 // E_INVAL error code means in this case that
139 // the file handler is invalid
140 nRes
= m_aFile
.setSize( uSize
);
141 if ( ( nRes
== ::osl::FileBase::E_NETWORK
142 || nRes
== ::osl::FileBase::E_INVAL
)
144 nRes
= m_aFile
.setSize( uSize
);
149 if ( !m_bDisconnect
)
150 nRes
= m_aFile
.setSize( uSize
);
156 ::osl::FileBase::RC
ReconnectingFile::getSize( sal_uInt64
&rSize
)
158 ::osl::FileBase::RC nRes
= ::osl::FileBase::E_NETWORK
;
160 if ( !m_bDisconnect
)
161 nRes
= m_aFile
.getSize( rSize
);
163 // E_INVAL error code means in this case that
164 // the file handler is invalid
165 if ( ( nRes
== ::osl::FileBase::E_NETWORK
166 || nRes
== ::osl::FileBase::E_INVAL
)
169 nRes
= m_aFile
.getSize( rSize
);
171 // the repairing should be disconnected, since the position might be wrong
172 // but the result should be retrieved
179 ::osl::FileBase::RC
ReconnectingFile::read( void *pBuffer
, sal_uInt64 uBytesRequested
, sal_uInt64
& rBytesRead
)
182 return ::osl::FileBase::E_NETWORK
;
184 return m_aFile
.read( pBuffer
, uBytesRequested
, rBytesRead
);
187 ::osl::FileBase::RC
ReconnectingFile::write(const void *pBuffer
, sal_uInt64 uBytesToWrite
, sal_uInt64
& rBytesWritten
)
190 return ::osl::FileBase::E_NETWORK
;
192 return m_aFile
.write( pBuffer
, uBytesToWrite
, rBytesWritten
);
195 ::osl::FileBase::RC
ReconnectingFile::sync() const
198 return ::osl::FileBase::E_NETWORK
;
200 return m_aFile
.sync();
203 } // namespace fileaccess