|
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 #include <e32std.h> |
|
17 #include <ecom/implementationproxy.h> |
|
18 #include "uloggerfileplugin.h" |
|
19 |
|
20 |
|
21 namespace Ulogger |
|
22 { |
|
23 /** |
|
24 Public Destructor |
|
25 */ |
|
26 CFileWriter::~CFileWriter() |
|
27 { |
|
28 if(iIsOpen) |
|
29 { |
|
30 iLog.Close(); |
|
31 } |
|
32 iFs.Close(); |
|
33 } |
|
34 |
|
35 /** |
|
36 Creates an instance of CFileWriter object |
|
37 @return a pointer to the new created CFileWriter Object |
|
38 @leave KErrNoMemory if no memory |
|
39 */ |
|
40 CFileWriter* CFileWriter::NewL() |
|
41 { |
|
42 CFileWriter *me = new (ELeave) CFileWriter; |
|
43 CleanupStack::PushL(me); |
|
44 me->ConstructL(); |
|
45 CleanupStack::Pop(); |
|
46 return me; |
|
47 } |
|
48 |
|
49 void CFileWriter::ConstructL() |
|
50 { |
|
51 User::LeaveIfError(iFs.Connect()); |
|
52 iIsOpen = EFalse; |
|
53 iFileName.Copy(KLogDefaultFileName); |
|
54 } |
|
55 |
|
56 //Default constructor |
|
57 CFileWriter::CFileWriter() |
|
58 :iMutex(NULL) |
|
59 { |
|
60 } |
|
61 |
|
62 void CFileWriter::CloseOutputPlugin() |
|
63 { |
|
64 if(!iIsOpen) |
|
65 { |
|
66 return; |
|
67 } |
|
68 iLog.Flush(); |
|
69 iLog.Close(); |
|
70 iIsOpen = EFalse; |
|
71 } |
|
72 |
|
73 TInt CFileWriter::ConfigureOutputPlugin(const RPointerArray<TPluginConfiguration> &aSettings) |
|
74 { |
|
75 CloseOutputPlugin(); |
|
76 |
|
77 TInt i = aSettings.Count(); |
|
78 while(i-->0) |
|
79 { |
|
80 TPluginConfiguration* set = aSettings[i]; |
|
81 if(set->Key().Compare(KOutputPath) == 0) |
|
82 { |
|
83 if(set->Value().Length() < iFileName.MaxLength()) |
|
84 iFileName.Copy(set->Value()); |
|
85 else |
|
86 return KErrGeneral; |
|
87 } |
|
88 } |
|
89 return OpenLog(); |
|
90 } |
|
91 |
|
92 TInt CFileWriter::OpenLog() |
|
93 { |
|
94 TInt err = KErrNone; |
|
95 if(!iIsOpen) |
|
96 { |
|
97 //Check that the log file exists, if not create a blank one. |
|
98 TInt err = iLog.Open(iFs, iFileName, EFileWrite | EFileShareAny); |
|
99 if(err==KErrPathNotFound || err==KErrNotFound) |
|
100 { |
|
101 err = iFs.MkDirAll(iFileName); |
|
102 if(err!=KErrNone && err!=KErrAlreadyExists) |
|
103 return err; |
|
104 err = iLog.Create(iFs, iFileName, EFileWrite | EFileShareAny); |
|
105 } |
|
106 if(err!=KErrNone) |
|
107 return err; |
|
108 iIsOpen = ETrue; |
|
109 } |
|
110 return err; |
|
111 } |
|
112 |
|
113 TInt CFileWriter::Write(const TDesC8& aText) |
|
114 { |
|
115 return WriteToFile(aText); |
|
116 } |
|
117 |
|
118 |
|
119 TInt CFileWriter::WriteToFile(const TDesC8& aText) |
|
120 { |
|
121 TInt err = KErrNone; |
|
122 if(!iIsOpen) |
|
123 { |
|
124 err = OpenLog(); |
|
125 if(err!=KErrNone) |
|
126 return err; |
|
127 } |
|
128 iLog.Write(0x7FFFFFFF, aText); |
|
129 |
|
130 return err; |
|
131 } |
|
132 |
|
133 |
|
134 TAny* CFileWriter::GetInterfaceL(TPluginInterface aInterfaceId) |
|
135 { |
|
136 if(aInterfaceId == MOutputPlugin::iInterfaceId) |
|
137 return static_cast<MOutputPlugin*>(this); |
|
138 else |
|
139 return NULL; |
|
140 } |
|
141 |
|
142 } // namespace |
|
143 |
|
144 //ECOM interface implementations |
|
145 |
|
146 // Map the interface implementation UIDs to implementation factory functions |
|
147 const TImplementationProxy ImplementationTable[] = |
|
148 { |
|
149 IMPLEMENTATION_PROXY_ENTRY(0x102836CA, Ulogger::CFileWriter::NewL) |
|
150 }; |
|
151 |
|
152 |
|
153 // Exported proxy for instantiation method resolution. |
|
154 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
155 TInt& aTableCount) |
|
156 { |
|
157 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
158 return ImplementationTable; |
|
159 } |