OpenCSD - CoreSight Trace Decode Library 1.8.3
Loading...
Searching...
No Matches
ocsd_dcd_mngr.h
Go to the documentation of this file.
1/*
2 * \file ocsd_dcd_mngr.h
3 * \brief OpenCSD : Decoder manager base class.
4 *
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
6 */
7
8/*
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef ARM_OCSD_DCD_MNGR_H_INCLUDED
36#define ARM_OCSD_DCD_MNGR_H_INCLUDED
37
38#include <new>
39
45
46template <class P, class Pt, class Pc>
48{
49public:
50 DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol);
51 virtual ~DecoderMngrBase() {};
52
53 // create decoder interface.
54 virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component);
56
57 virtual const ocsd_trace_protocol_t getProtocolType() const { return m_builtInProtocol; }
58
59// common
60 virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog);
61
62// pkt decoder
63 virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec);
64 virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor);
66
67// pkt processor
68 virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon);
69 virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer);
70 virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink);
71
72// data input connection interface
73 virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
74
75// generate a Config object from opaque config struct pointer.
76 virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct);
77
78// implemented by decoder handler derived classes
79 virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0;
80 virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; };
81 virtual CSConfig *createConfig(const void *pDataStruct) = 0;
82
83
84private:
85 const ocsd_trace_protocol_t m_builtInProtocol;
86};
87
88template <class P, class Pt, class Pc>
89 DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol) :
90 m_builtInProtocol(builtInProtocol)
91{
93 if(pDcdReg)
94 pDcdReg->registerDecoderTypeByName(decoderTypeName,this);
95}
96
97template <class P, class Pt, class Pc>
98ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createDecoder(const int create_flags, const int instID, const CSConfig *pConfig, TraceComponent **ppTrcComp)
99{
100 TraceComponent *pkt_proc = 0;
101 TraceComponent *pkt_dcd = 0;
102 bool bUseInstID = (create_flags & OCSD_CREATE_FLG_INST_ID) != 0;
103 bool bDecoder = (create_flags & OCSD_CREATE_FLG_FULL_DECODER) != 0;
104 bool bUnConfigured = (pConfig == 0);
105
106 const Pc *pConf = dynamic_cast< const Pc * >(pConfig);
107
108 // check inputs valid...
109 if((pConf == 0) && !bUnConfigured)
111
114
115 // always need a packet processor
116 pkt_proc = createPktProc(bUseInstID, instID);
117 if(!pkt_proc)
118 return OCSD_ERR_MEM;
119
120 // set the op mode flags
122
123 // set the configuration
124 TrcPktProcBase<P,Pt,Pc> *pProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> *>(pkt_proc);
125 if(pProcBase == 0)
127
128 if(!bUnConfigured)
129 pProcBase->setProtocolConfig(pConf);
130
131 *ppTrcComp = pkt_proc;
132
133 // may need a packet decoder
134 if(bDecoder)
135 {
136 // create the decoder
137 pkt_dcd = createPktDecode(bUseInstID, instID);
138 if(!pkt_dcd)
139 return OCSD_ERR_MEM;
140
141 // set the op mode flags
143
144 // get the decoder base
145 TrcPktDecodeBase<P,Pc> *pBase = dynamic_cast< TrcPktDecodeBase<P,Pc> *>(pkt_dcd);
146 if(pBase == 0)
148
149 if(!bUnConfigured)
150 pBase->setProtocolConfig(pConf);
151
152 // associate decoder with packet processor
153 // -> this means a TraceComponent with an associated component is a packet decoder.
154 // the associated component is the connected packet processor.
155 pkt_dcd->setAssocComponent(pkt_proc);
156
157 // connect packet processor and decoder
158 pProcBase->getPacketOutAttachPt()->attach(pBase);
159
160 *ppTrcComp = pkt_dcd;
161 }
162 return OCSD_OK;
163}
164
165template <class P, class Pt, class Pc>
167{
168 if(pComponent->getAssocComponent() != 0)
169 delete pComponent->getAssocComponent();
170 delete pComponent;
171 return OCSD_OK;
172}
173
174template <class P, class Pt, class Pc>
176{
177 return pComponent->getErrorLogAttachPt()->replace_first(pIErrorLog);
178}
179
180template <class P, class Pt, class Pc>
182{
184
185 if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
187
188 TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
189 if(pDcdI == 0)
191
192 if(pDcdI->getUsesIDecode())
193 err = pDcdI->getInstrDecodeAttachPt()->replace_first(pIInstrDec);
194
195 return err;
196}
197
198template <class P, class Pt, class Pc>
200{
202
203 if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
205
206 TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
207 if(pDcdI == 0)
209
210 if(pDcdI->getUsesMemAccess())
211 err = pDcdI->getMemoryAccessAttachPt()->replace_first(pMemAccessor);
212
213 return err;
214}
215
216template <class P, class Pt, class Pc>
218{
220
221 if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
222 return err;
223
224 TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
225 if(pDcdI == 0)
227
228 err = pDcdI->getTraceElemOutAttachPt()->replace_first(pOutSink);
229
230 return err;
231}
232
233template <class P, class Pt, class Pc>
235{
236 // find the packet processor
237 TraceComponent *pPktProc = pComponent;
238 if(pComponent->getAssocComponent() != 0)
239 pPktProc = pComponent->getAssocComponent();
240
241 TrcPktProcI *pPPI = dynamic_cast< TrcPktProcI * >(pPktProc);
242 if(pPPI == 0)
244
245 *ppDataIn = pPPI;
246
247 return OCSD_OK;
248}
249
250template <class P, class Pt, class Pc>
252{
253 // find the packet processor
254 TraceComponent *pPktProc = pComponent;
255 if(pComponent->getAssocComponent() != 0)
256 pPktProc = pComponent->getAssocComponent();
257
258 // get the packet processor
259 TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
260 if(pPktProcBase == 0)
262
263 // get the interface
264 IPktRawDataMon<P> *p_If = dynamic_cast< IPktRawDataMon<P> * >(pPktRawDataMon);
265 if(p_If == 0)
267
268 return pPktProcBase->getRawPacketMonAttachPt()->replace_first(p_If);
269}
270
271template <class P, class Pt, class Pc>
273{
274 // find the packet processor
275 TraceComponent *pPktProc = pComponent;
276 if(pComponent->getAssocComponent() != 0)
277 pPktProc = pComponent->getAssocComponent();
278
279 // get the packet processor
280 TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
281 if(pPktProcBase == 0)
283
284 // get the interface
285 ITrcPktIndexer<Pt> *p_If = dynamic_cast< ITrcPktIndexer<Pt> * >(pPktIndexer);
286 if(p_If == 0)
288
289 return pPktProcBase->getTraceIDIndexerAttachPt()->replace_first(p_If);
290}
291
292template <class P, class Pt, class Pc>
294{
295 // must be solo packet processor
296 if(pComponent->getAssocComponent() != 0)
298
299 // interface must be the correct one.
300 IPktDataIn<P> *pkt_in_i = dynamic_cast< IPktDataIn<P> * >(pPktDataInSink);
301 if(pkt_in_i == 0)
303
304 // get the packet processor
305 TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pComponent);
306 if(pPktProcBase == 0)
308
309 // attach
310 return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i);
311}
312
313template <class P, class Pt, class Pc>
315{
316 CSConfig *pConfig = createConfig(pDataStruct);
317 if(!pConfig)
318 return OCSD_ERR_MEM;
319 *pConfigBase = pConfig;
320 return OCSD_OK;
321}
322
323/****************************************************************************************************/
324/* Full decoder / packet process pair, templated base for creating decoder objects */
325/****************************************************************************************************/
326
327template< class P, // Packet class.
328 class Pt, // Packet enum type ID.
329 class Pc, // Processor config class.
330 class PcSt, // Processor config struct type
331 class PktProc, // Packet processor class.
332 class PktDcd> // Packet decoder class.
333class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc>
334{
335public:
336 DecodeMngrFullDcd (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
337 : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
338
339 virtual ~DecodeMngrFullDcd() {};
340
341 virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
342 {
343 TraceComponent *pComp;
344 if(useInstID)
345 pComp = new (std::nothrow) PktProc(instID);
346 else
347 pComp = new (std::nothrow) PktProc();
348 return pComp;
349 }
350
351 virtual TraceComponent *createPktDecode(const bool useInstID, const int instID)
352 {
353 TraceComponent *pComp;
354 if(useInstID)
355 pComp = new (std::nothrow)PktDcd(instID);
356 else
357 pComp = new (std::nothrow)PktDcd();
358 return pComp;
359 }
360
361 virtual CSConfig *createConfig(const void *pDataStruct)
362 {
363 return new (std::nothrow) Pc((PcSt *)pDataStruct);
364 }
365};
366
367/* full decode - extended config object - base + derived. */
368template< class P, // Packet class.
369 class Pt, // Packet enum type ID.
370 class Pc, // Processor config base class.
371 class PcEx, // Processor config derived class
372 class PcSt, // Processor config struct type
373 class PktProc, // Packet processor class.
374 class PktDcd> // Packet decoder class.
375 class DecodeMngrFullDcdExCfg : public DecoderMngrBase<P, Pt, Pc>
376{
377public:
378 DecodeMngrFullDcdExCfg(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
379 : DecoderMngrBase<P, Pt, Pc>(name, builtInProtocol) {};
380
382
383 virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
384 {
385 TraceComponent *pComp;
386 if (useInstID)
387 pComp = new (std::nothrow) PktProc(instID);
388 else
389 pComp = new (std::nothrow) PktProc();
390 return pComp;
391 }
392
393 virtual TraceComponent *createPktDecode(const bool useInstID, const int instID)
394 {
395 TraceComponent *pComp;
396 if (useInstID)
397 pComp = new (std::nothrow)PktDcd(instID);
398 else
399 pComp = new (std::nothrow)PktDcd();
400 return pComp;
401 }
402
403 virtual CSConfig *createConfig(const void *pDataStruct)
404 {
405 return new (std::nothrow) PcEx((PcSt *)pDataStruct);
406 }
407};
408
409
410/****************************************************************************************************/
411/* Packet processor only, templated base for creating decoder objects */
412/****************************************************************************************************/
413
414template< class P, // Packet class.
415 class Pt, // Packet enum type ID.
416 class Pc, // Processor config class.
417 class PcSt, // Processor config struct type
418 class PktProc> // Packet processor class.
419class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc>
420{
421public:
422 DecodeMngrPktProc (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
423 : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
424
425 virtual ~DecodeMngrPktProc() {};
426
427 virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
428 {
429 TraceComponent *pComp;
430 if(useInstID)
431 pComp = new (std::nothrow) PktProc(instID);
432 else
433 pComp = new (std::nothrow) PktProc();
434 return pComp;
435 }
436
437 virtual CSConfig *createConfig(const void *pDataStruct)
438 {
439 return new (std::nothrow) Pc((PcSt *)pDataStruct);
440 }
441};
442
443
444
445#endif // ARM_OCSD_DCD_MNGR_H_INCLUDED
446
447/* End of File ocsd_dcd_mngr.h */
Base class for configuration data on CoreSight trace component.
DecodeMngrFullDcdExCfg(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)
virtual CSConfig * createConfig(const void *pDataStruct)
virtual TraceComponent * createPktDecode(const bool useInstID, const int instID)
virtual ~DecodeMngrFullDcdExCfg()
DecodeMngrFullDcd(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
virtual TraceComponent * createPktDecode(const bool useInstID, const int instID)
virtual CSConfig * createConfig(const void *pDataStruct)
virtual ~DecodeMngrFullDcd()
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)
virtual ~DecodeMngrPktProc()
DecodeMngrPktProc(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
virtual CSConfig * createConfig(const void *pDataStruct)
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)
virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon)
attach a raw packet monitor to pkt processor (solo pkt processor, or pkt processor part of pair)
virtual const ocsd_trace_protocol_t getProtocolType() const
Get the built in protocol type ID managed by this instance - extern for custom decoders.
virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn)
get raw data input interface from packet processor
virtual ocsd_err_t destroyDecoder(TraceComponent *p_component)
DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol)
virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink)
attach generic output interface to pkt decoder
virtual ~DecoderMngrBase()
virtual TraceComponent * createPktDecode(const bool useInstID, const int instID)
virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink)
attach a packet data sink to pkt processor output (solo pkt processor only - instead of decoder when ...
virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog)
attach error logger to ptk-processor, or both of pkt processor and pkt decoder pair
virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer)
attach a packet indexer to pkt processor (solo pkt processor, or pkt processor part of pair)
virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor)
attach memory accessor to pkt decoder
virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct)
virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec)
attach instruction decoder to pkt decoder
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)=0
virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component)
virtual CSConfig * createConfig(const void *pDataStruct)=0
Interface class to an instruction opcode decoder.
Interface class providing an input for discrete protocol packets.
Interface class for packet processor monitor.
Interface to target memory access.
Error logging interface.
Interface to either trace data frame deformatter or packet processor.
Interface for the input of generic trace elements.
Templated interface class to index packet types.
Abstract base class to for interfaces templated types.
const ocsd_err_t registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact)
register a decoder manager interface
static OcsdLibDcdRegister * getDecoderRegister()
Base class for all decode components in the library.
componentAttachPt< ITraceErrorLog > * getErrorLogAttachPt()
ocsd_err_t setComponentOpMode(uint32_t op_flags)
void setAssocComponent(TraceComponent *assocComp)
TraceComponent * getAssocComponent()
componentAttachPt< ITargetMemAccess > * getMemoryAccessAttachPt()
const bool getUsesIDecode() const
const bool getUsesMemAccess() const
componentAttachPt< ITrcGenElemIn > * getTraceElemOutAttachPt()
componentAttachPt< IInstrDecode > * getInstrDecodeAttachPt()
Packet Processor base class. Provides common infrastructure and interconnections for packet processor...
componentAttachPt< IPktDataIn< P > > * getPacketOutAttachPt()
Attachement point for the protocol packet output.
componentAttachPt< ITrcPktIndexer< Pt > > * getTraceIDIndexerAttachPt()
Attachment point for a packet indexer.
componentAttachPt< IPktRawDataMon< P > > * getRawPacketMonAttachPt()
Attachment point for the protocol packet monitor.
Base Packet processing interface.
virtual ocsd_err_t replace_first(T *component)
virtual ocsd_err_t attach(T *component)
#define OCSD_OPFLG_PKTPROC_COMMON
enum _ocsd_trace_protocol_t ocsd_trace_protocol_t
#define OCSD_CREATE_FLG_FULL_DECODER
#define OCSD_OPFLG_COMP_MODE_MASK
#define OCSD_OPFLG_PKTDEC_COMMON
#define OCSD_CREATE_FLG_INST_ID
#define OCSD_CREATE_FLG_PACKET_PROC
enum _ocsd_err_t ocsd_err_t
@ OCSD_ERR_DCD_INTERFACE_UNUSED
@ OCSD_OK
@ OCSD_ERR_INVALID_PARAM_VAL
@ OCSD_ERR_INVALID_PARAM_TYPE
@ OCSD_ERR_MEM
ocsd_err_t setProtocolConfig(const Pc *config)
virtual ocsd_err_t setProtocolConfig(const Pc *config)
< Set the protocol specific configuration for the decoder.
OpenCSD : Standard Types used in the library interfaces.
OpenCSD : Trace Packet decoder base class.
OpenCSD : Trace packet processor base class.