114
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Implementation of ChspsLogBusFile.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "hspslogbusfile.h"
|
|
20 |
#include "e32debug.h"
|
|
21 |
#include "f32file.h"
|
|
22 |
// Constants
|
|
23 |
|
|
24 |
#ifdef HSPS_BUILD_LOG_IMPLEMENTATION
|
|
25 |
_LIT( KDefaultLoggingDirectory, "hsps" );
|
|
26 |
_LIT( KTimeFormatAndExtension, "%F%D_%M_%Y_%H_%T_%C.log"); // F=FORCE, dd_mm_yyyy_hh_mm_mmmmmm
|
|
27 |
const TInt KTimeFormatAndExtensionMaxLength = ( 2 + 1 ) + // 'dd_'
|
|
28 |
( 2 + 1 ) + // 'mm_'
|
|
29 |
( 4 + 1 ) + // 'yyyy_'
|
|
30 |
( 2 + 1 ) + // 'hh_'
|
|
31 |
( 2 + 1 ) + // 'mm_'
|
|
32 |
( 6 + 1 ) + // 'mmmmmm_'
|
|
33 |
( 4 ) + // '.log'
|
|
34 |
( 16 ) ; // overflow protection
|
|
35 |
#endif
|
|
36 |
|
|
37 |
// Methods
|
|
38 |
|
|
39 |
//----------------------------------------------------------------------------
|
|
40 |
// ChspsLogBusFile::~ChspsLogBusFile
|
|
41 |
// ----------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
#ifdef HSPS_BUILD_LOG_IMPLEMENTATION
|
|
44 |
EXPORT_C ChspsLogBusFile::~ChspsLogBusFile()
|
|
45 |
{
|
|
46 |
iFileLogger.CloseLog();
|
|
47 |
iFileLogger.Close();
|
|
48 |
|
|
49 |
delete iLoggingFile; iLoggingFile = NULL;
|
|
50 |
delete iLoggingDirectory; iLoggingDirectory = NULL;
|
|
51 |
}
|
|
52 |
#else
|
|
53 |
EXPORT_C ChspsLogBusFile::~ChspsLogBusFile()
|
|
54 |
{
|
|
55 |
}
|
|
56 |
#endif
|
|
57 |
//----------------------------------------------------------------------------
|
|
58 |
// ChspsLogBusFile::NewL
|
|
59 |
// ----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
EXPORT_C ChspsLogBusFile* ChspsLogBusFile::NewL( const TDesC& aLoggingFile,
|
|
62 |
const TDesC& aLoggingDirectory )
|
|
63 |
{
|
|
64 |
ChspsLogBusFile* self = ChspsLogBusFile::NewLC( aLoggingFile, aLoggingDirectory );
|
|
65 |
CleanupStack::Pop(); // self;
|
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
//----------------------------------------------------------------------------
|
|
70 |
// ChspsLogBusFile::NewLC
|
|
71 |
// ----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
EXPORT_C ChspsLogBusFile* ChspsLogBusFile::NewLC( const TDesC& aLoggingFile,
|
|
74 |
const TDesC& aLoggingDirectory )
|
|
75 |
{
|
|
76 |
ChspsLogBusFile* self = new (ELeave)ChspsLogBusFile();
|
|
77 |
CleanupStack::PushL(self);
|
|
78 |
self->ConstructL( aLoggingFile, aLoggingDirectory );
|
|
79 |
return self;
|
|
80 |
}
|
|
81 |
|
|
82 |
//----------------------------------------------------------------------------
|
|
83 |
// ChspsLogBusFile::CreateLogFilename
|
|
84 |
// ----------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
#ifdef HSPS_BUILD_LOG_IMPLEMENTATION
|
|
87 |
EXPORT_C TFileName ChspsLogBusFile::CreateLogFilename( const TDesC& aBaseline )
|
|
88 |
{
|
|
89 |
RFs fs;
|
|
90 |
if ( KErrNone == fs.Connect() )
|
|
91 |
{
|
|
92 |
fs.MkDirAll(_L("c:\\logs\\hsps\\"));
|
|
93 |
fs.Close();
|
|
94 |
}
|
|
95 |
|
|
96 |
TFileName fileName;
|
|
97 |
|
|
98 |
// Append baseline and trailing '_'.
|
|
99 |
fileName.Append( aBaseline );
|
|
100 |
fileName.Append( TChar('_') );
|
|
101 |
|
|
102 |
// Append Timestamp (formatting string contains extension).
|
|
103 |
TTime time;
|
|
104 |
time.HomeTime();
|
|
105 |
TBuf<KTimeFormatAndExtensionMaxLength> timestampAndExtension;
|
|
106 |
TRAPD( err, time.FormatL( timestampAndExtension, KTimeFormatAndExtension() ) );
|
|
107 |
if( err == KErrNone &&
|
|
108 |
( fileName.MaxLength() - fileName.Length() ) > timestampAndExtension.Length() )
|
|
109 |
{
|
|
110 |
fileName.Append( timestampAndExtension );
|
|
111 |
}
|
|
112 |
|
|
113 |
// Return created descriptor.
|
|
114 |
return fileName;
|
|
115 |
}
|
|
116 |
#else
|
|
117 |
EXPORT_C TFileName ChspsLogBusFile::CreateLogFilename( const TDesC& /*aBaseline*/ )
|
|
118 |
{
|
|
119 |
return KNullDesC();
|
|
120 |
}
|
|
121 |
#endif
|
|
122 |
|
|
123 |
//----------------------------------------------------------------------------
|
|
124 |
// ChspsLogBusFile::_LogText
|
|
125 |
// ----------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
#ifdef HSPS_BUILD_LOG_IMPLEMENTATION
|
|
128 |
void ChspsLogBusFile::_LogText( const TDesC& aMessage)
|
|
129 |
{
|
|
130 |
iFileLogger.Write( aMessage );
|
|
131 |
}
|
|
132 |
#else
|
|
133 |
void ChspsLogBusFile::_LogText( const TDesC& /*aMessage*/ )
|
|
134 |
{
|
|
135 |
}
|
|
136 |
#endif
|
|
137 |
|
|
138 |
//----------------------------------------------------------------------------
|
|
139 |
// ChspsLogBusFile::ChspsLogBusFile
|
|
140 |
// ----------------------------------------------------------------------------
|
|
141 |
//
|
|
142 |
ChspsLogBusFile::ChspsLogBusFile()
|
|
143 |
{
|
|
144 |
iLoggingFile = NULL;
|
|
145 |
iLoggingDirectory = NULL;
|
|
146 |
}
|
|
147 |
|
|
148 |
//----------------------------------------------------------------------------
|
|
149 |
// ChspsLogBusFile::ConstructL
|
|
150 |
// ----------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
#ifdef HSPS_BUILD_LOG_IMPLEMENTATION
|
|
153 |
void ChspsLogBusFile::ConstructL( const TDesC& aLoggingFile,
|
|
154 |
const TDesC& aLoggingDirectory )
|
|
155 |
{
|
|
156 |
iLoggingFile = aLoggingFile.AllocL();
|
|
157 |
if( aLoggingDirectory != KNullDesC() )
|
|
158 |
{
|
|
159 |
iLoggingDirectory = aLoggingDirectory.AllocL();
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
iLoggingDirectory = KDefaultLoggingDirectory().AllocL();
|
|
164 |
}
|
|
165 |
|
|
166 |
User::LeaveIfError( iFileLogger.Connect() );
|
|
167 |
iFileLogger.CreateLog( *iLoggingDirectory,
|
|
168 |
*iLoggingFile,
|
|
169 |
EFileLoggingModeOverwrite );
|
|
170 |
iFileLogger.SetDateAndTime( EFalse, ETrue );
|
|
171 |
}
|
|
172 |
#else
|
|
173 |
void ChspsLogBusFile::ConstructL( const TDesC& /*aLoggingFile*/,
|
|
174 |
const TDesC& /*aLoggingDirectory*/ )
|
|
175 |
{
|
|
176 |
}
|
|
177 |
#endif
|