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