|
1 // Copyright (c) 2002-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 // Header file for Phonebook Synchroniser's CPhoneBookManager class which |
|
15 // manages the parameters for the phone and each phonebook, including the |
|
16 // Look-Up Tables, Phonebook store handles and flags for the synchroniser |
|
17 // engine. |
|
18 // This class can be accessed from either the server side or engine side. |
|
19 // All applicable functions are mutex protected to prevent corruption from |
|
20 // being accessed simutantiously from two threads. CPhoneBook is not protected |
|
21 // hence why CPhoneBookManager does not give out the CPhoneBook object pointers, |
|
22 // but performs all operations itself, with mutex protection. |
|
23 // |
|
24 // |
|
25 |
|
26 /** |
|
27 @file |
|
28 @internalComponent |
|
29 */ |
|
30 |
|
31 #ifndef __PHONEBOOKMANAGER_H__ |
|
32 #define __PHONEBOOKMANAGER_H__ |
|
33 |
|
34 #include "phbksync.h" |
|
35 #include "phbksynclog.h" |
|
36 #include "Phonebook.h" |
|
37 #include "PhonebookIniFile.h" |
|
38 |
|
39 |
|
40 /** |
|
41 * This class holds data relating to the phonebooks. This includes the |
|
42 * current PIN status and security settings, as well as a table of parameters |
|
43 * associated with each phonebook. Each entry in this table consists of a |
|
44 * CPhoneBook class. |
|
45 * |
|
46 * The server owns a instance of this class, while the engine has a reference |
|
47 * to it. The data is protected from thread corruption by a mutex. |
|
48 */ |
|
49 class CPhoneBookManager : public CBase |
|
50 { |
|
51 public: |
|
52 static CPhoneBookManager* NewL(TUint32 aICCCaps); |
|
53 ~CPhoneBookManager(); |
|
54 |
|
55 // |
|
56 // Basic management of phonebook UIDs. These do not require shared-data |
|
57 // mutex protection as the will not change after construction. |
|
58 // |
|
59 inline TInt ValidatePhonebookUid(TUid aPhonebookUid) const; |
|
60 inline TInt GetPhonebookCount() const; |
|
61 inline TInt GetPhonebookUid(TInt aPosition, TUid& aPhonebookUid) const; |
|
62 |
|
63 // |
|
64 // General settings for all phonebooks. Since the data can change, the |
|
65 // functions use mutex protection. |
|
66 // |
|
67 TUid GetPhonebookUidFromContactId(TContactItemId aContactId); |
|
68 TUid GetPhonebookUidFromTemplateId(TContactItemId aGroupId); |
|
69 |
|
70 void GetPin1LockStatus(RMobilePhone::TMobilePhoneLockStatus& aLockStatus); |
|
71 void SetPin1LockStatus(RMobilePhone::TMobilePhoneLockStatus aLockStatus); |
|
72 |
|
73 void GetPin2LockStatus(RMobilePhone::TMobilePhoneLockStatus& aLockStatus); |
|
74 void SetPin2LockStatus(RMobilePhone::TMobilePhoneLockStatus aLockStatus); |
|
75 |
|
76 void GetHiddenKeyLockStatus(RMobilePhone::TMobilePhoneLockStatus& aLockStatus); |
|
77 void SetHiddenKeyLockStatus(RMobilePhone::TMobilePhoneLockStatus aLockStatus); |
|
78 |
|
79 void GetUsimAppLockStatus(RMobilePhone::TMobilePhoneLockStatus& aLockStatus); |
|
80 void SetUsimAppLockStatus(RMobilePhone::TMobilePhoneLockStatus aLockStatus); |
|
81 |
|
82 void GetUsimUniversalPinLockStatus(RMobilePhone::TMobilePhoneLockStatus& aLockStatus); |
|
83 void SetUsimUniversalPinLockStatus(RMobilePhone::TMobilePhoneLockStatus aLockStatus); |
|
84 |
|
85 void RecordSecurityEvent(RMobilePhone::TMobilePhoneSecurityEvent aSecurityEvent); |
|
86 |
|
87 TBool IsPin1Valid(); |
|
88 TBool IsPin2Valid(); |
|
89 TBool IsUsimAppPinValid(); |
|
90 |
|
91 // |
|
92 // Settings that are per phonebook. These functions are all mutex |
|
93 // protected. |
|
94 // |
|
95 TInt GetPhBkInfoRetrievedResult(TUid aPhonebookUid, TInt& aErrorCode); |
|
96 TInt SetPhBkInfoRetrievedResult(TUid aPhonebookUid, TInt aErrorCode); |
|
97 |
|
98 TInt GetSyncMode(TUid aPhonebookUid, RPhoneBookSession::TPhonebookSyncMode& aSyncMode); |
|
99 TInt SetSyncMode(TUid aPhonebookUid, RPhoneBookSession::TPhonebookSyncMode aSyncMode); |
|
100 |
|
101 TInt GetSyncState(TUid aPhonebookUid, RPhoneBookSession::TSyncState& aSyncState); |
|
102 TInt SetSyncState(TUid aPhonebookUid, RPhoneBookSession::TSyncState aSyncState); |
|
103 |
|
104 TInt GetLastSyncError(TUid aPhonebookUid, TInt& aLastSyncError); |
|
105 TInt SetLastSyncError(TUid aPhonebookUid, TInt aLastSyncError); |
|
106 |
|
107 TInt GetTemplateId(TUid aPhonebookUid, |
|
108 TContactItemId& aTemplateId); |
|
109 TInt SetTemplateId(TUid aPhonebookUid, |
|
110 TContactItemId aTemplateId); |
|
111 |
|
112 TInt GetGroupId(TUid aPhonebookUid, |
|
113 TContactItemId& aGroupId); |
|
114 TInt SetGroupId(TUid aPhonebookUid, |
|
115 TContactItemId aGroupId); |
|
116 |
|
117 TInt GetContactFields(TUid aPhonebookUid, |
|
118 RPhoneBookSession::TContactFieldsV3& aContactFields); |
|
119 TInt SetContactFields(TUid aPhonebookUid, |
|
120 const RPhoneBookSession::TContactFieldsV3& aContactFields); |
|
121 |
|
122 TInt GetPhoneBookStore(TUid aPhonebookUid, |
|
123 RMobilePhone& aPhone, |
|
124 RMobilePhoneBookStore& aPhonebookStore); |
|
125 TInt ClosePhoneBookStores(); |
|
126 |
|
127 TInt GetPhoneBookInfo(TUid aPhonebookUid, |
|
128 RMobilePhoneBookStore::TMobilePhoneBookInfoV5& aPhBkInfo); |
|
129 TInt SetPhoneBookInfo(TUid aPhonebookUid, |
|
130 const RMobilePhoneBookStore::TMobilePhoneBookInfoV5& aPhBkInfo); |
|
131 TInt AdjustPhoneBookInfoUsedEntries(TUid aPhonebookUid, TInt aChange); |
|
132 |
|
133 TInt GetLookUpTableSize(TUid aPhonebookUid, TInt& aSize); |
|
134 TInt SetLookUpTableSize(TUid aPhonebookUid, TInt aSize); |
|
135 TInt ClearLookUpTable(TUid aPhonebookUid); |
|
136 |
|
137 TInt IsEntryInTable(TUid aPhonebookUid, TContactItemId aContactId); |
|
138 TInt UpdateEntryInTable(TUid aPhonebookUid, TInt aSlotNum, |
|
139 TContactItemId aContactId); |
|
140 TInt UpdateEntryInTable(TUid aPhonebookUid, TInt aSlotNum, |
|
141 TContactItemId aContactId, |
|
142 TPhonebookSlotState aSlotState); |
|
143 |
|
144 TInt GetContactIdFromSlotNum(TUid aPhonebookUid, TInt aSlotNum, |
|
145 TContactItemId& aContactItemId); |
|
146 TInt GetSlotNumFromContactId(TUid aPhonebookUid, |
|
147 TContactItemId aContactId, |
|
148 TInt& aSlotNum); |
|
149 |
|
150 TInt GetNumFreeSlots(TUid aPhonebookUid, TInt& aNumOfFreeSlots); |
|
151 TInt GetFirstEmptySlot(TUid aPhonebookUid, TInt& aSlotNum); |
|
152 TInt GetMatchingEntries(TUid aPhonebookUid, TPhonebookSlotState aSlotState, |
|
153 RArray<TInt>& aEntries); |
|
154 |
|
155 TInt LogLookUpTable(TUid aPhonebookUid); |
|
156 |
|
157 private: |
|
158 CPhoneBookManager(); |
|
159 |
|
160 void ConstructL(TUint32 aICCCaps); |
|
161 TInt GetPhonebook(TUid aPhonebookUid, CPhoneBook*& aPhoneBookPtr) const; |
|
162 inline void AcquireMutex(); |
|
163 inline void ReleaseMutex(); |
|
164 |
|
165 RMutex iMutex; |
|
166 RPointerArray<CPhoneBook> iPhonebookList; |
|
167 CPhoneBookIniFile* iIniFile; |
|
168 TBool iIsPuk1Verified; |
|
169 RMobilePhone::TMobilePhoneLockStatus iPin1LockStatus; |
|
170 RMobilePhone::TMobilePhoneLockStatus iPin2LockStatus; |
|
171 RMobilePhone::TMobilePhoneLockStatus iHiddenKeyLockStatus; |
|
172 RMobilePhone::TMobilePhoneLockStatus iUsimAppLockStatus; |
|
173 RMobilePhone::TMobilePhoneLockStatus iUsimUniversalPinLockStatus; |
|
174 }; |
|
175 |
|
176 |
|
177 /** |
|
178 * Validates a phonebook UID as being supported by the Phonebook |
|
179 * Synchroniser with the current phone. This does not mean that |
|
180 * the phonebook is supported by the phone, but that PhBkSync |
|
181 * can use it. |
|
182 * |
|
183 * @param aPhonebookUid UID of the phonebook to validate. |
|
184 * |
|
185 * @return Returns KErrNone if valid, a system error code otherwise. |
|
186 */ |
|
187 inline TInt CPhoneBookManager::ValidatePhonebookUid(TUid aPhonebookUid) const |
|
188 { |
|
189 // |
|
190 // Validate the UID by getting the parameters for the phonebook. If |
|
191 // the UID is not valid, then it won't be found. |
|
192 // |
|
193 CPhoneBook* phonebookParams; |
|
194 TInt result = GetPhonebook(aPhonebookUid, phonebookParams); |
|
195 |
|
196 return result; |
|
197 } // CPhoneBookManager::ValidatePhonebookUid |
|
198 |
|
199 |
|
200 /** |
|
201 * Returns the number of phonebooks supported by the Phonebook Synchroniser |
|
202 * using the current phone. |
|
203 * |
|
204 * @return Number of phonebooks supported. |
|
205 * |
|
206 * @see CPhoneBookManager::GetPhonebookUid |
|
207 */ |
|
208 inline TInt CPhoneBookManager::GetPhonebookCount() const |
|
209 { |
|
210 return iPhonebookList.Count(); |
|
211 } // CPhoneBookManager::GetPhonebookCount |
|
212 |
|
213 |
|
214 /** |
|
215 * Get the phonebook UID for a particular index in the list of phonebooks. |
|
216 * This can be used to iterate the list of phonebooks. |
|
217 * |
|
218 * @param aPosition Index of the phonebook in the list. |
|
219 * @param aPhonebookUid Set with the phonebook UID on successful exit. |
|
220 * |
|
221 * @return Returns KErrNone if successful, a system error code otherwise. |
|
222 * |
|
223 * @see CPhoneBookManager::GetPhonebookCount() |
|
224 */ |
|
225 inline TInt CPhoneBookManager::GetPhonebookUid(TInt aPosition, |
|
226 TUid& aPhonebookUid) const |
|
227 { |
|
228 // |
|
229 // Check the position is valid and if so the return the UID... |
|
230 // |
|
231 if (aPosition < 0 || aPosition >= iPhonebookList.Count()) |
|
232 { |
|
233 return KErrArgument; |
|
234 } |
|
235 |
|
236 aPhonebookUid = iPhonebookList[aPosition]->GetPhonebookUid(); |
|
237 |
|
238 return KErrNone; |
|
239 } // CPhoneBookManager::GetPhonebookUid |
|
240 |
|
241 |
|
242 /** |
|
243 * Acquires the process local mutex used to protect the shared data. |
|
244 */ |
|
245 inline void CPhoneBookManager::AcquireMutex() |
|
246 { |
|
247 LOGPARAMS2(_L8("AcquireMutex(): Thread ID=%d"), (TUint) RThread().Id()); |
|
248 |
|
249 iMutex.Wait(); |
|
250 } // CPhoneBookManager::AcquireMutex |
|
251 |
|
252 |
|
253 /** |
|
254 * Releases the process local mutex used to protect the shared data. |
|
255 */ |
|
256 inline void CPhoneBookManager::ReleaseMutex() |
|
257 { |
|
258 LOGPARAMS2(_L8("ReleaseMutex(): Thread ID=%d"), (TUint) RThread().Id()); |
|
259 |
|
260 iMutex.Signal(); |
|
261 } // CPhoneBookManager::ReleaseMutex |
|
262 |
|
263 |
|
264 #endif // __PHONEBOOKMANAGER_H__ |