|
1 // Copyright (c) 2005-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 : SIPRefresh.cpp |
|
15 // Part of : SIPAPI |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sipdefs.h" |
|
22 #include "siperr.h" |
|
23 #include "SipAssert.h" |
|
24 #include "sipstrings.h" |
|
25 #include "sipclientconnection.h" |
|
26 #include "siprefresh.h" |
|
27 #include "sipclienttransaction.h" |
|
28 #include "siprefreshassociation.h" |
|
29 #include "transactionassociation.h" |
|
30 |
|
31 |
|
32 #ifdef CPPUNIT_TEST |
|
33 |
|
34 #include "TestCleanupStack.h" |
|
35 |
|
36 #undef EXPORT_C |
|
37 #define EXPORT_C |
|
38 |
|
39 #endif |
|
40 |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CSIPRefresh::NewL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C CSIPRefresh* CSIPRefresh::NewL() |
|
47 { |
|
48 CSIPRefresh* self = CSIPRefresh::NewLC(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CSIPRefresh::NewLC |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CSIPRefresh* CSIPRefresh::NewLC() |
|
58 { |
|
59 CSIPRefresh* self = new (ELeave) CSIPRefresh(); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSIPRefresh::CSIPRefresh |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CSIPRefresh::CSIPRefresh() : iState(EConstructing) |
|
70 { |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CSIPRefresh::ConstructL |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void CSIPRefresh::ConstructL() |
|
78 { |
|
79 SIPStrings::OpenL(); |
|
80 iState = EInactive; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CSIPRefresh::~CSIPRefresh |
|
85 // If iState is EConstructing, string pool was not opened. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 EXPORT_C CSIPRefresh::~CSIPRefresh() |
|
89 { |
|
90 if (iClientTransaction) |
|
91 { |
|
92 iClientTransaction->RemoveRefresh(); |
|
93 } |
|
94 |
|
95 if (iOwner) |
|
96 { |
|
97 iOwner->DeletingRefresh(*this, iRefreshId); |
|
98 } |
|
99 |
|
100 iRequestType.Close(); |
|
101 if (iState != EConstructing) |
|
102 { |
|
103 SIPStrings::Close(); |
|
104 } |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CSIPRefresh::State |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C CSIPRefresh::TState CSIPRefresh::State() const |
|
112 { |
|
113 return iState; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CSIPRefresh::IsStandAlone |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C TBool CSIPRefresh::IsStandAlone() const |
|
121 { |
|
122 return iOwner && (iOwner->CheckIfStandAlone() == KErrNone); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CSIPRefresh::SIPTransaction |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 EXPORT_C const CSIPClientTransaction* CSIPRefresh::SIPTransaction() const |
|
130 { |
|
131 return iClientTransaction; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CSIPRefresh::TerminateL |
|
136 // No need to check if this is a standalone refresh, as UpdateRefreshL leaves |
|
137 // with the proper error if this refresh isn't standalone. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C CSIPClientTransaction* |
|
141 CSIPRefresh::TerminateL(CSIPMessageElements* aElements) |
|
142 { |
|
143 CheckStateL(); |
|
144 return iOwner->UpdateRefreshL(*this, aElements, ETrue); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CSIPRefresh::UpdateL |
|
149 // No need to check if this is a standalone refresh, as UpdateRefreshL leaves |
|
150 // with the proper error if this refresh isn't standalone. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C CSIPClientTransaction* |
|
154 CSIPRefresh::UpdateL(CSIPMessageElements* aElements) |
|
155 { |
|
156 CheckStateL(); |
|
157 return iOwner->UpdateRefreshL(*this, aElements, EFalse); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CSIPRefresh::operator== |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C TBool CSIPRefresh::operator==(const CSIPRefresh& aRefresh) const |
|
165 { |
|
166 if (!iRefreshId || !aRefresh.iRefreshId) |
|
167 { |
|
168 //If either of the ids is empty, the refreshes are not considired same, |
|
169 //unless the objects are actually same |
|
170 return this == &aRefresh; |
|
171 } |
|
172 |
|
173 return iRefreshId == aRefresh.iRefreshId; |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CSIPRefresh::IntervalL |
|
178 // Allow getting interval even before active state. |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C TUint CSIPRefresh::IntervalL() const |
|
182 { |
|
183 __ASSERT_ALWAYS(iOwner, User::Leave(KErrSIPResourceNotAvailable)); |
|
184 |
|
185 return iOwner->TransactionAssociation().ClientConnectionL(). |
|
186 RefreshIntervalL(iRefreshId); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CSIPRefresh::SetIntervalL |
|
191 // Allow interval setting even before active state. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C void CSIPRefresh::SetIntervalL(TUint aInterval) |
|
195 { |
|
196 __ASSERT_ALWAYS(iOwner, User::Leave(KErrSIPResourceNotAvailable)); |
|
197 __ASSERT_ALWAYS(aInterval > 0, User::Leave(KErrArgument)); |
|
198 |
|
199 return iOwner->TransactionAssociation().ClientConnectionL(). |
|
200 SetRefreshIntervalL(iRefreshId, aInterval); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CSIPRefresh::SetRefreshOwner |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CSIPRefresh::SetRefreshOwner(MSIPRefreshAssociation& aAssoc) |
|
208 { |
|
209 iOwner = &aAssoc; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CSIPRefresh::RemoveRefreshOwner |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CSIPRefresh::RemoveRefreshOwner(const MSIPRefreshAssociation& aAssoc) |
|
217 { |
|
218 __SIP_ASSERT_RETURN(iOwner == &aAssoc, KErrUnknown); |
|
219 |
|
220 iOwner = NULL; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CSIPRefresh::ChangeState |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CSIPRefresh::ChangeState(CSIPRefresh::TState aNextState) |
|
228 { |
|
229 iState = aNextState; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CSIPRefresh::RefreshId |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 TUint32 CSIPRefresh::RefreshId() const |
|
237 { |
|
238 return iRefreshId; |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CSIPRefresh::SetRefreshIdIfEmpty |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CSIPRefresh::SetRefreshIdIfEmpty(TUint32 aRefreshId) |
|
246 { |
|
247 if (!iRefreshId) |
|
248 { |
|
249 iRefreshId = aRefreshId; |
|
250 } |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CSIPRefresh::RequestType |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 RStringF CSIPRefresh::RequestType() const |
|
258 { |
|
259 return iRequestType; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CSIPRefresh::SetRequestType |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CSIPRefresh::SetRequestType(RStringF aType) |
|
267 { |
|
268 iRequestType.Close(); |
|
269 iRequestType = aType.Copy(); |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSIPRefresh::DoesMatch |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 TBool CSIPRefresh::DoesMatch(TUint32 aRefreshId) const |
|
277 { |
|
278 return aRefreshId == iRefreshId; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CSIPRefresh::AddTransaction |
|
283 // Refresh is associated to a new client transaction. iClientTransaction might |
|
284 // be non-NULL in case application has not deleted the previous transaction yet. |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CSIPRefresh::AddTransaction(CSIPClientTransaction& aTransaction) |
|
288 { |
|
289 //Remove possibly existing association to current transaction |
|
290 if (iClientTransaction) |
|
291 { |
|
292 iClientTransaction->RemoveRefresh(); |
|
293 } |
|
294 |
|
295 iClientTransaction = &aTransaction; |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CSIPRefresh::RemoveTransaction |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 void CSIPRefresh::RemoveTransaction() |
|
303 { |
|
304 __SIP_ASSERT_RETURN(iClientTransaction, KErrNotFound); |
|
305 |
|
306 iClientTransaction = NULL; |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CSIPRefresh::Transaction |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 CSIPClientTransaction* CSIPRefresh::Transaction() |
|
314 { |
|
315 return iClientTransaction; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CSIPRefresh::UpdateRefreshState |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 void CSIPRefresh::UpdateRefreshState(TUint aStatusCode) |
|
323 { |
|
324 if (aStatusCode >= 300) |
|
325 { |
|
326 ChangeState(CSIPRefresh::ETerminated); |
|
327 } |
|
328 else |
|
329 { |
|
330 if (aStatusCode >= 200) |
|
331 { |
|
332 ChangeState(CSIPRefresh::EActive); |
|
333 } |
|
334 } |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CSIPRefresh::CheckStateL |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CSIPRefresh::CheckStateL() const |
|
342 { |
|
343 __ASSERT_ALWAYS(iState == EActive, |
|
344 User::Leave(KErrSIPInvalidTransactionState)); |
|
345 __ASSERT_ALWAYS(iOwner, User::Leave(KErrSIPResourceNotAvailable)); |
|
346 } |