1 /* 2 * \file ocsd_c_api_obj.h 3 * \brief OpenCSD : C API callback objects. 4 * 5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. 6 */ 7 8 #ifndef ARM_OCSD_C_API_OBJ_H_INCLUDED 9 #define ARM_OCSD_C_API_OBJ_H_INCLUDED 10 11 #include "opencsd/c_api/ocsd_c_api_types.h" 12 #include "interfaces/trc_gen_elem_in_i.h" 13 #include "common/ocsd_msg_logger.h" 14 15 class TraceElemCBBase 16 { 17 public: TraceElemCBBase()18 TraceElemCBBase() {}; ~TraceElemCBBase()19 virtual ~TraceElemCBBase() {}; 20 }; 21 22 class GenTraceElemCBObj : public ITrcGenElemIn, public TraceElemCBBase 23 { 24 public: 25 GenTraceElemCBObj(FnTraceElemIn pCBFn, const void *p_context); ~GenTraceElemCBObj()26 virtual ~GenTraceElemCBObj() {}; 27 28 virtual ocsd_datapath_resp_t TraceElemIn(const ocsd_trc_index_t index_sop, 29 const uint8_t trc_chan_id, 30 const OcsdTraceElement &elem); 31 32 private: 33 FnTraceElemIn m_c_api_cb_fn; 34 const void *m_p_cb_context; 35 }; 36 37 38 39 template<class TrcPkt> 40 class PktCBObj : public IPktDataIn<TrcPkt> 41 { 42 public: PktCBObj(FnDefPktDataIn pCBFunc,const void * p_context)43 PktCBObj( FnDefPktDataIn pCBFunc, const void *p_context) 44 { 45 m_c_api_cb_fn = pCBFunc; 46 m_p_context = p_context; 47 }; 48 ~PktCBObj()49 virtual ~PktCBObj() {}; 50 PacketDataIn(const ocsd_datapath_op_t op,const ocsd_trc_index_t index_sop,const TrcPkt * p_packet_in)51 virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op, 52 const ocsd_trc_index_t index_sop, 53 const TrcPkt *p_packet_in) 54 { 55 const void *c_pkt_struct = 0; 56 if(op == OCSD_OP_DATA) 57 c_pkt_struct = p_packet_in->c_pkt(); // always output the c struct packet 58 return m_c_api_cb_fn(m_p_context,op,index_sop,c_pkt_struct); 59 }; 60 61 private: 62 FnDefPktDataIn m_c_api_cb_fn; 63 const void *m_p_context; 64 }; 65 66 // void specialisation for custom decoders that pass packets as const void * pointers 67 template<> 68 class PktCBObj<void> : public IPktDataIn<void> 69 { 70 public: PktCBObj(FnDefPktDataIn pCBFunc,const void * p_context)71 PktCBObj(FnDefPktDataIn pCBFunc, const void *p_context) 72 { 73 m_c_api_cb_fn = pCBFunc; 74 m_p_context = p_context; 75 }; 76 ~PktCBObj()77 virtual ~PktCBObj() {}; 78 PacketDataIn(const ocsd_datapath_op_t op,const ocsd_trc_index_t index_sop,const void * p_packet_in)79 virtual ocsd_datapath_resp_t PacketDataIn(const ocsd_datapath_op_t op, 80 const ocsd_trc_index_t index_sop, 81 const void *p_packet_in) 82 { 83 return m_c_api_cb_fn(m_p_context, op, index_sop, p_packet_in); 84 }; 85 86 private: 87 FnDefPktDataIn m_c_api_cb_fn; 88 const void *m_p_context; 89 }; 90 91 92 template<class TrcPkt> 93 class PktMonCBObj : public IPktRawDataMon<TrcPkt> 94 { 95 public: PktMonCBObj(FnDefPktDataMon pCBFunc,const void * p_context)96 PktMonCBObj( FnDefPktDataMon pCBFunc, const void *p_context) 97 { 98 m_c_api_cb_fn = pCBFunc; 99 m_p_context = p_context; 100 }; 101 ~PktMonCBObj()102 virtual ~PktMonCBObj() {}; 103 RawPacketDataMon(const ocsd_datapath_op_t op,const ocsd_trc_index_t index_sop,const TrcPkt * p_packet_in,const uint32_t size,const uint8_t * p_data)104 virtual void RawPacketDataMon( const ocsd_datapath_op_t op, 105 const ocsd_trc_index_t index_sop, 106 const TrcPkt *p_packet_in, 107 const uint32_t size, 108 const uint8_t *p_data) 109 { 110 const void *c_pkt_struct = 0; 111 if(op == OCSD_OP_DATA) 112 c_pkt_struct = p_packet_in->c_pkt(); // always output the c struct packet 113 m_c_api_cb_fn(m_p_context,op,index_sop,c_pkt_struct,size,p_data); 114 }; 115 116 private: 117 FnDefPktDataMon m_c_api_cb_fn; 118 const void *m_p_context; 119 }; 120 121 // void specialisation for custom decoders that pass packets as const void * pointers 122 template<> 123 class PktMonCBObj<void> : public IPktRawDataMon<void> 124 { 125 public: PktMonCBObj(FnDefPktDataMon pCBFunc,const void * p_context)126 PktMonCBObj(FnDefPktDataMon pCBFunc, const void *p_context) 127 { 128 m_c_api_cb_fn = pCBFunc; 129 m_p_context = p_context; 130 }; 131 ~PktMonCBObj()132 virtual ~PktMonCBObj() {}; RawPacketDataMon(const ocsd_datapath_op_t op,const ocsd_trc_index_t index_sop,const void * p_packet_in,const uint32_t size,const uint8_t * p_data)133 virtual void RawPacketDataMon(const ocsd_datapath_op_t op, 134 const ocsd_trc_index_t index_sop, 135 const void *p_packet_in, 136 const uint32_t size, 137 const uint8_t *p_data) 138 { 139 m_c_api_cb_fn(m_p_context, op, index_sop, p_packet_in, size, p_data); 140 }; 141 142 private: 143 FnDefPktDataMon m_c_api_cb_fn; 144 const void *m_p_context; 145 }; 146 147 /* handler for default string print CB object */ 148 class DefLogStrCBObj : public ocsdMsgLogStrOutI 149 { 150 public: DefLogStrCBObj()151 DefLogStrCBObj() 152 { 153 m_c_api_cb_fn = 0; 154 m_p_context = 0; 155 }; 156 ~DefLogStrCBObj()157 virtual ~DefLogStrCBObj() 158 { 159 m_c_api_cb_fn = 0; 160 m_p_context = 0; 161 }; 162 setCBFn(const void * p_context,FnDefLoggerPrintStrCB pCBFn)163 void setCBFn(const void *p_context, FnDefLoggerPrintStrCB pCBFn) 164 { 165 m_c_api_cb_fn = pCBFn; 166 m_p_context = p_context; 167 }; 168 printOutStr(const std::string & outStr)169 virtual void printOutStr(const std::string &outStr) 170 { 171 if(m_c_api_cb_fn) 172 m_c_api_cb_fn(m_p_context, outStr.c_str(), outStr.length()); 173 } 174 175 private: 176 FnDefLoggerPrintStrCB m_c_api_cb_fn; 177 const void *m_p_context; 178 }; 179 180 #endif // ARM_OCSD_C_API_OBJ_H_INCLUDED 181 182 /* End of File ocsd_c_api_obj.h */ 183