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