|
1 /* |
|
2 * Copyright (c) 2002 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: Basic printing profile implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "BTServiceUtils.h" |
|
22 #include "BTSBPPController.h" |
|
23 #include "BTSUDebug.h" |
|
24 |
|
25 #include <obexheaders.h> |
|
26 #include <obexutils.rsg> |
|
27 #include <obexutilsuilayer.h> |
|
28 |
|
29 // CONSTANTS |
|
30 _LIT8( KBTSDirectPrintingUUID, "\x00\x00\x11\x18\x00\x00\x10\x00\x80\x00\x00\x80\x5F\x9B\x34\xFB" ); |
|
31 _LIT8( KBTSXHTMLPrintType, "application/vnd.pwg-xhtml-print+xml\0" ); |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CBTSBPPController::CBTSBPPController |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CBTSBPPController::CBTSBPPController( MBTServiceObserver* aObserver, |
|
42 const CBTServiceParameterList* aList ) : |
|
43 iServerState( EBTSBPPSrvIdle ), |
|
44 iClientDone( EFalse ), |
|
45 iObserverPtr( aObserver ), |
|
46 iListPtr( aList ) |
|
47 { |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CBTSBPPController::ConstructL |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CBTSBPPController::ConstructL( const TBTDevAddr& aRemoteDevice, |
|
56 const TUint aRemotePort, |
|
57 CBTEngDiscovery* aBTConnectionPtr ) |
|
58 { |
|
59 FLOG(_L("[BTSU]\t CBTSBPPController::ConstructL()")); |
|
60 |
|
61 // Create an array of obex headers |
|
62 // |
|
63 RArray<CObexHeader*> headers; |
|
64 CleanupClosePushL( headers ); |
|
65 |
|
66 CObexHeader* targetHdr = CObexHeader::NewL(); |
|
67 CleanupStack::PushL( targetHdr ); |
|
68 targetHdr->SetByteSeqL( KBTSUTargetHeader, KBTSDirectPrintingUUID ); |
|
69 headers.Append( targetHdr ); |
|
70 |
|
71 // Create obex client |
|
72 // |
|
73 CreateClientL ( this, aRemoteDevice, aRemotePort, headers ); |
|
74 |
|
75 CleanupStack::Pop( 2 ); // targetHdr, headers |
|
76 headers.Close(); |
|
77 |
|
78 // Start the object server if there were referenced objects |
|
79 // |
|
80 if ( iListPtr->HasAnyReferencedObjects() ) |
|
81 { |
|
82 iServer = CBTSBPPObjectServer::NewL( this, |
|
83 aBTConnectionPtr, |
|
84 aRemoteDevice ); |
|
85 } |
|
86 |
|
87 FLOG(_L("[BTSU]\t CBTSBPPController::ConstructL() completed")); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CBTSBPPController::NewL |
|
92 // Two-phased constructor. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CBTSBPPController* CBTSBPPController::NewL( MBTServiceObserver* aObserver, |
|
96 const TUint aRemotePort, |
|
97 const TBTDevAddr& aRemoteDevice, |
|
98 const CBTServiceParameterList* aList, |
|
99 CBTEngDiscovery* aBTConnectionPtr ) |
|
100 { |
|
101 CBTSBPPController* self = new( ELeave ) CBTSBPPController( aObserver, aList ); |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL( aRemoteDevice, aRemotePort, aBTConnectionPtr ); |
|
104 CleanupStack::Pop(self); |
|
105 return self; |
|
106 } |
|
107 |
|
108 |
|
109 // Destructor |
|
110 CBTSBPPController::~CBTSBPPController() |
|
111 { |
|
112 delete iClient; |
|
113 delete iServer; |
|
114 delete iServerWait; |
|
115 } |
|
116 |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CBTSBPPController::ConnectCompleted |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CBTSBPPController::ConnectCompleted( TInt aStatus ) |
|
123 { |
|
124 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::ConnectCompleted() %d"), aStatus )); |
|
125 |
|
126 if ( aStatus ) |
|
127 { |
|
128 // The connect operation failed. |
|
129 // |
|
130 iObserverPtr->ControllerComplete( EBTSConnectingFailed ); |
|
131 } |
|
132 else |
|
133 { |
|
134 TRAPD( error, SelectAndSendL() ); |
|
135 |
|
136 if ( error ) |
|
137 { |
|
138 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::SelectAndSendL() leaved with %d"), error )); |
|
139 iObserverPtr->ControllerComplete( EBTSPuttingFailed ); |
|
140 } |
|
141 } |
|
142 |
|
143 FLOG(_L("[BTSU]\t CBTSBPPController::ConnectCompleted() completed")); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CBTSBPPController::PutCompleted |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 void CBTSBPPController::PutCompleted( TInt aStatus, const CObexHeaderSet* /*aPutResponse*/ ) |
|
151 { |
|
152 FLOG(_L("[BTSU]\t CBTSBPPController::PutCompleted()")); |
|
153 |
|
154 if ( aStatus ) |
|
155 { |
|
156 // The put operation failed. |
|
157 // |
|
158 iObserverPtr->ControllerComplete( aStatus ); |
|
159 } |
|
160 else |
|
161 { |
|
162 iClientDone = ETrue; |
|
163 |
|
164 if ( iServer == NULL || // Server was not needed at all or |
|
165 !iServer->HasReferencedObjects() || // no referenced objects in current file or |
|
166 iServerState == EBTSBPPSrvDone ) // server is done. |
|
167 { |
|
168 // Object sent and server done, check if there are |
|
169 // more files to send. |
|
170 // |
|
171 TRAPD( error, SelectAndSendL() ); |
|
172 |
|
173 if ( error ) |
|
174 { |
|
175 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::SelectAndSendL() leaved with %d"), error )); |
|
176 iObserverPtr->ControllerComplete( EBTSPuttingFailed ); |
|
177 } |
|
178 } |
|
179 else if ( iServerState == EBTSBPPSrvIdle ) |
|
180 { |
|
181 __ASSERT_DEBUG( iServerWait == NULL, BTSUPanic( EBTSUPanicExistingObject ) ); |
|
182 |
|
183 // Object sent but server isn't serving yet. |
|
184 // Wait for a connection attempt. |
|
185 // |
|
186 |
|
187 TRAPD(error, iServerWait = CBTSBPPServerWait::NewL( this )); |
|
188 |
|
189 if ( error ) |
|
190 { |
|
191 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPServerWait::NewL() leaved with %d"), error )); |
|
192 iObserverPtr->ControllerComplete( EBTSPuttingFailed ); |
|
193 } |
|
194 |
|
195 } |
|
196 } |
|
197 |
|
198 FLOG(_L("[BTSU]\t CBTSBPPController::PutCompleted() completed")); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CBTSBPPController::GetCompleted |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CBTSBPPController::GetCompleted( TInt /*aStatus*/, CObexBufObject* /*aGetResponse*/ ) |
|
206 { |
|
207 FLOG(_L("[BTSU]\t CBTSBPPController::GetCompleted() ERROR: unsolicited callback")); |
|
208 __ASSERT_DEBUG( EFalse, BTSUPanic( EBTSUPanicInternalError ) ); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CBTSBPPController::ClientConnectionClosed |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CBTSBPPController::ClientConnectionClosed() |
|
216 { |
|
217 FLOG(_L("[BTSU]\t CBTSBPPController::ClientConnectionClosed()")); |
|
218 |
|
219 // Everything is now ready. |
|
220 // |
|
221 iObserverPtr->ControllerComplete( EBTSNoError ); |
|
222 |
|
223 FLOG(_L("[BTSU]\t CBTSBPPController::ClientConnectionClosed() completed")); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CBTSBPPController::ServerError |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void CBTSBPPController::ServerError( TInt aError ) |
|
231 { |
|
232 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::ServerError() %d"), aError ) ); |
|
233 |
|
234 // Mark server as ready and if client is ready, complete the controller. |
|
235 // |
|
236 iServerState = EBTSBPPSrvDone; |
|
237 |
|
238 if ( iClientDone ) |
|
239 { |
|
240 iObserverPtr->ControllerComplete( aError ); |
|
241 } |
|
242 else |
|
243 { |
|
244 // Server ready, no need to wait anymore |
|
245 // |
|
246 if ( iServerWait ) |
|
247 { |
|
248 delete iServerWait; |
|
249 iServerWait = NULL; |
|
250 } |
|
251 } |
|
252 |
|
253 FLOG(_L("[BTSU]\t CBTSBPPController::ServerError() completed")); |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CBTSBPPController::ServerConnectionEstablished |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CBTSBPPController::ServerConnectionEstablished() |
|
261 { |
|
262 FLOG(_L("[BTSU]\t CBTSBPPController::ServerConnectionEstablished()")); |
|
263 |
|
264 iServerState = EBTSBPPSrvServing; |
|
265 |
|
266 if ( iServerWait ) |
|
267 { |
|
268 // The wait for server connection can now be stopped. |
|
269 // |
|
270 delete iServerWait; |
|
271 iServerWait = NULL; |
|
272 } |
|
273 |
|
274 FLOG(_L("[BTSU]\t CBTSBPPController::ServerConnectionEstablished() completed")); |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CBTSBPPController::ServerConnectionClosed |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CBTSBPPController::ServerConnectionClosed() |
|
282 { |
|
283 FLOG(_L("[BTSU]\t CBTSBPPController::ServerConnectionClosed()")); |
|
284 |
|
285 iServerState = EBTSBPPSrvDone; |
|
286 |
|
287 if ( iClientDone ) |
|
288 { |
|
289 // The client was waiting for server, but now another object |
|
290 // can be sent. |
|
291 // |
|
292 TRAPD( error, SelectAndSendL() ); |
|
293 |
|
294 if ( error ) |
|
295 { |
|
296 iObserverPtr->ControllerComplete( error ); |
|
297 } |
|
298 } |
|
299 |
|
300 FLOG(_L("[BTSU]\t CBTSBPPController::ServerConnectionClosed() completed")); |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CBTSBPPController::WaitComplete |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CBTSBPPController::WaitComplete() |
|
308 { |
|
309 FLOG(_L("[BTSU]\t CBTSBPPController::WaitComplete()")); |
|
310 |
|
311 // For some reason the printer didn't establish server connection although |
|
312 // there were referenced objects |
|
313 // |
|
314 delete iServerWait; |
|
315 iServerWait = NULL; |
|
316 |
|
317 // The client was waiting for server, but now another object |
|
318 // can be sent. |
|
319 // |
|
320 TRAPD( error, SelectAndSendL() ); |
|
321 |
|
322 if ( error ) |
|
323 { |
|
324 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::SelectAndSendL() leaved with %d"), error )); |
|
325 iObserverPtr->ControllerComplete( EBTSPuttingFailed ); |
|
326 } |
|
327 |
|
328 FLOG(_L("[BTSU]\t CBTSBPPController::WaitComplete() completed")); |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CBTSBPPController::SelectAndSendL |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CBTSBPPController::SelectAndSendL() |
|
336 { |
|
337 FLOG(_L("[BTSU]\t CBTSBPPController::SelectAndSendL()")); |
|
338 |
|
339 TBTSUXhtmlParam param; |
|
340 param.iFileName = NULL; |
|
341 param.iRefObjectList = NULL; |
|
342 |
|
343 if ( iListPtr->XhtmlCount() > 0 && iSendIndex < iListPtr->XhtmlCount() ) |
|
344 { |
|
345 // Get next xhtml parameter |
|
346 // |
|
347 param = iListPtr->XhtmlAt( iSendIndex ); |
|
348 iSendIndex++; |
|
349 } |
|
350 |
|
351 if ( param.iFileName != NULL ) |
|
352 { |
|
353 FTRACE(FPrint(_L("[BTSU]\t CBTSBPPController::SelectAndSendL() fileName='%S'"), param.iFileName )); |
|
354 |
|
355 if ( iServer ) |
|
356 { |
|
357 // Pass the list of referenced objects in the file to object server. |
|
358 // |
|
359 iServer->SetReferencedObjectList( param.iRefObjectList ); |
|
360 } |
|
361 |
|
362 // Create an array of obex headers |
|
363 // |
|
364 RArray<CObexHeader*> headers; |
|
365 CleanupClosePushL( headers ); |
|
366 |
|
367 CObexHeader* typeHdr = CObexHeader::NewL(); |
|
368 CleanupStack::PushL( typeHdr ); |
|
369 typeHdr->SetByteSeqL( KBTSUTypeHeader, KBTSXHTMLPrintType ); |
|
370 headers.Append( typeHdr ); |
|
371 |
|
372 // Send object. |
|
373 // |
|
374 iClient->PutObjectL( headers, *param.iFileName ); |
|
375 |
|
376 CleanupStack::Pop( 2 ); // typeHdr, headers |
|
377 headers.Close(); |
|
378 |
|
379 // A new object is being sent. Reset states. |
|
380 // |
|
381 iClientDone = EFalse; |
|
382 iServerState = EBTSBPPSrvIdle; |
|
383 } |
|
384 else |
|
385 { |
|
386 FLOG(_L("[BTSU]\t CBTSBPPController::SelectAndSendL() all objects sent, closing connection")); |
|
387 |
|
388 // All objects sent, close client connection. |
|
389 // |
|
390 iClient->CloseClientConnection(); |
|
391 } |
|
392 |
|
393 FLOG(_L("[BTSU]\t CBTSBPPController::SelectAndSendL() completed")); |
|
394 } |
|
395 |
|
396 //----------------------------------------------------------------------------- |
|
397 // void CBTSBPPController::ResetFileHandleL |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 void CBTSBPPController::ResetFileHandleL() |
|
401 { |
|
402 } |
|
403 |
|
404 //----------------------------------------------------------------------------- |
|
405 // void CBTSBPPController::ConnectTimedOut() |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 void CBTSBPPController::ConnectTimedOut() |
|
409 { |
|
410 iObserverPtr->ConnectTimedOut(); |
|
411 } |
|
412 // End of File |