56
|
1 |
// Copyright (c) 2007-2010 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 |
// Trace Core
|
|
15 |
//
|
|
16 |
|
|
17 |
#include "TraceCore.h"
|
|
18 |
#include "TraceCoreOstLddIf.h"
|
|
19 |
#include "TraceCoreDebug.h"
|
|
20 |
#include "TraceCoreMediaIfCallback.h"
|
|
21 |
#include "TraceCoreSubscriber.h"
|
|
22 |
#include "TraceCoreMessageUtils.h"
|
|
23 |
#include "TraceCoreOstHeader.h"
|
|
24 |
#include "OstTraceDefinitions.h"
|
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
26 |
#include "TraceCoreOstLddIfTraces.h"
|
|
27 |
#endif
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Default DFC queue priority
|
|
31 |
*/
|
|
32 |
const TUint8 KDefaultDfcPriority = 3;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Prints a message
|
|
36 |
*
|
|
37 |
* @param aMsg Reference to a message.
|
|
38 |
*/
|
|
39 |
static void DebugPrintMsg( const TDesC8& /*aMsg*/ )
|
|
40 |
{
|
|
41 |
// Message structure print
|
|
42 |
}
|
|
43 |
|
|
44 |
static DTraceCoreOstLddIf* TraceCoreOstLddIf = NULL;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Constructor
|
|
48 |
*/
|
|
49 |
DTraceCoreOstLddIf::DTraceCoreOstLddIf()
|
|
50 |
: DTraceCoreMediaIf( KMediaIfSendSupported | KMediaIfSendTraceSupported )
|
|
51 |
, iReceiveDfc( DTraceCoreOstLddIf::ReceiveDfc, this, DTraceCore::GetActivationQ(), KDefaultDfcPriority )
|
|
52 |
, iStatus( 0 )
|
|
53 |
, iTraceCoreOstConnectionRegistered( EFalse )
|
|
54 |
, iTraceCoreOstConnection( NULL )
|
|
55 |
{
|
|
56 |
// No implementation in constructor
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Destructor
|
|
62 |
*/
|
|
63 |
DTraceCoreOstLddIf::~DTraceCoreOstLddIf()
|
|
64 |
{
|
|
65 |
iCallback = NULL;
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
/**
|
|
70 |
* Initializes the OstLddIf
|
|
71 |
*
|
|
72 |
* @param aCallBack Callback to TraceCore
|
|
73 |
*/
|
|
74 |
TInt DTraceCoreOstLddIf::Init( MTraceCoreMediaIfCallback& aCallback )
|
|
75 |
{
|
|
76 |
iCallback = &aCallback;
|
|
77 |
TraceCoreOstLddIf = this;
|
|
78 |
return KErrNone;
|
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Handle incoming messages from OstConnection
|
|
84 |
*
|
|
85 |
* @param aPtr Pointer to DTraceCoreOstLddIf class.
|
|
86 |
*/
|
|
87 |
void DTraceCoreOstLddIf::ReceiveDfc( TAny* aPtr )
|
|
88 |
{
|
|
89 |
DTraceCoreOstLddIf* TraceCoreOstLddIf = static_cast< DTraceCoreOstLddIf* >( aPtr );
|
|
90 |
__ASSERT_DEBUG( TraceCoreOstLddIf != NULL, Kern::Fault( "DTraceCoreOstLddIf::ReceiveDfc - NULL", KErrGeneral ) );
|
|
91 |
TraceCoreOstLddIf->ReceiveDfc();
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Processes incoming OST messages
|
|
97 |
*/
|
|
98 |
void DTraceCoreOstLddIf::ReceiveDfc()
|
|
99 |
{
|
|
100 |
// Determine the message we received
|
|
101 |
if ( iReceiveBuffer.Length() > OstHeader::OstBaseProtocol::KOstHeaderLengthOffset )
|
|
102 |
{
|
|
103 |
DebugPrintMsg ( iReceiveBuffer );
|
|
104 |
if ( iCallback != NULL )
|
|
105 |
{
|
|
106 |
NotifyCallback();
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
/**
|
|
113 |
* Notifies the callback with the incoming message
|
|
114 |
*
|
|
115 |
* @return one of symbian error codes
|
|
116 |
*/
|
|
117 |
void DTraceCoreOstLddIf::NotifyCallback()
|
|
118 |
{
|
|
119 |
// Header length is header size + remainders
|
|
120 |
TInt headerLength = OstHeader::OstBaseProtocol::KOstBaseHeaderSize;
|
|
121 |
|
|
122 |
// Check message ID
|
|
123 |
TTraceMessage traceMsg;
|
|
124 |
traceMsg.iMessageId = iReceiveBuffer[ OstHeader::OstBaseProtocol::KOstHeaderProtocolIdOffset ];
|
|
125 |
|
|
126 |
// If message ID is TraceCore Protocol, the header is longer and the message ID might be in different place
|
|
127 |
if (traceMsg.iMessageId == OstConstants::OstBaseProtocol::KOstTraceCoreProtocol)
|
|
128 |
{
|
|
129 |
headerLength += OstHeader::OstTraceCoreProtocol::KHeaderSize;
|
|
130 |
|
|
131 |
// Subscriber protocol
|
|
132 |
if (iReceiveBuffer[ OstHeader::OstBaseProtocol::KOstBaseHeaderSize +
|
|
133 |
OstHeader::OstTraceCoreProtocol::KProtocolIdOffset ] ==
|
|
134 |
OstHeader::OstTraceCoreProtocol::KSubscriberProtocol)
|
|
135 |
{
|
|
136 |
traceMsg.iMessageId = iReceiveBuffer[ OstHeader::OstBaseProtocol::KOstBaseHeaderSize +
|
|
137 |
OstHeader::OstTraceCoreProtocol::KSubscriberIdOffset ];
|
|
138 |
}
|
|
139 |
}
|
|
140 |
|
|
141 |
if ( iReceiveBuffer.Length() < headerLength )
|
|
142 |
{
|
|
143 |
headerLength = iReceiveBuffer.Length();
|
|
144 |
}
|
|
145 |
|
|
146 |
// Create TraceMessage
|
|
147 |
TPtrC header( iReceiveBuffer.Ptr(), headerLength );
|
|
148 |
TPtrC data( NULL, 0 );
|
|
149 |
if ( iReceiveBuffer.Length() > headerLength ) {
|
|
150 |
data.Set( iReceiveBuffer.Ptr() + headerLength, iReceiveBuffer.Length() - headerLength );
|
|
151 |
}
|
|
152 |
|
|
153 |
traceMsg.iMsgFormat = EMessageHeaderFormatOst;
|
|
154 |
traceMsg.iHeader = &header;
|
|
155 |
traceMsg.iData = &data;
|
|
156 |
|
|
157 |
// Set Sender media to be same as receiver
|
|
158 |
iCallback->SetSenderMedia(this);
|
|
159 |
|
|
160 |
iCallback->MessageReceived( traceMsg );
|
|
161 |
}
|
|
162 |
|
|
163 |
|
|
164 |
/**
|
|
165 |
* Sends messages to USB OstConnection
|
|
166 |
*
|
|
167 |
* @param aMsg Message to be sent.
|
|
168 |
* @return KErrNone if send successful
|
|
169 |
*/
|
|
170 |
TInt DTraceCoreOstLddIf::Send( TTraceMessage& aMsg )
|
|
171 |
{
|
|
172 |
TInt ret = KErrArgument;
|
|
173 |
if ( aMsg.iData != NULL )
|
|
174 |
{
|
|
175 |
ret = TTraceCoreMessageUtils::GetMessageLength( aMsg );
|
|
176 |
if ( ret > 0 )
|
|
177 |
{
|
|
178 |
// First send the phone formatted start character
|
|
179 |
// Send trace data and end trace
|
|
180 |
SendData( aMsg );
|
|
181 |
if ( aMsg.iHeader != NULL )
|
|
182 |
{
|
|
183 |
DebugPrintMsg( iSendBuffer );
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
DebugPrintMsg( *aMsg.iData );
|
|
188 |
}
|
|
189 |
}
|
|
190 |
else
|
|
191 |
{
|
|
192 |
ret = KErrArgument;
|
|
193 |
}
|
|
194 |
}
|
|
195 |
|
|
196 |
return ret;
|
|
197 |
}
|
|
198 |
|
|
199 |
|
|
200 |
/**
|
|
201 |
* Sends message to TraceCoreOstLdd
|
|
202 |
*
|
|
203 |
* @param aMsg Message to be sent.
|
|
204 |
*/
|
|
205 |
void DTraceCoreOstLddIf::SendData( TTraceMessage& aMsg )
|
|
206 |
{
|
|
207 |
if ( aMsg.iHeader != NULL )
|
|
208 |
{
|
|
209 |
// Utility function is used to merge the data
|
|
210 |
TInt ret = TTraceCoreMessageUtils::MergeHeaderAndData( aMsg, iSendBuffer );
|
|
211 |
|
|
212 |
if ( ret == KErrNone )
|
|
213 |
{
|
|
214 |
if(iTraceCoreOstConnection)
|
|
215 |
{
|
|
216 |
iTraceCoreOstConnection->TxMessage( iSendBuffer );
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
else
|
|
221 |
{
|
|
222 |
// Header doesn't exists, all data is in data part
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
/**
|
|
228 |
* Similar to send, except does not generate traces, since they would loop back to this function
|
|
229 |
*
|
|
230 |
* @param aMsg Message to be sent.
|
|
231 |
* @return KErrNone if send successful
|
|
232 |
*/
|
|
233 |
TInt DTraceCoreOstLddIf::SendTrace(const TDesC8& aMsg)
|
|
234 |
{
|
|
235 |
TInt ret(KErrNone);
|
|
236 |
|
|
237 |
if ( iTraceCoreOstConnection && iTraceCoreOstConnectionRegistered )
|
|
238 |
{
|
|
239 |
iTraceCoreOstConnection->TxMessage(aMsg);
|
|
240 |
}
|
|
241 |
else
|
|
242 |
{
|
|
243 |
ret = KErrGeneral;
|
|
244 |
}
|
|
245 |
|
|
246 |
return ret;
|
|
247 |
}
|
|
248 |
|
|
249 |
|
|
250 |
/**
|
|
251 |
* GetSet
|
|
252 |
*
|
|
253 |
* @param aFunc Function choosed (@see ETraceCoreOstLddIfGetSet)
|
|
254 |
* @return TDfc* if aFunc is EGetDfc, TDes8* EGetBuf and 0 with ESetWriter.
|
|
255 |
*/
|
|
256 |
EXPORT_C TUint32 DTraceCoreOstLddIf::GetSet(TTraceCoreOstLddIfGetSet aFunc, TUint32 aParam)
|
|
257 |
{
|
|
258 |
OstTraceExt2( TRACE_FLOW, DTRACECOREOSTLDDIF_GETSET_ENTRY, "> DTraceCoreOstLddIf::GetSet aFunc:%d, aParam:%d", aFunc, aParam );
|
|
259 |
|
|
260 |
TUint32 ret(0);
|
|
261 |
switch(aFunc)
|
|
262 |
{
|
|
263 |
case EGetDfc:
|
|
264 |
{
|
|
265 |
TraceCoreOstLddIf->iTraceCoreOstConnectionRegistered = ETrue;
|
|
266 |
ret = reinterpret_cast<TUint32>(&(TraceCoreOstLddIf->iReceiveDfc));
|
|
267 |
break;
|
|
268 |
}
|
|
269 |
case EGetBuf:
|
|
270 |
{
|
|
271 |
ret = reinterpret_cast<TUint32>(&(TraceCoreOstLddIf->iReceiveBuffer));
|
|
272 |
break;
|
|
273 |
}
|
|
274 |
case ESetWriter:
|
|
275 |
{
|
|
276 |
// Set Writer to XTI if parameter is 0, otherwise USB
|
|
277 |
DTraceCore* traceCore = DTraceCore::GetInstance();
|
|
278 |
if ( traceCore != NULL )
|
|
279 |
{
|
|
280 |
// TraceSwitch uses 0 for XTI writer and 1 to OST writer
|
|
281 |
// So it is not mapping one to one to enum found in TraceCoreWriter.h
|
|
282 |
// for example to EWriterTypeXTI = 1
|
|
283 |
// See TraceCoreWriter.h
|
|
284 |
if(aParam==0)
|
|
285 |
{
|
|
286 |
traceCore->SwitchToWriter(EWriterTypeXTI);
|
|
287 |
}
|
|
288 |
else if(aParam==1)
|
|
289 |
{
|
|
290 |
traceCore->SwitchToWriter(EWriterTypeUSBPhonet);
|
|
291 |
}
|
|
292 |
// For other writers (>2) we use same as the enum
|
|
293 |
else if(aParam > EWriterTypeUSBPhonet)
|
|
294 |
{
|
|
295 |
traceCore->SwitchToWriter((TWriterType) aParam);
|
|
296 |
}
|
|
297 |
}
|
|
298 |
break;
|
|
299 |
}
|
|
300 |
case ERegister:
|
|
301 |
{
|
|
302 |
TraceCoreOstLddIf->iTraceCoreOstConnection = (MTraceCoreOstConnectionIf*)aParam;
|
|
303 |
break;
|
|
304 |
}
|
|
305 |
default:
|
|
306 |
__ASSERT_DEBUG( EFalse, Kern::Fault( "DTraceCoreOstLddIf::GetSet: Default case!", KErrArgument ) );
|
|
307 |
break;
|
|
308 |
}
|
|
309 |
|
|
310 |
return ret;
|
|
311 |
}
|
|
312 |
|
|
313 |
// End of File
|