2 * \file ocsd_dcd_mngr.h
3 * \brief OpenCSD : Decoder manager base class.
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
35 #ifndef ARM_OCSD_DCD_MNGR_H_INCLUDED
36 #define ARM_OCSD_DCD_MNGR_H_INCLUDED
38 #include "opencsd/ocsd_if_types.h"
39 #include "common/ocsd_dcd_mngr_i.h"
40 #include "common/ocsd_lib_dcd_register.h"
41 #include "common/trc_pkt_decode_base.h"
42 #include "common/trc_pkt_proc_base.h"
44 template <class P, class Pt, class Pc>
45 class DecoderMngrBase : public IDecoderMngr
48 DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol);
49 virtual ~DecoderMngrBase() {};
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);
55 virtual const ocsd_trace_protocol_t getProtocolType() const { return m_builtInProtocol; }
58 virtual ocsd_err_t attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog);
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);
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);
70 // data input connection interface
71 virtual ocsd_err_t getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn);
73 // generate a Config object from opaque config struct pointer.
74 virtual ocsd_err_t createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct);
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;
83 ocsd_trace_protocol_t m_builtInProtocol; //!< Protocol ID if built in type.
86 template <class P, class Pt, class Pc>
87 DecoderMngrBase<P,Pt,Pc>::DecoderMngrBase(const std::string &decoderTypeName, ocsd_trace_protocol_t builtInProtocol)
89 OcsdLibDcdRegister *pDcdReg = OcsdLibDcdRegister::getDecoderRegister();
91 pDcdReg->registerDecoderTypeByName(decoderTypeName,this);
92 m_builtInProtocol = builtInProtocol;
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)
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);
104 const Pc *pConf = dynamic_cast< const Pc * >(pConfig);
106 // check inputs valid...
107 if((pConf == 0) && !bUnConfigured)
108 return OCSD_ERR_INVALID_PARAM_TYPE;
110 if((create_flags & (OCSD_CREATE_FLG_PACKET_PROC | OCSD_CREATE_FLG_FULL_DECODER)) == 0)
111 return OCSD_ERR_INVALID_PARAM_VAL;
113 // always need a packet processor
114 pkt_proc = createPktProc(bUseInstID, instID);
118 // set the configuration
119 TrcPktProcBase<P,Pt,Pc> *pProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> *>(pkt_proc);
121 return OCSD_ERR_INVALID_PARAM_TYPE;
124 pProcBase->setProtocolConfig(pConf);
126 *ppTrcComp = pkt_proc;
128 // may need a packet decoder
131 // create the decoder
132 pkt_dcd = createPktDecode(bUseInstID, instID);
136 // get the decoder base
137 TrcPktDecodeBase<P,Pc> *pBase = dynamic_cast< TrcPktDecodeBase<P,Pc> *>(pkt_dcd);
139 return OCSD_ERR_INVALID_PARAM_TYPE;
142 pBase->setProtocolConfig(pConf);
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);
149 // connect packet processor and decoder
150 pProcBase->getPacketOutAttachPt()->attach(pBase);
152 *ppTrcComp = pkt_dcd;
157 template <class P, class Pt, class Pc>
158 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::destroyDecoder(TraceComponent *pComponent)
160 if(pComponent->getAssocComponent() != 0)
161 delete pComponent->getAssocComponent();
166 template <class P, class Pt, class Pc>
167 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachErrorLogger(TraceComponent *pComponent, ITraceErrorLog *pIErrorLog)
169 return pComponent->getErrorLogAttachPt()->replace_first(pIErrorLog);
172 template <class P, class Pt, class Pc>
173 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachInstrDecoder(TraceComponent *pComponent, IInstrDecode *pIInstrDec)
175 ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED;
177 if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
178 return OCSD_ERR_INVALID_PARAM_TYPE;
180 TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
182 return OCSD_ERR_INVALID_PARAM_TYPE;
184 if(pDcdI->getUsesIDecode())
185 err = pDcdI->getInstrDecodeAttachPt()->replace_first(pIInstrDec);
190 template <class P, class Pt, class Pc>
191 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachMemAccessor(TraceComponent *pComponent, ITargetMemAccess *pMemAccessor)
193 ocsd_err_t err = OCSD_ERR_DCD_INTERFACE_UNUSED;
195 if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
196 return OCSD_ERR_INVALID_PARAM_TYPE;
198 TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
200 return OCSD_ERR_INVALID_PARAM_TYPE;
202 if(pDcdI->getUsesMemAccess())
203 err = pDcdI->getMemoryAccessAttachPt()->replace_first(pMemAccessor);
208 template <class P, class Pt, class Pc>
209 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachOutputSink(TraceComponent *pComponent, ITrcGenElemIn *pOutSink)
211 ocsd_err_t err = OCSD_ERR_INVALID_PARAM_TYPE;
213 if(pComponent->getAssocComponent() == 0) // no associated component - so this is a packet processor
216 TrcPktDecodeI *pDcdI = dynamic_cast< TrcPktDecodeI * >(pComponent);
218 return OCSD_ERR_INVALID_PARAM_TYPE;
220 err = pDcdI->getTraceElemOutAttachPt()->replace_first(pOutSink);
225 template <class P, class Pt, class Pc>
226 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::getDataInputI(TraceComponent *pComponent, ITrcDataIn **ppDataIn)
228 // find the packet processor
229 TraceComponent *pPktProc = pComponent;
230 if(pComponent->getAssocComponent() != 0)
231 pPktProc = pComponent->getAssocComponent();
233 TrcPktProcI *pPPI = dynamic_cast< TrcPktProcI * >(pPktProc);
235 return OCSD_ERR_INVALID_PARAM_TYPE;
242 template <class P, class Pt, class Pc>
243 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktMonitor(TraceComponent *pComponent, ITrcTypedBase *pPktRawDataMon)
245 // find the packet processor
246 TraceComponent *pPktProc = pComponent;
247 if(pComponent->getAssocComponent() != 0)
248 pPktProc = pComponent->getAssocComponent();
250 // get the packet processor
251 TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
252 if(pPktProcBase == 0)
253 return OCSD_ERR_INVALID_PARAM_TYPE;
256 IPktRawDataMon<P> *p_If = dynamic_cast< IPktRawDataMon<P> * >(pPktRawDataMon);
258 return OCSD_ERR_INVALID_PARAM_TYPE;
260 return pPktProcBase->getRawPacketMonAttachPt()->replace_first(p_If);
263 template <class P, class Pt, class Pc>
264 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktIndexer(TraceComponent *pComponent, ITrcTypedBase *pPktIndexer)
266 // find the packet processor
267 TraceComponent *pPktProc = pComponent;
268 if(pComponent->getAssocComponent() != 0)
269 pPktProc = pComponent->getAssocComponent();
271 // get the packet processor
272 TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pPktProc);
273 if(pPktProcBase == 0)
274 return OCSD_ERR_INVALID_PARAM_TYPE;
277 ITrcPktIndexer<Pt> *p_If = dynamic_cast< ITrcPktIndexer<Pt> * >(pPktIndexer);
279 return OCSD_ERR_INVALID_PARAM_TYPE;
281 return pPktProcBase->getTraceIDIndexerAttachPt()->replace_first(p_If);
284 template <class P, class Pt, class Pc>
285 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::attachPktSink(TraceComponent *pComponent, ITrcTypedBase *pPktDataInSink)
287 // must be solo packet processor
288 if(pComponent->getAssocComponent() != 0)
289 return OCSD_ERR_INVALID_PARAM_TYPE;
291 // interface must be the correct one.
292 IPktDataIn<P> *pkt_in_i = dynamic_cast< IPktDataIn<P> * >(pPktDataInSink);
294 return OCSD_ERR_INVALID_PARAM_TYPE;
296 // get the packet processor
297 TrcPktProcBase<P,Pt,Pc> *pPktProcBase = dynamic_cast< TrcPktProcBase<P,Pt,Pc> * >(pComponent);
298 if(pPktProcBase == 0)
299 return OCSD_ERR_INVALID_PARAM_TYPE;
302 return pPktProcBase->getPacketOutAttachPt()->replace_first(pkt_in_i);
305 template <class P, class Pt, class Pc>
306 ocsd_err_t DecoderMngrBase<P,Pt,Pc>::createConfigFromDataStruct(CSConfig **pConfigBase, const void *pDataStruct)
308 CSConfig *pConfig = createConfig(pDataStruct);
311 *pConfigBase = pConfig;
315 /****************************************************************************************************/
316 /* Full decoder / packet process pair, templated base for creating decoder objects */
317 /****************************************************************************************************/
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>
328 DecodeMngrFullDcd (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
329 : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
331 virtual ~DecodeMngrFullDcd() {};
333 virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
335 TraceComponent *pComp;
337 pComp = new (std::nothrow) PktProc(instID);
339 pComp = new (std::nothrow) PktProc();
343 virtual TraceComponent *createPktDecode(const bool useInstID, const int instID)
345 TraceComponent *pComp;
347 pComp = new (std::nothrow)PktDcd(instID);
349 pComp = new (std::nothrow)PktDcd();
353 virtual CSConfig *createConfig(const void *pDataStruct)
355 return new (std::nothrow) Pc((PcSt *)pDataStruct);
359 /****************************************************************************************************/
360 /* Packet processor only, templated base for creating decoder objects */
361 /****************************************************************************************************/
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>
371 DecodeMngrPktProc (const std::string &name, ocsd_trace_protocol_t builtInProtocol)
372 : DecoderMngrBase<P,Pt,Pc>(name,builtInProtocol) {};
374 virtual ~DecodeMngrPktProc() {};
376 virtual TraceComponent *createPktProc(const bool useInstID, const int instID)
378 TraceComponent *pComp;
380 pComp = new (std::nothrow) PktProc(instID);
382 pComp = new (std::nothrow) PktProc();
386 virtual CSConfig *createConfig(const void *pDataStruct)
388 return new (std::nothrow) Pc((PcSt *)pDataStruct);
394 #endif // ARM_OCSD_DCD_MNGR_H_INCLUDED
396 /* End of File ocsd_dcd_mngr.h */