OpenCSD - CoreSight Trace Decode Library  0.9.2
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 "opencsd/ocsd_if_types.h"
39 #include "common/ocsd_dcd_mngr_i.h"
43 
44 template <class P, class Pt, class Pc>
46 {
47 public:
48  DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol);
49  virtual ~DecoderMngrBase() {};
50 
51  // create decoder interface.
52  virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component);
53  virtual ocsd_err_t destroyDecoder(TraceComponent *p_component);
54 
55  virtual const ocsd_trace_protocol_t getProtocolType() const { return m_builtInProtocol; }
56 
57 // common
58  virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog);
59 
60 // pkt decoder
61  virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec);
62  virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor);
63  virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink);
64 
65 // pkt processor
66  virtual ocsd_err_t attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon);
67  virtual ocsd_err_t attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer);
68  virtual ocsd_err_t attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink);
69 
70 // data input connection interface
71  virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
72 
73 // generate a Config object from opaque config struct pointer.
74  virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct);
75 
76 // implemented by decoder handler derived classes
77  virtual TraceComponent *createPktProc(const bool useInstID, const int instID) = 0;
78  virtual TraceComponent *createPktDecode(const bool useInstID, const int instID) { return 0; };
79  virtual CSConfig *createConfig(const void *pDataStruct) = 0;
80 
81 
82 private:
83  ocsd_trace_protocol_t m_builtInProtocol;
84 };
85 
86 template <class P, class Pt, class Pc>
87 DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol)
88 {
90  if(pDcdReg)
91  pDcdReg->registerDecoderTypeByName(decoderTypeName,this);
92  m_builtInProtocol = builtInProtocol;
93 }
94 
95 template <class P, class Pt, class Pc>
96 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createDecoder(const int create_flags, const int instID, const CSConfig *pConfig, TraceComponent **ppTrcComp)
97 {
98  TraceComponent *pkt_proc = 0;
99  TraceComponent *pkt_dcd = 0;
100  bool bUseInstID = (create_flags & OCSD_CREATE_FLG_INST_ID) != 0;
101  bool bDecoder = (create_flags & OCSD_CREATE_FLG_FULL_DECODER) != 0;
102  bool bUnConfigured = (pConfig == 0);
103 
104  const Pc *pConf = dynamic_cast< const Pc * >(pConfig);
105 
106  // check inputs valid...
107  if((pConf == 0) && !bUnConfigured)
109 
110  if((create_flags & (OCSD_CREATE_FLG_PACKET_PROC | OCSD_CREATE_FLG_FULL_DECODER)) == 0)
112 
113  // always need a packet processor
114  pkt_proc = createPktProc(bUseInstID, instID);
115  if(!pkt_proc)
116  return OCSD_ERR_MEM;
117 
118  // set the configuration
119  TrcPktProcBase<P,Pt,Pc> *pProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> *>(pkt_proc);
120  if(pProcBase == 0)
122 
123  if(!bUnConfigured)
124  pProcBase->setProtocolConfig(pConf);
125 
126  *ppTrcComp = pkt_proc;
127 
128  // may need a packet decoder
129  if(bDecoder)
130  {
131  // create the decoder
132  pkt_dcd = createPktDecode(bUseInstID, instID);
133  if(!pkt_dcd)
134  return OCSD_ERR_MEM;
135 
136  // get the decoder base
137  TrcPktDecodeBase<P,Pc> *pBase = dynamic_cast< TrcPktDecodeBase<P,Pc> *>(pkt_dcd);
138  if(pBase == 0)
140 
141  if(!bUnConfigured)
142  pBase->setProtocolConfig(pConf);
143 
144  // associate decoder with packet processor
145  // -> this means a TraceComponent with an associated component is a packet decoder.
146  // the associated component is the connected packet processor.
147  pkt_dcd->setAssocComponent(pkt_proc);
148 
149  // connect packet processor and decoder
150  pProcBase->getPacketOutAttachPt()->attach(pBase);
151 
152  *ppTrcComp = pkt_dcd;
153  }
154  return OCSD_OK;
155 }
156 
157 template <class P, class Pt, class Pc>
159 {
160  if(pComponent->getAssocComponent() != 0)
161  delete pComponent->getAssocComponent();
162  delete pComponent;
163  return OCSD_OK;
164 }
165 
166 template <class P, class Pt, class Pc>
168 {
169  return pComponent->getErrorLogAttachPt()->replace_first(pIErrorLog);
170 }
171 
172 template <class P, class Pt, class Pc>
174 {
176 
177  if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
179 
180  TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
181  if(pDcdI == 0)
183 
184  if(pDcdI->getUsesIDecode())
185  err = pDcdI->getInstrDecodeAttachPt()->replace_first(pIInstrDec);
186 
187  return err;
188 }
189 
190 template <class P, class Pt, class Pc>
192 {
194 
195  if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
197 
198  TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
199  if(pDcdI == 0)
201 
202  if(pDcdI->getUsesMemAccess())
203  err = pDcdI->getMemoryAccessAttachPt()->replace_first(pMemAccessor);
204 
205  return err;
206 }
207 
208 template <class P, class Pt, class Pc>
210 {
212 
213  if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
214  return err;
215 
216  TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
217  if(pDcdI == 0)
219 
220  err = pDcdI->getTraceElemOutAttachPt()->replace_first(pOutSink);
221 
222  return err;
223 }
224 
225 template <class P, class Pt, class Pc>
227 {
228  // find the packet processor
229  TraceComponent *pPktProc = pComponent;
230  if(pComponent->getAssocComponent() != 0)
231  pPktProc = pComponent->getAssocComponent();
232 
233  TrcPktProcI *pPPI = dynamic_cast< TrcPktProcI * >(pPktProc);
234  if(pPPI == 0)
236 
237  *ppDataIn = pPPI;
238 
239  return OCSD_OK;
240 }
241 
242 template <class P, class Pt, class Pc>
244 {
245  // find the packet processor
246  TraceComponent *pPktProc = pComponent;
247  if(pComponent->getAssocComponent() != 0)
248  pPktProc = pComponent->getAssocComponent();
249 
250  // get the packet processor
251  TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
252  if(pPktProcBase == 0)
254 
255  // get the interface
256  IPktRawDataMon<P> *p_If = dynamic_cast< IPktRawDataMon<P> * >(pPktRawDataMon);
257  if(p_If == 0)
259 
260  return pPktProcBase->getRawPacketMonAttachPt()->replace_first(p_If);
261 }
262 
263 template <class P, class Pt, class Pc>
265 {
266  // find the packet processor
267  TraceComponent *pPktProc = pComponent;
268  if(pComponent->getAssocComponent() != 0)
269  pPktProc = pComponent->getAssocComponent();
270 
271  // get the packet processor
272  TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
273  if(pPktProcBase == 0)
275 
276  // get the interface
277  ITrcPktIndexer<Pt> *p_If = dynamic_cast< ITrcPktIndexer<Pt> * >(pPktIndexer);
278  if(p_If == 0)
280 
281  return pPktProcBase->getTraceIDIndexerAttachPt()->replace_first(p_If);
282 }
283 
284 template <class P, class Pt, class Pc>
286 {
287  // must be solo packet processor
288  if(pComponent->getAssocComponent() != 0)
290 
291  // interface must be the correct one.
292  IPktDataIn<P> *pkt_in_i = dynamic_cast< IPktDataIn<P> * >(pPktDataInSink);
293  if(pkt_in_i == 0)
295 
296  // get the packet processor
297  TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pComponent);
298  if(pPktProcBase == 0)
300 
301  // attach
302  return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i);
303 }
304 
305 template <class P, class Pt, class Pc>
307 {
308  CSConfig *pConfig = createConfig(pDataStruct);
309  if(!pConfig)
310  return OCSD_ERR_MEM;
311  *pConfigBase = pConfig;
312  return OCSD_OK;
313 }
314 
315 /****************************************************************************************************/
316 /* Full decoder / packet process pair, templated base for creating decoder objects */
317 /****************************************************************************************************/
318 
319 template< class P, // Packet class.
320  class Pt, // Packet enum type ID.
321  class Pc, // Processor config class.
322  class PcSt, // Processor config struct type
323  class PktProc, // Packet processor class.
324  class PktDcd> // Packet decoder class.
325 class DecodeMngrFullDcd : public DecoderMngrBase<P,Pt,Pc>
326 {
327 public:
328  DecodeMngrFullDcd (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
329  : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
330 
331  virtual ~DecodeMngrFullDcd() {};
332 
333  virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
334  {
335  TraceComponent *pComp;
336  if(useInstID)
337  pComp = new (std::nothrow) PktProc(instID);
338  else
339  pComp = new (std::nothrow) PktProc();
340  return pComp;
341  }
342 
343  virtual TraceComponent *createPktDecode(const bool useInstID, const int instID)
344  {
345  TraceComponent *pComp;
346  if(useInstID)
347  pComp = new (std::nothrow)PktDcd(instID);
348  else
349  pComp = new (std::nothrow)PktDcd();
350  return pComp;
351  }
352 
353  virtual CSConfig *createConfig(const void *pDataStruct)
354  {
355  return new (std::nothrow) Pc((PcSt *)pDataStruct);
356  }
357 };
358 
359 /****************************************************************************************************/
360 /* Packet processor only, templated base for creating decoder objects */
361 /****************************************************************************************************/
362 
363 template< class P, // Packet class.
364  class Pt, // Packet enum type ID.
365  class Pc, // Processor config class.
366  class PcSt, // Processor config struct type
367  class PktProc> // Packet processor class.
368 class DecodeMngrPktProc : public DecoderMngrBase<P,Pt,Pc>
369 {
370 public:
371  DecodeMngrPktProc (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
372  : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
373 
374  virtual ~DecodeMngrPktProc() {};
375 
376  virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
377  {
378  TraceComponent *pComp;
379  if(useInstID)
380  pComp = new (std::nothrow) PktProc(instID);
381  else
382  pComp = new (std::nothrow) PktProc();
383  return pComp;
384  }
385 
386  virtual CSConfig *createConfig(const void *pDataStruct)
387  {
388  return new (std::nothrow) Pc((PcSt *)pDataStruct);
389  }
390 };
391 
392 
393 
394 #endif // ARM_OCSD_DCD_MNGR_H_INCLUDED
395 
396 /* End of File ocsd_dcd_mngr.h */
DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol)
Definition: ocsd_dcd_mngr.h:87
DecodeMngrFullDcd(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
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) ...
Interface to target memory access.
Abstract base class to for interfaces templated types.
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 ...
DecodeMngrPktProc(const std::string &name, ocsd_trace_protocol_t builtInProtocol)
virtual ocsd_err_t replace_first(T *component)
virtual ~DecodeMngrFullDcd()
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)
const ocsd_err_t registerDecoderTypeByName(const std::string &name, IDecoderMngr *p_decoder_fact)
register a decoder manager interface
static OcsdLibDcdRegister * getDecoderRegister()
virtual ocsd_err_t destroyDecoder(TraceComponent *p_component)
componentAttachPt< ITrcGenElemIn > * getTraceElemOutAttachPt()
Packet Processor base class. Provides common infrastructure and interconnections for packet processor...
Base class for all decode components in the library.
Definition: trc_component.h:56
ocsd_err_t setProtocolConfig(const Pc *config)
Interface class to an instruction opcode decoder.
const bool getUsesMemAccess() const
enum _ocsd_err_t ocsd_err_t
TraceComponent * getAssocComponent()
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) ...
Interface to either trace data frame deformatter or packet processor.
Interface for the input of generic trace elements.
virtual CSConfig * createConfig(const void *pDataStruct)
Templated interface class to index packet types.
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)=0
virtual ~DecodeMngrPktProc()
const bool getUsesIDecode() const
virtual ocsd_err_t setProtocolConfig(const Pc *config)
< Set the protocol specific configuration for the decoder.
virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct)
OpenCSD : Trace Packet decoder base class.
#define OCSD_CREATE_FLG_PACKET_PROC
componentAttachPt< IPktRawDataMon< P > > * getRawPacketMonAttachPt()
Attachment point for the protocol packet monitor.
componentAttachPt< IInstrDecode > * getInstrDecodeAttachPt()
componentAttachPt< IPktDataIn< P > > * getPacketOutAttachPt()
Attachement point for the protocol packet output.
virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn)
get raw data input interface from packet processor
virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog)
attach error logger to ptk-processor, or both of pkt processor and pkt decoder pair ...
Base class for configuration data on CoreSight trace component.
Definition: trc_cs_config.h:49
virtual ocsd_err_t attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec)
attach instruction decoder to pkt decoder
Base Packet processing interface.
virtual const ocsd_trace_protocol_t getProtocolType() const
Get the built in protocol type ID managed by this instance - extern for custom decoders.
Definition: ocsd_dcd_mngr.h:55
virtual ocsd_err_t attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor)
attach memory accessor to pkt decoder
Error logging interface.This class provides a standard interface to the decoder error logger for all ...
virtual TraceComponent * createPktProc(const bool useInstID, const int instID)
virtual TraceComponent * createPktDecode(const bool useInstID, const int instID)
virtual ocsd_err_t attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink)
attach generic output interface to pkt decoder
componentAttachPt< ITrcPktIndexer< Pt > > * getTraceIDIndexerAttachPt()
Attachment point for a packet indexer.
virtual ocsd_err_t createDecoder(const int create_flags, const int instID, const CSConfig *p_config, TraceComponent **p_component)
Definition: ocsd_dcd_mngr.h:96
virtual CSConfig * createConfig(const void *pDataStruct)
OpenCSD : Standard Types used in the library interfaces.
Interface class providing an input for discrete protocol packets.
Definition: trc_pkt_in_i.h:54
virtual TraceComponent * createPktDecode(const bool useInstID, const int instID)
Definition: ocsd_dcd_mngr.h:78
enum _ocsd_trace_protocol_t ocsd_trace_protocol_t
void setAssocComponent(TraceComponent *assocComp)
virtual ocsd_err_t attach(T *component)
OpenCSD : Trace packet processor base class.
#define OCSD_CREATE_FLG_INST_ID
#define OCSD_CREATE_FLG_FULL_DECODER
componentAttachPt< ITraceErrorLog > * getErrorLogAttachPt()
Definition: trc_component.h:67
virtual CSConfig * createConfig(const void *pDataStruct)=0
componentAttachPt< ITargetMemAccess > * getMemoryAccessAttachPt()
Interface class for packet processor monitor.
virtual ~DecoderMngrBase()
Definition: ocsd_dcd_mngr.h:49