|
1 // Copyright (c) 2006-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 : Transmitter.cpp |
|
15 // Part of : Transaction |
|
16 // Version : SIP/5.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <in_sock.h> |
|
22 |
|
23 #include "siperr.h" |
|
24 #include "SipAssert.h" |
|
25 #include "CSipConnectionMgr.h" |
|
26 #include "TSIPTransportParams.h" |
|
27 #include "SipLogs.h" |
|
28 |
|
29 #include "Transmitter.h" |
|
30 #include "SendStatus.h" |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CTransmitter::NewL |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CTransmitter* CTransmitter::NewL(MSipConnectionMgr& aConnectionMgr) |
|
37 { |
|
38 return new (ELeave) CTransmitter(aConnectionMgr); |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CTransmitter::CTransmitter |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CTransmitter::CTransmitter(MSipConnectionMgr& aConnectionMgr) : |
|
46 CActive(EPriorityStandard), |
|
47 iConnectionMgr(aConnectionMgr) |
|
48 { |
|
49 CActiveScheduler::Add(this); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CTransmitter::~CTransmitter |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CTransmitter::~CTransmitter() |
|
57 { |
|
58 Cancel(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CTransmitter::SendRequestL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CTransmitter::SendRequestL(CSIPRequest& aReq, |
|
66 const TInetAddr& aAddress, |
|
67 TBool aForceUDP, |
|
68 const TSIPTransportParams& aParams, |
|
69 const CUri8* aOutboundProxy, |
|
70 MSendStatus* aObserver) |
|
71 { |
|
72 __SIP_ASSERT_LEAVE(aObserver, KErrArgument); |
|
73 |
|
74 if (IsActive()) |
|
75 { |
|
76 User::Leave(KErrAlreadyExists); |
|
77 } |
|
78 iConnectionMgr.SendL(aParams, |
|
79 aReq, |
|
80 aForceUDP, |
|
81 aOutboundProxy, |
|
82 aAddress, |
|
83 iStatus); |
|
84 iObserver = aObserver; |
|
85 SetActive(); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CTransmitter::SendResponseL |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CTransmitter::SendResponseL(CSIPResponse& aResp, |
|
93 const TSIPTransportParams& aParams, |
|
94 MSendStatus* aObserver, |
|
95 TTransactionId aTransactionId) |
|
96 { |
|
97 __SIP_ASSERT_LEAVE(aObserver, KErrArgument); |
|
98 |
|
99 if (IsActive()) |
|
100 { |
|
101 User::Leave(KErrAlreadyExists); |
|
102 } |
|
103 |
|
104 iConnectionMgr.SendL(aParams, aResp, aTransactionId, iStatus); |
|
105 iObserver = aObserver; |
|
106 SetActive(); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CTransmitter::TcpDisconnect |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CTransmitter::TcpDisconnect(TInetAddr& aRemoteAddr, |
|
114 const TSIPTransportParams& aParams) const |
|
115 { |
|
116 iConnectionMgr.TcpDisconnect(aParams, aRemoteAddr); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CTransmitter::MapErrorCode |
|
121 // ICMP Errors are seperated with a new Error Code KErrSIPICMPFailure |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CTransmitter::MapErrorCode(TInt aError) const |
|
125 { |
|
126 switch (aError) |
|
127 { |
|
128 //Connection is (temporarily) not available. Treat as sending error. |
|
129 case CSIPConnection::ESuspended: |
|
130 case CSIPConnection::EInactive: |
|
131 return KErrSIPTransportFailure; |
|
132 //ICMP errors |
|
133 case CSipConnectionMgr::EHostUnreachable: |
|
134 case CSipConnectionMgr::ENetUnreachable: |
|
135 case CSipConnectionMgr::EPortUnreachable: |
|
136 case CSipConnectionMgr::EProtocolUnreachable: |
|
137 return KErrSIPICMPFailure; |
|
138 |
|
139 default: |
|
140 return aError; |
|
141 } |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CTransmitter::DetachCallback |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CTransmitter::DetachCallback(MSendStatus* aObserver) |
|
149 { |
|
150 if (iObserver == aObserver) |
|
151 { |
|
152 iObserver = NULL; |
|
153 Cancel(); |
|
154 } |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CTransmitter::CancelSendResponses |
|
159 // CTransmitter doesn't cancel its possibly existing send request yet. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CTransmitter::CancelSendResponses(TTransactionId aTransactionId, |
|
163 TBool aAlso2xx) const |
|
164 { |
|
165 iConnectionMgr.CancelResponseSend(aTransactionId, aAlso2xx); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CTransmitter::DoCancel |
|
170 // If ConnectionMgr didn't cancel the request, complete it if iStatus is still |
|
171 // KRequestPending. If ConnectionMgr used User::RequestComplete but RunL hasn't |
|
172 // been called, CTransmitter is still active, but iStatus isn't KRequestPending. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CTransmitter::DoCancel() |
|
176 { |
|
177 __SIP_LOG("CTransmitter::DoCancel") |
|
178 |
|
179 if (iConnectionMgr.CancelSend(iStatus) != KErrNone && |
|
180 iStatus == KRequestPending) |
|
181 { |
|
182 __SIP_LOG("CTransmitter::DoCancel cancel own request") |
|
183 |
|
184 TRequestStatus* status = &iStatus; |
|
185 User::RequestComplete(status, KErrCancel); |
|
186 } |
|
187 |
|
188 __SIP_LOG("CTransmitter::DoCancel ends") |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CTransmitter::RunL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CTransmitter::RunL() |
|
196 { |
|
197 if (iObserver) |
|
198 { |
|
199 if (iStatus.Int() == KErrNone) |
|
200 { |
|
201 iObserver->SendCompleteL(); |
|
202 } |
|
203 else |
|
204 { |
|
205 iObserver->SendFailedL(MapErrorCode(iStatus.Int())); |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CTransmitter::RunError |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TInt CTransmitter::RunError(TInt aError) |
|
215 { |
|
216 __SIP_INT_LOG1("CTransmitter::RunError, err=", aError) |
|
217 |
|
218 if (iObserver) |
|
219 { |
|
220 iObserver->LeaveFromTransmitter(aError); |
|
221 } |
|
222 |
|
223 if (aError == KErrNoMemory) |
|
224 { |
|
225 return aError; |
|
226 } |
|
227 |
|
228 return KErrNone; |
|
229 } |