|
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: Implements the functionality of RApdu class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "SwimEtelApdu.h" |
|
22 #include "etelext.h" // EEtelPanicNullHandle |
|
23 #include "WimTrace.h" // for trace logging |
|
24 |
|
25 #ifdef _DEBUG |
|
26 #include <flogger.h> |
|
27 #endif |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // RApdu::RApdu |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 RApdu::RApdu() |
|
38 { |
|
39 _WIMTRACE(_L("WIM|SwimReader|RApdu::RApdu|Begin")); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // RApdu::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // Virtual function which extensions may overload. Called in Open() |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void RApdu::ConstructL() |
|
49 { |
|
50 _WIMTRACE(_L("WIM|SwimReader|RApdu::ConstructL|Begin")); |
|
51 //Create new CustomAPI instance |
|
52 iCustomApi = new( ELeave ) RMmCustomAPI; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // RApdu::APDUReq |
|
58 // Message Transmission |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void RApdu::APDUReq( TRequestStatus& aStatus, RMmCustomAPI::TApdu& aMsg ) |
|
62 { |
|
63 _WIMTRACE(_L("WIM|SwimReader|RApdu::APDUReq|Begin")); |
|
64 aStatus = KRequestPending; |
|
65 // Send APDU to Etel through CustomAPI |
|
66 iCustomApi->SendAPDUReq( aStatus, aMsg ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // RApdu::CancelAPDUReq |
|
71 // Cancel Message Transmission |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void RApdu::CancelAPDUReq() |
|
75 { |
|
76 iCustomApi->CancelAsyncRequest( ECustomSendAPDUReqIPC ); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // RApdu::Destruct |
|
81 // Destructor. Called in Close() |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void RApdu::Destruct() |
|
85 { |
|
86 _WIMTRACE(_L("WIM|SwimReader|RApdu::Destruct|Begin")); |
|
87 if ( iCustomApi ) |
|
88 { |
|
89 iCustomApi->Close(); |
|
90 delete iCustomApi; |
|
91 iCustomApi = NULL; |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // RApdu::Close |
|
97 // Close a phone and connection to CustomAPI |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void RApdu::Close() |
|
101 { |
|
102 _WIMTRACE(_L("WIM|SwimReader|RApdu::Close|Begin")); |
|
103 CloseSubSession( EEtelClose ); |
|
104 iPhone.Close(); |
|
105 if ( iCustomApi ) |
|
106 { |
|
107 iCustomApi->Close(); |
|
108 } |
|
109 Destruct(); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // RApdu::Open |
|
114 // Open a phone by name and CustomAPI session |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TInt RApdu::Open( RTelServer& aServer, const TDesC &aName ) |
|
118 { |
|
119 _WIMTRACE(_L("WIM|SwimReader|RApdu::Open|Begin")); |
|
120 __ASSERT_ALWAYS( aServer.Handle() != 0, |
|
121 PanicClient( EEtelPanicNullHandle ) ); |
|
122 __ASSERT_ALWAYS( aName.Length() != 0, PanicClient( KErrBadName ) ); |
|
123 |
|
124 TRAPD( ret, ConstructL() ); |
|
125 if ( ret ) |
|
126 { |
|
127 Destruct(); |
|
128 return ret; |
|
129 } |
|
130 |
|
131 //RMobilePhone phone; |
|
132 |
|
133 // Open phone |
|
134 ret = iPhone.Open( aServer, aName ); |
|
135 |
|
136 if ( ret != KErrNone ) |
|
137 { |
|
138 #ifdef _DEBUG |
|
139 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
140 EFileLoggingModeAppend, |
|
141 _L( "EtelApdu::Open: phone open failed: %d" ), |
|
142 ret ); |
|
143 #endif |
|
144 Destruct(); |
|
145 iPhone.Close(); |
|
146 return ret; |
|
147 } |
|
148 |
|
149 // Open new CustomAPI session for phone |
|
150 ret = iCustomApi->Open( iPhone ); |
|
151 |
|
152 if ( ret != KErrNone ) |
|
153 { |
|
154 #ifdef _DEBUG |
|
155 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
156 EFileLoggingModeAppend, |
|
157 _L( "EtelApdu::Open: CustomAPI open failed: %d" ), |
|
158 ret ); |
|
159 #endif |
|
160 Destruct(); |
|
161 iPhone.Close(); |
|
162 return ret; |
|
163 } |
|
164 |
|
165 return ret; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // PanicClient |
|
170 // Panic the client on client side |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void PanicClient( TInt aFault ) |
|
174 { |
|
175 _WIMTRACE(_L("WIM|SwimReader|RApdu::PanicClient|Begin")); |
|
176 _LIT( KETelClientFault,"Etel Client Fault" ); |
|
177 User::Panic( KETelClientFault, aFault ); |
|
178 } |
|
179 |
|
180 // End of file |