1 /* |
|
2 * Copyright (c) 2005 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: MMCScBkupLogger implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "MMCScBkupLogger.h" |
|
20 |
|
21 // System includes |
|
22 #include <coemain.h> |
|
23 #include <e32svr.h> |
|
24 #include <flogger.h> |
|
25 |
|
26 #if defined(__MMCSCBKUPLOGGING_ENABLED__) |
|
27 |
|
28 // Constants |
|
29 const TInt KMMCScBkupLoggingMaxLogTextLength = 1024; |
|
30 const TInt KMMCScBkupLoggingMaxLogSize = 10240; |
|
31 |
|
32 // ========================= MEMBER FUNCTIONS ================================ |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // MMCScBkupLogger::LogRaw() |
|
36 // |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 void MMCScBkupLogger::LogRaw( const TDesC& aData ) |
|
40 { |
|
41 #if defined(__MMCSCBKUPLOGGING_MODE_FILE__) |
|
42 |
|
43 _LIT( KMMCScBkupLoggingDir, "FMBkup" ); |
|
44 _LIT( KMMCScBkupLoggingFileName, "FMBkup.txt" ); |
|
45 |
|
46 ///////////// |
|
47 // FLOGGER |
|
48 ///////////// |
|
49 RFileLogger::Write( KMMCScBkupLoggingDir, KMMCScBkupLoggingFileName, EFileLoggingModeAppend, aData ); |
|
50 |
|
51 #elif defined(__MMCSCBKUPLOGGING_MODE_RDEBUG__) |
|
52 |
|
53 ///////////// |
|
54 // RDEBUG |
|
55 ///////////// |
|
56 _LIT( KLogComponentName, "[MMC] "); |
|
57 HBufC* printBuf = HBufC::New( aData.Length() + KLogComponentName().Length() ); |
|
58 if ( printBuf ) |
|
59 { |
|
60 TPtr pBuf( printBuf->Des() ); |
|
61 pBuf.Append( KLogComponentName ); |
|
62 pBuf.Append( aData ); |
|
63 RDebug::Print( *printBuf ); |
|
64 delete printBuf; |
|
65 } |
|
66 else |
|
67 { |
|
68 RDebug::Print( aData ); |
|
69 } |
|
70 |
|
71 #endif |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // MMCScBkupLogger::Log() |
|
77 // |
|
78 // |
|
79 // --------------------------------------------------------------------------- |
|
80 void MMCScBkupLogger::Log( TRefByValue<const TDesC> aFmt, ... ) |
|
81 { |
|
82 VA_LIST list; |
|
83 VA_START( list, aFmt ); |
|
84 |
|
85 HBufC* buf = HBufC::New( KMMCScBkupLoggingMaxLogTextLength ); |
|
86 if ( buf ) |
|
87 { |
|
88 TPtr pBuf( buf->Des() ); |
|
89 pBuf.FormatList(aFmt, list); |
|
90 LogRaw( *buf ); |
|
91 delete buf; |
|
92 } |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // MMCScBkupLogger::DataType() |
|
98 // |
|
99 // |
|
100 // --------------------------------------------------------------------------- |
|
101 const TDesC& MMCScBkupLogger::DataType( TMMCScBkupOwnerDataType aType ) |
|
102 { |
|
103 switch( aType ) |
|
104 { |
|
105 case EMMCScBkupOwnerDataTypeDataOwner: |
|
106 { |
|
107 _LIT(KRet, "EMMCScBkupOwnerDataTypeDataOwner"); |
|
108 return KRet; |
|
109 } |
|
110 case EMMCScBkupOwnerDataTypeJavaData: |
|
111 { |
|
112 _LIT(KRet, "EMMCScBkupOwnerDataTypeJavaData"); |
|
113 return KRet; |
|
114 } |
|
115 case EMMCScBkupOwnerDataTypePublicData: |
|
116 { |
|
117 _LIT(KRet, "EMMCScBkupOwnerDataTypePublicData"); |
|
118 return KRet; |
|
119 } |
|
120 case EMMCScBkupOwnerDataTypeSystemData: |
|
121 { |
|
122 _LIT(KRet, "EMMCScBkupOwnerDataTypeSystemData"); |
|
123 return KRet; |
|
124 } |
|
125 case EMMCScBkupOwnerDataTypeActiveData: |
|
126 { |
|
127 _LIT(KRet, "EMMCScBkupOwnerDataTypeActiveData"); |
|
128 return KRet; |
|
129 } |
|
130 case EMMCScBkupOwnerDataTypePassiveData: |
|
131 { |
|
132 _LIT(KRet, "EMMCScBkupOwnerDataTypePassiveData"); |
|
133 return KRet; |
|
134 } |
|
135 case EMMCScBkupOwnerDataTypeAny: |
|
136 { |
|
137 _LIT(KRet, "EMMCScBkupOwnerDataTypeAny"); |
|
138 return KRet; |
|
139 } |
|
140 default: |
|
141 break; |
|
142 } |
|
143 |
|
144 _LIT(KRet, "UNKNOWN!"); |
|
145 return KRet; |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // MMCScBkupLogger::FriendlyNameForSID() |
|
151 // |
|
152 // |
|
153 // --------------------------------------------------------------------------- |
|
154 const TDesC& MMCScBkupLogger::FriendlyNameForSID( TSecureId aSID ) |
|
155 { |
|
156 switch( aSID.iId ) |
|
157 { |
|
158 case 0x10202be9: |
|
159 { |
|
160 _LIT(KRet, "[CentRep]"); |
|
161 return KRet; |
|
162 } |
|
163 case 0x10008d38: |
|
164 { |
|
165 _LIT(KRet, "[FavouritesSrv]"); |
|
166 return KRet; |
|
167 } |
|
168 case 0x101f51f2: |
|
169 { |
|
170 _LIT(KRet, "[RightsServer]"); |
|
171 return KRet; |
|
172 } |
|
173 case 0x101f7993: |
|
174 { |
|
175 _LIT(KRet, "[VpnManager]"); |
|
176 return KRet; |
|
177 } |
|
178 case 0x101fd288: |
|
179 { |
|
180 _LIT(KRet, "[EventMediator]"); |
|
181 return KRet; |
|
182 } |
|
183 default: |
|
184 break; |
|
185 } |
|
186 |
|
187 _LIT(KRet, ""); |
|
188 return KRet; |
|
189 } |
|
190 |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // MMCScBkupLogger::LogFile() |
|
194 // |
|
195 // |
|
196 // --------------------------------------------------------------------------- |
|
197 void MMCScBkupLogger::LogFile( TRefByValue<const TDesC> aFmt, ... ) |
|
198 { |
|
199 VA_LIST list; |
|
200 VA_START( list, aFmt ); |
|
201 |
|
202 HBufC* buf = HBufC::New( KMMCScBkupLoggingMaxLogTextLength ); |
|
203 if ( buf ) |
|
204 { |
|
205 TPtr pBuf( buf->Des() ); |
|
206 pBuf.FormatList(aFmt, list); |
|
207 #ifdef _DEBUG |
|
208 LogRaw( *buf ); |
|
209 #endif |
|
210 RFile64 file; |
|
211 RFs& fsSession(CCoeEnv::Static()->FsSession()); |
|
212 TEntry entry; |
|
213 TInt error; |
|
214 |
|
215 if ( fsSession.Entry( KMMCScBkupLoggingFullPathAndName, entry ) == KErrNone ) |
|
216 { |
|
217 error = file.Open( fsSession, KMMCScBkupLoggingFullPathAndName, EFileWrite | EFileShareExclusive ); |
|
218 } |
|
219 else |
|
220 { |
|
221 entry.iSize = 0; |
|
222 error = file.Create( fsSession, KMMCScBkupLoggingFullPathAndName, EFileWrite | EFileShareExclusive ); |
|
223 } |
|
224 |
|
225 if(error == KErrNone) |
|
226 { |
|
227 TInt64 size = 0; |
|
228 |
|
229 error = file.Size( size ); |
|
230 if(error == KErrNone && size < KMMCScBkupLoggingMaxLogSize) |
|
231 { |
|
232 HBufC8* buf8 = HBufC8::New( KMMCScBkupLoggingMaxLogTextLength ); |
|
233 if(buf8) |
|
234 { |
|
235 const TText8 KLineFeed( '\n' ); |
|
236 TPtr8 data( buf8->Des() ); |
|
237 |
|
238 data.Copy(buf->Des()); |
|
239 data.Append(KLineFeed); |
|
240 file.Write(static_cast<TInt64>(entry.iSize), data); |
|
241 delete buf8; |
|
242 } |
|
243 } |
|
244 } |
|
245 file.Close(); |
|
246 delete buf; |
|
247 } |
|
248 } |
|
249 |
|
250 #endif |
|
251 |
|