|
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: Implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CTcSIPProfileContainer.h" |
|
20 #include "TTcSIPReceived.h" |
|
21 #include "CTcSIPContext.h" |
|
22 #include "SipConstants.h" |
|
23 #include "sipprofile.h" |
|
24 #include "sipmanagedprofile.h" |
|
25 |
|
26 #include "tclog.h" |
|
27 #include "TesterConstants.h" |
|
28 #include "ErrorHandling.h" |
|
29 |
|
30 CTcSIPProfileContainer* CTcSIPProfileContainer::NewL( |
|
31 CTcSIPContext& aContext, |
|
32 CSIP& aSip ) |
|
33 { |
|
34 CTcSIPProfileContainer* self = |
|
35 new( ELeave ) CTcSIPProfileContainer( aContext, |
|
36 aSip ); |
|
37 |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 |
|
42 return self; |
|
43 } |
|
44 |
|
45 CTcSIPProfileContainer::~CTcSIPProfileContainer() |
|
46 { |
|
47 TcLog::Write( _L8("CTcSIPContext::~CTcSIPContext() start\n") ); |
|
48 |
|
49 iProfiles.ResetAndDestroy(); |
|
50 iManagedProfiles.ResetAndDestroy(); |
|
51 |
|
52 delete iProfileRegistry; |
|
53 delete iManagedProfileRegistry; |
|
54 delete iTimer; |
|
55 iReceiveQueue.Reset(); |
|
56 |
|
57 TcLog::Write( _L8("CTcSIPContext::~CTcSIPContext() end\n") ); |
|
58 } |
|
59 |
|
60 CTcSIPProfileContainer::CTcSIPProfileContainer( CTcSIPContext& aContext, CSIP& aSip ) |
|
61 : iContext( aContext ), iSip( aSip ), iReceiveQueue( 1 ), iProfiles( 2 ), iManagedProfiles( 2 ) |
|
62 { |
|
63 } |
|
64 |
|
65 void CTcSIPProfileContainer::ConstructL() |
|
66 { |
|
67 iTimer = CDeltaTimer::NewL( CActive::EPriorityStandard ); |
|
68 TCallBack cb( ReceiveTimeout, this ); |
|
69 iReceiveTimeout.Set( cb ); |
|
70 |
|
71 TcLog::Write( _L8("CTcSIPProfileContainer::ConstructL() initializing SIP Profiles client\n") ); |
|
72 // Could be used only MangedProfile or UserProfile.. |
|
73 iManagedProfileRegistry = CSIPManagedProfileRegistry::NewL( *this ); |
|
74 iProfileRegistry = CSIPProfileRegistry::NewL( iSip, *this ); |
|
75 |
|
76 TcLog::Write( _L8("CTcSIPProfileContainer::ConstructL() end\n") ); |
|
77 } |
|
78 |
|
79 |
|
80 // |
|
81 // -- MSIPProfileRegistryObserver functions ----------------------------------- |
|
82 // |
|
83 |
|
84 void CTcSIPProfileContainer::ProfileRegistryEventOccurred(TUint32 aProfileId, TEvent aEvent) |
|
85 { |
|
86 TTcProfileReceived received; |
|
87 received.iProfileId = aProfileId; |
|
88 |
|
89 switch (aEvent) |
|
90 { |
|
91 case MSIPProfileRegistryObserver::EProfileCreated: |
|
92 { |
|
93 received.iEvent = ETcProfileCreated; |
|
94 break; |
|
95 } |
|
96 case MSIPProfileRegistryObserver::EProfileUpdated: |
|
97 { |
|
98 received.iEvent = ETcProfileUpdated; |
|
99 break; |
|
100 } |
|
101 case MSIPProfileRegistryObserver::EProfileRegistered: |
|
102 { |
|
103 received.iEvent = ETcProfileRegistrationStatusChanged; |
|
104 received.iRegStatus = ETcStatusRegistered; |
|
105 break; |
|
106 } |
|
107 case MSIPProfileRegistryObserver::EProfileDeregistered: |
|
108 { |
|
109 received.iEvent = ETcProfileRegistrationStatusChanged; |
|
110 received.iRegStatus = ETcStatusUnregistered; |
|
111 break; |
|
112 } |
|
113 case MSIPProfileRegistryObserver::EProfileDestroyed: |
|
114 { |
|
115 received.iEvent = ETcProfileDestroyed; |
|
116 break; |
|
117 } |
|
118 default: |
|
119 { |
|
120 received.iEvent = ETcUnknown; |
|
121 break; |
|
122 } |
|
123 } |
|
124 QueueProfileReceived( received ); |
|
125 } |
|
126 |
|
127 void CTcSIPProfileContainer::ProfileRegistryErrorOccurred(TUint32 aProfileId, TInt aError ) |
|
128 { |
|
129 TTcProfileReceived received; |
|
130 received.iProfileId = aProfileId; |
|
131 received.iEvent = ETcProfileRegistryErrorOccurred; |
|
132 received.iError = aError; |
|
133 QueueProfileReceived( received ); |
|
134 } |
|
135 |
|
136 // |
|
137 // -- Public functions -------------------------------------------------------- |
|
138 // |
|
139 |
|
140 TTcProfileReceived CTcSIPProfileContainer::ReceivedProfileItemL( TInt aTimeout ) |
|
141 { |
|
142 if( iReceiveQueue.Count() == 0 ) |
|
143 { |
|
144 // wait for items to arrive |
|
145 iTimer->Queue( aTimeout * KSecondAsMicros, iReceiveTimeout ); |
|
146 iActiveWait.Start(); |
|
147 } |
|
148 |
|
149 // Is the queue still empty ? (i.e. timeout occurred) |
|
150 if( iReceiveQueue.Count() == 0 ) |
|
151 { |
|
152 User::Leave( KErrTimedOut ); |
|
153 } |
|
154 |
|
155 // Get the first (oldest) item from the array |
|
156 TTcProfileReceived item = iReceiveQueue[ 0 ]; |
|
157 |
|
158 // ..and remove it from the array |
|
159 iReceiveQueue.Delete( 0 ); |
|
160 iReceiveQueue.Compress(); |
|
161 return item; |
|
162 } |
|
163 |
|
164 void CTcSIPProfileContainer::AddManagedProfileL( CSIPManagedProfile* aManagedProfile ) |
|
165 { |
|
166 CleanupStack::PushL( aManagedProfile ); |
|
167 |
|
168 TUint32 id( 0 ); |
|
169 User::LeaveIfError( aManagedProfile->GetParameter( KSIPProfileId, id ) ); |
|
170 |
|
171 // Array may contain multiple instances with same profileId |
|
172 CTcSIPManagedProfile* tcprofile = new ( ELeave ) CTcSIPManagedProfile( aManagedProfile, (TInt)id ); |
|
173 CleanupStack::Pop( aManagedProfile ); |
|
174 CleanupStack::PushL( tcprofile ); |
|
175 User::LeaveIfError( iManagedProfiles.Append( tcprofile ) ); |
|
176 CleanupStack::Pop(); |
|
177 } |
|
178 |
|
179 |
|
180 CSIPProfile& CTcSIPProfileContainer::GetProfileByIdL( TInt aProfileId ) |
|
181 { |
|
182 CSIPProfile* profile = 0; |
|
183 |
|
184 // Check whether profile is already stored into our internal array |
|
185 TInt count = iProfiles.Count(); |
|
186 for( TInt i=0; i < count; i++ ) |
|
187 { |
|
188 if( iProfiles[ i ]->ProfileId() == aProfileId ) |
|
189 { |
|
190 return iProfiles[ i ]->Profile(); |
|
191 } |
|
192 |
|
193 } |
|
194 // Profile wasn't found from internal array, create new instance through registry |
|
195 // and store it |
|
196 profile = ProfileRegistry().ProfileL( aProfileId ); |
|
197 |
|
198 CleanupStack::PushL( profile ); |
|
199 CTcSIPProfile* item = new ( ELeave ) CTcSIPProfile( profile, aProfileId ); |
|
200 CleanupStack::Pop( profile ); |
|
201 |
|
202 CleanupStack::PushL( item ); |
|
203 User::LeaveIfError( iProfiles.Append( item ) ); |
|
204 CleanupStack::Pop( item ); |
|
205 |
|
206 return *profile; |
|
207 } |
|
208 |
|
209 |
|
210 CSIPManagedProfile& CTcSIPProfileContainer::GetManagedProfileByIdL( TInt aManagedProfileId ) |
|
211 { |
|
212 CSIPManagedProfile* profile = 0; |
|
213 |
|
214 // Check whether profile is already stored into our internal array |
|
215 for( TInt i = 0; i < iManagedProfiles.Count(); i++ ) |
|
216 { |
|
217 if( iManagedProfiles[ i ]->ProfileId() == aManagedProfileId ) |
|
218 { |
|
219 return iManagedProfiles[ i ]->Profile(); |
|
220 } |
|
221 |
|
222 } |
|
223 // Profile wasn't found from internal array, create new instance through registry |
|
224 // and store it |
|
225 profile = static_cast< CSIPManagedProfile* >( ManagedProfileRegistry().ProfileL( aManagedProfileId ) ); |
|
226 |
|
227 CleanupStack::PushL( profile ); |
|
228 CTcSIPManagedProfile* item = new ( ELeave ) CTcSIPManagedProfile( profile, aManagedProfileId ); |
|
229 CleanupStack::Pop( profile ); |
|
230 |
|
231 CleanupStack::PushL( item ); |
|
232 User::LeaveIfError( iManagedProfiles.Append( item ) ); |
|
233 CleanupStack::Pop( item ); |
|
234 |
|
235 return *profile; |
|
236 } |
|
237 |
|
238 CSIPManagedProfile& CTcSIPProfileContainer::GetDefaultProfileL() |
|
239 { |
|
240 CSIPManagedProfile* profile = static_cast< CSIPManagedProfile* >( ManagedProfileRegistry().DefaultProfileL() ); |
|
241 |
|
242 AddManagedProfileL( profile ); |
|
243 |
|
244 return *profile; |
|
245 } |
|
246 |
|
247 void CTcSIPProfileContainer::DeleteProfileById( TInt aProfileId ) |
|
248 { |
|
249 CTcSIPProfile* tcprofile = 0; |
|
250 for( TInt i = 0; i < iProfiles.Count(); i++ ) |
|
251 { |
|
252 tcprofile = iProfiles[ i ]; |
|
253 |
|
254 if( tcprofile->ProfileId() == aProfileId ) |
|
255 { |
|
256 iProfiles.Remove( i ); |
|
257 delete tcprofile; |
|
258 return; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 void CTcSIPProfileContainer::DeleteManagedProfileById( TInt aManagedProfileId ) |
|
264 { |
|
265 CTcSIPManagedProfile* tcprofile = 0; |
|
266 for( TInt i = 0; i < iManagedProfiles.Count(); i++ ) |
|
267 { |
|
268 tcprofile = iManagedProfiles[ i ]; |
|
269 if( tcprofile->ProfileId() == aManagedProfileId ) |
|
270 { |
|
271 iManagedProfiles.Remove( i ); |
|
272 delete tcprofile; |
|
273 return; |
|
274 } |
|
275 } |
|
276 } |
|
277 // |
|
278 // -- Internal utility functions ---------------------------------------------- |
|
279 // |
|
280 |
|
281 void CTcSIPProfileContainer::QueueProfileReceived( TTcProfileReceived& aItem ) |
|
282 { |
|
283 TcLog::WriteFormat( _L8("CTcSIPProfileContainer::QueueProfileReceived( ProfileId = %d, Event = %d, Error = %d )"), aItem.iProfileId, aItem.iEvent, aItem.iError ); |
|
284 |
|
285 TRAPD( err, iReceiveQueue.AppendL( aItem ) ); |
|
286 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
287 |
|
288 if( iActiveWait.IsStarted() ) |
|
289 { |
|
290 iTimer->Remove( iReceiveTimeout ); |
|
291 iActiveWait.AsyncStop(); |
|
292 } |
|
293 } |
|
294 |
|
295 |
|
296 TInt CTcSIPProfileContainer::ReceiveTimeout( TAny* aSelf ) |
|
297 { |
|
298 CTcSIPProfileContainer& self = |
|
299 *reinterpret_cast< CTcSIPProfileContainer* >( aSelf ); |
|
300 if( self.iActiveWait.IsStarted() ) |
|
301 { |
|
302 self.iActiveWait.AsyncStop(); |
|
303 } |
|
304 |
|
305 return KErrNone; |
|
306 } |
|
307 |
|
308 |
|
309 // |
|
310 // -- Helper classes ------------------------------------------------------------ |
|
311 // |
|
312 |
|
313 |
|
314 CTcSIPProfile::CTcSIPProfile( CSIPProfile* aProfile, TInt aProfileId ) |
|
315 { |
|
316 iProfile = aProfile; |
|
317 iProfileId = aProfileId; |
|
318 } |
|
319 |
|
320 CTcSIPProfile::~CTcSIPProfile() |
|
321 { |
|
322 delete iProfile; |
|
323 } |
|
324 |
|
325 |
|
326 CSIPProfile& CTcSIPProfile::Profile() |
|
327 { |
|
328 return *iProfile; |
|
329 } |
|
330 |
|
331 TInt CTcSIPProfile::ProfileId() |
|
332 { |
|
333 return iProfileId; |
|
334 } |
|
335 |
|
336 |
|
337 CTcSIPManagedProfile::CTcSIPManagedProfile( CSIPManagedProfile* aManagedProfile, TInt aManagedProfileId ) |
|
338 { |
|
339 iManagedProfile = aManagedProfile; |
|
340 iManagedProfileId = aManagedProfileId; |
|
341 } |
|
342 |
|
343 CTcSIPManagedProfile::~CTcSIPManagedProfile() |
|
344 { |
|
345 delete iManagedProfile; |
|
346 } |
|
347 |
|
348 CSIPManagedProfile& CTcSIPManagedProfile::Profile() |
|
349 { |
|
350 return *iManagedProfile; |
|
351 } |
|
352 |
|
353 TInt CTcSIPManagedProfile::ProfileId() |
|
354 { |
|
355 return iManagedProfileId; |
|
356 } |
|
357 |
|
358 |