|
1 /* |
|
2 * Copyright (c) 2009 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 the License "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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <kern_priv.h> // For __ASSERT_CRITICAL published partner |
|
21 #include "p2pif.h" // For DP2PIf |
|
22 #include "p2proutertrace.h" // For ASSERT.. |
|
23 #include "p2pinternaldefs.h" // For EP2PAsyncOpen etc.. |
|
24 #include "p2pkernelchannel.h" // For DP2PKernelChannel |
|
25 |
|
26 // Constants |
|
27 const TInt KFirstParam( 0 ); |
|
28 const TInt KSecondParam( 1 ); |
|
29 const TInt KThirdParam( 2 ); |
|
30 const TInt KOneParam( 2 ); |
|
31 const TInt KTwoParams( 2 ); |
|
32 const TInt KThreeParams( 3 ); |
|
33 |
|
34 // Faults |
|
35 enum TP2PIfFaults |
|
36 { |
|
37 EP2PIfMemAllocFailure = 0x00, |
|
38 EP2PIfMemAllocFailure2, |
|
39 EP2PIfNotThreadContext, |
|
40 EP2PIfNotThreadContext2, |
|
41 EP2PIfNullParam, |
|
42 EP2PIfNullPtr, |
|
43 EP2PNotNullPtr, |
|
44 EP2PIfWrongResponseToRequest, |
|
45 EP2PIfWrongResponseToRequest2, |
|
46 EP2PIfWrongResponseToRequest3, |
|
47 EP2PIfWrongResponseToRequest4, |
|
48 EP2PIfWrongResponseToRequest5, |
|
49 EP2PIfWrongResponseToRequest6, |
|
50 EP2PIfWrongResponseToRequest7, |
|
51 EP2PIfWrongResponseToRequest8, |
|
52 EP2PIfWrongResponseToRequest9, |
|
53 }; |
|
54 |
|
55 EXPORT_C MP2PIf* TP2PFactory::NewP2PIfF() |
|
56 { |
|
57 |
|
58 C_TRACE((_T("TP2PFactory::NewP2PIfF<>"))); |
|
59 return DP2PIf::NewF(); |
|
60 |
|
61 } |
|
62 |
|
63 DP2PIf* DP2PIf::NewF() |
|
64 { |
|
65 |
|
66 C_TRACE((_T("DP2PIf::NewF>") )); |
|
67 DP2PIf* tmp = new DP2PIf(); |
|
68 ASSERT_RESET_ALWAYS( tmp, ( EP2PIfMemAllocFailure | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
69 C_TRACE((_T("DP2PIf::NewF 0x%x<"), tmp )); |
|
70 return tmp; |
|
71 |
|
72 } |
|
73 |
|
74 DP2PIf::DP2PIf( |
|
75 // None |
|
76 ) |
|
77 { |
|
78 |
|
79 C_TRACE((_T("DP2PIf::DP2PIf 0x%x>"), this )); |
|
80 __ASSERT_CRITICAL;// From kern_priv.h published partner |
|
81 ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PIfNotThreadContext | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
82 iKernelChannel = new DP2PKernelChannel(); |
|
83 ASSERT_RESET_ALWAYS( iKernelChannel, ( EP2PIfMemAllocFailure2 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
84 C_TRACE((_T("DP2PIf::DP2PIf 0x%x<"), this )); |
|
85 |
|
86 } |
|
87 |
|
88 DP2PIf::~DP2PIf( |
|
89 // None |
|
90 ) |
|
91 { |
|
92 |
|
93 C_TRACE((_T("DP2PIf::~DP2PIf 0x%x>"), this )); |
|
94 Close(); |
|
95 if( iKernelChannel ) |
|
96 { |
|
97 delete iKernelChannel; |
|
98 iKernelChannel = NULL; |
|
99 } |
|
100 C_TRACE((_T("DP2PIf::~DP2PIf 0x%x<"), this )); |
|
101 |
|
102 } |
|
103 |
|
104 TDes8& DP2PIf::AllocateBlock( |
|
105 const TUint16 aSize |
|
106 ) |
|
107 { |
|
108 |
|
109 C_TRACE( ( _T( "DP2PIf::AllocateBlock 0x%x %d>" ), this, aSize ) ); |
|
110 TDes8* temp = NULL; |
|
111 TInt size( aSize ); |
|
112 TAny* params[ KTwoParams ]; |
|
113 params[ KFirstParam ] = reinterpret_cast<TAny*>( &size ); |
|
114 params[ KSecondParam ] = reinterpret_cast<TAny*>( &temp ); |
|
115 // Get's the current thread's thread message. |
|
116 TThreadMessage& m = Kern::Message(); |
|
117 m.iValue = EP2PAllocateBlock; |
|
118 m.iArg[ KFirstParam ] = params; |
|
119 // Other asserts in kernel channel. |
|
120 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest4 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
121 C_TRACE( ( _T( "DP2PIf::AllocateBlock 0x%x %d<" ), this, aSize ) ); |
|
122 return *temp; |
|
123 |
|
124 } |
|
125 |
|
126 void DP2PIf::Close( |
|
127 // None |
|
128 ) |
|
129 { |
|
130 |
|
131 C_TRACE( ( _T( "DP2PIf::Close 0x%x>" ), this ) ); |
|
132 // Get's the current thread's thread message. |
|
133 TThreadMessage& m = Kern::Message(); |
|
134 m.iValue = EP2PClose; |
|
135 m.iArg[ KFirstParam ] = NULL; |
|
136 // Other asserts in kernel channel. |
|
137 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
138 C_TRACE( ( _T( "DP2PIf::Close 0x%x<" ), this ) ); |
|
139 |
|
140 } |
|
141 |
|
142 void DP2PIf::ConnectionLost( |
|
143 TInt& aStatus, |
|
144 const TDfc& aConnectionResetedCompletedDfc |
|
145 ) |
|
146 { |
|
147 |
|
148 C_TRACE( ( _T( "DP2PIf::ConnectionLost 0x%x>" ), this, &aStatus, &aConnectionResetedCompletedDfc ) ); |
|
149 aStatus = KRequestPending; |
|
150 TAny* params[ KTwoParams ]; |
|
151 params[ KFirstParam ] = reinterpret_cast<TAny*>( &aStatus ); |
|
152 params[ KSecondParam ] = reinterpret_cast<TAny*>( &const_cast<TDfc&>( aConnectionResetedCompletedDfc ) ); |
|
153 TThreadMessage& m = Kern::Message(); |
|
154 m.iValue = EP2PAsyncConnectionLost; |
|
155 m.iArg[ KFirstParam ] = params; |
|
156 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest8 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
157 C_TRACE( ( _T( "DP2PIf::ConnectionLost 0x%x<" ), this, &aStatus, &aConnectionResetedCompletedDfc ) ); |
|
158 |
|
159 } |
|
160 |
|
161 void DP2PIf::ConnectionLostCancel( |
|
162 // None |
|
163 ) |
|
164 { |
|
165 |
|
166 C_TRACE( ( _T( "DP2PIf::ConnectionLostCancel 0x%x>" ), this ) ); |
|
167 TThreadMessage& m = Kern::Message(); |
|
168 m.iValue = KMaxTInt; |
|
169 m.iArg[ KFirstParam ] = reinterpret_cast<TAny*>( EP2PAsyncConnectionLost ); |
|
170 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest9 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
171 C_TRACE( ( _T( "DP2PIf::ConnectionLostCancel 0x%x<" ), this ) ); |
|
172 |
|
173 } |
|
174 |
|
175 void DP2PIf::DeallocateBlock( |
|
176 TDes8& aDataBlock |
|
177 ) |
|
178 { |
|
179 |
|
180 C_TRACE( ( _T( "DP2PIf::DeallocateBlock 0x%x b 0x%x>" ), this, &aDataBlock ) ); |
|
181 TAny* params[ KOneParam ]; |
|
182 params[ KFirstParam ] = reinterpret_cast<TAny*>( &aDataBlock ); |
|
183 // Get's the current thread's thread message. |
|
184 TThreadMessage& m = Kern::Message(); |
|
185 m.iValue = EP2PDeallocateBlock; |
|
186 m.iArg[ KFirstParam ] = params; |
|
187 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest5 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
188 C_TRACE( ( _T( "DP2PIf::DeallocateBlock 0x%x b 0x%x<" ), this, &aDataBlock ) ); |
|
189 |
|
190 } |
|
191 |
|
192 void DP2PIf::Open( |
|
193 const TP2PProtocol aP2PProtocolId, |
|
194 TInt& aDfcStatus, |
|
195 TDfc& aOpenCompleteDfc |
|
196 ) |
|
197 { |
|
198 |
|
199 C_TRACE( ( _T( "DP2PIf::Open 0x%x 0x%x 0x%x %d 0x%x>" ), this, aP2PProtocolId, &aDfcStatus, aDfcStatus, &aOpenCompleteDfc ) ); |
|
200 TAny* params[ KThreeParams ]; |
|
201 aDfcStatus = KRequestPending; |
|
202 params[ KFirstParam ] = reinterpret_cast<TAny*>( &aDfcStatus ); |
|
203 params[ KSecondParam ] = reinterpret_cast<TAny*>( &aOpenCompleteDfc ); |
|
204 params[ KThirdParam ] = reinterpret_cast<TAny*>( aP2PProtocolId ); |
|
205 // Get's the current thread's thread message. |
|
206 TThreadMessage& m = Kern::Message(); |
|
207 m.iValue = EP2PAsyncOpen; |
|
208 m.iArg[ KFirstParam ] = params; |
|
209 // Other asserts in kernel channel. |
|
210 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest2 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
211 C_TRACE( ( _T( "DP2PIf::Open 0x%x 0x%x 0x%x %d 0x%x<" ), this, aP2PProtocolId, &aDfcStatus, aDfcStatus, &aOpenCompleteDfc ) ); |
|
212 |
|
213 } |
|
214 |
|
215 void DP2PIf::OpenCancel( |
|
216 // None |
|
217 ) |
|
218 { |
|
219 |
|
220 C_TRACE( ( _T( "DP2PIf::OpenCancel 0x%x>"), this ) ); |
|
221 // Get's the current thread's thread message. |
|
222 TThreadMessage& m = Kern::Message(); |
|
223 m.iValue = KMaxTInt; |
|
224 m.iArg[ KFirstParam ] = reinterpret_cast<TAny*>( EP2PAsyncOpen ); |
|
225 // Other asserts in kernel channel. |
|
226 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest3 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
227 C_TRACE( ( _T( "DP2PIf::OpenCancel 0x%x<"), this ) ); |
|
228 |
|
229 } |
|
230 |
|
231 void DP2PIf::Receive( |
|
232 TDes8*& aRxDataBlock, |
|
233 TInt& aStatus, |
|
234 const TDfc& aReceiveCompletedDfc |
|
235 ) |
|
236 { |
|
237 |
|
238 C_TRACE( ( _T( "DP2PIf::Receive 0x%x 0x%x 0x%x 0x%x>"), this, aRxDataBlock, &aStatus, &aReceiveCompletedDfc ) ); |
|
239 ASSERT_RESET_ALWAYS( !aRxDataBlock, ( EP2PNotNullPtr | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
240 aStatus = KRequestPending; |
|
241 TAny* params[ KThreeParams ]; |
|
242 params[ KFirstParam ] = reinterpret_cast<TAny*>( &aStatus ); |
|
243 params[ KSecondParam ] = reinterpret_cast<TAny*>( &const_cast<TDfc&>( aReceiveCompletedDfc ) ); |
|
244 params[ KThirdParam ] = reinterpret_cast<TAny*>( &aRxDataBlock ); |
|
245 // Get's the current thread's thread message. |
|
246 TThreadMessage& m = Kern::Message(); |
|
247 m.iValue = EP2PAsyncReceive; |
|
248 m.iArg[ KFirstParam ] = params; |
|
249 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest6 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
250 C_TRACE( ( _T( "DP2PIf::Receive 0x%x 0x%x 0x%x 0x%x<"), this, aRxDataBlock, &aStatus, &aReceiveCompletedDfc ) ); |
|
251 |
|
252 } |
|
253 |
|
254 void DP2PIf::ReceiveCancel() |
|
255 { |
|
256 |
|
257 C_TRACE( ( _T( "DP2PIf::ReceiveCancel 0x%x>" ), this ) ); |
|
258 TThreadMessage& m = Kern::Message(); |
|
259 m.iValue = KMaxTInt; |
|
260 m.iArg[ KFirstParam ] = reinterpret_cast<TAny*>( EP2PAsyncReceive ); |
|
261 ASSERT_RESET_ALWAYS( ( KErrNone == iKernelChannel->HandleRequest( m ) ), ( EP2PIfWrongResponseToRequest7 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
262 C_TRACE( ( _T( "DP2PIf::ReceiveCancel 0x%x<" ), this ) ); |
|
263 |
|
264 } |
|
265 |
|
266 void DP2PIf::Release() |
|
267 { |
|
268 |
|
269 C_TRACE( ( _T( "DP2PIf::Release 0x%x>" ), this ) ); |
|
270 __ASSERT_CRITICAL;// From kern_priv.h published partner |
|
271 ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PIfNotThreadContext2 | EDP2PIfTraceId << KClassIdentifierShift ) ); |
|
272 delete this; |
|
273 C_TRACE( ( _T( "DP2PIf::Release 0x%x<" ), this ) ); |
|
274 |
|
275 } |
|
276 |
|
277 TInt DP2PIf::Send( |
|
278 TDes8& aData |
|
279 ) |
|
280 { |
|
281 |
|
282 C_TRACE( ( _T( "DP2PIf::Send 0x%x b 0x%x>"), this, &aData ) ); |
|
283 TAny* params[ KOneParam ]; |
|
284 params[ KFirstParam ] = reinterpret_cast<TAny*>( &aData ); |
|
285 // Get's the current thread's thread message. |
|
286 TThreadMessage& m = Kern::Message(); |
|
287 m.iValue = EP2PSend; |
|
288 m.iArg[ KFirstParam ] = params; |
|
289 TInt retValue( iKernelChannel->HandleRequest( m ) ); |
|
290 C_TRACE( ( _T( "DP2PIf::Send 0x%x b 0x%x %d<"), this, &aData, retValue ) ); |
|
291 return retValue; |
|
292 |
|
293 } |
|
294 |
|
295 // End of file |