|
1 /* |
|
2 * Copyright (c) 2006-2008 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: Receive data from User of NAT Connectivity Framework. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "natfwsocketreceiver.h" |
|
22 #include "natfwsocketmediaconnwrapperlogs.h" |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CNATFWSocketReceiver::CNATFWSocketReceiver( ) |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CNATFWSocketReceiver::CNATFWSocketReceiver( |
|
32 MNATFWSocketReceiverObserver& aRecObs, TUint aProtocol ) : |
|
33 CActive(EPriorityStandard), iProtocol( aProtocol ), iObserver( aRecObs ) |
|
34 { |
|
35 __SOCKETMEDIACONNWRAPPER( |
|
36 "CNATFWSocketReceiver::CNATFWSocketReceiver start") |
|
37 |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CNATFWSocketReceiver* CNATFWSocketReceiver::NewL( ) |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CNATFWSocketReceiver* CNATFWSocketReceiver::NewL( |
|
47 MNATFWSocketReceiverObserver& aRecObs, TUint aProtocol ) |
|
48 { |
|
49 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketReceiver::NewL start" ) |
|
50 |
|
51 CNATFWSocketReceiver* self = |
|
52 new (ELeave) CNATFWSocketReceiver ( aRecObs, aProtocol ); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CNATFWSocketReceiver::~CNATFWSocketReceiver() |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CNATFWSocketReceiver::~CNATFWSocketReceiver() |
|
63 { |
|
64 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketReceiver::~CNATFWSocketReceiver" ) |
|
65 |
|
66 Cancel(); |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CNATFWSocketReceiver::StartListening( ) |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CNATFWSocketReceiver::StartListening( const RSocket& aSocket ) |
|
75 { |
|
76 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketReceiver::StartListening" ) |
|
77 |
|
78 iSocket = aSocket; |
|
79 |
|
80 if ( KProtocolInetUdp == iProtocol ) |
|
81 { |
|
82 iSocket.RecvFrom( iBuffer, iRemoteAddress, 0, iStatus ); |
|
83 } |
|
84 if ( KProtocolInetTcp == iProtocol ) |
|
85 { |
|
86 iSocket.RecvOneOrMore( iBuffer, 0, iStatus, iSockDataLength ); |
|
87 } |
|
88 |
|
89 SetActive(); |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CNATFWSocketReceiver::SetReceivingStateForMuxWrapper( ) |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CNATFWSocketReceiver::SetReceivingStateForMuxWrapper( |
|
98 TNATFWStreamingState aState ) |
|
99 { |
|
100 __SOCKETMEDIACONNWRAPPER( |
|
101 "CNATFWSocketReceiver::SetReceivingStateForMuxWrapper" ) |
|
102 |
|
103 iWrapperMuxReceiveState = aState; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CNATFWSocketReceiver::RunL( ) |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CNATFWSocketReceiver::RunL( ) |
|
112 { |
|
113 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketReceiver::RunL" ) |
|
114 |
|
115 if ( KErrEof != iStatus.Int() && KErrNone != iStatus.Int() ) |
|
116 { |
|
117 __SOCKETMEDIACONNWRAPPER_INT1( |
|
118 "CNATFWSocketReceiver::RunL:", iStatus.Int() ) |
|
119 |
|
120 User::Leave( KErrArgument ); |
|
121 } |
|
122 |
|
123 if ( EStreamingStateActive == iWrapperMuxReceiveState ) |
|
124 { |
|
125 iObserver.DeliverBuffer( iBuffer ); |
|
126 } |
|
127 |
|
128 if ( KProtocolInetUdp == iProtocol ) |
|
129 { |
|
130 iSocket.RecvFrom( iBuffer, iRemoteAddress, 0, iStatus ); |
|
131 } |
|
132 |
|
133 if ( KProtocolInetTcp == iProtocol ) |
|
134 { |
|
135 if ( KErrEof == iStatus.Int() ) |
|
136 { |
|
137 Cancel(); |
|
138 return; |
|
139 } |
|
140 else |
|
141 { |
|
142 iSocket.RecvOneOrMore( iBuffer, 0, iStatus, iSockDataLength ); |
|
143 } |
|
144 } |
|
145 |
|
146 SetActive(); |
|
147 } |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CNATFWSocketReceiver::DoCancel( ) |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CNATFWSocketReceiver::DoCancel( ) |
|
155 { |
|
156 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketReceiver::DoCancel" ) |
|
157 |
|
158 iSocket.CancelAll(); |
|
159 } |
|
160 |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CNATFWSocketReceiver::RunError( ) |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CNATFWSocketReceiver::RunError( TInt aError ) |
|
167 { |
|
168 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketReceiver::RunError" ) |
|
169 |
|
170 return aError; |
|
171 } |
|
172 |
|
173 |