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