|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <centralrepository.h> |
|
20 #include <ecom/ecom.h> |
|
21 #include <f32file.h> |
|
22 #include <bautils.h> |
|
23 |
|
24 #include "epos_cpospsycrlog.h" |
|
25 |
|
26 // Constant Definitions |
|
27 const TUid KPosPsyInterfaceUid = {0x101f7a7c}; |
|
28 const TInt KMaximumNameLength = 25; |
|
29 _LIT(KPsyTesterDir, ":\\logs\\psytester\\"); |
|
30 |
|
31 |
|
32 // Global Functions |
|
33 // --------------------------------------------------------- |
|
34 // ResetAndDestroy Resets and destroys the members in a RImplInfoPtrArray. This |
|
35 // function can be used as a TCleanupItem. |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 void ResetAndDestroy( |
|
39 TAny* aArray) |
|
40 { |
|
41 ((RImplInfoPtrArray*)aArray)->ResetAndDestroy(); |
|
42 } |
|
43 |
|
44 |
|
45 // ================= MEMBER FUNCTIONS ======================= |
|
46 |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // |
|
50 CPosPSYCRLog::CPosPSYCRLog() |
|
51 { |
|
52 } |
|
53 |
|
54 // EPOC default constructor can leave. |
|
55 void CPosPSYCRLog::ConstructL() |
|
56 { |
|
57 User::LeaveIfError(iFileSession.Connect()); |
|
58 } |
|
59 |
|
60 // Two-phased constructor. |
|
61 CPosPSYCRLog* CPosPSYCRLog::NewL() |
|
62 { |
|
63 CPosPSYCRLog* self = new (ELeave) CPosPSYCRLog; |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(self); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // Destructor |
|
71 CPosPSYCRLog::~CPosPSYCRLog() |
|
72 { |
|
73 REComSession::FinalClose(); |
|
74 iFileSession.Close(); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------- |
|
78 // CPosPSYLog::OpenLogL |
|
79 // |
|
80 // (other items were commented in a header). |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 void CPosPSYCRLog::OpenLogL(TUid aUid ) |
|
84 { |
|
85 // Get the name of the PSY |
|
86 RImplInfoPtrArray implInfoArray; |
|
87 CleanupStack::PushL(TCleanupItem(*ResetAndDestroy, &implInfoArray)); |
|
88 REComSession::ListImplementationsL(KPosPsyInterfaceUid, implInfoArray); |
|
89 |
|
90 TInt found = 0, index; |
|
91 |
|
92 for (index = 0; index < implInfoArray.Count() && !found; index++) |
|
93 { |
|
94 found = (aUid == implInfoArray[index]->ImplementationUid()); |
|
95 } |
|
96 if (!found) |
|
97 { |
|
98 User::Leave(KErrNotFound); |
|
99 } |
|
100 |
|
101 if(index > 0) |
|
102 index --; |
|
103 |
|
104 TBuf<KMaximumNameLength> psyDisplayName; |
|
105 const TDesC& displayName = implInfoArray[index]->DisplayName(); |
|
106 TInt copyLength = Min(displayName.Length(), KMaximumNameLength); |
|
107 psyDisplayName.Copy(displayName.Left(copyLength)); |
|
108 |
|
109 TLex psyName(psyDisplayName); |
|
110 |
|
111 TBuf<KMaxFileName> fileName; |
|
112 |
|
113 TDriveNumber cDrive; |
|
114 User::LeaveIfError(BaflUtils::GetSystemDrive(cDrive)); |
|
115 TChar cDriveChar; |
|
116 User::LeaveIfError(RFs::DriveToChar(cDrive, cDriveChar)); |
|
117 TFileName crTesterExe; |
|
118 fileName.Append(cDriveChar); |
|
119 fileName.Append(KPsyTesterDir); |
|
120 |
|
121 while (!psyName.Eos()) |
|
122 { |
|
123 if (psyName.Peek().IsDigit() || psyName.Peek().IsAlpha()) |
|
124 { |
|
125 fileName.Append(psyName.Get()); |
|
126 } |
|
127 else |
|
128 { |
|
129 psyName.Inc(); |
|
130 } |
|
131 } |
|
132 |
|
133 fileName.Append('_'); |
|
134 |
|
135 TLex psyUidLex(aUid.Name()); |
|
136 |
|
137 while (!psyUidLex.Eos()) |
|
138 { |
|
139 if (psyUidLex.Peek() != '[' && psyUidLex.Peek() != ']') |
|
140 { |
|
141 fileName.Append(psyUidLex.Get()); |
|
142 } |
|
143 else |
|
144 { |
|
145 psyUidLex.Inc(); |
|
146 } |
|
147 } |
|
148 |
|
149 _LIT(KLogExtension,".txt"); |
|
150 |
|
151 fileName.Append(KLogExtension); |
|
152 |
|
153 TInt error = iCurrentLogFile.Open(iFileSession, fileName, EFileWrite | EFileShareExclusive); |
|
154 if(KErrNone != error) |
|
155 { |
|
156 User::LeaveIfError(error); |
|
157 } |
|
158 |
|
159 iCurrentLogFile.Seek(ESeekEnd, iCurrentPosition); |
|
160 |
|
161 CleanupStack::PopAndDestroy(&implInfoArray); |
|
162 |
|
163 return; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------- |
|
167 // CPosPSYLog::AppendLineL |
|
168 // |
|
169 // (other items were commented in a header). |
|
170 // --------------------------------------------------------- |
|
171 |
|
172 void CPosPSYCRLog::CloseLog() |
|
173 { |
|
174 iCurrentLogFile.Flush(); |
|
175 iCurrentLogFile.Close(); |
|
176 } |
|
177 // --------------------------------------------------------- |
|
178 // CPosPSYLog::AppendLineL |
|
179 // |
|
180 // (other items were commented in a header). |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 void CPosPSYCRLog::AppendLineL( |
|
184 const TDesC& aLine) |
|
185 { |
|
186 HBufC8* buf; |
|
187 buf = HBufC8::NewLC(aLine.Length()); |
|
188 TPtr8 ptr = buf->Des(); |
|
189 ptr.Zero(); |
|
190 ptr.Append(aLine); |
|
191 iCurrentLogFile.Write(ptr); |
|
192 CleanupStack::PopAndDestroy(buf); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------- |
|
196 // CPosPSYLog::AppendLineL |
|
197 // |
|
198 // (other items were commented in a header). |
|
199 // --------------------------------------------------------- |
|
200 // |
|
201 void CPosPSYCRLog::AppendLineL( |
|
202 const TInt aNumber) |
|
203 { |
|
204 TBuf<KMaxNumberSize> number; |
|
205 number.AppendNum(aNumber); |
|
206 AppendLineL(number); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CPosPSYLog::AppendLineL |
|
211 // |
|
212 // (other items were commented in a header). |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 void CPosPSYCRLog::AppendInfoMsgL(TDesC &aMsg) |
|
216 { |
|
217 AppendLineL(KInfoMessage); |
|
218 AppendLineL(aMsg); |
|
219 AppendLineL(KNewLine); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------- |
|
223 // CPosPSYLog::AppendLineL |
|
224 // |
|
225 // (other items were commented in a header). |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CPosPSYCRLog::AppendWarningMsgL(TDesC &aMsg) |
|
229 { |
|
230 AppendLineL(KWarningMessage); |
|
231 AppendLineL(aMsg); |
|
232 AppendLineL(KNewLine); |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CPosPSYLog::AppendLineL |
|
237 // |
|
238 // (other items were commented in a header). |
|
239 // --------------------------------------------------------- |
|
240 // |
|
241 void CPosPSYCRLog::AppendErrorMsgL(TDesC &aMsg) |
|
242 { |
|
243 AppendLineL(KErrorMessage); |
|
244 AppendLineL(aMsg); |
|
245 AppendLineL(KNewLine); |
|
246 } |
|
247 // End of File |