|
1 /* |
|
2 * Copyright (c) 2002 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: Multiple context manager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWPBindingContextManager.h" |
|
21 #include <d32dbms.h> |
|
22 #include <sysutil.h> |
|
23 #include "MWPContextExtension.h" |
|
24 #include "MWPContextExtensionArray.h" |
|
25 #include "WPEngineDebug.h" |
|
26 #include "ProvisioningDebug.h" |
|
27 |
|
28 |
|
29 // CONSTANTS |
|
30 /// Size of the database grows 16 bytes plus the actual data. Tested empirically. |
|
31 const TInt KNewSaveDataSizeEstimate = 16; |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CWPBindingContextManager::CWPBindingContextManager |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CWPBindingContextManager::CWPBindingContextManager() |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CWPBindingContextManager::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CWPBindingContextManager::ConstructL() |
|
51 { |
|
52 CWPMultiContextManager::ConstructL(); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CWPBindingContextManager::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CWPBindingContextManager* CWPBindingContextManager::NewL() |
|
61 { |
|
62 CWPBindingContextManager* self = NewLC(); |
|
63 CleanupStack::Pop(); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CWPBindingContextManager::NewLC |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CWPBindingContextManager* CWPBindingContextManager::NewLC() |
|
74 { |
|
75 CWPBindingContextManager* self = new( ELeave ) CWPBindingContextManager; |
|
76 |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 |
|
80 return self; |
|
81 } |
|
82 |
|
83 // Destructor |
|
84 CWPBindingContextManager::~CWPBindingContextManager() |
|
85 { |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CWPBindingContextManager::DeleteContextL |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CWPBindingContextManager::DeleteContextL( MWPContextExtensionArray& aArray, |
|
93 TUint32 aUid ) |
|
94 { |
|
95 CheckDatabaseL(); |
|
96 |
|
97 // Make sure that all context data has been deleted |
|
98 while( DeleteContextDataL( aArray, aUid ) ) |
|
99 { |
|
100 } |
|
101 |
|
102 // Delete the actual context |
|
103 CWPMultiContextManager::DeleteContextL( aArray, aUid ); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CWPBindingContextManager::DeleteContextDataL |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TBool CWPBindingContextManager::DeleteContextDataL( |
|
111 MWPContextExtensionArray& aArray, TUint32 aUid ) |
|
112 { |
|
113 CheckDatabaseL(); |
|
114 |
|
115 // Call DeleteL() for all related adapter extensions |
|
116 RDbTable table; |
|
117 OpenLC( KDbTableData, table ); |
|
118 CDbColSet* colset = table.ColSetL(); |
|
119 TInt adapterIdCol( colset->ColNo( KDbColumnDataAdapterId ) ); |
|
120 TInt saveDataCol( colset->ColNo( KDbColumnDataSaveData ) ); |
|
121 delete colset; |
|
122 |
|
123 User::LeaveIfError( table.SetIndex( KDbIndexDataContextId ) ); |
|
124 TBool found( table.SeekL( TDbSeekKey( TUint( aUid ) ) ) ); |
|
125 if( found ) |
|
126 { |
|
127 table.GetL(); |
|
128 TUint32 adapterId( table.ColUint32( adapterIdCol ) ); |
|
129 TPtrC8 saveData( table.ColDes8( saveDataCol ) ); |
|
130 |
|
131 for( TInt i( 0 ); i < aArray.MwpceCount(); i++ ) |
|
132 { |
|
133 if( aArray.MwpcePoint( i ).Uid() == adapterId ) |
|
134 { |
|
135 DVA( "DeleteContextDataL: Deleting data using adapter %08x", |
|
136 adapterId ); |
|
137 aArray.MwpcePoint( i ).DeleteL( saveData ); |
|
138 DVA( "DeleteContextDataL: Deleted data using adapter %08x", |
|
139 adapterId ); |
|
140 } |
|
141 } |
|
142 table.DeleteL(); |
|
143 } |
|
144 |
|
145 CleanupStack::PopAndDestroy(); // table |
|
146 return found; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CWPBindingContextManager::ContextDataCountL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 TInt CWPBindingContextManager::ContextDataCountL( TUint32 aUid ) |
|
154 { |
|
155 FLOG( _L( "[Provisioning] CWPBindingContextManager::ContextDataCountL:" ) ); |
|
156 CheckDatabaseL(); |
|
157 |
|
158 // Call DeleteL() for all related adapter extensions |
|
159 RDbTable table; |
|
160 OpenLC( KDbTableData, table, RDbRowSet::EReadOnly ); |
|
161 CDbColSet* colset = table.ColSetL(); |
|
162 TInt contextId( colset->ColNo( KDbColumnDataContextId ) ); |
|
163 delete colset; |
|
164 |
|
165 User::LeaveIfError( table.SetIndex( KDbIndexDataContextId ) ); |
|
166 table.SeekL( TDbSeekKey( TUint( aUid ) ) ); |
|
167 TInt found( 0 ); |
|
168 while( table.AtRow() && |
|
169 (table.GetL(), table.ColUint32( contextId ) == aUid ) ) |
|
170 { |
|
171 found++; |
|
172 table.NextL(); |
|
173 } |
|
174 FTRACE(RDebug::Print(_L("[Provisioning] CWPBindingContextManager::ContextDataCountL count (%d)"), found)); |
|
175 CleanupStack::PopAndDestroy(); // table |
|
176 return found; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CWPBindingContextManager::SaveL |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CWPBindingContextManager::SaveL( |
|
184 MWPContextExtension& aExtension, TInt aItem ) |
|
185 { |
|
186 FLOG( _L( "[Provisioning] CWPBindingContextManager::SaveL:" ) ); |
|
187 |
|
188 CheckDatabaseL(); |
|
189 |
|
190 // Grab save data only if a context is active |
|
191 if( CurrentContextL() != KWPMgrUidNoContext ) |
|
192 { |
|
193 FLOG( _L( "[Provisioning] CWPBindingContextManager::SaveL: 1" ) ); |
|
194 TPtrC8 saveData( aExtension.SaveDataL( aItem ) ); |
|
195 if( saveData != KNullDesC8 ) |
|
196 { |
|
197 if( SysUtil::FFSSpaceBelowCriticalLevelL( |
|
198 NULL, KNewSaveDataSizeEstimate+saveData.Length() ) ) |
|
199 { |
|
200 User::Leave( KErrDiskFull ); |
|
201 } |
|
202 |
|
203 RDbTable table; |
|
204 OpenLC( KDbTableData, table ); |
|
205 |
|
206 CDbColSet* colset = table.ColSetL(); |
|
207 TInt contextIdCol( colset->ColNo( KDbColumnDataContextId ) ); |
|
208 TInt adapterIdCol( colset->ColNo( KDbColumnDataAdapterId ) ); |
|
209 TInt saveDataCol( colset->ColNo( KDbColumnDataSaveData ) ); |
|
210 delete colset; |
|
211 |
|
212 DatabaseBeginLC(); |
|
213 |
|
214 InsertBeginLC( table ); |
|
215 table.SetColL( contextIdCol, CurrentContextL() ); |
|
216 table.SetColL( adapterIdCol, aExtension.Uid() ); |
|
217 table.SetColL( saveDataCol, saveData ); |
|
218 InsertCommitLP( table ); |
|
219 |
|
220 DatabaseCommitLP(); |
|
221 CleanupStack::PopAndDestroy(); // table |
|
222 } |
|
223 } |
|
224 FLOG( _L( "[Provisioning] CWPBindingContextManager::SaveL: done" ) ); |
|
225 } |
|
226 |
|
227 // End of File |