|
1 /* |
|
2 * Copyright (c) 2010 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: This file contains STIFUnit implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <S32STOR.H> |
|
19 #include <S32FILE.H> |
|
20 |
|
21 #include "diclog.h" |
|
22 #include "globaldata.h" |
|
23 |
|
24 _LIT(KDicLogFileName, "c:\\logs\\diclog"); |
|
25 |
|
26 DicLog::DicLog() |
|
27 { |
|
28 |
|
29 } |
|
30 |
|
31 DicLog::~DicLog() |
|
32 { |
|
33 |
|
34 } |
|
35 |
|
36 void DicLog::WriteIntLogL(const TDesC& aFileName, const TUid aUid, const TInt32 aValue) |
|
37 { |
|
38 RFs fs; |
|
39 User::LeaveIfError(fs.Connect()); |
|
40 CleanupClosePushL(fs); |
|
41 |
|
42 TInt err=KErrGeneral; |
|
43 err = fs.MkDir(aFileName); |
|
44 if(KErrAlreadyExists == err || KErrNone == err) |
|
45 { |
|
46 CDictionaryStore *dicStore = CDictionaryFileStore::OpenLC(fs, aFileName, TUid::Uid(0x0001)); |
|
47 |
|
48 RDictionaryWriteStream in; |
|
49 in.AssignLC(*dicStore,aUid); |
|
50 in.WriteInt32L(aValue); |
|
51 in.CommitL(); |
|
52 dicStore->CommitL(); |
|
53 |
|
54 CleanupStack::PopAndDestroy(&in); |
|
55 CleanupStack::PopAndDestroy(dicStore); |
|
56 } |
|
57 else |
|
58 { |
|
59 User::Leave(err); |
|
60 } |
|
61 |
|
62 CleanupStack::PopAndDestroy(&fs); |
|
63 } |
|
64 |
|
65 TInt DicLog::WriteIntLog(const TDesC& aFileName, const TUid aUid, const TInt32 aValue) |
|
66 { |
|
67 TRAPD(err, DicLog::WriteIntLogL(aFileName, aUid, aValue)); |
|
68 return err; |
|
69 } |
|
70 |
|
71 TInt DicLog::WriteIntLog(const TUid aUid, const TInt32 aValue) |
|
72 { |
|
73 TBuf<KIntValue60> fileNmae(KDicLogFileName); |
|
74 return DicLog::WriteIntLog(fileNmae, aUid, aValue); |
|
75 } |
|
76 |
|
77 void DicLog::WriteLogL(const TDesC& aFileName, const TUid aUid, const TDesC& aLog) |
|
78 { |
|
79 RFs fs; |
|
80 User::LeaveIfError(fs.Connect()); |
|
81 CleanupClosePushL(fs); |
|
82 |
|
83 TInt err=KErrGeneral; |
|
84 err = fs.MkDir(aFileName); |
|
85 if(KErrAlreadyExists == err || KErrNone == err) |
|
86 { |
|
87 CDictionaryStore *dicStore = CDictionaryFileStore::OpenLC(fs, aFileName, TUid::Uid(0x0001)); |
|
88 |
|
89 RDictionaryWriteStream in; |
|
90 in.AssignLC(*dicStore,aUid); |
|
91 in.WriteL(aLog); |
|
92 in.CommitL(); |
|
93 dicStore->CommitL(); |
|
94 |
|
95 CleanupStack::PopAndDestroy(&in); |
|
96 CleanupStack::PopAndDestroy(dicStore); |
|
97 } |
|
98 else |
|
99 { |
|
100 User::Leave(err); |
|
101 } |
|
102 |
|
103 CleanupStack::PopAndDestroy(&fs); |
|
104 } |
|
105 |
|
106 TInt DicLog::WriteLog(const TDesC& aFileName, const TUid aUid, const TDesC& aLog) |
|
107 { |
|
108 TRAPD(err, DicLog::WriteLogL(aFileName, aUid, aLog)); |
|
109 return err; |
|
110 } |
|
111 |
|
112 TInt DicLog::ReadLog(const TDesC& aFileName, const TUid aUid, TDes& aLog) |
|
113 { |
|
114 TInt err=KErrGeneral; |
|
115 TRAP(err, DicLog::ReadLogL(aFileName, aUid, aLog)); |
|
116 |
|
117 return err; |
|
118 } |
|
119 |
|
120 void DicLog::ReadLogL(const TDesC& aFileName, const TUid aUid, TDes& aLog) |
|
121 { |
|
122 RFs fs; |
|
123 User::LeaveIfError(fs.Connect()); |
|
124 CleanupClosePushL(fs); |
|
125 |
|
126 CDictionaryStore *dicStore = CDictionaryFileStore::OpenLC(fs, aFileName, TUid::Uid(0x0001)); |
|
127 |
|
128 RDictionaryReadStream out; |
|
129 out.OpenLC(*dicStore,aUid); |
|
130 out.ReadL(aLog); |
|
131 |
|
132 CleanupStack::PopAndDestroy(&out); |
|
133 CleanupStack::PopAndDestroy(dicStore); |
|
134 |
|
135 CleanupStack::PopAndDestroy(&fs); |
|
136 } |
|
137 |
|
138 TInt DicLog::ReadIntLog(const TUid aUid, TInt32& aValue) |
|
139 { |
|
140 TBuf<KIntValue60> fileNmae(KDicLogFileName); |
|
141 return DicLog::ReadIntLog(fileNmae, aUid, aValue); |
|
142 } |
|
143 |
|
144 TInt DicLog::ReadIntLog(const TDesC& aFileName, const TUid aUid, TInt32& aValue) |
|
145 { |
|
146 TInt err=KErrGeneral; |
|
147 TRAP(err, DicLog::ReadIntLogL(aFileName, aUid, aValue)); |
|
148 |
|
149 return err; |
|
150 } |
|
151 |
|
152 void DicLog::ReadIntLogL(const TDesC& aFileName, const TUid aUid, TInt32& aValue) |
|
153 { |
|
154 RFs fs; |
|
155 User::LeaveIfError(fs.Connect()); |
|
156 CleanupClosePushL(fs); |
|
157 |
|
158 CDictionaryStore *dicStore = CDictionaryFileStore::OpenLC(fs, aFileName, TUid::Uid(0x0001)); |
|
159 |
|
160 RDictionaryReadStream out; |
|
161 out.OpenLC(*dicStore,aUid); |
|
162 aValue=out.ReadInt32L(); |
|
163 |
|
164 CleanupStack::PopAndDestroy(&out); |
|
165 CleanupStack::PopAndDestroy(dicStore); |
|
166 |
|
167 CleanupStack::PopAndDestroy(&fs); |
|
168 } |
|
169 |
|
170 TInt DicLog::WriteLog(const TUid aUid, const TDesC& aLog) |
|
171 { |
|
172 TBuf<KIntValue60> fileNmae(KDicLogFileName); |
|
173 return DicLog::WriteLog(fileNmae, aUid, aLog); |
|
174 } |
|
175 |
|
176 TInt DicLog::ReadLog(const TUid aUid, TDes& aLog) |
|
177 { |
|
178 TBuf<KIntValue60> fileNmae(KDicLogFileName); |
|
179 return DicLog::ReadLog(fileNmae, aUid, aLog); |
|
180 } |
|
181 |
|
182 TInt DicLog::RemoveLogFile() |
|
183 { |
|
184 TBuf<KIntValue60> fileNmae(KDicLogFileName); |
|
185 return RemoveLogFile(fileNmae); |
|
186 } |
|
187 |
|
188 TInt DicLog::RemoveLogFile(const TDesC& aFileName) |
|
189 { |
|
190 TInt err=KErrGeneral; |
|
191 TRAP(err, DicLog::RemoveLogFileL(aFileName)); |
|
192 |
|
193 return err; |
|
194 } |
|
195 |
|
196 void DicLog::RemoveLogFileL(const TDesC& aFileName) |
|
197 { |
|
198 RFs fs; |
|
199 User::LeaveIfError(fs.Connect()); |
|
200 CleanupClosePushL(fs); |
|
201 |
|
202 User::LeaveIfError(fs.Delete(aFileName)); |
|
203 CleanupStack::PopAndDestroy(&fs); |
|
204 } |