|
1 /* |
|
2 * Copyright (c) 2007 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: Definitions needed for common stream functionality |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /* |
|
20 * TODO: When local media is of type RComm, listening on it is started with |
|
21 * RComm::NotifyDataAvailable() call. Check that USB ACM port and Irda RCOMM |
|
22 * (and any other new media in the future) behaves correctly so that when |
|
23 * RComm::ReadOneOrMore() is issued, the read is issued immediately without |
|
24 * checking for new data. If waiting for new data happens in this |
|
25 * NotifyDataAvailable/ReadOneOrMore combination, raise a defect to Symbian. |
|
26 */ |
|
27 |
|
28 #include "DunStream.h" |
|
29 #include "DunDebug.h" |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // Destructor. |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CDunStream::~CDunStream() |
|
36 { |
|
37 FTRACE(FPrint( _L("CDunStream::~CDunStream()" ))); |
|
38 ResetData(); |
|
39 FTRACE(FPrint( _L("CDunStream::~CDunStream() complete" ))); |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Resets data to initial values |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 void CDunStream::ResetData() |
|
47 { |
|
48 // APIs affecting this: |
|
49 // AddConnMonCallback() |
|
50 iCallbacksR.Close(); |
|
51 iCallbacksW.Close(); |
|
52 // AddSkippedError() |
|
53 iOkErrorsR.Close(); |
|
54 iOkErrorsW.Close(); |
|
55 // Internal |
|
56 Initialize(); |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Adds error code to consider as "no error" to either endpoint |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 TInt CDunStream::AddSkippedError( TInt aError, |
|
64 TDunOperationType aOperationType ) |
|
65 { |
|
66 FTRACE(FPrint( _L("CDunStream::AddSkippedError()" ) )); |
|
67 RArray<TInt>* okErrors = NULL; |
|
68 if ( aOperationType == EDunOperationTypeRead ) |
|
69 { |
|
70 okErrors = &iOkErrorsR; |
|
71 } |
|
72 else if ( aOperationType == EDunOperationTypeWrite ) |
|
73 { |
|
74 okErrors = &iOkErrorsW; |
|
75 } |
|
76 else |
|
77 { |
|
78 FTRACE(FPrint( _L("CDunStream::AddSkippedError() (ERROR) complete" ) )); |
|
79 return KErrGeneral; |
|
80 } |
|
81 if ( aError >= 0 ) // errors can't be >= 0 |
|
82 { |
|
83 FTRACE(FPrint( _L("CDunStream::AddSkippedError() (ERROR) complete" ) )); |
|
84 return KErrGeneral; |
|
85 } |
|
86 TInt retTemp = okErrors->Find( aError ); |
|
87 if ( retTemp != KErrNotFound ) |
|
88 { |
|
89 FTRACE(FPrint( _L("CDunStream::AddSkippedError() (already exists) complete" ) )); |
|
90 return KErrAlreadyExists; |
|
91 } |
|
92 retTemp = okErrors->Append( aError ); |
|
93 if ( retTemp != KErrNone ) |
|
94 { |
|
95 FTRACE(FPrint( _L("CDunStream::AddSkippedError() (append failed!) complete" ) )); |
|
96 return retTemp; |
|
97 } |
|
98 FTRACE(FPrint( _L("CDunStream::AddSkippedError() complete" ) )); |
|
99 return KErrNone; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Adds callback for line status change controlling |
|
104 // The callback will be called when serious read error is detected |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CDunStream::AddConnMonCallback( MDunConnMon* aCallback, |
|
108 TDunOperationType aOperationType ) |
|
109 { |
|
110 FTRACE(FPrint( _L("CDunStream::AddConnMonCallback()" ) )); |
|
111 RPointerArray<MDunConnMon>* callbacks = NULL; |
|
112 if ( aOperationType == EDunOperationTypeRead ) |
|
113 { |
|
114 callbacks = &iCallbacksR; |
|
115 } |
|
116 else if ( aOperationType == EDunOperationTypeWrite ) |
|
117 { |
|
118 callbacks = &iCallbacksW; |
|
119 } |
|
120 else |
|
121 { |
|
122 FTRACE(FPrint( _L("CDunStream::AddConnMonCallback() (ERROR) complete" ) )); |
|
123 return KErrGeneral; |
|
124 } |
|
125 if ( !aCallback ) |
|
126 { |
|
127 FTRACE(FPrint( _L("CDunStream::AddConnMonCallback() (aCallback) not initialized!" ) )); |
|
128 return KErrGeneral; |
|
129 } |
|
130 TInt retTemp = callbacks->Find( aCallback ); |
|
131 if ( retTemp != KErrNotFound ) |
|
132 { |
|
133 FTRACE(FPrint( _L("CDunStream::AddCallback() (already exists) complete" ) )); |
|
134 return KErrAlreadyExists; |
|
135 } |
|
136 retTemp = callbacks->Append( aCallback ); |
|
137 if ( retTemp != KErrNone ) |
|
138 { |
|
139 FTRACE(FPrint( _L("CDunStream::AddCallback() (append failed!) complete" ) )); |
|
140 return retTemp; |
|
141 } |
|
142 FTRACE(FPrint( _L("CDunStream::AddCallback() complete" ) )); |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // Sets buffering for this stream |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CDunStream::SetBuffering( TPtr8* aBufferPtr ) |
|
151 { |
|
152 FTRACE(FPrint( _L("CDunStream::SetBuffering()" ) )); |
|
153 if ( !aBufferPtr ) |
|
154 { |
|
155 FTRACE(FPrint( _L("CDunStream::SetBuffering() (aBufferPtr) not initialized!" ) )); |
|
156 return KErrGeneral; |
|
157 } |
|
158 if ( iBufferPtr ) |
|
159 { |
|
160 FTRACE(FPrint( _L("CDunStream::SetBuffering() (already exists) complete" ) )); |
|
161 return KErrAlreadyExists; |
|
162 } |
|
163 iBufferPtr = aBufferPtr; |
|
164 FTRACE(FPrint( _L("CDunStream::SetBuffering() complete" ) )); |
|
165 return KErrNone; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // Sets media to use for this endpoint |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CDunStream::SetMedia( RComm* aComm, TDunMediaContext aMediaContext ) |
|
173 { |
|
174 FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm)" ) )); |
|
175 if ( !aComm ) |
|
176 { |
|
177 FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm) (aComm not initialized!) complete" ) )); |
|
178 return KErrGeneral; |
|
179 } |
|
180 if ( aMediaContext == EDunMediaContextNetwork ) |
|
181 { |
|
182 iNetwork = aComm; |
|
183 } |
|
184 else if ( aMediaContext == EDunMediaContextLocal ) |
|
185 { |
|
186 iComm = aComm; |
|
187 } |
|
188 else |
|
189 { |
|
190 FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm) (ERROR) complete" ))); |
|
191 return KErrGeneral; |
|
192 } |
|
193 FTRACE(FPrint( _L("CDunStream::SetMedia() (RComm) complete" ) )); |
|
194 return KErrNone; |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // Sets media to use for this endpoint |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CDunStream::SetMedia( RSocket* aSocket, |
|
202 TDunMediaContext aMediaContext ) |
|
203 { |
|
204 FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket)" ) )); |
|
205 if ( !aSocket ) |
|
206 { |
|
207 FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket) (aSocket not initialized!) complete" ) )); |
|
208 return KErrGeneral; |
|
209 } |
|
210 if ( aMediaContext == EDunMediaContextLocal ) |
|
211 { |
|
212 iSocket = aSocket; |
|
213 } |
|
214 else |
|
215 { |
|
216 FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket) (not supported) complete" ) )); |
|
217 return KErrNotSupported; |
|
218 } |
|
219 FTRACE(FPrint( _L("CDunStream::SetMedia() (RSocket) complete" ) )); |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // Gets media context |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 TDunMediaContext CDunStream::GetMediaContext( TDunStreamType aStreamType ) |
|
228 { |
|
229 FTRACE(FPrint( _L("CDunStream::GetMediaContext()" ) )); |
|
230 if ( aStreamType == EDunStreamTypeUpstream ) |
|
231 { |
|
232 if ( iOperationType == EDunOperationTypeRead ) |
|
233 { |
|
234 return EDunMediaContextLocal; |
|
235 } |
|
236 else if ( iOperationType == EDunOperationTypeWrite ) |
|
237 { |
|
238 return EDunMediaContextNetwork; |
|
239 } |
|
240 else |
|
241 { |
|
242 return EDunMediaContextUndefined; |
|
243 } |
|
244 } |
|
245 else if ( aStreamType == EDunStreamTypeDownstream ) |
|
246 { |
|
247 if ( iOperationType == EDunOperationTypeRead ) |
|
248 { |
|
249 return EDunMediaContextNetwork; |
|
250 } |
|
251 else if ( iOperationType == EDunOperationTypeWrite ) |
|
252 { |
|
253 return EDunMediaContextLocal; |
|
254 } |
|
255 else |
|
256 { |
|
257 return EDunMediaContextUndefined; |
|
258 } |
|
259 } |
|
260 FTRACE(FPrint( _L("CDunStream::GetMediaContext() complete" ) )); |
|
261 return EDunMediaContextUndefined; |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Check whether an error code is severe error or not |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 TInt CDunStream::ProcessErrorCondition( TInt aError, TBool& aIsError ) |
|
269 { |
|
270 FTRACE(FPrint( _L("CDunStream::ProcessErrorCondition() (Dir=%d)" ), iDirection)); |
|
271 aIsError = EFalse; |
|
272 if ( aError != KErrNone ) |
|
273 { |
|
274 aIsError = ETrue; |
|
275 RArray<TInt>* okErrors = NULL; |
|
276 if ( iOperationType == EDunOperationTypeRead ) |
|
277 { |
|
278 okErrors = &iOkErrorsR; |
|
279 } |
|
280 else // iOperationType == EDunOperationTypeWrite |
|
281 { |
|
282 okErrors = &iOkErrorsW; |
|
283 } |
|
284 TInt retTemp = okErrors->Find( aError ); |
|
285 if ( retTemp == KErrNotFound ) |
|
286 { |
|
287 FTRACE(FPrint( _L("CDunStream::ProcessErrorCondition() (Dir=%d) (%d=ETrue) complete" ), iDirection, aError)); |
|
288 return ETrue; |
|
289 } |
|
290 } |
|
291 FTRACE(FPrint( _L("CDunStream::ProcessErrorCondition() (Dir=%d) (%d=EFalse) complete" ), iDirection, aError)); |
|
292 return EFalse; |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // CDunStream::CDunStream |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 CDunStream::CDunStream() : CActive( EPriorityHigh ) |
|
300 { |
|
301 Initialize(); |
|
302 CActiveScheduler::Add( this ); |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // Initializes this class |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 void CDunStream::Initialize() |
|
310 { |
|
311 // Don't initialize iUtility here (it is set through NewL) |
|
312 iBufferPtr = NULL; |
|
313 iReadLengthSocket = 0; |
|
314 iOperationType = EDunOperationTypeUndefined; |
|
315 iTransferState = EDunStateIdle; |
|
316 iDirection = EDunDirectionUndefined; |
|
317 iNetwork = NULL; |
|
318 iSocket = NULL; |
|
319 iComm = NULL; |
|
320 } |