|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : sipSigcompcompartmentctx.cpp |
|
15 // Part of : SIPSigComp |
|
16 // Version : SIP/3.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sipsigcompcompartmentctx.h" |
|
22 #include "sigcompcompartment.h" |
|
23 #include "MCompartmentCtxOwner.h" |
|
24 #include "MCompartmentCtxUser.h" |
|
25 |
|
26 const TInt KUserArrayGranularity = 4; |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CSipSigCompCompartmentCtx::NewL |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CSipSigCompCompartmentCtx* CSipSigCompCompartmentCtx::NewL( |
|
33 MCompartmentCtxOwner& aMyOwner, |
|
34 const CSigComp& aSigComp, |
|
35 const TInetAddr& aAddress, |
|
36 TUint32 aIapId, |
|
37 TBool aDynamicCompression ) |
|
38 { |
|
39 CSipSigCompCompartmentCtx* self = |
|
40 CSipSigCompCompartmentCtx::NewLC( aMyOwner, |
|
41 aSigComp, |
|
42 aAddress, |
|
43 aIapId, |
|
44 aDynamicCompression ); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSipSigCompCompartmentCtx::NewLC |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CSipSigCompCompartmentCtx* CSipSigCompCompartmentCtx::NewLC( |
|
55 MCompartmentCtxOwner& aMyOwner, |
|
56 const CSigComp& aSigComp, |
|
57 const TInetAddr& aAddress, |
|
58 TUint32 aIapId, |
|
59 TBool aDynamicCompression ) |
|
60 { |
|
61 CSipSigCompCompartmentCtx* self = |
|
62 new ( ELeave ) CSipSigCompCompartmentCtx( aMyOwner, |
|
63 aSigComp, |
|
64 aAddress, |
|
65 aIapId, |
|
66 aDynamicCompression ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CSipSigCompCompartmentCtx::ConstructL |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CSipSigCompCompartmentCtx::ConstructL() |
|
77 { |
|
78 iSigCompCompartment = |
|
79 CSigCompCompartment::NewL( iSigComp, iDynamicCompression ); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CSipSigCompCompartmentCtx::~CSipSigCompCompartmentCtx |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CSipSigCompCompartmentCtx::~CSipSigCompCompartmentCtx() |
|
87 { |
|
88 iUserArray.Reset(); |
|
89 iUserArray.Close(); |
|
90 delete iSigCompCompartment; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CSipSigCompCompartmentCtx::Compartment |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CSigCompCompartment* CSipSigCompCompartmentCtx::Compartment() |
|
98 { |
|
99 return iSigCompCompartment; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSipSigCompCompartmentCtx::AttachCompartmentUserL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CSipSigCompCompartmentCtx::AttachCompartmentUserL( |
|
107 MCompartmentCtxUser* aUser ) |
|
108 { |
|
109 // If entry of aUser existed already in array, fail silently |
|
110 TInt err = iUserArray.InsertInAddressOrder( aUser ); |
|
111 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
112 { |
|
113 User::Leave( err ); |
|
114 } |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CSipSigCompCompartmentCtx::DetachCompartmentUser |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CSipSigCompCompartmentCtx::DetachCompartmentUser( |
|
122 MCompartmentCtxUser* aUser ) |
|
123 { |
|
124 TInt index = iUserArray.Find( aUser ); |
|
125 if ( index != KErrNotFound ) |
|
126 { |
|
127 iUserArray.Remove( index ); |
|
128 iUserArray.Compress(); |
|
129 } |
|
130 |
|
131 // If no more users, compartment can be deleted |
|
132 if ( iUserArray.Count() == 0 ) |
|
133 { |
|
134 iMyOwner.KillMe( this ); |
|
135 } |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CSipSigCompCompartmentCtx::Match |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TBool CSipSigCompCompartmentCtx::Match( |
|
143 const TInetAddr& aAddress, |
|
144 TUint32 aIapId ) const |
|
145 { |
|
146 // Don't care about address port |
|
147 return ( !aAddress.IsWildAddr() && |
|
148 iAddress.Match( aAddress ) && |
|
149 iIapId == aIapId ); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CSipSigCompCompartmentCtx::SetCurrentState |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CSipSigCompCompartmentCtx::SetCurrentState( |
|
157 CSipSigCompCompartmentCtx::TState aCurrentState ) |
|
158 { |
|
159 iCurrentState = aCurrentState; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CSipSigCompCompartmentCtx::SendFailedL |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CSipSigCompCompartmentCtx::SendFailedL() |
|
167 { |
|
168 if ( iCurrentState == CSipSigCompCompartmentCtx::EAlive ) |
|
169 { |
|
170 ResetCompartmentL(); |
|
171 } |
|
172 else |
|
173 { |
|
174 NotifyUsersAboutSelfDestruction(); |
|
175 iMyOwner.KillMe( this ); |
|
176 } |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CSipSigCompCompartmentCtx::NotifyUsersAboutSelfDestruction |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CSipSigCompCompartmentCtx::NotifyUsersAboutSelfDestruction() |
|
184 { |
|
185 TInt lastIndex( iUserArray.Count() - 1 ); |
|
186 for ( TInt i = lastIndex; i >= 0; i-- ) |
|
187 { |
|
188 iUserArray[ i ]->CompartmentDeleted(); |
|
189 } |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CSipSigCompCompartmentCtx::ResetCompartmentL |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CSipSigCompCompartmentCtx::ResetCompartmentL() |
|
197 { |
|
198 delete iSigCompCompartment; |
|
199 iSigCompCompartment = 0; |
|
200 iSigCompCompartment = |
|
201 CSigCompCompartment::NewL( iSigComp, iDynamicCompression ); |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // Constructor |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 CSipSigCompCompartmentCtx::CSipSigCompCompartmentCtx( |
|
209 MCompartmentCtxOwner& aMyOwner, |
|
210 const CSigComp& aSigComp, |
|
211 const TInetAddr& aAddress, |
|
212 TUint32 aIapId, |
|
213 TBool aDynamicCompression ) : |
|
214 iMyOwner( aMyOwner ), |
|
215 iSigComp( aSigComp ), |
|
216 iAddress( aAddress ), |
|
217 iIapId( aIapId ), |
|
218 iDynamicCompression( aDynamicCompression ), |
|
219 iUserArray( KUserArrayGranularity ), |
|
220 iCurrentState( CSipSigCompCompartmentCtx::EIdle ) |
|
221 { |
|
222 } |
|
223 |