|
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: See class definition below. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CTcSIPClientDiscoveryContainer.h" |
|
19 #include "SipConstants.h" |
|
20 #include "ErrorHandling.h" |
|
21 |
|
22 #include <sipclientdiscovery.h> |
|
23 #include <sipheaderbase.h> |
|
24 |
|
25 const TInt KReceivedEventsQueueGranularity = 4; |
|
26 |
|
27 CTcSIPClientDiscoveryContainer* CTcSIPClientDiscoveryContainer::NewL( |
|
28 CTcSIPContext& aContext, |
|
29 TUid aUid ) |
|
30 { |
|
31 CTcSIPClientDiscoveryContainer* self = |
|
32 new ( ELeave ) CTcSIPClientDiscoveryContainer( aContext, aUid ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CTcSIPClientDiscoveryContainer::~CTcSIPClientDiscoveryContainer() |
|
40 { |
|
41 delete iSipClientDiscovery; |
|
42 delete iTimer; |
|
43 iReceivedEventsQueue.Reset(); |
|
44 } |
|
45 |
|
46 |
|
47 CTcSIPClientDiscoveryContainer::CTcSIPClientDiscoveryContainer( CTcSIPContext& aContext, TUid aUid ) |
|
48 : iContext( aContext ), |
|
49 iReceivedEventsQueue( KReceivedEventsQueueGranularity ), |
|
50 iUid( aUid ) |
|
51 { |
|
52 } |
|
53 |
|
54 void CTcSIPClientDiscoveryContainer::ConstructL() |
|
55 { |
|
56 iTimer = CDeltaTimer::NewL( CActive::EPriorityStandard ); |
|
57 TCallBack cb( ReceiveTimeout, this ); |
|
58 iReceiveTimeout.Set( cb ); |
|
59 |
|
60 iSipClientDiscovery = CSIPClientDiscovery::NewL( *this, iUid ); |
|
61 } |
|
62 |
|
63 void CTcSIPClientDiscoveryContainer::ChannelResolvedL( TUid aChannel, TUint32 aRequestId ) |
|
64 { |
|
65 TTcClientDiscoveryEvent event; |
|
66 event.iType = ETcClientDiscoveryChannelResolved; |
|
67 event.iChannel = aChannel; |
|
68 event.iRequestId = aRequestId; |
|
69 TRAPD( err, QueueReceivedEventL( event ) ); |
|
70 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
71 } |
|
72 |
|
73 void CTcSIPClientDiscoveryContainer::ClientNotFoundL( |
|
74 TUint32 aRequestId, |
|
75 TUint /*aStatusCode*/, |
|
76 RStringF /*aReasonPhrase*/, |
|
77 RPointerArray<CSIPHeaderBase> aHeaders, |
|
78 HBufC8* aContent ) |
|
79 { |
|
80 // At the moment care only about requestId |
|
81 TTcClientDiscoveryEvent event; |
|
82 event.iType = ETcClientDiscoveryClientNotFound; |
|
83 event.iRequestId = aRequestId; |
|
84 TRAPD( err, QueueReceivedEventL( event ) ); |
|
85 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
86 |
|
87 aHeaders.ResetAndDestroy(); |
|
88 delete aContent; |
|
89 } |
|
90 |
|
91 void CTcSIPClientDiscoveryContainer::ErrorOccurred( TInt aError, TUint32 aRequestId ) |
|
92 { |
|
93 TTcClientDiscoveryEvent event; |
|
94 event.iType = ETcClientDiscoveryError; |
|
95 event.iRequestId = aRequestId; |
|
96 event.iError = aError; |
|
97 TRAPD( err, QueueReceivedEventL( event ) ); |
|
98 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
99 } |
|
100 |
|
101 |
|
102 TTcClientDiscoveryEvent CTcSIPClientDiscoveryContainer::ReceivedClientDiscoveryEventL( TInt aTimeout ) |
|
103 { |
|
104 if( iReceivedEventsQueue.Count() == 0 ) |
|
105 { |
|
106 // wait for items to arrive |
|
107 iTimer->Queue( aTimeout * KSecondAsMicros, iReceiveTimeout ); |
|
108 iActiveWait.Start(); |
|
109 } |
|
110 |
|
111 // Is the queue still empty ? (i.e. timeout occurred) |
|
112 if( iReceivedEventsQueue.Count() == 0 ) |
|
113 { |
|
114 User::Leave( KErrTimedOut ); |
|
115 } |
|
116 |
|
117 TTcClientDiscoveryEvent event = iReceivedEventsQueue[ 0 ]; |
|
118 iReceivedEventsQueue.Delete( 0 ); |
|
119 iReceivedEventsQueue.Compress(); |
|
120 |
|
121 return event; |
|
122 } |
|
123 |
|
124 void CTcSIPClientDiscoveryContainer::QueueReceivedEventL( TTcClientDiscoveryEvent& aClientDiscoveryEvent ) |
|
125 { |
|
126 TRAPD( err, iReceivedEventsQueue.AppendL( aClientDiscoveryEvent ) ); |
|
127 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
128 |
|
129 if( iActiveWait.IsStarted() ) |
|
130 { |
|
131 iTimer->Remove( iReceiveTimeout ); |
|
132 iActiveWait.AsyncStop(); |
|
133 } |
|
134 } |
|
135 |
|
136 TInt CTcSIPClientDiscoveryContainer::ReceiveTimeout( TAny* aSelf ) |
|
137 { |
|
138 CTcSIPClientDiscoveryContainer& self = |
|
139 *reinterpret_cast< CTcSIPClientDiscoveryContainer* >( aSelf ); |
|
140 if( self.iActiveWait.IsStarted() ) |
|
141 { |
|
142 self.iActiveWait.AsyncStop(); |
|
143 } |
|
144 |
|
145 return KErrNone; |
|
146 } |