1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 namespace fileaccess
{
34 void ReconnectingFile::disconnect()
37 m_bDisconnect
= sal_True
;
40 sal_Bool
ReconnectingFile::reconnect()
42 sal_Bool bResult
= sal_False
;
46 if ( m_aFile
.open( m_nFlags
) == ::osl::FileBase::E_None
47 || m_aFile
.open( osl_File_OpenFlag_Read
) == ::osl::FileBase::E_None
)
49 m_bDisconnect
= sal_False
;
57 ::osl::FileBase::RC
ReconnectingFile::open( sal_uInt32 uFlags
)
59 ::osl::FileBase::RC nResult
= m_aFile
.open( uFlags
);
60 if ( nResult
== ::osl::FileBase::E_None
)
62 if ( uFlags
& osl_File_OpenFlag_Create
)
63 m_nFlags
= (uFlags
& ( ~osl_File_OpenFlag_Create
)) | osl_File_OpenFlag_Write
;
67 m_bFlagsSet
= sal_True
;
73 ::osl::FileBase::RC
ReconnectingFile::close()
76 m_bFlagsSet
= sal_False
;
77 m_bDisconnect
= sal_False
;
79 return m_aFile
.close();
82 ::osl::FileBase::RC
ReconnectingFile::setPos( sal_uInt32 uHow
, sal_Int64 uPos
)
84 ::osl::FileBase::RC nRes
= ::osl::FileBase::E_NETWORK
;
86 if ( uHow
== osl_Pos_Absolut
&& uPos
> 0 )
91 nRes
= m_aFile
.setPos( uHow
, uPos
);
95 // E_INVAL error code means in this case that
96 // the file handler is invalid
97 nRes
= m_aFile
.setPos( uHow
, uPos
);
98 if ( ( nRes
== ::osl::FileBase::E_NETWORK
99 || nRes
== ::osl::FileBase::E_INVAL
)
101 nRes
= m_aFile
.setPos( uHow
, uPos
);
106 if ( !m_bDisconnect
)
107 nRes
= m_aFile
.setPos( uHow
, uPos
);
113 ::osl::FileBase::RC
ReconnectingFile::getPos( sal_uInt64
& uPos
)
116 return ::osl::FileBase::E_NETWORK
;
118 return m_aFile
.getPos( uPos
);
121 ::osl::FileBase::RC
ReconnectingFile::setSize( sal_uInt64 uSize
)
123 ::osl::FileBase::RC nRes
= ::osl::FileBase::E_NETWORK
;
130 nRes
= m_aFile
.setSize( uSize
);
134 // E_INVAL error code means in this case that
135 // the file handler is invalid
136 nRes
= m_aFile
.setSize( uSize
);
137 if ( ( nRes
== ::osl::FileBase::E_NETWORK
138 || nRes
== ::osl::FileBase::E_INVAL
)
140 nRes
= m_aFile
.setSize( uSize
);
145 if ( !m_bDisconnect
)
146 nRes
= m_aFile
.setSize( uSize
);
152 ::osl::FileBase::RC
ReconnectingFile::getSize( sal_uInt64
&rSize
)
154 ::osl::FileBase::RC nRes
= ::osl::FileBase::E_NETWORK
;
156 if ( !m_bDisconnect
)
157 nRes
= m_aFile
.getSize( rSize
);
159 // E_INVAL error code means in this case that
160 // the file handler is invalid
161 if ( ( nRes
== ::osl::FileBase::E_NETWORK
162 || nRes
== ::osl::FileBase::E_INVAL
)
165 nRes
= m_aFile
.getSize( rSize
);
167 // the repairing should be disconnected, since the position might be wrong
168 // but the result should be retrieved
175 ::osl::FileBase::RC
ReconnectingFile::read( void *pBuffer
, sal_uInt64 uBytesRequested
, sal_uInt64
& rBytesRead
)
178 return ::osl::FileBase::E_NETWORK
;
180 return m_aFile
.read( pBuffer
, uBytesRequested
, rBytesRead
);
183 ::osl::FileBase::RC
ReconnectingFile::write(const void *pBuffer
, sal_uInt64 uBytesToWrite
, sal_uInt64
& rBytesWritten
)
186 return ::osl::FileBase::E_NETWORK
;
188 return m_aFile
.write( pBuffer
, uBytesToWrite
, rBytesWritten
);
191 ::osl::FileBase::RC
ReconnectingFile::sync() const
194 return ::osl::FileBase::E_NETWORK
;
196 return m_aFile
.sync();
199 } // namespace fileaccess
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */