1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "ccentralrepositoryhandler.h" |
|
23 |
|
24 #include "xqsettingskey.h" |
|
25 |
|
26 CCentralRepositoryHandler* CCentralRepositoryHandler::NewL(TUid aUid) |
|
27 { |
|
28 CCentralRepositoryHandler* self = new (ELeave) CCentralRepositoryHandler(aUid); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 void CCentralRepositoryHandler::ConstructL() |
|
36 { |
|
37 iRepository = CRepository::NewL(m_uid); |
|
38 } |
|
39 |
|
40 CCentralRepositoryHandler::CCentralRepositoryHandler(TUid aUid) : |
|
41 m_uid(aUid) |
|
42 { |
|
43 } |
|
44 |
|
45 CCentralRepositoryHandler::~CCentralRepositoryHandler() |
|
46 { |
|
47 foreach (CCenRepMonitor* monitor, m_monitors) |
|
48 delete monitor; |
|
49 |
|
50 delete iRepository; |
|
51 } |
|
52 |
|
53 void CCentralRepositoryHandler::setObserver(MSettingsHandlerObserver* observer) |
|
54 { |
|
55 m_observer = observer; |
|
56 } |
|
57 |
|
58 TInt CCentralRepositoryHandler::deleteKey(unsigned long key) |
|
59 { |
|
60 return iRepository->Delete(key); |
|
61 } |
|
62 |
|
63 TInt CCentralRepositoryHandler::resetKey(unsigned long key) |
|
64 { |
|
65 return iRepository->Reset(key); |
|
66 } |
|
67 |
|
68 TInt CCentralRepositoryHandler::resetRepository() |
|
69 { |
|
70 return iRepository->Reset(); |
|
71 } |
|
72 |
|
73 TInt CCentralRepositoryHandler::getValue(unsigned long key, TInt& value) |
|
74 { |
|
75 return iRepository->Get(key, value); |
|
76 } |
|
77 |
|
78 TInt CCentralRepositoryHandler::getValue(unsigned long key, TReal& value) |
|
79 { |
|
80 return iRepository->Get(key, value); |
|
81 } |
|
82 |
|
83 void CCentralRepositoryHandler::getValueL(unsigned long key, RBuf8& value) |
|
84 { |
|
85 TInt actualLength; |
|
86 TInt err = iRepository->Get(key, value, actualLength); |
|
87 if (err == KErrOverflow) |
|
88 { |
|
89 value.ReAllocL(actualLength); |
|
90 err = iRepository->Get(key, value); |
|
91 } |
|
92 User::LeaveIfError(err); |
|
93 } |
|
94 |
|
95 void CCentralRepositoryHandler::getValueL(unsigned long key, RBuf16& value) |
|
96 { |
|
97 TInt actualLength; |
|
98 TInt err = iRepository->Get(key, value, actualLength); |
|
99 if (err == KErrOverflow) |
|
100 { |
|
101 value.ReAllocL(actualLength); |
|
102 err = iRepository->Get(key, value); |
|
103 } |
|
104 User::LeaveIfError(err); |
|
105 } |
|
106 |
|
107 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TInt& value) |
|
108 { |
|
109 return iRepository->Set(key, value); |
|
110 } |
|
111 |
|
112 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TReal& value) |
|
113 { |
|
114 return iRepository->Set(key, value); |
|
115 } |
|
116 |
|
117 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TDesC8& value) |
|
118 { |
|
119 return iRepository->Set(key, value); |
|
120 } |
|
121 |
|
122 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TDesC16& value) |
|
123 { |
|
124 return iRepository->Set(key, value); |
|
125 } |
|
126 |
|
127 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TInt& value) |
|
128 { |
|
129 return iRepository->Create(key, value); |
|
130 } |
|
131 |
|
132 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TReal& value) |
|
133 { |
|
134 return iRepository->Create(key, value); |
|
135 } |
|
136 |
|
137 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TDesC8& value) |
|
138 { |
|
139 return iRepository->Create(key, value); |
|
140 } |
|
141 |
|
142 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TDesC16& value) |
|
143 { |
|
144 return iRepository->Create(key, value); |
|
145 } |
|
146 |
|
147 bool CCentralRepositoryHandler::handleStartMonitoring(const XQSettingsKey& key, XQSettingsManager::Type type, MSettingsHandlerObserver& observer, TInt& error) |
|
148 { |
|
149 if (m_monitors.contains(key.key())) |
|
150 { |
|
151 error = KErrAlreadyExists; |
|
152 return false; |
|
153 } |
|
154 CCenRepMonitor* newMonitor = new CCenRepMonitor(*iRepository, key, type, observer); |
|
155 if (newMonitor) |
|
156 { |
|
157 m_monitors[key.key()] = newMonitor; |
|
158 error = newMonitor->StartMonitoring(); |
|
159 return error == KErrNone; |
|
160 } |
|
161 error = KErrNoMemory; |
|
162 return false; |
|
163 } |
|
164 |
|
165 bool CCentralRepositoryHandler::handleStopMonitoring(const XQSettingsKey& key, TInt& error) |
|
166 { |
|
167 if (!m_monitors.contains(key.key())) |
|
168 { |
|
169 error = KErrNotFound; |
|
170 return false; |
|
171 } |
|
172 const long int itemKey = key.key(); |
|
173 CCenRepMonitor* monitor = m_monitors[itemKey]; |
|
174 m_monitors.remove(itemKey); |
|
175 delete monitor; |
|
176 |
|
177 return error == KErrNone; |
|
178 } |
|
179 |
|
180 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, RArray<TUint32>& aFoundKeys) |
|
181 { |
|
182 return iRepository->FindL(partialKey, mask, aFoundKeys); |
|
183 } |
|
184 |
|
185 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TInt& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
186 { |
|
187 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
188 } |
|
189 |
|
190 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TReal& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
191 { |
|
192 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
193 } |
|
194 |
|
195 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TDesC8& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
196 { |
|
197 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
198 } |
|
199 |
|
200 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TDesC16& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
201 { |
|
202 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
203 } |
|
204 |
|
205 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
206 TInt CCentralRepositoryHandler::startTransaction(CRepository::TTransactionMode transactionMode) |
|
207 { |
|
208 return iRepository->StartTransaction(transactionMode); |
|
209 } |
|
210 #else |
|
211 TInt CCentralRepositoryHandler::startTransaction(CRepository::TTransactionMode /*transactionMode*/) |
|
212 { |
|
213 return KErrNotSupported; |
|
214 } |
|
215 #endif |
|
216 |
|
217 TInt CCentralRepositoryHandler::commitTransaction() |
|
218 { |
|
219 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
220 TUint32 keyInfo; |
|
221 return iRepository->CommitTransaction(keyInfo); |
|
222 #else |
|
223 return KErrNotSupported; |
|
224 #endif |
|
225 } |
|
226 |
|
227 void CCentralRepositoryHandler::cancelTransaction() |
|
228 { |
|
229 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
230 iRepository->CancelTransaction(); |
|
231 #endif |
|
232 } |
|
233 |
|
234 void CCentralRepositoryHandler::failTransaction() |
|
235 { |
|
236 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
237 iRepository->FailTransaction(); |
|
238 #endif |
|
239 } |
|
240 |
|
241 TInt CCentralRepositoryHandler::transactionState() const |
|
242 { |
|
243 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
244 return iRepository->TransactionState(); |
|
245 #else |
|
246 return KErrNotSupported; |
|
247 #endif |
|
248 } |
|
249 |
|