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: accesslog.hxx,v $
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 #ifndef CONNECTIVITY_HSQLDB_ACCESSLOG_HXX
32 #define CONNECTIVITY_HSQLDB_ACCESSLOG_HXX
38 #include <rtl/ustring.hxx>
39 #include <rtl/string.hxx>
41 namespace connectivity
{ namespace hsqldb
46 ::rtl::OUString m_sFileName
;
49 LogFile( JNIEnv
* env
, jstring streamName
, const sal_Char
* _pAsciiSuffix
);
52 void writeString( const sal_Char
* _pString
, bool _bEndLine
= true );
53 void create() { getLogFile(); }
60 class OperationLogFile
: public LogFile
63 OperationLogFile( JNIEnv
* env
, jstring streamName
, const sal_Char
* _pAsciiSuffix
)
64 :LogFile( env
, streamName
, ( ::rtl::OString( _pAsciiSuffix
) += ".op" ).getStr() )
68 void logOperation( const sal_Char
* _pOp
)
70 writeString( _pOp
, true );
73 void logOperation( const sal_Char
* _pOp
, jlong _nLongArg
)
75 ::rtl::OString
sLine( _pOp
);
77 sLine
+= ::rtl::OString::valueOf( _nLongArg
);
79 writeString( sLine
.getStr(), true );
82 void logReturn( jlong _nRetVal
)
84 ::rtl::OString
sLine( " -> " );
85 sLine
+= ::rtl::OString::valueOf( _nRetVal
);
86 writeString( sLine
.getStr(), true );
89 void logReturn( jint _nRetVal
)
91 ::rtl::OString
sLine( " -> " );
92 sLine
+= ::rtl::OString::valueOf( _nRetVal
);
93 writeString( sLine
.getStr(), true );
98 writeString( "-------------------------------", true );
99 writeString( "", true );
104 class DataLogFile
: public LogFile
107 DataLogFile( JNIEnv
* env
, jstring streamName
, const sal_Char
* _pAsciiSuffix
)
108 :LogFile( env
, streamName
, _pAsciiSuffix
)
112 void write( jint value
)
114 fputc( value
, getLogFile() );
115 fflush( getLogFile() );
118 void write( const sal_Int8
* buffer
, sal_Int32 bytesRead
)
120 fwrite( buffer
, sizeof(sal_Int8
), bytesRead
, getLogFile() );
121 fflush( getLogFile() );
124 sal_Int64
seek( sal_Int64 pos
)
126 FILE* pFile
= getLogFile();
127 fseek( pFile
, 0, SEEK_END
);
128 if ( ftell( pFile
) < pos
)
130 sal_Int8
filler( 0 );
131 while ( ftell( pFile
) < pos
)
132 fwrite( &filler
, sizeof( sal_Int8
), 1, pFile
);
135 fseek( pFile
, pos
, SEEK_SET
);
136 return ftell( pFile
);
141 return ftell( getLogFile() );
148 #endif // CONNECTIVITY_HSQLDB_ACCESSLOG_HXX