|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "t_crepositorydata.h" |
|
21 |
|
22 /*@{*/ |
|
23 //Command literals |
|
24 _LIT(KCmdNewL, "NewL"); |
|
25 _LIT(KCmdDestructor, "~"); |
|
26 _LIT(KCmdSet, "Set"); |
|
27 /*@}*/ |
|
28 |
|
29 /*@{*/ |
|
30 //INI Key names literals |
|
31 _LIT(KRepUID, "RepUID"); |
|
32 _LIT(KRepItemID, "ItemID"); |
|
33 _LIT(KRepSetValue, "SetValue"); |
|
34 /*@{*/ |
|
35 |
|
36 /** |
|
37 * Two phase constructor |
|
38 * |
|
39 * @leave system wide error |
|
40 */ |
|
41 CT_CRepositoryData* CT_CRepositoryData::NewL() |
|
42 { |
|
43 CT_CRepositoryData* ret = new (ELeave) CT_CRepositoryData(); |
|
44 CleanupStack::PushL(ret); |
|
45 ret->ConstructL(); |
|
46 CleanupStack::Pop(ret); |
|
47 return ret; |
|
48 } |
|
49 |
|
50 /** |
|
51 * Private constructor. First phase construction |
|
52 */ |
|
53 CT_CRepositoryData::CT_CRepositoryData() |
|
54 : |
|
55 iRepository(NULL) |
|
56 { |
|
57 } |
|
58 |
|
59 /** |
|
60 * Second phase construction |
|
61 * @internalComponent |
|
62 * @return N/A |
|
63 * @pre None |
|
64 * @post None |
|
65 * @leave system wide error |
|
66 */ |
|
67 void CT_CRepositoryData::ConstructL() |
|
68 { |
|
69 } |
|
70 |
|
71 /** |
|
72 * Public destructor |
|
73 */ |
|
74 CT_CRepositoryData::~CT_CRepositoryData() |
|
75 { |
|
76 DestroyData(); |
|
77 } |
|
78 |
|
79 /** |
|
80 * Return a pointer to the object that the data wraps |
|
81 * |
|
82 * @return pointer to the object that the data wraps |
|
83 */ |
|
84 TAny* CT_CRepositoryData::GetObject() |
|
85 { |
|
86 return iRepository; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Helper Destructor |
|
91 */ |
|
92 void CT_CRepositoryData::DestroyData() |
|
93 { |
|
94 if(iRepository) |
|
95 { |
|
96 delete iRepository; |
|
97 iRepository = NULL; |
|
98 } |
|
99 } |
|
100 |
|
101 /** |
|
102 * Process a command read from the Ini file |
|
103 * @param aCommand - The command to process |
|
104 * @param aSection - The section get from the *.ini file of the project T_Wlan |
|
105 * @param aAsyncErrorIndex - Command index dor async calls to returns errors to |
|
106 * @return TBool - ETrue if the command is process |
|
107 * @leave - system wide error |
|
108 */ |
|
109 TBool CT_CRepositoryData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
110 { |
|
111 TBool ret = ETrue; |
|
112 |
|
113 if (aCommand == KCmdNewL) |
|
114 { |
|
115 DoCmdNewL(aSection); |
|
116 } |
|
117 else if (aCommand == KCmdDestructor) |
|
118 { |
|
119 DoCmdDestructor(); |
|
120 } |
|
121 else if (aCommand == KCmdSet) |
|
122 { |
|
123 DoCmdSet(aSection); |
|
124 } |
|
125 else |
|
126 { |
|
127 ERR_PRINTF1(_L("Unknown command.")); |
|
128 ret=EFalse; |
|
129 } |
|
130 |
|
131 return ret; |
|
132 } |
|
133 |
|
134 /** |
|
135 * Create an instance of CRepository |
|
136 * @param aSection - Section to read from the ini file |
|
137 * @return void |
|
138 */ |
|
139 void CT_CRepositoryData::DoCmdNewL(const TTEFSectionName& aSection) |
|
140 { |
|
141 INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdNewL")); |
|
142 DestroyData(); |
|
143 TBool dataOk = ETrue; |
|
144 |
|
145 TInt parRepUID = 0; |
|
146 if(!GetHexFromConfig(aSection, KRepUID, parRepUID)) |
|
147 { |
|
148 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepUID); |
|
149 SetBlockResult(EFail); |
|
150 dataOk = EFalse; |
|
151 } |
|
152 |
|
153 if(dataOk) |
|
154 { |
|
155 TUid repUid; |
|
156 repUid.Null(); |
|
157 repUid = TUid::Uid(parRepUID); |
|
158 TRAPD(error, iRepository = CRepository::NewL(repUid)); |
|
159 if(error != KErrNone) |
|
160 { |
|
161 ERR_PRINTF2(_L("Could not create CRepository: error %d"), error); |
|
162 SetError(error); |
|
163 } |
|
164 } |
|
165 |
|
166 INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdNewL")); |
|
167 } |
|
168 |
|
169 /** |
|
170 * Delete an instance of CRepository |
|
171 * @param |
|
172 * @return |
|
173 */ |
|
174 void CT_CRepositoryData::DoCmdDestructor() |
|
175 { |
|
176 INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdDestroyData")); |
|
177 DestroyData(); |
|
178 INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdDestroyData")); |
|
179 } |
|
180 |
|
181 /** |
|
182 * Setting the central repository |
|
183 * @param aSection - Section to read from the ini file |
|
184 * @return void |
|
185 */ |
|
186 void CT_CRepositoryData::DoCmdSet(const TTEFSectionName& aSection) |
|
187 { |
|
188 INFO_PRINTF1(_L("*START* CT_CRepositoryData::DoCmdSet")); |
|
189 TBool dataOk = ETrue; |
|
190 |
|
191 TInt parRepItemID; |
|
192 if(!GetHexFromConfig(aSection, KRepItemID, parRepItemID)) |
|
193 { |
|
194 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepItemID); |
|
195 SetBlockResult(EFail); |
|
196 dataOk = EFalse; |
|
197 } |
|
198 |
|
199 TInt parRepSetValue; |
|
200 if(!GetIntFromConfig(aSection, KRepSetValue, parRepSetValue)) |
|
201 { |
|
202 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepSetValue); |
|
203 SetBlockResult(EFail); |
|
204 dataOk = EFalse; |
|
205 } |
|
206 |
|
207 if(dataOk) |
|
208 { |
|
209 TInt error = KErrNone; |
|
210 INFO_PRINTF2(_L("ItemId = %d"),parRepItemID); |
|
211 INFO_PRINTF2(_L("DataId = %d"),parRepSetValue); |
|
212 |
|
213 error = iRepository->Set(parRepItemID, parRepSetValue); |
|
214 |
|
215 if(error != KErrNone) |
|
216 { |
|
217 ERR_PRINTF3(_L("Setting the central repository parameter %d failed with error %d"), parRepItemID, error); |
|
218 SetError(error); |
|
219 } |
|
220 } |
|
221 INFO_PRINTF1(_L("*END* CT_CRepositoryData::DoCmdSet")); |
|
222 } |