|
1 /* |
|
2 * Copyright (c) 2003 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: Keeps track, creates and destroys connector objects |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "ScardConnectionRegistry.h" |
|
22 #include "ScardServer.h" |
|
23 #include "ScardConnector.h" |
|
24 #include "ScardServerBase.h" |
|
25 #include "WimTrace.h" |
|
26 |
|
27 #ifdef _DEBUG // for logging |
|
28 #include "ScardLogs.h" |
|
29 #include <flogger.h> |
|
30 #endif |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CScardConnectionRegistry::CScardConnectionRegistry |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CScardConnectionRegistry::CScardConnectionRegistry() |
|
41 { |
|
42 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::CScardConnectionRegistry|Begin")); |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CScardConnectionRegistry::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CScardConnectionRegistry::ConstructL( CScardServer* aServer ) |
|
51 { |
|
52 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::ConstructL|Begin")); |
|
53 iServer = aServer; |
|
54 iConnectors = new( ELeave ) CArrayFixFlat<TConnectionHandle>( 1 ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CScardConnectionRegistry::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CScardConnectionRegistry* CScardConnectionRegistry::NewL( |
|
63 CScardServer* aServer ) |
|
64 { |
|
65 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::NewL|Begin")); |
|
66 CScardConnectionRegistry* self = new( ELeave ) CScardConnectionRegistry(); |
|
67 |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL( aServer ); |
|
70 CleanupStack::Pop( self ); |
|
71 |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 // Destructor |
|
77 CScardConnectionRegistry::~CScardConnectionRegistry() |
|
78 { |
|
79 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::~CScardConnectionRegistry|Begin")); |
|
80 while ( iConnectors->Count() ) |
|
81 { |
|
82 TConnectionHandle& handle = iConnectors->At( 0 ); |
|
83 delete handle.iConnector; |
|
84 iConnectors->Delete( 0 ); |
|
85 } |
|
86 delete iConnectors; |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CScardConnectionRegistry::ConnectToReaderL |
|
92 // Connect to reader |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CScardConnectionRegistry::ConnectToReaderL( |
|
96 CScardSession* aClient, |
|
97 const RMessage2& aMessage ) |
|
98 { |
|
99 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::ConnectToReaderL|Begin")); |
|
100 #ifdef _DEBUG |
|
101 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
102 EFileLoggingModeAppend, |
|
103 _L( "CScardConnectionRegistry::ConnectToReaderL entered.\n" ) ); |
|
104 #endif |
|
105 TConnectionHandle handle; |
|
106 handle.iClient = aClient; |
|
107 CScardConnector* conn = NULL; |
|
108 RThread thread; |
|
109 |
|
110 TInt err1 = thread.Open( KScardServerName ); |
|
111 |
|
112 if ( err1 != KErrNone ) |
|
113 { |
|
114 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::ConnectToReaderL|Thread open failed")); |
|
115 } |
|
116 |
|
117 TRAPD( err, conn = CScardConnector::NewL( this, thread, aMessage ) ); |
|
118 if ( err ) |
|
119 { |
|
120 #ifdef _DEBUG |
|
121 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
122 EFileLoggingModeAppend, |
|
123 _L( "CScardConnectionRegistry::ConnectToReaderL: creating connector\ |
|
124 failed: %d \n" ), err ); |
|
125 #endif |
|
126 aMessage.Complete( err ); |
|
127 return; |
|
128 } |
|
129 CleanupStack::PushL( conn ); |
|
130 handle.iConnector = conn; |
|
131 iConnectors->AppendL( handle ); |
|
132 conn->ConnectToReaderL(); |
|
133 CleanupStack::Pop(conn); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CScardConnectionRegistry::ReconnectToReader |
|
138 // Find the connector managing the session, and instruct it to reconnect. |
|
139 // If the connector is not found, panic will occur. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 /* |
|
143 void CScardConnectionRegistry::ReconnectToReaderL( |
|
144 CScardSession* aClient, |
|
145 const RMessage& aMessage ) |
|
146 { |
|
147 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::ReconnectToReader|Begin")); |
|
148 for ( TInt i( 0 ); i < iConnectors->Count(); i++ ) |
|
149 { |
|
150 if ( iConnectors->At( i ).iClient == aClient ) |
|
151 { |
|
152 // The session needs to be detached from the previous reader |
|
153 // (it wasn't the one we wanted after all) |
|
154 aClient->DisconnectFromReader(); |
|
155 |
|
156 // Now tell the connector to start reconnecting |
|
157 iConnectors->At( i ).iConnector->ReconnectToReaderL( aMessage ); |
|
158 return; |
|
159 } |
|
160 } |
|
161 User::Panic( _L( "Connector registry failure" ), |
|
162 KScServerPanicInternalError ); |
|
163 } |
|
164 */ |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CScardConnectionRegistry::CancelConnection |
|
168 // Cancel connection |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CScardConnectionRegistry::CancelConnection( CScardSession* aSession ) |
|
172 { |
|
173 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::CancelConnection|Begin")); |
|
174 for ( TInt i( 0 ); i < iConnectors->Count(); i++ ) |
|
175 { |
|
176 if ( iConnectors->At( i ).iClient == aSession ) |
|
177 { |
|
178 iConnectors->At( i ).iConnector->Cancel(); |
|
179 return; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CScardConnectionRegistry::ConnectDone |
|
186 // Connection has been established. Complete client message. |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CScardConnectionRegistry::ConnectDone( |
|
190 CScardConnector* aConnector, |
|
191 const TReaderID& aReaderID, |
|
192 const TInt& aErrorCode ) |
|
193 { |
|
194 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::ConnectDone|Begin")); |
|
195 #ifdef _DEBUG |
|
196 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
197 EFileLoggingModeAppend, |
|
198 _L( "CScardConnectionRegistry::ConnectDone to reader %d with status\ |
|
199 %d.\n" ), aReaderID, aErrorCode ); |
|
200 #endif |
|
201 for ( TInt i( 0 ); i < iConnectors->Count(); i++ ) |
|
202 { |
|
203 #ifdef _DEBUG |
|
204 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
205 EFileLoggingModeAppend, |
|
206 _L( "CScardConnectionRegistry::ConnectDone finding correct\ |
|
207 connector out of %d.\n" ), iConnectors->Count() ); |
|
208 #endif |
|
209 TConnectionHandle& connection = iConnectors->At( i ); |
|
210 if ( connection.iConnector == aConnector ) |
|
211 { |
|
212 #ifdef _DEBUG |
|
213 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
214 EFileLoggingModeAppend, |
|
215 _L( "CScardConnectionRegistry::ConnectDone connector\ |
|
216 found.\n" ) ); |
|
217 #endif |
|
218 connection.iClient->ConnectionDone( aReaderID, |
|
219 connection.iConnector->Message(), aErrorCode ); |
|
220 connection.iConnector->Message().Complete( aErrorCode ); |
|
221 return; |
|
222 } |
|
223 } |
|
224 User::Panic( _L( "Registry failure" ), KScServerPanicInternalError ); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CScardConnectionRegistry::RemoveConnector |
|
229 // Remove connector. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 void CScardConnectionRegistry::RemoveConnector( CScardConnector* aConnector ) |
|
233 { |
|
234 _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::RemoveConnector|Begin")); |
|
235 #ifdef _DEBUG |
|
236 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
237 EFileLoggingModeAppend, |
|
238 _L( "CScardConnectionRegistry::RemoveConnector.\n" ) ); |
|
239 #endif |
|
240 for ( TInt i( 0 ); i < iConnectors->Count(); i++ ) |
|
241 { |
|
242 if ( iConnectors->At( i ).iConnector == aConnector ) |
|
243 { |
|
244 #ifdef _DEBUG |
|
245 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
246 EFileLoggingModeAppend, |
|
247 _L( "CScardConnectionRegistry::RemoveConnector connector\ |
|
248 found.\n" ) ); |
|
249 #endif |
|
250 iConnectors->Delete( i ); |
|
251 return; |
|
252 } |
|
253 } |
|
254 User::Panic( _L( "Registry failure" ), KScServerPanicInternalError ); |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CScardConnectionRegistry::Server |
|
259 // Return pointer to Scard server object |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 CScardServer* CScardConnectionRegistry::Server() const |
|
263 { |
|
264 return iServer; |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CScardConnectionRegistry::Connection |
|
269 // Return connection handle |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 TConnectionHandle& CScardConnectionRegistry::Connection( TInt aLocation ) const |
|
273 { |
|
274 return iConnectors->At( aLocation ); |
|
275 } |
|
276 |
|
277 // End of File |