|
1 /* |
|
2 * Copyright (c) 2004 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: Store API to retrieve presence attribute models. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngAttributeStore2Imp.h" |
|
20 #include "CPEngNWSessionSlotID2Imp.h" |
|
21 #include "CPEngNWSessionSlotStorageProxy.h" |
|
22 #include "MPEngPresenceAttrManager.h" |
|
23 #include "PEngAttrLibFactory.h" |
|
24 |
|
25 |
|
26 #include <MPEngPresenceAttrModel2.h> |
|
27 #include <CPEngNWSessionSlotID2.h> |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 // ============================ LOCAL FUNCTIONS =============================== |
|
33 |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // AddOptionsByOwner() |
|
37 // Adds the EPEngUserAttribute instance option bit if |
|
38 // user presence ID is used. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 void AddOptionsByOwner( TInt& aInstanceOptions, const TDesC& aPresenceID ) |
|
42 { |
|
43 if ( aPresenceID == KPEngUserOwnPresenceId ) |
|
44 { |
|
45 aInstanceOptions = aInstanceOptions | EPEngUserAttribute; |
|
46 } |
|
47 else |
|
48 { |
|
49 aInstanceOptions = aInstanceOptions | EPEngCreationNotAllowed; |
|
50 } |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // HandleLoadErrorsByOwnerL() |
|
56 // For user own attribute, the not found error is ignored |
|
57 // (default attribute data is returned). |
|
58 // For other attributes (cached ones), it is handled. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void HandleLoadErrorsByOwnerL( TInt aLoadErr, |
|
62 const TDesC& aPresenceID ) |
|
63 { |
|
64 if ( aPresenceID == KPEngUserOwnPresenceId ) |
|
65 { |
|
66 return; |
|
67 } |
|
68 |
|
69 User::LeaveIfError( aLoadErr ); |
|
70 } |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 // ============================ MEMBER FUNCTIONS =============================== |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CPEngAttributeStore2Imp::NewL() |
|
80 // Two-phased constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CPEngAttributeStore2Imp* CPEngAttributeStore2Imp::NewL( |
|
84 const CPEngNWSessionSlotID2& aNWSessionSlotID, |
|
85 TInt aPriority ) |
|
86 { |
|
87 CPEngAttributeStore2Imp* self = |
|
88 new ( ELeave ) CPEngAttributeStore2Imp( aPriority ); |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL( aNWSessionSlotID ); |
|
91 CleanupStack::Pop( self ); |
|
92 return self; |
|
93 } |
|
94 |
|
95 |
|
96 |
|
97 // Destructor |
|
98 CPEngAttributeStore2Imp::~CPEngAttributeStore2Imp() |
|
99 { |
|
100 if ( iAttrManager ) |
|
101 { |
|
102 iAttrManager->Close(); |
|
103 } |
|
104 |
|
105 delete iUsedSlot; |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CPEngAttributeStore2Imp::CPEngAttributeStore2Imp |
|
112 // C++ default constructor can NOT contain any code, that |
|
113 // might leave. |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CPEngAttributeStore2Imp::CPEngAttributeStore2Imp( TInt aPriority ) |
|
117 : iCActivePriority( aPriority ) |
|
118 { |
|
119 } |
|
120 |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CPEngAttributeStore2Imp::ConstructL() |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CPEngAttributeStore2Imp::ConstructL( const CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
127 { |
|
128 iUsedSlot = CPEngNWSessionSlotStorageProxy::NewL( aNWSessionSlotID ); |
|
129 iAttrManager = PEngAttrLibFactory::AttributeManagerInstanceL( iUsedSlot->BaseId() ); |
|
130 } |
|
131 |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CPEngAttributeStore2Imp::GetAttribute() |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CPEngAttributeStore2Imp::GetAttribute( |
|
138 TUint32 aType, |
|
139 const TDesC& aPresenceID, |
|
140 MPEngPresenceAttrModel2*& aModel ) const |
|
141 { |
|
142 aModel = NULL; |
|
143 TInt instanceOptions = EPEngStorableModel; |
|
144 AddOptionsByOwner( instanceOptions, aPresenceID ); |
|
145 |
|
146 TRAPD( err, |
|
147 { |
|
148 MPEngPresenceAttrModel2* model = NULL; |
|
149 |
|
150 TInt loadErr = iAttrManager->LoadAttributeLC( model, |
|
151 aPresenceID, |
|
152 aType, |
|
153 instanceOptions ); |
|
154 HandleLoadErrorsByOwnerL( loadErr, |
|
155 aPresenceID ); |
|
156 |
|
157 CleanupStack::Pop(); //model |
|
158 aModel = model; |
|
159 } ); |
|
160 |
|
161 return err; |
|
162 } |
|
163 |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CPEngAttributeStore2Imp::GetAndLockAttribute() |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 TInt CPEngAttributeStore2Imp::GetAndLockAttribute( |
|
170 TUint32 aType, |
|
171 const TDesC& aPresenceID, |
|
172 MPEngPresenceAttrModel2*& aModel ) |
|
173 { |
|
174 aModel = NULL; |
|
175 TInt instanceOptions = EPEngStorableModel | |
|
176 EPEngEditLockedModel; |
|
177 AddOptionsByOwner( instanceOptions, aPresenceID ); |
|
178 |
|
179 TRAPD( err, |
|
180 { |
|
181 MPEngPresenceAttrModel2* model = NULL; |
|
182 |
|
183 |
|
184 TInt loadErr = iAttrManager->LoadAttributeLC( model, |
|
185 aPresenceID, |
|
186 aType, |
|
187 instanceOptions ); |
|
188 |
|
189 HandleLoadErrorsByOwnerL( loadErr, |
|
190 aPresenceID ); |
|
191 |
|
192 |
|
193 CleanupStack::Pop(); //model |
|
194 aModel = model; |
|
195 } ); |
|
196 |
|
197 return err; |
|
198 } |
|
199 |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CPEngAttributeStore2Imp::StoreAttribute() |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CPEngAttributeStore2Imp::StoreAttribute( |
|
206 MPEngPresenceAttrModel2& aModel, |
|
207 TBool aReleaseEditLock ) |
|
208 { |
|
209 TRAPD( err, iAttrManager->StoreEditLockedAttributeL( aModel ) ); |
|
210 if ( aReleaseEditLock && ( err == KErrNone ) ) |
|
211 { |
|
212 err = UnLockAttribute( aModel ); |
|
213 } |
|
214 |
|
215 return err; |
|
216 } |
|
217 |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CPEngAttributeStore2Imp::UnLockAttribute() |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 TInt CPEngAttributeStore2Imp::UnLockAttribute( |
|
224 MPEngPresenceAttrModel2& aModel ) |
|
225 { |
|
226 return iAttrManager->StopEditSupport( aModel ); |
|
227 } |
|
228 |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CPEngAttributeStore2Imp::AttributeAvailable() |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CPEngAttributeStore2Imp::AttributeAvailable( TUint32 aType, |
|
235 const TDesC& aPresenceID ) const |
|
236 { |
|
237 TInt instanceOptions = EPEngStorableModel | |
|
238 EPEngEditLockedModel; |
|
239 AddOptionsByOwner( instanceOptions, aPresenceID ); |
|
240 |
|
241 |
|
242 TRAPD( err, |
|
243 { |
|
244 MPEngPresenceAttrModel2* model = NULL; |
|
245 iAttrManager->LoadAttributeLC( model, |
|
246 aPresenceID, |
|
247 aType, |
|
248 instanceOptions ); |
|
249 |
|
250 CleanupStack::PopAndDestroy(); //model |
|
251 } ); |
|
252 |
|
253 return err; |
|
254 } |
|
255 |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CPEngAttributeStore2Imp::AttributeTypeSupported() |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CPEngAttributeStore2Imp::AttributeTypeSupported( TUint32 aType ) const |
|
262 { |
|
263 TArray< TUint32 > attributeTypes = iAttrManager->KnownAttributeTypes(); |
|
264 const TInt typeCount = attributeTypes.Count(); |
|
265 |
|
266 for ( TInt ii = 0; ii < typeCount; ii++ ) |
|
267 { |
|
268 if ( attributeTypes[ ii ] == aType ) |
|
269 { |
|
270 return KErrNone; |
|
271 } |
|
272 } |
|
273 |
|
274 return KErrNotSupported; |
|
275 } |
|
276 |
|
277 |
|
278 |
|
279 // End of File |
|
280 |
|
281 |