|
1 /* |
|
2 * Copyright (c) 2007 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 class is used for data table manipulations. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 |
|
21 //XMPP includes |
|
22 // #include "// GFLOGger.h" |
|
23 |
|
24 #include "xmppsettingsrecord.h" |
|
25 #include "xmppsettingsapicommon.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 CXmppSettingsRecord::CXmppSettingsRecord( |
|
30 CRepository& aRepository ): |
|
31 iRepository( aRepository ) |
|
32 { |
|
33 |
|
34 } |
|
35 |
|
36 CXmppSettingsRecord* CXmppSettingsRecord::NewL( |
|
37 CRepository& aRepository ) |
|
38 { |
|
39 CXmppSettingsRecord* self = CXmppSettingsRecord::NewLC( aRepository ); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CXmppSettingsRecord* CXmppSettingsRecord::NewLC( |
|
45 CRepository& aRepository ) |
|
46 { |
|
47 CXmppSettingsRecord* self |
|
48 = new( ELeave ) CXmppSettingsRecord( aRepository ); |
|
49 CleanupStack::PushL( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 CXmppSettingsRecord::~CXmppSettingsRecord() |
|
55 { |
|
56 // GFLOG1("CXmppSettingsRecord::~CXmppSettingsRecord"); |
|
57 iSettingsRecordKeyArray.Reset(); |
|
58 iSettingsRecordKeyArray.Close(); |
|
59 } |
|
60 |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Finds settingsRecord key. Leaves if not found. |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CXmppSettingsRecord::FindSettingsRecordKeyL( |
|
67 TUint32 aSettingsRecordId, |
|
68 TUint32& aSettingsRecordKey ) |
|
69 { |
|
70 GetSettingsRecordkeysL(); |
|
71 |
|
72 TInt counter( iSettingsRecordKeyArray.Count() ); |
|
73 TInt key = KErrNotFound; |
|
74 for (TInt i = 0; i< counter; i++) |
|
75 { |
|
76 TInt id( 0 ); |
|
77 User::LeaveIfError( iRepository.Get( iSettingsRecordKeyArray[i], |
|
78 id ) ); |
|
79 if ( id == aSettingsRecordId ) |
|
80 { |
|
81 key = iSettingsRecordKeyArray[i]; |
|
82 break; |
|
83 } |
|
84 } |
|
85 aSettingsRecordKey = key; |
|
86 |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // returns list of all id keys. |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CXmppSettingsRecord::GetSettingsRecordkeysL( |
|
94 RArray<TUint32>& aResults ) |
|
95 { |
|
96 GetSettingsRecordkeysL(); |
|
97 |
|
98 TInt count( iSettingsRecordKeyArray.Count() ); |
|
99 for ( TInt i=0; i < count; i++ ) |
|
100 { |
|
101 aResults.Append( iSettingsRecordKeyArray[i] ); |
|
102 } |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // This method creates new settings id. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CXmppSettingsRecord::CreateSettingsRecordIdL( |
|
110 TUint32& aNewSettingId ) |
|
111 { |
|
112 // GFLOG1("CXmppSettingsRecord::CreateSettingsRecordIdL - IN"); |
|
113 |
|
114 TUint32 nextFreeSlot( 0 ); |
|
115 |
|
116 NextFreeSlotL( nextFreeSlot ); |
|
117 |
|
118 TInt settingId( 0 ); |
|
119 |
|
120 TInt error( iRepository.Get( KCurrentSettingIdIndex, settingId ) ); |
|
121 // LOGERR("CXmppSettingsRecord::CreateSettingsRecordIdL - iRepository.Get( KCurrentSettingIdIndex ) - error: %d", error); |
|
122 |
|
123 if ( !error ) |
|
124 { |
|
125 settingId++; |
|
126 // GFLOG3("CXmppSettingsRecord::CreateSettingsRecordIdL - nextFreeSlot: 0x%08x, settingId: %d",nextFreeSlot, settingId); |
|
127 error = iRepository.Create( nextFreeSlot, settingId ); |
|
128 // LOGERR("CXmppSettingsRecord::CreateSettingsRecordIdL - iRepository.Create( nextFreeSlot ) - error: %d", error); |
|
129 if ( !error ) |
|
130 { |
|
131 error = iRepository.Set( KCurrentSettingIdIndex, settingId ); |
|
132 aNewSettingId = settingId; |
|
133 } |
|
134 } |
|
135 User::LeaveIfError( error ); |
|
136 // GFLOG1("CXmppSettingsRecord::CreateSettingsRecordIdL - OUT"); |
|
137 } |
|
138 |
|
139 |
|
140 // PRIVATE |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // returns next free slot key. |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CXmppSettingsRecord::NextFreeSlotL( |
|
148 TUint32& aFreekey ) |
|
149 { |
|
150 // First, find all rows and get count. |
|
151 const TUint32 shift = 0x00010000; |
|
152 |
|
153 GetSettingsRecordkeysL(); |
|
154 |
|
155 const TInt count( iSettingsRecordKeyArray.Count() ); |
|
156 // GFLOG2("CXmppSettingsRecord::NextFreeSlotL - count: %d",count); |
|
157 |
|
158 if ( count == 0 ) |
|
159 { |
|
160 aFreekey = KXmppKeyDataTable; |
|
161 } |
|
162 // check for free slots |
|
163 else |
|
164 { |
|
165 TBool foundFreeSlot( EFalse ); |
|
166 |
|
167 // go through all indexes and try to find free one. |
|
168 for ( TInt i=0; i < count; i++ ) |
|
169 { |
|
170 TUint32 tmpKey( KXmppKeyDataTable | ( i * shift ) ); |
|
171 TInt answer( iSettingsRecordKeyArray.Find( tmpKey ) ); |
|
172 |
|
173 if ( answer == KErrNotFound ) |
|
174 { |
|
175 foundFreeSlot = ETrue; |
|
176 aFreekey = tmpKey; |
|
177 break; |
|
178 } |
|
179 } |
|
180 if ( !foundFreeSlot ) |
|
181 { |
|
182 // GFLOG1("CXmppSettingsRecord::NextFreeSlotL - no free slots, creating new"); |
|
183 aFreekey = KXmppKeyDataTable | ( count * shift ); |
|
184 } |
|
185 } |
|
186 // GFLOG2("CXmppSettingsRecord::NextFreeSlotL - aFreekey: 0x%08x",aFreekey); |
|
187 |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // Find all unique settings ids. |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CXmppSettingsRecord::GetSettingsRecordkeysL() |
|
195 { |
|
196 iSettingsRecordKeyArray.Reset(); |
|
197 |
|
198 TInt error = iRepository.FindL( KXmppKeyDataTable, |
|
199 KXmppMaskAllRows, |
|
200 iSettingsRecordKeyArray ); |
|
201 |
|
202 // GFLOG2("CXmppSettingsRecord::GetSettingsRecordkeysL - iSettingsRecordKeyArray.Count(): %d",iSettingsRecordKeyArray.Count()); |
|
203 |
|
204 } |