LibreOffice Module connectivity (master) 1
accesslog.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#ifdef HSQLDB_DBG
23
24#include <jni.h>
25#include <rtl/ustring.hxx>
26#include <rtl/string.hxx>
27
29{
30 class LogFile
31 {
32 private:
33 OUString m_sFileName;
34
35 public:
36 LogFile( JNIEnv* env, jstring streamName, const char* _pAsciiSuffix );
37
38 public:
39 void writeString( const char* _pString, bool _bEndLine = true );
40 void create() { getLogFile(); }
41 virtual void close();
42
43 protected:
44 FILE*& getLogFile();
45 };
46
47 class OperationLogFile : public LogFile
48 {
49 public:
50 OperationLogFile( JNIEnv* env, jstring streamName, const char* _pAsciiSuffix )
51 :LogFile( env, streamName, ( OString( _pAsciiSuffix ) += ".op" ).getStr() )
52 {
53 }
54
55 void logOperation( const char* _pOp )
56 {
57 writeString( _pOp, true );
58 }
59
60 void logOperation( const char* _pOp, jlong _nLongArg )
61 {
62 OString sLine( _pOp );
63 sLine += "( ";
64 sLine += OString::number( _nLongArg );
65 sLine += " )";
66 writeString( sLine.getStr(), true );
67 }
68
69 void logReturn( jlong _nRetVal )
70 {
71 OString sLine( " -> " );
72 sLine += OString::number( _nRetVal );
73 writeString( sLine.getStr(), true );
74 }
75
76 void logReturn( jint _nRetVal )
77 {
78 OString sLine( " -> " );
79 sLine += OString::number( _nRetVal );
80 writeString( sLine.getStr(), true );
81 }
82
83 virtual void close()
84 {
85 writeString( "-------------------------------", true );
86 writeString( "", true );
87 LogFile::close();
88 }
89 };
90
91 class DataLogFile : public LogFile
92 {
93 public:
94 DataLogFile( JNIEnv* env, jstring streamName, const char* _pAsciiSuffix )
95 :LogFile( env, streamName, _pAsciiSuffix )
96 {
97 }
98
99 void write( jint value )
100 {
101 fputc( value, getLogFile() );
102 fflush( getLogFile() );
103 }
104
105 void write( const sal_Int8* buffer, sal_Int32 bytesRead )
106 {
107 fwrite( buffer, sizeof(sal_Int8), bytesRead, getLogFile() );
108 fflush( getLogFile() );
109 }
110
111 sal_Int64 seek( sal_Int64 pos )
112 {
113 FILE* pFile = getLogFile();
114 fseek( pFile, 0, SEEK_END );
115 if ( ftell( pFile ) < pos )
116 {
117 sal_Int8 filler( 0 );
118 while ( ftell( pFile ) < pos )
119 fwrite( &filler, sizeof( sal_Int8 ), 1, pFile );
120 fflush( pFile );
121 }
122 fseek( pFile, pos, SEEK_SET );
123 return ftell( pFile );
124 }
125
126 sal_Int64 tell()
127 {
128 return ftell( getLogFile() );
129 }
130 };
131
132} }
133#endif
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool close
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
sal_uInt32 writeString(sal_uInt8 *buffer, const sal_Unicode *v)
signed char sal_Int8