|
1 /* |
|
2 * Copyright (c) 2006 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: Simple Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <s32mem.h> |
|
25 |
|
26 // own simple |
|
27 #include "msimpleconnection.h" |
|
28 #include "simpleconnection.h" |
|
29 #include "simplecommon.h" |
|
30 #include "simpleenginerequest.h" |
|
31 #include "simplesipconnection.h" |
|
32 #include "simpleengineutils.h" |
|
33 #include "simpleclient.h" |
|
34 #include "simpleerrors.h" |
|
35 |
|
36 #ifdef _DEBUG |
|
37 #include "simpledebugutils.h" |
|
38 #endif |
|
39 |
|
40 // ================= MEMBER FUNCTIONS ======================= |
|
41 // |
|
42 |
|
43 // ---------------------------------------------------------- |
|
44 // CSimpleClient::CSimpleClient |
|
45 // ---------------------------------------------------------- |
|
46 // |
|
47 CSimpleClient::CSimpleClient( |
|
48 MSimpleConnection& aConn ) |
|
49 : iConn( aConn ), |
|
50 iOpId(0), |
|
51 iSipStatus(0), |
|
52 iRetryAfterTime(0), |
|
53 iRequestList( CSimpleEngineRequest::LinkOffset()), |
|
54 iRequest( MSimpleEngineRequest::ENone ), |
|
55 iDestroyedPtr( NULL ) |
|
56 { |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------- |
|
60 // CSimpleClient::~CSimpleClient |
|
61 // ---------------------------------------------------------- |
|
62 // |
|
63 CSimpleClient::~CSimpleClient() |
|
64 { |
|
65 DeleteRequests(); |
|
66 |
|
67 if ( iDestroyedPtr ) |
|
68 { |
|
69 // We are called inside callback |
|
70 *iDestroyedPtr = ETrue; |
|
71 iDestroyedPtr = NULL; |
|
72 } |
|
73 |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------- |
|
77 // CSimpleClient::BaseConstructL |
|
78 // ---------------------------------------------------------- |
|
79 // |
|
80 void CSimpleClient::BaseConstructL() |
|
81 { |
|
82 iLimitLowerValue = TSimpleEngineUtils::OpIdRange(); |
|
83 iLimitUpperValue = iLimitLowerValue + KRangeSize; |
|
84 iOpId = iLimitLowerValue; |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // CSimpleClient::IncreaseOpId |
|
89 // ---------------------------------------------------------------------------- |
|
90 void CSimpleClient::IncreaseOpId( ) |
|
91 { |
|
92 iOpId++; |
|
93 if( iOpId >= iLimitUpperValue ) |
|
94 { |
|
95 iOpId = iLimitLowerValue; |
|
96 } |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CSimpleClient::DeleteRequests |
|
101 // ----------------------------------------------------------------------------- |
|
102 void CSimpleClient::DeleteRequests() |
|
103 { |
|
104 #ifdef _DEBUG |
|
105 TSimpleLogger::Log(_L("SimpleClient: DeleteRequests this=%d" ), (TInt)this ); |
|
106 #endif |
|
107 // Delete all buffered transaction requests |
|
108 TDblQueIter<CSimpleEngineRequest> rIter( iRequestList ); |
|
109 rIter.SetToFirst(); |
|
110 |
|
111 while ( rIter ) |
|
112 { |
|
113 CSimpleEngineRequest* req = rIter; |
|
114 rIter++; //lint !e1757 |
|
115 // delete corresponding request from another DLL too. |
|
116 req->ModifyType( MSimpleEngineRequest::EDestroy ); |
|
117 TRAP_IGNORE( SendReqL( *req ) ); |
|
118 // delete request from this DLL. |
|
119 req->Destroy(); |
|
120 } |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CSimpleClient::SearchRequests |
|
125 // ----------------------------------------------------------------------------- |
|
126 CSimpleEngineRequest* CSimpleClient::SearchRequests( TInt aOpId ) |
|
127 { |
|
128 #ifdef _DEBUG |
|
129 TSimpleLogger::Log(_L("SimpleClient: SearchRequests this=%d" ), (TInt)this ); |
|
130 #endif |
|
131 // Delete all buffered transaction requests |
|
132 TDblQueIter<CSimpleEngineRequest> rIter( iRequestList ); |
|
133 rIter.SetToFirst(); |
|
134 |
|
135 while ( rIter ) |
|
136 { |
|
137 CSimpleEngineRequest* req = rIter; |
|
138 rIter++; //lint !e1757 |
|
139 if ( req->OpId() == aOpId ) |
|
140 { |
|
141 return req; |
|
142 } |
|
143 } |
|
144 return (CSimpleEngineRequest*)NULL; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CSimpleClient::SendReqL |
|
149 // ----------------------------------------------------------------------------- |
|
150 void CSimpleClient::SendReqL( MSimpleEngineRequest& aReq ) |
|
151 { |
|
152 CSimpleConnection* conn = STATIC_CAST( CSimpleConnection*, &iConn); //lint !e826 |
|
153 CSimpleSipConnection* engine = conn->Connection(); |
|
154 engine->DispatchReqL( aReq ); |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------- |
|
158 // CSimpleClient::ResponseReason |
|
159 // ---------------------------------------------------------- |
|
160 // |
|
161 TInt CSimpleClient::ResponseReason( |
|
162 MSimpleEngineRequest& aR ) |
|
163 { |
|
164 switch ( aR.ResponseReason() ) |
|
165 { |
|
166 case MSimpleEngineRequest::ENoReason: |
|
167 return KErrNone; |
|
168 |
|
169 case MSimpleEngineRequest::ERejected: |
|
170 return KSimpleErrRejected; |
|
171 |
|
172 case MSimpleEngineRequest::ETimeout: |
|
173 return KSimpleErrTimeout; |
|
174 |
|
175 case MSimpleEngineRequest::EDeactivated: |
|
176 return KSimpleErrDeactivated; |
|
177 |
|
178 case MSimpleEngineRequest::EProbation: |
|
179 return KSimpleErrProbation; |
|
180 |
|
181 case MSimpleEngineRequest::ENoresource: |
|
182 return KSimpleErrNoresource; |
|
183 |
|
184 case MSimpleEngineRequest::EGiveup: |
|
185 return KSimpleErrGiveup; |
|
186 |
|
187 default: |
|
188 return KErrNone; |
|
189 }; //lint !e960 |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------- |
|
193 // CSimpleClient::DoSIPStatus |
|
194 // ---------------------------------------------------------- |
|
195 // |
|
196 TUint CSimpleClient::DoSIPStatus( ) |
|
197 { |
|
198 return iSipStatus; |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------- |
|
202 // CSimpleClient::DoRetryAfter |
|
203 // ---------------------------------------------------------- |
|
204 // |
|
205 TUint CSimpleClient::DoRetryAfter( ) |
|
206 { |
|
207 return iRetryAfterTime; |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------- |
|
211 // CSimpleClient::GetSIPStatus |
|
212 // ---------------------------------------------------------- |
|
213 // |
|
214 void CSimpleClient::GetSIPStatus( TInt aOpId ) |
|
215 { |
|
216 CSimpleConnection* conn = STATIC_CAST( CSimpleConnection*, &iConn); //lint !e826 |
|
217 CSimpleSipConnection* engine = conn->Connection(); |
|
218 iSipStatus = engine->SIPStatus( aOpId, iRetryAfterTime ); |
|
219 } |