|
1 /* |
|
2 * Copyright (c) 2005 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 |
|
20 |
|
21 #include "CTcMCEProfileContainer.h" |
|
22 #include "CTcMCEContext.h" |
|
23 #include "MCEConstants.h" |
|
24 #include "sipprofile.h" |
|
25 #include "e32base.h" |
|
26 |
|
27 const TInt KReceiveQueueGranularity( 1 ); |
|
28 const TInt KProfileArrayGranularity( 2 ); |
|
29 |
|
30 CTcMCEProfileContainer* CTcMCEProfileContainer::NewL( CTcMCEContext& aContext, |
|
31 CSIP& aSip ) |
|
32 { |
|
33 CTcMCEProfileContainer* self = |
|
34 new( ELeave ) CTcMCEProfileContainer( aContext, aSip ); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 CTcMCEProfileContainer::~CTcMCEProfileContainer() |
|
43 { |
|
44 iProfiles.ResetAndDestroy(); |
|
45 |
|
46 delete iProfileRegistry; |
|
47 iReceiveQueue.Reset(); |
|
48 } |
|
49 |
|
50 CTcMCEProfileContainer::CTcMCEProfileContainer( CTcMCEContext& aContext, |
|
51 CSIP& aSip ) : |
|
52 iContext( aContext ), |
|
53 iSip( aSip ), |
|
54 iReceiveQueue( KReceiveQueueGranularity ), |
|
55 iProfiles( KProfileArrayGranularity ) |
|
56 { |
|
57 } |
|
58 |
|
59 void CTcMCEProfileContainer::ConstructL() |
|
60 { |
|
61 iProfileRegistry = CSIPProfileRegistry::NewL( iSip, *this ); |
|
62 } |
|
63 |
|
64 |
|
65 |
|
66 // |
|
67 // -- MSIPProfileRegistryObserver functions ----------------------------------- |
|
68 // |
|
69 |
|
70 void CTcMCEProfileContainer::ProfileRegistryEventOccurred(TUint32 aProfileId, |
|
71 TEvent aEvent) |
|
72 { |
|
73 TTcProfileReceived received; |
|
74 received.iProfileId = aProfileId; |
|
75 |
|
76 switch (aEvent) |
|
77 { |
|
78 case MSIPProfileRegistryObserver::EProfileCreated: |
|
79 { |
|
80 received.iEvent = ETcProfileCreated; |
|
81 break; |
|
82 } |
|
83 case MSIPProfileRegistryObserver::EProfileUpdated: |
|
84 { |
|
85 received.iEvent = ETcProfileUpdated; |
|
86 break; |
|
87 } |
|
88 case MSIPProfileRegistryObserver::EProfileRegistered: |
|
89 { |
|
90 CSIPProfile& profile = GetProfileByIdL(aProfileId); |
|
91 // Expect to be the right profile |
|
92 if (iWait.IsStarted()) |
|
93 { |
|
94 //CActiveScheduler::Stop(); |
|
95 iWait.AsyncStop(); |
|
96 } |
|
97 |
|
98 // The control returns to CTcMCEProfileContainer::RegisterProfileL |
|
99 break; |
|
100 } |
|
101 case MSIPProfileRegistryObserver::EProfileDeregistered: |
|
102 { |
|
103 received.iEvent = ETcProfileRegistrationStatusChanged; |
|
104 break; |
|
105 } |
|
106 case MSIPProfileRegistryObserver::EProfileDestroyed: |
|
107 { |
|
108 received.iEvent = ETcProfileDestroyed; |
|
109 break; |
|
110 } |
|
111 default: |
|
112 { |
|
113 received.iEvent = ETcUnknown; |
|
114 break; |
|
115 } |
|
116 } |
|
117 QueueProfileReceived( received ); |
|
118 } |
|
119 |
|
120 void CTcMCEProfileContainer::ProfileRegistryErrorOccurred(TUint32 aProfileId, |
|
121 TInt aError ) |
|
122 { |
|
123 TTcProfileReceived received; |
|
124 received.iProfileId = aProfileId; |
|
125 received.iEvent = ETcProfileRegistryErrorOccurred; |
|
126 received.iError = aError; |
|
127 QueueProfileReceived( received ); |
|
128 CSIPProfile& profile = GetProfileByIdL(aProfileId); |
|
129 if (iWait.IsStarted()) |
|
130 { |
|
131 //CActiveScheduler::Stop(); |
|
132 iWait.AsyncStop(); |
|
133 } |
|
134 } |
|
135 |
|
136 // |
|
137 // -- MSIPConnectionObserver dummy functions |
|
138 // |
|
139 |
|
140 void CTcMCEProfileContainer::IncomingRequest (CSIPServerTransaction* /*aTransaction*/) |
|
141 { |
|
142 // NOP |
|
143 } |
|
144 void CTcMCEProfileContainer::IncomingRequest (CSIPServerTransaction* /*aTransaction*/, |
|
145 CSIPDialog& /*aDialog*/) |
|
146 { |
|
147 // NOP |
|
148 } |
|
149 void CTcMCEProfileContainer::IncomingResponse (CSIPClientTransaction& /*aTransaction*/) |
|
150 { |
|
151 // NOP |
|
152 } |
|
153 void CTcMCEProfileContainer::IncomingResponse (CSIPClientTransaction& /*aTransaction*/, |
|
154 CSIPDialogAssocBase& /*aDialogAssoc*/) |
|
155 { |
|
156 // NOP |
|
157 } |
|
158 void CTcMCEProfileContainer::IncomingResponse (CSIPClientTransaction& /*aTransaction*/, |
|
159 CSIPInviteDialogAssoc* /*aDialogAssoc*/) |
|
160 { |
|
161 // NOP |
|
162 } |
|
163 void CTcMCEProfileContainer::IncomingResponse (CSIPClientTransaction& /*aTransaction*/, |
|
164 CSIPRegistrationBinding& /*aRegistration*/) |
|
165 { |
|
166 // NOP |
|
167 } |
|
168 void CTcMCEProfileContainer::ErrorOccured (TInt /*aError*/, |
|
169 CSIPTransactionBase& /*aTransaction*/) |
|
170 { |
|
171 // NOP |
|
172 } |
|
173 void CTcMCEProfileContainer::ErrorOccured (TInt /*aError*/, |
|
174 CSIPClientTransaction& /*aTransaction*/, |
|
175 CSIPRegistrationBinding& /*aRegistration*/) |
|
176 { |
|
177 // NOP |
|
178 } |
|
179 void CTcMCEProfileContainer::ErrorOccured (TInt /*aError*/, |
|
180 CSIPTransactionBase& /*aTransaction*/, |
|
181 CSIPDialogAssocBase& /*aDialogAssoc*/) |
|
182 { |
|
183 // NOP |
|
184 } |
|
185 void CTcMCEProfileContainer::ErrorOccured (TInt /*aError*/, CSIPRefresh& /*aSIPRefresh*/) |
|
186 { |
|
187 // NOP |
|
188 } |
|
189 void CTcMCEProfileContainer::ErrorOccured (TInt /*aError*/, |
|
190 CSIPRegistrationBinding& /*aRegistration*/) |
|
191 { |
|
192 // NOP |
|
193 } |
|
194 void CTcMCEProfileContainer::ErrorOccured (TInt /*aError*/, |
|
195 CSIPDialogAssocBase& /*aDialogAssoc*/) |
|
196 { |
|
197 // NOP |
|
198 } |
|
199 void CTcMCEProfileContainer::InviteCompleted (CSIPClientTransaction& /*aTransaction*/) |
|
200 { |
|
201 // NOP |
|
202 } |
|
203 void CTcMCEProfileContainer::InviteCanceled (CSIPServerTransaction& /*aTransaction*/) |
|
204 { |
|
205 // NOP |
|
206 } |
|
207 void CTcMCEProfileContainer::ConnectionStateChanged (CSIPConnection::TState /*aState*/) |
|
208 { |
|
209 // NOP |
|
210 } |
|
211 |
|
212 // |
|
213 // -- Public functions -------------------------------------------------------- |
|
214 // |
|
215 |
|
216 TTcProfileReceived CTcMCEProfileContainer::ReceivedProfileItemL( TInt /*aTimeout*/ ) |
|
217 { |
|
218 // Get the first (oldest) item from the array |
|
219 TTcProfileReceived item = iReceiveQueue[ 0 ]; |
|
220 |
|
221 // ..and remove it from the array |
|
222 iReceiveQueue.Delete( 0 ); |
|
223 iReceiveQueue.Compress(); |
|
224 return item; |
|
225 } |
|
226 |
|
227 void CTcMCEProfileContainer::AddProfileL( CSIPProfile* aProfile ) |
|
228 { |
|
229 CleanupStack::PushL( aProfile ); |
|
230 |
|
231 TUint32 id( 0 ); |
|
232 User::LeaveIfError( aProfile->GetParameter( KSIPProfileId, id ) ); |
|
233 |
|
234 // Array may contain multiple instances with same profileId |
|
235 CTcSIPProfile* tcprofile = |
|
236 new ( ELeave ) CTcSIPProfile( aProfile, (TInt)id ); |
|
237 CleanupStack::Pop( aProfile ); |
|
238 CleanupStack::PushL( tcprofile ); |
|
239 User::LeaveIfError( iProfiles.Append( tcprofile ) ); |
|
240 CleanupStack::Pop( tcprofile ); |
|
241 } |
|
242 |
|
243 CSIPProfile& CTcMCEProfileContainer::GetDefaultProfileL() |
|
244 { |
|
245 CSIPProfile* profile = |
|
246 static_cast< CSIPProfile* >( ProfileRegistry().DefaultProfileL() ); |
|
247 |
|
248 AddProfileL( profile ); |
|
249 |
|
250 return *profile; |
|
251 } |
|
252 |
|
253 CSIPProfile& CTcMCEProfileContainer::GetProfileByIdL( TInt aProfileId ) |
|
254 { |
|
255 CSIPProfile* profile = 0; |
|
256 |
|
257 // Check whether profile is already stored into our internal array |
|
258 TInt count = iProfiles.Count(); |
|
259 for( TInt i=0; i < count; i++ ) |
|
260 { |
|
261 if( iProfiles[ i ]->ProfileId() == aProfileId ) |
|
262 { |
|
263 return iProfiles[ i ]->Profile(); |
|
264 } |
|
265 |
|
266 } |
|
267 // Profile wasn't found from internal array, create new instance through |
|
268 // registry and store it |
|
269 profile = ProfileRegistry().ProfileL( aProfileId ); |
|
270 |
|
271 if ( !profile ) |
|
272 { |
|
273 User::Leave( KErrNotFound ); |
|
274 } |
|
275 |
|
276 AddProfileL( profile ); |
|
277 |
|
278 return *profile; |
|
279 } |
|
280 |
|
281 CSIPProfile& CTcMCEProfileContainer::RegisterProfileL(TInt aProfileId) |
|
282 { |
|
283 CSIPProfile& profile = GetProfileByIdL(aProfileId); |
|
284 ProfileRegistry().EnableL(profile, *this); |
|
285 if (!profile.IsContextActive()) |
|
286 { |
|
287 //CActiveScheduler::Start(); |
|
288 iWait.Start(); |
|
289 } |
|
290 |
|
291 // After calling CActiveScheduler::Stop() the control returns here |
|
292 return profile; |
|
293 } |
|
294 |
|
295 |
|
296 TInt CTcMCEProfileContainer::DisableProfileL(TInt aProfileId) |
|
297 { |
|
298 CSIPProfile& profile = GetProfileByIdL(aProfileId); |
|
299 TInt err=0; |
|
300 if (profile.IsContextActive()) |
|
301 { |
|
302 err = ProfileRegistry().Disable(profile); |
|
303 } |
|
304 |
|
305 // After calling CActiveScheduler::Stop() the control returns here |
|
306 return err; |
|
307 } |
|
308 // |
|
309 // -- Internal utility functions ---------------------------------------------- |
|
310 // |
|
311 |
|
312 void CTcMCEProfileContainer::QueueProfileReceived( TTcProfileReceived& aItem ) |
|
313 { |
|
314 |
|
315 TRAPD( err, iReceiveQueue.AppendL( aItem ) ); |
|
316 __ASSERT_ALWAYS( !err, User::Panic( KMceErrOOMInObserver, KErrNoMemory ) ); |
|
317 } |
|
318 |
|
319 // |
|
320 // -- Helper classes ---------------------------------------------------------- |
|
321 // |
|
322 |
|
323 |
|
324 CTcSIPProfile::CTcSIPProfile( CSIPProfile* aProfile, TInt aProfileId ) |
|
325 { |
|
326 iProfile = aProfile; |
|
327 iProfileId = aProfileId; |
|
328 } |
|
329 |
|
330 CTcSIPProfile::~CTcSIPProfile() |
|
331 { |
|
332 delete iProfile; |
|
333 } |
|
334 |
|
335 CSIPProfile& CTcSIPProfile::Profile() |
|
336 { |
|
337 return *iProfile; |
|
338 } |
|
339 |
|
340 TInt CTcSIPProfile::ProfileId() |
|
341 { |
|
342 return iProfileId; |
|
343 } |