1 /* |
1 /* |
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 #include "ActiveWriter.h" |
20 #include "ActiveWriter.h" |
21 #include "AcmConstants.h" |
21 #include "AcmConstants.h" |
22 #include "AcmPanic.h" |
22 #include "AcmPanic.h" |
23 #include "WriteObserver.h" |
23 #include "WriteObserver.h" |
24 #include "AcmUtils.h" |
24 #include "AcmUtils.h" |
25 #include <usb/usblogger.h> |
25 #include "OstTraceDefinitions.h" |
|
26 #ifdef OST_TRACE_COMPILER_IN_USE |
|
27 #include "ActiveWriterTraces.h" |
|
28 #endif |
26 |
29 |
27 #ifdef __FLOG_ACTIVE |
|
28 _LIT8(KLogComponent, "ECACM"); |
|
29 #endif |
|
30 |
30 |
31 CActiveWriter::CActiveWriter(MWriteObserver& aParent, RDevUsbcClient& aLdd, TEndpointNumber aEndpoint) |
31 CActiveWriter::CActiveWriter(MWriteObserver& aParent, RDevUsbcClient& aLdd, TEndpointNumber aEndpoint) |
32 : CActive(KEcacmAOPriority), |
32 : CActive(KEcacmAOPriority), |
33 iParent(aParent), |
33 iParent(aParent), |
34 iLdd(aLdd), |
34 iLdd(aLdd), |
42 * complete. |
42 * complete. |
43 * @param aLdd The LDD handle to be used for posting write requests. |
43 * @param aLdd The LDD handle to be used for posting write requests. |
44 * @param aEndpoint The endpoint to write to. |
44 * @param aEndpoint The endpoint to write to. |
45 */ |
45 */ |
46 { |
46 { |
|
47 OstTraceFunctionEntry0( CACTIVEWRITER_CACTIVEWRITER_CONS_ENTRY ); |
47 CActiveScheduler::Add(this); |
48 CActiveScheduler::Add(this); |
|
49 OstTraceFunctionExit0( CACTIVEWRITER_CACTIVEWRITER_CONS_EXIT ); |
48 } |
50 } |
49 |
51 |
50 CActiveWriter::~CActiveWriter() |
52 CActiveWriter::~CActiveWriter() |
51 /** |
53 /** |
52 * Destructor. |
54 * Destructor. |
53 */ |
55 */ |
54 { |
56 { |
55 LOG_FUNC |
57 OstTraceFunctionEntry0( CACTIVEWRITER_CACTIVEWRITER_DES_ENTRY ); |
56 |
|
57 Cancel(); |
58 Cancel(); |
|
59 OstTraceFunctionExit0( CACTIVEWRITER_CACTIVEWRITER_DES_EXIT ); |
58 } |
60 } |
59 |
61 |
60 CActiveWriter* CActiveWriter::NewL(MWriteObserver& aParent, |
62 CActiveWriter* CActiveWriter::NewL(MWriteObserver& aParent, |
61 RDevUsbcClient& aLdd, |
63 RDevUsbcClient& aLdd, |
62 TEndpointNumber aEndpoint) |
64 TEndpointNumber aEndpoint) |
68 * @param aLdd The LDD handle to be used for posting write requests. |
70 * @param aLdd The LDD handle to be used for posting write requests. |
69 * @param aEndpoint The endpoint to write to. |
71 * @param aEndpoint The endpoint to write to. |
70 * @return Ownership of a new CActiveWriter object. |
72 * @return Ownership of a new CActiveWriter object. |
71 */ |
73 */ |
72 { |
74 { |
73 LOG_STATIC_FUNC_ENTRY |
75 OstTraceFunctionEntry0( CACTIVEWRITER_NEWL_ENTRY ); |
74 |
|
75 CActiveWriter* self = new(ELeave) CActiveWriter(aParent, aLdd, aEndpoint); |
76 CActiveWriter* self = new(ELeave) CActiveWriter(aParent, aLdd, aEndpoint); |
|
77 OstTraceFunctionExit0( CACTIVEWRITER_NEWL_EXIT ); |
76 return self; |
78 return self; |
77 } |
79 } |
78 |
80 |
79 void CActiveWriter::Write(const TDesC8& aDes, |
81 void CActiveWriter::Write(const TDesC8& aDes, |
80 TInt aLen, |
82 TInt aLen, |
85 * @param aDes A descriptor to write. |
87 * @param aDes A descriptor to write. |
86 * @param aLen The length to write. |
88 * @param aLen The length to write. |
87 * @param aZlp Whether ZLP termination may be required. |
89 * @param aZlp Whether ZLP termination may be required. |
88 */ |
90 */ |
89 { |
91 { |
90 LOGTEXT(_L8(">>CActiveWriter::Write")); |
92 OstTraceFunctionEntry0( CACTIVEWRITER_WRITE_ENTRY ); |
91 |
93 |
92 if ( aZlp ) |
94 if ( aZlp ) |
93 { |
95 { |
94 // the driver can be relied on to correctly handle appended ZLPs |
96 // the driver can be relied on to correctly handle appended ZLPs |
95 // so use them when necessary.. |
97 // so use them when necessary.. |
96 iLdd.Write(iStatus, iEndpoint, aDes, aLen, ETrue); |
98 iLdd.Write(iStatus, iEndpoint, aDes, aLen, ETrue); |
107 |
109 |
108 if ( full64BytePacket == EFalse || aLen == 0 ) |
110 if ( full64BytePacket == EFalse || aLen == 0 ) |
109 { |
111 { |
110 iLdd.Write(iStatus, iEndpoint, aDes, aLen, EFalse); |
112 iLdd.Write(iStatus, iEndpoint, aDes, aLen, EFalse); |
111 iWritingState = ECompleteMessage; |
113 iWritingState = ECompleteMessage; |
112 LOGTEXT2(_L8("CActiveWriter::Writing %d bytes"), aLen); |
114 OstTrace1( TRACE_NORMAL, CACTIVEWRITER_WRITE, "CActiveWriter::Write;Writing %d bytes", aLen ); |
113 } |
115 } |
114 else |
116 else |
115 { |
117 { |
116 // we do need to split the descriptor, sending aLen-1 bytes now |
118 // we do need to split the descriptor, sending aLen-1 bytes now |
117 // and sending a second portion with the remaining 1 byte later |
119 // and sending a second portion with the remaining 1 byte later |
123 iSecondPortion.Set(aDes.Left(aLen).Right(1)); |
125 iSecondPortion.Set(aDes.Left(aLen).Right(1)); |
124 |
126 |
125 iLdd.Write(iStatus, iEndpoint, iFirstPortion, aLen-1, EFalse); |
127 iLdd.Write(iStatus, iEndpoint, iFirstPortion, aLen-1, EFalse); |
126 |
128 |
127 iWritingState = EFirstMessagePart; |
129 iWritingState = EFirstMessagePart; |
128 LOGTEXT3(_L8("CActiveWriter::Writing %d bytes of the %d"), aLen-1, aLen); |
130 OstTraceExt2( TRACE_NORMAL, CACTIVEWRITER_WRITE_DUP1, |
|
131 "CActiveWriter::Write;Writing %d bytes of the %d", aLen-1, aLen ); |
129 } |
132 } |
130 } |
133 } |
131 SetActive(); |
134 SetActive(); |
132 |
135 OstTraceFunctionExit0( CACTIVEWRITER_WRITE_EXIT ); |
133 LOGTEXT(_L8("<<CActiveWriter::Write")); |
|
134 } |
136 } |
135 |
137 |
136 void CActiveWriter::DoCancel() |
138 void CActiveWriter::DoCancel() |
137 /** |
139 /** |
138 * Cancel an outstanding write. |
140 * Cancel an outstanding write. |
139 */ |
141 */ |
140 { |
142 { |
141 LOG_FUNC |
143 OstTraceFunctionEntry0( CACTIVEWRITER_DOCANCEL_ENTRY ); |
142 |
|
143 iLdd.WriteCancel(iEndpoint); |
144 iLdd.WriteCancel(iEndpoint); |
|
145 OstTraceFunctionExit0( CACTIVEWRITER_DOCANCEL_EXIT ); |
144 } |
146 } |
145 |
147 |
146 void CActiveWriter::RunL() |
148 void CActiveWriter::RunL() |
147 /** |
149 /** |
148 * This function will be called when the write completes. It notifies the |
150 * This function will be called when the write completes. It notifies the |
149 * parent class of the completion. |
151 * parent class of the completion. |
150 */ |
152 */ |
151 { |
153 { |
152 LOG_LINE |
154 OstTraceFunctionEntry0( CACTIVEWRITER_RUNL_ENTRY ); |
153 LOGTEXT2(_L8(">>CActiveWriter::RunL iStatus=%d"), iStatus.Int()); |
155 OstTrace1( TRACE_NORMAL, CACTIVEWRITER_RUNL, "CActiveWriter::RunL;iStatus=%d", iStatus.Int() ); |
154 |
156 |
155 if ( iWritingState == EFirstMessagePart ) |
157 if ( iWritingState == EFirstMessagePart ) |
156 { |
158 { |
157 if ( iStatus.Int() == KErrNone ) |
159 if ( iStatus.Int() == KErrNone ) |
158 { |
160 { |
159 // now send the second part.. |
161 // now send the second part.. |
160 iLdd.Write(iStatus, iEndpoint, iSecondPortion, iSecondPortion.Length(), EFalse); |
162 iLdd.Write(iStatus, iEndpoint, iSecondPortion, iSecondPortion.Length(), EFalse); |
161 iWritingState = EFinalMessagePart; |
163 iWritingState = EFinalMessagePart; |
162 LOGTEXT(_L8("CActiveWriter::Writing 1 byte to complete original nx64 byte message")); |
164 OstTrace0( TRACE_NORMAL, CACTIVEWRITER_RUNL_DUP1, |
163 |
165 "CActiveWriter::RunL;Writing 1 byte to complete original nx64 byte message" ); |
164 SetActive(); |
166 SetActive(); |
165 } |
167 } |
166 else |
168 else |
167 { |
169 { |
168 // the writing of the first part failed |
170 // the writing of the first part failed |