|
1 /* |
|
2 * Copyright (c) 2002-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: |
|
15 * class for imps access client. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include "impsservercommon.h" |
|
23 #include "impsaccesshandler.h" |
|
24 #include "impsaccesscommand.h" |
|
25 #include "impsaccesscli.h" |
|
26 #include "impserrors.h" |
|
27 #include "impsclient.h" |
|
28 #include "impsutils.h" |
|
29 |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // RImpsAccessClient2::RImpsAccessClient2 |
|
36 // ---------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C RImpsAccessClient2::RImpsAccessClient2() : |
|
39 RImpsClient2(), |
|
40 iCommand( NULL ), |
|
41 iHandlerCallBack( NULL ), |
|
42 iLoginOpId( 0 ), |
|
43 iLoginCancelled( EFalse ) |
|
44 { |
|
45 SetOpIdRange( ); |
|
46 } |
|
47 |
|
48 // ---------------------------------------------------------------------------- |
|
49 // RImpsAccessClient2::RegisterL |
|
50 // ---------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C void RImpsAccessClient2::RegisterL( |
|
53 RImpsEng& aEngine, |
|
54 MImpsAccessHandler2* aObserver, |
|
55 TInt aPriority ) |
|
56 { |
|
57 iHandlerCallBack = aObserver; |
|
58 iHandler = CImpsAccessHandler2::NewL( *this, aPriority ); |
|
59 iCommand = CImpsAccessCommand2::NewL( *this ); |
|
60 iActiveCommand = iCommand; |
|
61 |
|
62 // Start the handler |
|
63 iHandler->StartRun(); |
|
64 iHandleNew = ETrue; |
|
65 iAnyContent = EFalse; |
|
66 |
|
67 TInt err = DoRegister( aEngine, iHandler ); |
|
68 User::LeaveIfError( err ); |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // RImpsAccessClient2::Unregister() |
|
73 // ---------------------------------------------------------------------------- |
|
74 EXPORT_C void RImpsAccessClient2::Unregister() |
|
75 { |
|
76 DoUnregister(); |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // RImpsAccessClient2::LoginL() |
|
81 // ---------------------------------------------------------------------------- |
|
82 EXPORT_C TInt RImpsAccessClient2::LoginL( TImpsCspIdentifier aCspId, |
|
83 const TDesC& aPsw, |
|
84 const TDesC& aClientId, |
|
85 TUint32 aAP, |
|
86 const TDesC* aKey1, |
|
87 const TDesC* aKey2 ) |
|
88 { |
|
89 if ( !iRunning ) |
|
90 { |
|
91 User::Leave( KImpsErrorNotRegistered); |
|
92 } |
|
93 |
|
94 // Check length of parameters |
|
95 if ( ( aCspId.Sap().Length() > KImpsMaxSAP ) || |
|
96 ( aPsw.Length() > KImpsMaxPwd ) || |
|
97 ( aClientId.Length() > KImpsMaxClientId ) ) |
|
98 { |
|
99 User::Leave( KErrArgument); |
|
100 } |
|
101 |
|
102 iEngine->SetCspIdentifier( aCspId ); |
|
103 |
|
104 IncreaseOpId( ); |
|
105 |
|
106 iCommand->SetParametersL( aCspId.Sap(), aCspId.UserId(), aPsw, aClientId, |
|
107 aAP, aKey1, aKey2 ); |
|
108 iCommand->StartRunL( iOpId, EImpsServWVLogin); |
|
109 |
|
110 SendReceive( EImpsServWVLogin, |
|
111 TIpcArgs( &iCommand->iMessagePtr, iOpId), iCommand->iStatus ); |
|
112 #ifndef _NO_IMPS_LOGGING_ |
|
113 CImpsClientLogger::Log(_L("RImpsAccessClient2::LoginL opId=%d"), iOpId); |
|
114 #endif |
|
115 // store the operation id |
|
116 // and set variable to false |
|
117 iLoginOpId = iOpId; |
|
118 iLoginCancelled = EFalse; |
|
119 |
|
120 return iOpId; |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // RImpsAccessClient2::ReactiveLoginL() |
|
125 // ---------------------------------------------------------------------------- |
|
126 EXPORT_C TInt RImpsAccessClient2::ReactiveLoginL( TImpsCspIdentifier aCspId, |
|
127 const TDesC& aPsw, |
|
128 const TDesC& aClientId, |
|
129 TUint32 aAP, |
|
130 const TDesC* aKey1, |
|
131 const TDesC* aKey2 ) |
|
132 { |
|
133 if ( !iRunning ) |
|
134 { |
|
135 User::Leave( KImpsErrorNotRegistered); |
|
136 } |
|
137 |
|
138 // Check length of parameters |
|
139 if ( ( aCspId.Sap().Length() > KImpsMaxSAP ) || |
|
140 ( aPsw.Length() > KImpsMaxPwd ) || |
|
141 ( aClientId.Length() > KImpsMaxClientId ) ) |
|
142 { |
|
143 User::Leave( KErrArgument); |
|
144 } |
|
145 |
|
146 iEngine->SetCspIdentifier( aCspId ); |
|
147 |
|
148 IncreaseOpId( ); |
|
149 |
|
150 iCommand->SetParametersL( aCspId.Sap(), aCspId.UserId(), aPsw, aClientId, |
|
151 aAP, aKey1, aKey2 ); |
|
152 iCommand->StartRunL( iOpId, EImpsServReactiveLogin); |
|
153 |
|
154 SendReceive( EImpsServReactiveLogin, |
|
155 TIpcArgs( &iCommand->iMessagePtr, iOpId), iCommand->iStatus ); |
|
156 #ifndef _NO_IMPS_LOGGING_ |
|
157 CImpsClientLogger::Log(_L("RImpsAccessClient2::ReactiveLoginL opId=%d"), iOpId); |
|
158 #endif |
|
159 // store the operation id |
|
160 // and set variable to false |
|
161 iLoginOpId = iOpId; |
|
162 iLoginCancelled = EFalse; |
|
163 |
|
164 return iOpId; |
|
165 } |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // RImpsAccessClient2::LogoutL() |
|
169 // ---------------------------------------------------------------------------- |
|
170 |
|
171 EXPORT_C TInt RImpsAccessClient2::LogoutL( ) |
|
172 { |
|
173 |
|
174 if ( !iRunning ) |
|
175 { |
|
176 User::Leave( KImpsErrorNotRegistered ); |
|
177 } |
|
178 |
|
179 IncreaseOpId( ); |
|
180 |
|
181 // Command does not need to know which one, force or not. |
|
182 iCommand->StartRunL( iOpId, EImpsServWVLogout ); |
|
183 |
|
184 TImpsServRequest req = ( EImpsServWVLogout ); |
|
185 // p[ 0 ] = iOpId |
|
186 SendReceive( req, TIpcArgs(iOpId), iCommand->iStatus ); |
|
187 #ifndef _NO_IMPS_LOGGING_ |
|
188 CImpsClientLogger::Log(_L("RImpsAccessClient2::LogoutL opId=%d"), iOpId); |
|
189 #endif |
|
190 return iOpId; |
|
191 |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // RImpsAccessClient2::NumberOfSessionsL() |
|
196 // ---------------------------------------------------------------------------- |
|
197 EXPORT_C TInt RImpsAccessClient2::NumberOfSessionsL( TImpsCspIdentifier& aCspId ) |
|
198 { |
|
199 TInt myLen = aCspId.UserId().Size() + aCspId.Sap().Size(); |
|
200 |
|
201 // some extra space for elements needed |
|
202 HBufC8* msgStream = HBufC8::NewL( myLen + 50 ); |
|
203 CleanupStack::PushL( msgStream ); // << msgStream |
|
204 *msgStream = KNullDesC8; |
|
205 |
|
206 CDesCArrayFlat* myTempArr = new ( ELeave )CDesCArrayFlat( 2 ); |
|
207 CleanupStack::PushL( myTempArr ); // << myTempArr |
|
208 |
|
209 TImpsPackedEntity packedMessage( msgStream ); |
|
210 |
|
211 myTempArr->AppendL( aCspId.Sap() ); |
|
212 myTempArr->AppendL( aCspId.UserId() ); |
|
213 |
|
214 const TUint8* pS = msgStream->Ptr(); |
|
215 |
|
216 packedMessage.DoPackArray( pS, myTempArr ); |
|
217 // update the length of the buffer |
|
218 msgStream->Des().SetLength( pS-msgStream->Ptr() ); |
|
219 |
|
220 TInt nbrOfSessions = SendReceive( EImpsServNbrSessions, TIpcArgs( msgStream) ); |
|
221 |
|
222 myTempArr->Reset(); |
|
223 CleanupStack::PopAndDestroy( 2 ); // >> msgStream, myTempArr |
|
224 #ifndef _NO_IMPS_LOGGING_ |
|
225 CImpsClientLogger::Log(_L("RImpsAccessClient2::NumberOfSessionsL opId=%d"), iOpId); |
|
226 #endif |
|
227 return nbrOfSessions; |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // RImpsAccessClient2::CancelLoginL() |
|
232 // ---------------------------------------------------------------------------- |
|
233 EXPORT_C void RImpsAccessClient2::CancelLoginL( TInt aCancelOpId ) |
|
234 { |
|
235 if ( iLoginOpId != aCancelOpId ) |
|
236 { |
|
237 User::Leave( KErrArgument ); |
|
238 } |
|
239 |
|
240 TInt ret = SendReceive( EImpsServCancelLogin, TIpcArgs( aCancelOpId ) ); |
|
241 |
|
242 // set variable to true |
|
243 iLoginCancelled = ETrue; |
|
244 |
|
245 #ifndef _NO_IMPS_LOGGING_ |
|
246 CImpsClientLogger::Log(_L("RImpsAccessClient2::CancelLoginL opId=%d ret=%d"), aCancelOpId, ret ); |
|
247 #endif |
|
248 } |
|
249 |
|
250 // ---------------------------------------------------------------------------- |
|
251 // RImpsAccessClient2::CloseCspSessionsL() |
|
252 // ---------------------------------------------------------------------------- |
|
253 EXPORT_C void RImpsAccessClient2::CloseCspSessionsL( ) |
|
254 { |
|
255 TImpsServRequest req = ( EImpsServCloseAll ); |
|
256 SendReceive( req, TIpcArgs() ); |
|
257 #ifndef _NO_IMPS_LOGGING_ |
|
258 CImpsClientLogger::Log(_L("RImpsAccessClient2::CloseCspSessionsL") ); |
|
259 #endif |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // RImpsAccessClient2::DoRegister() |
|
264 // ---------------------------------------------------------------------------- |
|
265 TInt RImpsAccessClient2::DoRegister( |
|
266 RImpsEng& aEngine, |
|
267 CImpsHandler2* aHandler ) |
|
268 { |
|
269 return DoRegister2( aEngine, aHandler, EImpsAccessRegister2 ); |
|
270 } |
|
271 |
|
272 // ---------------------------------------------------------------------------- |
|
273 // RImpsAccessClient2::Handler |
|
274 // ---------------------------------------------------------------------------- |
|
275 MImpsAccessHandler2* RImpsAccessClient2::Handler( ) |
|
276 { |
|
277 return iHandlerCallBack; |
|
278 } |
|
279 |
|
280 // ---------------------------------------------------------------------------- |
|
281 // RImpsAccessClient2::LoginOpId() |
|
282 // ---------------------------------------------------------------------------- |
|
283 TInt RImpsAccessClient2::LoginOpId() |
|
284 { |
|
285 return iLoginOpId; |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
|
289 // RImpsAccessClient2::LoginCancelled() |
|
290 // ---------------------------------------------------------------------------- |
|
291 TBool RImpsAccessClient2::LoginCancelled() |
|
292 { |
|
293 return iLoginCancelled; |
|
294 } |
|
295 |
|
296 // ---------------------------------------------------------------------------- |
|
297 // RImpsAccessClient2::CancelHandled() |
|
298 // ---------------------------------------------------------------------------- |
|
299 void RImpsAccessClient2::CancelHandled() |
|
300 { |
|
301 iLoginOpId = 0; |
|
302 iLoginCancelled = EFalse; |
|
303 } |
|
304 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
305 |
|
306 // End of File |