Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / hsqldb / accesslog.hxx
blob99af74503f3c1187aa98b038124abd030e678b59
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX
23 #ifdef HSQLDB_DBG
25 #include <stdio.h>
26 #include <jni.h>
27 #include <rtl/ustring.hxx>
28 #include <rtl/string.hxx>
30 namespace connectivity { namespace hsqldb
32 class LogFile
34 private:
35 OUString m_sFileName;
37 public:
38 LogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix );
40 public:
41 void writeString( const sal_Char* _pString, bool _bEndLine = true );
42 void create() { getLogFile(); }
43 virtual void close();
45 protected:
46 FILE*& getLogFile();
49 class OperationLogFile : public LogFile
51 public:
52 OperationLogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix )
53 :LogFile( env, streamName, ( OString( _pAsciiSuffix ) += ".op" ).getStr() )
57 void logOperation( const sal_Char* _pOp )
59 writeString( _pOp, true );
62 void logOperation( const sal_Char* _pOp, jlong _nLongArg )
64 OString sLine( _pOp );
65 sLine += "( ";
66 sLine += OString::number( _nLongArg );
67 sLine += " )";
68 writeString( sLine.getStr(), true );
71 void logReturn( jlong _nRetVal )
73 OString sLine( " -> " );
74 sLine += OString::number( _nRetVal );
75 writeString( sLine.getStr(), true );
78 void logReturn( jint _nRetVal )
80 OString sLine( " -> " );
81 sLine += OString::number( _nRetVal );
82 writeString( sLine.getStr(), true );
85 virtual void close()
87 writeString( "-------------------------------", true );
88 writeString( "", true );
89 LogFile::close();
93 class DataLogFile : public LogFile
95 public:
96 DataLogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix )
97 :LogFile( env, streamName, _pAsciiSuffix )
101 void write( jint value )
103 fputc( value, getLogFile() );
104 fflush( getLogFile() );
107 void write( const sal_Int8* buffer, sal_Int32 bytesRead )
109 fwrite( buffer, sizeof(sal_Int8), bytesRead, getLogFile() );
110 fflush( getLogFile() );
113 sal_Int64 seek( sal_Int64 pos )
115 FILE* pFile = getLogFile();
116 fseek( pFile, 0, SEEK_END );
117 if ( ftell( pFile ) < pos )
119 sal_Int8 filler( 0 );
120 while ( ftell( pFile ) < pos )
121 fwrite( &filler, sizeof( sal_Int8 ), 1, pFile );
122 fflush( pFile );
124 fseek( pFile, pos, SEEK_SET );
125 return ftell( pFile );
128 sal_Int64 tell()
130 return ftell( getLogFile() );
135 #endif
137 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */