|
1 // Copyright (c) 2007-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 /** |
|
19 @file te_tracecontroltestplugin.cpp |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32debug.h> |
|
25 #include <implementationproxy.h> |
|
26 #include "te_tracecontroltestplugin.h" |
|
27 |
|
28 #if defined(__TEST_LIGHTLOGGER_ENABLED) |
|
29 #include "te_lightlogger.h" |
|
30 #endif |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 /** |
|
37 Public Destructor |
|
38 */ |
|
39 CTestFileWriter::~CTestFileWriter() |
|
40 { |
|
41 if(iIsOpen) |
|
42 { |
|
43 iLog.Close(); |
|
44 } |
|
45 iFs.Close(); |
|
46 } |
|
47 |
|
48 /** |
|
49 Creates an instance of CTestFileWriter object |
|
50 @return a pointer to the new created CTestFileWriter Object |
|
51 @leave KErrNoMemory if no memory |
|
52 */ |
|
53 CTestFileWriter* CTestFileWriter::NewL() |
|
54 { |
|
55 CTestFileWriter *me = new (ELeave) CTestFileWriter; |
|
56 CleanupStack::PushL(me); |
|
57 me->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return me; |
|
60 } |
|
61 |
|
62 void CTestFileWriter::ConstructL() |
|
63 { |
|
64 User::LeaveIfError(iFs.Connect()); |
|
65 iIsOpen = EFalse; |
|
66 iErrorCode = 0; |
|
67 iCountDown = 3; |
|
68 iFileName.Copy(KTestLogDefaultFileName); |
|
69 } |
|
70 |
|
71 //Default constructor |
|
72 CTestFileWriter::CTestFileWriter():iMutex(NULL) |
|
73 { |
|
74 } |
|
75 |
|
76 |
|
77 void CTestFileWriter::CloseOutputPlugin() |
|
78 { |
|
79 if(!iIsOpen) |
|
80 { |
|
81 return; |
|
82 } |
|
83 iLog.Flush(); |
|
84 iLog.Close(); |
|
85 iIsOpen = EFalse; |
|
86 } |
|
87 |
|
88 void CTestFileWriter::DoClearLog() |
|
89 { |
|
90 OpenLog(); |
|
91 if(iIsOpen) |
|
92 { |
|
93 iLog.Close(); |
|
94 iIsOpen = EFalse; |
|
95 iFs.Delete(iFileName); |
|
96 } |
|
97 } |
|
98 |
|
99 TInt CTestFileWriter::ConfigureOutputPlugin(const RPointerArray<TPluginConfiguration>& aConfigs) |
|
100 { |
|
101 CloseOutputPlugin(); |
|
102 |
|
103 TInt i = aConfigs.Count(); |
|
104 while(i-->0) |
|
105 { |
|
106 TPluginConfiguration* set = aConfigs[i]; |
|
107 if(set->Key().Compare(KTestOutputPath) == 0) |
|
108 { |
|
109 if(set->Value().Length() < iFileName.MaxLength()) |
|
110 { |
|
111 iFileName.Copy(set->Value()); |
|
112 } |
|
113 } |
|
114 else if(set->Key().Compare(KErrorCode) == 0) |
|
115 { |
|
116 iErrorCode = KErrGeneral; |
|
117 } |
|
118 } |
|
119 return KErrNone; |
|
120 } |
|
121 |
|
122 |
|
123 TInt CTestFileWriter::OpenLog() |
|
124 { |
|
125 TInt err = KErrNone; |
|
126 if(!iIsOpen) |
|
127 { |
|
128 //Check that the log file exists, if not create a blank one. |
|
129 TInt err = iLog.Open(iFs, iFileName, EFileWrite | EFileShareAny); |
|
130 if(err==KErrPathNotFound || err==KErrNotFound) |
|
131 { |
|
132 err = iFs.MkDirAll(iFileName); |
|
133 if(err!=KErrNone && err!=KErrAlreadyExists) |
|
134 { |
|
135 return err; |
|
136 } |
|
137 err = iLog.Create(iFs, iFileName, EFileWrite | EFileShareAny); |
|
138 } |
|
139 if(err!=KErrNone) |
|
140 { |
|
141 return err; |
|
142 } |
|
143 iIsOpen = ETrue; |
|
144 } |
|
145 return err; |
|
146 } |
|
147 |
|
148 TInt CTestFileWriter::Write(const TDesC8& aText) |
|
149 { |
|
150 #if defined(__TEST_LIGHTLOGGER_ENABLED) && defined(__VERBOSE_MODE) |
|
151 __TEST_MARK_METHOD("CFileWriter::Write") |
|
152 #endif |
|
153 |
|
154 if(!iErrorCode) |
|
155 return WriteToFile(aText); |
|
156 else |
|
157 { |
|
158 if(--iCountDown > 0) |
|
159 return KErrNone; |
|
160 else |
|
161 { |
|
162 RDebug::Printf("Returning error code (%d) from test plugin", iErrorCode); |
|
163 User::InfoPrint(_L("writing with error - ok")); |
|
164 return iErrorCode; |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 TBool CTestFileWriter::DoOwnProcessing() |
|
170 { |
|
171 return EFalse; |
|
172 } |
|
173 |
|
174 TInt CTestFileWriter::WriteToFile(const TDesC8& aText) |
|
175 { |
|
176 TInt err = KErrNone; |
|
177 if(!iIsOpen) |
|
178 { |
|
179 err = OpenLog(); |
|
180 if(err!=KErrNone) |
|
181 return err; |
|
182 } |
|
183 iLog.Write(0x7FFFFFFF, aText); |
|
184 |
|
185 return err; |
|
186 } |
|
187 |
|
188 |
|
189 TAny* CTestFileWriter::GetInterfaceL(CPlugin::TPluginInterface aInterfaceId) |
|
190 { |
|
191 if(aInterfaceId == MOutputPlugin::iInterfaceId) |
|
192 return static_cast<MOutputPlugin*>(this); |
|
193 else |
|
194 return NULL; |
|
195 } |
|
196 |
|
197 |
|
198 |
|
199 //ECOM interface implementations |
|
200 |
|
201 // Map the interface implementation UIDs to implementation factory functions |
|
202 const TImplementationProxy ImplementationTable[] = |
|
203 { |
|
204 // {{0x102836BF},CTestFileWriter::NewL} |
|
205 IMPLEMENTATION_PROXY_ENTRY(0x102836BF, CTestFileWriter::NewL) |
|
206 }; |
|
207 |
|
208 |
|
209 // Exported proxy for instantiation method resolution. |
|
210 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
211 TInt& aTableCount) |
|
212 { |
|
213 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
214 return ImplementationTable; |
|
215 } |