1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <obex/internal/obexactiverw.h> |
|
17 #include <obex/internal/obexpacket.h> |
|
18 #include <obex/transport/mobextransportnotify.h> |
|
19 #include <obex/transport/obexconnector.h> |
|
20 #include "ObexTransportUtil.h" |
|
21 #include "logger.h" |
|
22 |
|
23 #ifdef __FLOG_ACTIVE |
|
24 _LIT8(KLogComponent, "OBEXCT"); |
|
25 #endif |
|
26 |
|
27 /** |
|
28 Constructor |
|
29 |
|
30 @param aPriority a priority |
|
31 @param aOwner the owner |
|
32 @param aInfo connection information |
|
33 */ |
|
34 CObexActiveRW::CObexActiveRW(TPriority aPriority, |
|
35 MObexTransportNotify& aOwner, |
|
36 TObexConnectionInfo& aInfo) |
|
37 : CActive (aPriority), |
|
38 iOwner(aOwner), |
|
39 iLocation (NULL, 0) |
|
40 { |
|
41 LOG_LINE |
|
42 LOG_FUNC |
|
43 |
|
44 CActiveScheduler::Add (this); |
|
45 iPacketBased = aInfo.iSocketType==TObexConnectionInfo::ESocketPacket ? ETrue : EFalse; |
|
46 } |
|
47 |
|
48 /** |
|
49 Destructor |
|
50 */ |
|
51 CObexActiveRW::~CObexActiveRW() |
|
52 { |
|
53 LOG_LINE |
|
54 LOG_FUNC |
|
55 |
|
56 Cancel(); |
|
57 } |
|
58 |
|
59 /** |
|
60 Start a new write or read |
|
61 Reset the pointer descriptor to the start of the buffer and make the call to |
|
62 start the transfer |
|
63 |
|
64 @param aPacket the obex packet to read or write |
|
65 */ |
|
66 void CObexActiveRW::NewRequest(CObexPacket& aPacket) |
|
67 { |
|
68 LOG_FUNC |
|
69 |
|
70 iPacket = &aPacket; |
|
71 iCount = 0; |
|
72 // Set descriptor to start of buffer |
|
73 // Size pointer according to either the number of bytes remaining in packet |
|
74 // OR maximum number of bytes we can receive (see Remaining()) |
|
75 iLocation.Set(iPacket->iBuffer, 0, Remaining ()); |
|
76 DoTransfer(); |
|
77 } |
|
78 |
|
79 /* |
|
80 Non-virtual method calling virtual method StartTransfer. BC protection. |
|
81 |
|
82 @param aPacket the obex packet to transfer |
|
83 */ |
|
84 void CObexActiveRW::Transfer(CObexPacket& aPacket) |
|
85 { |
|
86 LOG_FUNC |
|
87 |
|
88 StartTransfer(aPacket); |
|
89 } |
|
90 |
|
91 /** |
|
92 RunL called after a read/write has completed |
|
93 Check to see if we need to issue another request, otherwise process the |
|
94 complete packet |
|
95 */ |
|
96 EXPORT_C void CObexActiveRW::RunL() |
|
97 { |
|
98 LOG_LINE |
|
99 LOG_FUNC |
|
100 LOG1(_L8("\tiStatus = %d"), iStatus.Int()); |
|
101 |
|
102 /* |
|
103 TBuf<256> hexBuf; |
|
104 FTRACE(FPrint(_L("CObexActiveRW::RunL iLocation.Length() = %d"), iLocation.Length())); |
|
105 for (TInt i = 0; i < iLocation.Length(); i++) |
|
106 { |
|
107 hexBuf.AppendFormat(_L("%02X "), iLocation[i]); |
|
108 if ((i % 16) == 15) |
|
109 { |
|
110 FLOG(hexBuf); |
|
111 hexBuf = KNullDesC; |
|
112 } |
|
113 } |
|
114 FLOG(hexBuf); |
|
115 */ |
|
116 |
|
117 // Check the request completed OK |
|
118 if ( iStatus != KErrNone ) |
|
119 { |
|
120 iOwner.Error(iStatus.Int()); |
|
121 return; |
|
122 } |
|
123 |
|
124 // Update the byte count and check to see if the transfer is complete |
|
125 iCount += iLocation.Size(); |
|
126 if ( CompleteTransfer() ) |
|
127 { |
|
128 // Inform interested parties |
|
129 OnCompleteTransfer(); |
|
130 return; |
|
131 } |
|
132 // Otherwise update the buffer pointer and start another transfer |
|
133 LOG1(_L8("CObexActiveRW::RunL Setting location, remaining=%d"), Remaining()); |
|
134 iLocation.Set (&iPacket->iBuffer[iCount], 0, Remaining()); |
|
135 if ( iLocation.MaxLength() > 0 ) |
|
136 { |
|
137 DoTransfer(); |
|
138 } |
|
139 } |
|