1 /*
2 * \file ocsd_c_api.cpp
3 * \brief OpenCSD : "C" API libary implementation.
4 *
5 * \copyright Copyright (c) 2015, 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 #include <cstring>
36
37 /* pull in the C++ decode library */
38 #include "opencsd.h"
39
40 /* C-API and wrapper objects */
41 #include "opencsd/c_api/opencsd_c_api.h"
42 #include "ocsd_c_api_obj.h"
43
44 /** MSVC2010 unwanted export workaround */
45 #ifdef WIN32
46 #if (_MSC_VER == 1600)
47 #include <new>
48 namespace std { const nothrow_t nothrow = nothrow_t(); }
49 #endif
50 #endif
51
52 /*******************************************************************************/
53 /* C API internal helper function declarations */
54 /*******************************************************************************/
55
56 static ocsd_err_t ocsd_create_pkt_sink_cb(ocsd_trace_protocol_t protocol, FnDefPktDataIn pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj );
57 static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPktDataMon pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj );
58 static ocsd_err_t ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle, DecodeTree **ppDT);
59
60 /*******************************************************************************/
61 /* C library data - additional data on top of the C++ library objects */
62 /*******************************************************************************/
63
64 /* keep a list of interface objects for a decode tree for later disposal */
65 typedef struct _lib_dt_data_list {
66 std::vector<ITrcTypedBase *> cb_objs;
67 DefLogStrCBObj s_def_log_str_cb;
68 } lib_dt_data_list;
69
70 /* map lists to handles */
71 static std::map<dcd_tree_handle_t, lib_dt_data_list *> s_data_map;
72
73 /*******************************************************************************/
74 /* C API functions */
75 /*******************************************************************************/
76
77 /** Get Library version. Return a 32 bit version in form MMMMnnpp - MMMM = major version, nn = minor version, pp = patch version */
ocsd_get_version(void)78 OCSD_C_API uint32_t ocsd_get_version(void)
79 {
80 return ocsdVersion::vers_num();
81 }
82
83 /** Get library version string */
ocsd_get_version_str(void)84 OCSD_C_API const char * ocsd_get_version_str(void)
85 {
86 return ocsdVersion::vers_str();
87 }
88
89
90 /*** Decode tree creation etc. */
91
ocsd_create_dcd_tree(const ocsd_dcd_tree_src_t src_type,const uint32_t deformatterCfgFlags)92 OCSD_C_API dcd_tree_handle_t ocsd_create_dcd_tree(const ocsd_dcd_tree_src_t src_type, const uint32_t deformatterCfgFlags)
93 {
94 dcd_tree_handle_t handle = C_API_INVALID_TREE_HANDLE;
95 handle = (dcd_tree_handle_t)DecodeTree::CreateDecodeTree(src_type,deformatterCfgFlags);
96 if(handle != C_API_INVALID_TREE_HANDLE)
97 {
98 lib_dt_data_list *pList = new (std::nothrow) lib_dt_data_list;
99 if(pList != 0)
100 {
101 s_data_map.insert(std::pair<dcd_tree_handle_t, lib_dt_data_list *>(handle,pList));
102 }
103 else
104 {
105 ocsd_destroy_dcd_tree(handle);
106 handle = C_API_INVALID_TREE_HANDLE;
107 }
108 }
109 return handle;
110 }
111
ocsd_destroy_dcd_tree(const dcd_tree_handle_t handle)112 OCSD_C_API void ocsd_destroy_dcd_tree(const dcd_tree_handle_t handle)
113 {
114 if(handle != C_API_INVALID_TREE_HANDLE)
115 {
116 GenTraceElemCBObj * pIf = (GenTraceElemCBObj *)(((DecodeTree *)handle)->getGenTraceElemOutI());
117 if(pIf != 0)
118 delete pIf;
119
120 /* need to clear any associated callback data. */
121 std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
122 it = s_data_map.find(handle);
123 if(it != s_data_map.end())
124 {
125 std::vector<ITrcTypedBase *>::iterator itcb;
126 itcb = it->second->cb_objs.begin();
127 while(itcb != it->second->cb_objs.end())
128 {
129 delete *itcb;
130 itcb++;
131 }
132 it->second->cb_objs.clear();
133 delete it->second;
134 s_data_map.erase(it);
135 }
136 DecodeTree::DestroyDecodeTree((DecodeTree *)handle);
137 }
138 }
139
140 /*** Decode tree process data */
141
ocsd_dt_process_data(const dcd_tree_handle_t handle,const ocsd_datapath_op_t op,const ocsd_trc_index_t index,const uint32_t dataBlockSize,const uint8_t * pDataBlock,uint32_t * numBytesProcessed)142 OCSD_C_API ocsd_datapath_resp_t ocsd_dt_process_data(const dcd_tree_handle_t handle,
143 const ocsd_datapath_op_t op,
144 const ocsd_trc_index_t index,
145 const uint32_t dataBlockSize,
146 const uint8_t *pDataBlock,
147 uint32_t *numBytesProcessed)
148 {
149 ocsd_datapath_resp_t resp = OCSD_RESP_FATAL_NOT_INIT;
150 if(handle != C_API_INVALID_TREE_HANDLE)
151 resp = ((DecodeTree *)handle)->TraceDataIn(op,index,dataBlockSize,pDataBlock,numBytesProcessed);
152 return resp;
153 }
154
155 /*** Decode tree - decoder management */
156
ocsd_dt_create_decoder(const dcd_tree_handle_t handle,const char * decoder_name,const int create_flags,const void * decoder_cfg,unsigned char * pCSID)157 OCSD_C_API ocsd_err_t ocsd_dt_create_decoder(const dcd_tree_handle_t handle,
158 const char *decoder_name,
159 const int create_flags,
160 const void *decoder_cfg,
161 unsigned char *pCSID
162 )
163 {
164 ocsd_err_t err = OCSD_OK;
165 DecodeTree *dt = (DecodeTree *)handle;
166 std::string dName = decoder_name;
167 IDecoderMngr *pDcdMngr;
168 err = OcsdLibDcdRegister::getDecoderRegister()->getDecoderMngrByName(dName,&pDcdMngr);
169 if(err != OCSD_OK)
170 return err;
171
172 CSConfig *pConfig = 0;
173 err = pDcdMngr->createConfigFromDataStruct(&pConfig,decoder_cfg);
174 if(err != OCSD_OK)
175 return err;
176
177 err = dt->createDecoder(dName,create_flags,pConfig);
178 if(err == OCSD_OK)
179 *pCSID = pConfig->getTraceID();
180 delete pConfig;
181 return err;
182 }
183
ocsd_dt_remove_decoder(const dcd_tree_handle_t handle,const unsigned char CSID)184 OCSD_C_API ocsd_err_t ocsd_dt_remove_decoder( const dcd_tree_handle_t handle,
185 const unsigned char CSID)
186 {
187 return ((DecodeTree *)handle)->removeDecoder(CSID);
188 }
189
ocsd_dt_attach_packet_callback(const dcd_tree_handle_t handle,const unsigned char CSID,const ocsd_c_api_cb_types callback_type,void * p_fn_callback_data,const void * p_context)190 OCSD_C_API ocsd_err_t ocsd_dt_attach_packet_callback( const dcd_tree_handle_t handle,
191 const unsigned char CSID,
192 const ocsd_c_api_cb_types callback_type,
193 void *p_fn_callback_data,
194 const void *p_context)
195 {
196 ocsd_err_t err = OCSD_OK;
197 DecodeTree *pDT = static_cast<DecodeTree *>(handle);
198 DecodeTreeElement *pElem = pDT->getDecoderElement(CSID);
199 if(pElem == 0)
200 return OCSD_ERR_INVALID_ID; // cannot find entry for that CSID
201
202 ITrcTypedBase *pDataInSink = 0; // pointer to a sink callback object
203 switch(callback_type)
204 {
205 case OCSD_C_API_CB_PKT_SINK:
206 err = ocsd_create_pkt_sink_cb(pElem->getProtocol(),(FnDefPktDataIn)p_fn_callback_data,p_context,&pDataInSink);
207 if(err == OCSD_OK)
208 err = pElem->getDecoderMngr()->attachPktSink(pElem->getDecoderHandle(), pDataInSink);
209 break;
210
211 case OCSD_C_API_CB_PKT_MON:
212 err = ocsd_create_pkt_mon_cb(pElem->getProtocol(),(FnDefPktDataMon)p_fn_callback_data,p_context,&pDataInSink);
213 if (err == OCSD_OK)
214 err = pElem->getDecoderMngr()->attachPktMonitor(pElem->getDecoderHandle(), pDataInSink);
215 break;
216
217 default:
218 err = OCSD_ERR_INVALID_PARAM_VAL;
219 }
220
221 if(err == OCSD_OK)
222 {
223 if (err == OCSD_OK)
224 {
225 // save object pointer for destruction later.
226 std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
227 it = s_data_map.find(handle);
228 if (it != s_data_map.end())
229 it->second->cb_objs.push_back(pDataInSink);
230 }
231 else
232 delete pDataInSink;
233 }
234 return err;
235 }
236
237 /*** Decode tree set element output */
238
ocsd_dt_set_gen_elem_outfn(const dcd_tree_handle_t handle,FnTraceElemIn pFn,const void * p_context)239 OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_outfn(const dcd_tree_handle_t handle, FnTraceElemIn pFn, const void *p_context)
240 {
241
242 GenTraceElemCBObj * pCBObj = new (std::nothrow)GenTraceElemCBObj(pFn, p_context);
243 if(pCBObj)
244 {
245 ((DecodeTree *)handle)->setGenTraceElemOutI(pCBObj);
246 return OCSD_OK;
247 }
248 return OCSD_ERR_MEM;
249 }
250
251
252 /*** Default error logging */
253
ocsd_def_errlog_init(const ocsd_err_severity_t verbosity,const int create_output_logger)254 OCSD_C_API ocsd_err_t ocsd_def_errlog_init(const ocsd_err_severity_t verbosity, const int create_output_logger)
255 {
256 if(DecodeTree::getDefaultErrorLogger()->initErrorLogger(verbosity,(bool)(create_output_logger != 0)))
257 return OCSD_OK;
258 return OCSD_ERR_NOT_INIT;
259 }
260
ocsd_def_errlog_config_output(const int output_flags,const char * log_file_name)261 OCSD_C_API ocsd_err_t ocsd_def_errlog_config_output(const int output_flags, const char *log_file_name)
262 {
263 ocsdMsgLogger *pLogger = DecodeTree::getDefaultErrorLogger()->getOutputLogger();
264 if(pLogger)
265 {
266 pLogger->setLogOpts(output_flags & C_API_MSGLOGOUT_MASK);
267 if(log_file_name != NULL)
268 {
269 pLogger->setLogFileName(log_file_name);
270 }
271 return OCSD_OK;
272 }
273 return OCSD_ERR_NOT_INIT;
274 }
275
276
ocsd_def_errlog_set_strprint_cb(const dcd_tree_handle_t handle,void * p_context,FnDefLoggerPrintStrCB p_str_print_cb)277 OCSD_C_API ocsd_err_t ocsd_def_errlog_set_strprint_cb(const dcd_tree_handle_t handle, void *p_context, FnDefLoggerPrintStrCB p_str_print_cb)
278 {
279 ocsdMsgLogger *pLogger = DecodeTree::getDefaultErrorLogger()->getOutputLogger();
280 if (pLogger)
281 {
282 std::map<dcd_tree_handle_t, lib_dt_data_list *>::iterator it;
283 it = s_data_map.find(handle);
284 if (it != s_data_map.end())
285 {
286 DefLogStrCBObj *pCBObj = &(it->second->s_def_log_str_cb);
287 pCBObj->setCBFn(p_context, p_str_print_cb);
288 pLogger->setStrOutFn(pCBObj);
289 int logOpts = pLogger->getLogOpts();
290 logOpts |= (int)(ocsdMsgLogger::OUT_STR_CB);
291 pLogger->setLogOpts(logOpts);
292 return OCSD_OK;
293 }
294 }
295 return OCSD_ERR_NOT_INIT;
296 }
297
ocsd_def_errlog_msgout(const char * msg)298 OCSD_C_API void ocsd_def_errlog_msgout(const char *msg)
299 {
300 ocsdMsgLogger *pLogger = DecodeTree::getDefaultErrorLogger()->getOutputLogger();
301 if(pLogger)
302 pLogger->LogMsg(msg);
303 }
304
305 /*** Convert packet to string */
306
ocsd_pkt_str(const ocsd_trace_protocol_t pkt_protocol,const void * p_pkt,char * buffer,const int buffer_size)307 OCSD_C_API ocsd_err_t ocsd_pkt_str(const ocsd_trace_protocol_t pkt_protocol, const void *p_pkt, char *buffer, const int buffer_size)
308 {
309 ocsd_err_t err = OCSD_OK;
310 if((buffer == NULL) || (buffer_size < 2))
311 return OCSD_ERR_INVALID_PARAM_VAL;
312
313 std::string pktStr = "";
314 buffer[0] = 0;
315
316 switch(pkt_protocol)
317 {
318 case OCSD_PROTOCOL_ETMV4I:
319 trcPrintElemToString<EtmV4ITrcPacket,ocsd_etmv4_i_pkt>(p_pkt, pktStr);
320 break;
321
322 case OCSD_PROTOCOL_ETMV3:
323 trcPrintElemToString<EtmV3TrcPacket,ocsd_etmv3_pkt>(p_pkt, pktStr);
324 break;
325
326 case OCSD_PROTOCOL_STM:
327 trcPrintElemToString<StmTrcPacket,ocsd_stm_pkt>(p_pkt, pktStr);
328 break;
329
330 case OCSD_PROTOCOL_PTM:
331 trcPrintElemToString<PtmTrcPacket,ocsd_ptm_pkt>(p_pkt, pktStr);
332 break;
333
334 default:
335 if (OCSD_PROTOCOL_IS_CUSTOM(pkt_protocol))
336 err = ocsd_cust_protocol_to_str(pkt_protocol, p_pkt, buffer, buffer_size);
337 else
338 err = OCSD_ERR_NO_PROTOCOL;
339 break;
340 }
341
342 if(pktStr.size() > 0)
343 {
344 strncpy(buffer,pktStr.c_str(),buffer_size-1);
345 buffer[buffer_size-1] = 0;
346 }
347 return err;
348 }
349
ocsd_gen_elem_str(const ocsd_generic_trace_elem * p_pkt,char * buffer,const int buffer_size)350 OCSD_C_API ocsd_err_t ocsd_gen_elem_str(const ocsd_generic_trace_elem *p_pkt, char *buffer, const int buffer_size)
351 {
352 ocsd_err_t err = OCSD_OK;
353 if((buffer == NULL) || (buffer_size < 2))
354 return OCSD_ERR_INVALID_PARAM_VAL;
355 std::string str;
356 trcPrintElemToString<OcsdTraceElement,ocsd_generic_trace_elem>(p_pkt,str);
357 if(str.size() > 0)
358 {
359 strncpy(buffer,str.c_str(),buffer_size -1);
360 buffer[buffer_size-1] = 0;
361 }
362 return err;
363 }
364
365 /*** Decode tree -- memory accessor control */
366
ocsd_dt_add_binfile_mem_acc(const dcd_tree_handle_t handle,const ocsd_vaddr_t address,const ocsd_mem_space_acc_t mem_space,const char * filepath)367 OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const char *filepath)
368 {
369 ocsd_err_t err = OCSD_OK;
370 DecodeTree *pDT;
371 err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
372 if(err == OCSD_OK)
373 err = pDT->addBinFileMemAcc(address,mem_space,filepath);
374 return err;
375 }
376
ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle,const ocsd_file_mem_region_t * region_array,const int num_regions,const ocsd_mem_space_acc_t mem_space,const char * filepath)377 OCSD_C_API ocsd_err_t ocsd_dt_add_binfile_region_mem_acc(const dcd_tree_handle_t handle, const ocsd_file_mem_region_t *region_array, const int num_regions, const ocsd_mem_space_acc_t mem_space, const char *filepath)
378 {
379 ocsd_err_t err = OCSD_OK;
380 DecodeTree *pDT;
381 err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
382 if(err == OCSD_OK)
383 err = pDT->addBinFileRegionMemAcc(region_array,num_regions,mem_space,filepath);
384 return err;
385 }
386
ocsd_dt_add_buffer_mem_acc(const dcd_tree_handle_t handle,const ocsd_vaddr_t address,const ocsd_mem_space_acc_t mem_space,const uint8_t * p_mem_buffer,const uint32_t mem_length)387 OCSD_C_API ocsd_err_t ocsd_dt_add_buffer_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space, const uint8_t *p_mem_buffer, const uint32_t mem_length)
388 {
389 ocsd_err_t err = OCSD_OK;
390 DecodeTree *pDT;
391 err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
392 if(err == OCSD_OK)
393 err = pDT->addBufferMemAcc(address,mem_space,p_mem_buffer,mem_length);
394 return err;
395 }
396
ocsd_dt_add_callback_mem_acc(const dcd_tree_handle_t handle,const ocsd_vaddr_t st_address,const ocsd_vaddr_t en_address,const ocsd_mem_space_acc_t mem_space,Fn_MemAcc_CB p_cb_func,const void * p_context)397 OCSD_C_API ocsd_err_t ocsd_dt_add_callback_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAcc_CB p_cb_func, const void *p_context)
398 {
399 ocsd_err_t err = OCSD_OK;
400 DecodeTree *pDT;
401 err = ocsd_check_and_add_mem_acc_mapper(handle,&pDT);
402 if(err == OCSD_OK)
403 err = pDT->addCallbackMemAcc(st_address,en_address,mem_space,p_cb_func,p_context);
404 return err;
405 }
406
ocsd_dt_add_callback_trcid_mem_acc(const dcd_tree_handle_t handle,const ocsd_vaddr_t st_address,const ocsd_vaddr_t en_address,const ocsd_mem_space_acc_t mem_space,Fn_MemAccID_CB p_cb_func,const void * p_context)407 OCSD_C_API ocsd_err_t ocsd_dt_add_callback_trcid_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_vaddr_t en_address, const ocsd_mem_space_acc_t mem_space, Fn_MemAccID_CB p_cb_func, const void *p_context)
408 {
409 ocsd_err_t err = OCSD_OK;
410 DecodeTree *pDT;
411 err = ocsd_check_and_add_mem_acc_mapper(handle, &pDT);
412 if (err == OCSD_OK)
413 err = pDT->addCallbackIDMemAcc(st_address, en_address, mem_space, p_cb_func, p_context);
414 return err;
415 }
416
417
ocsd_dt_remove_mem_acc(const dcd_tree_handle_t handle,const ocsd_vaddr_t st_address,const ocsd_mem_space_acc_t mem_space)418 OCSD_C_API ocsd_err_t ocsd_dt_remove_mem_acc(const dcd_tree_handle_t handle, const ocsd_vaddr_t st_address, const ocsd_mem_space_acc_t mem_space)
419 {
420 ocsd_err_t err = OCSD_OK;
421
422 if(handle != C_API_INVALID_TREE_HANDLE)
423 {
424 DecodeTree *pDT = static_cast<DecodeTree *>(handle);
425 err = pDT->removeMemAccByAddress(st_address,mem_space);
426 }
427 else
428 err = OCSD_ERR_INVALID_PARAM_VAL;
429 return err;
430 }
431
ocsd_tl_log_mapped_mem_ranges(const dcd_tree_handle_t handle)432 OCSD_C_API void ocsd_tl_log_mapped_mem_ranges(const dcd_tree_handle_t handle)
433 {
434 if(handle != C_API_INVALID_TREE_HANDLE)
435 {
436 DecodeTree *pDT = static_cast<DecodeTree *>(handle);
437 pDT->logMappedRanges();
438 }
439 }
440
ocsd_gen_elem_init(ocsd_generic_trace_elem * p_pkt,const ocsd_gen_trc_elem_t elem_type)441 OCSD_C_API void ocsd_gen_elem_init(ocsd_generic_trace_elem *p_pkt, const ocsd_gen_trc_elem_t elem_type)
442 {
443 p_pkt->elem_type = elem_type;
444 p_pkt->flag_bits = 0;
445 p_pkt->ptr_extended_data = 0;
446 }
447
ocsd_dt_set_raw_frame_printer(const dcd_tree_handle_t handle,int flags)448 OCSD_C_API ocsd_err_t ocsd_dt_set_raw_frame_printer(const dcd_tree_handle_t handle, int flags)
449 {
450 if (handle != C_API_INVALID_TREE_HANDLE)
451 return ((DecodeTree *)handle)->addRawFramePrinter(0, (uint32_t)flags);
452 return OCSD_ERR_NOT_INIT;
453 }
454
ocsd_dt_set_gen_elem_printer(const dcd_tree_handle_t handle)455 OCSD_C_API ocsd_err_t ocsd_dt_set_gen_elem_printer(const dcd_tree_handle_t handle)
456 {
457 if (handle != C_API_INVALID_TREE_HANDLE)
458 return ((DecodeTree *)handle)->addGenElemPrinter(0);
459 return OCSD_ERR_NOT_INIT;
460 }
461
ocsd_dt_set_pkt_protocol_printer(const dcd_tree_handle_t handle,uint8_t cs_id,int monitor)462 OCSD_C_API ocsd_err_t ocsd_dt_set_pkt_protocol_printer(const dcd_tree_handle_t handle, uint8_t cs_id, int monitor)
463 {
464 ocsd_err_t err = OCSD_ERR_NOT_INIT;
465 if (handle != C_API_INVALID_TREE_HANDLE)
466 {
467 DecodeTree *p_tree = (DecodeTree *)handle;
468 err = p_tree->addPacketPrinter(cs_id, (bool)(monitor != 0), 0);
469 }
470 return err;
471 }
472
473 /*******************************************************************************/
474 /* C API local fns */
475 /*******************************************************************************/
ocsd_create_pkt_sink_cb(ocsd_trace_protocol_t protocol,FnDefPktDataIn pPktInFn,const void * p_context,ITrcTypedBase ** ppCBObj)476 static ocsd_err_t ocsd_create_pkt_sink_cb(ocsd_trace_protocol_t protocol, FnDefPktDataIn pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj )
477 {
478 ocsd_err_t err = OCSD_OK;
479 *ppCBObj = 0;
480
481 switch(protocol)
482 {
483 case OCSD_PROTOCOL_ETMV4I:
484 *ppCBObj = new (std::nothrow) PktCBObj<EtmV4ITrcPacket>(pPktInFn,p_context);
485 break;
486
487 case OCSD_PROTOCOL_ETMV3:
488 *ppCBObj = new (std::nothrow) PktCBObj<EtmV3TrcPacket>(pPktInFn,p_context);
489 break;
490
491 case OCSD_PROTOCOL_PTM:
492 *ppCBObj = new (std::nothrow) PktCBObj<PtmTrcPacket>(pPktInFn,p_context);
493 break;
494
495 case OCSD_PROTOCOL_STM:
496 *ppCBObj = new (std::nothrow) PktCBObj<StmTrcPacket>(pPktInFn,p_context);
497 break;
498
499 default:
500 if ((protocol >= OCSD_PROTOCOL_CUSTOM_0) && (protocol < OCSD_PROTOCOL_END))
501 {
502 *ppCBObj = new (std::nothrow) PktCBObj<void>(pPktInFn, p_context);
503 }
504 else
505 err = OCSD_ERR_NO_PROTOCOL;
506 break;
507 }
508
509 if((*ppCBObj == 0) && (err == OCSD_OK))
510 err = OCSD_ERR_MEM;
511
512 return err;
513 }
514
ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol,FnDefPktDataMon pPktInFn,const void * p_context,ITrcTypedBase ** ppCBObj)515 static ocsd_err_t ocsd_create_pkt_mon_cb(ocsd_trace_protocol_t protocol, FnDefPktDataMon pPktInFn, const void *p_context, ITrcTypedBase **ppCBObj )
516 {
517 ocsd_err_t err = OCSD_OK;
518 *ppCBObj = 0;
519
520 switch(protocol)
521 {
522 case OCSD_PROTOCOL_ETMV4I:
523 *ppCBObj = new (std::nothrow) PktMonCBObj<EtmV4ITrcPacket>(pPktInFn,p_context);
524 break;
525
526 case OCSD_PROTOCOL_ETMV3:
527 *ppCBObj = new (std::nothrow) PktMonCBObj<EtmV3TrcPacket>(pPktInFn,p_context);
528 break;
529
530 case OCSD_PROTOCOL_PTM:
531 *ppCBObj = new (std::nothrow) PktMonCBObj<PtmTrcPacket>(pPktInFn,p_context);
532 break;
533
534 case OCSD_PROTOCOL_STM:
535 *ppCBObj = new (std::nothrow) PktMonCBObj<StmTrcPacket>(pPktInFn,p_context);
536 break;
537
538 default:
539 if ((protocol >= OCSD_PROTOCOL_CUSTOM_0) && (protocol < OCSD_PROTOCOL_END))
540 {
541 *ppCBObj = new (std::nothrow) PktMonCBObj<void>(pPktInFn, p_context);
542 }
543 else
544 err = OCSD_ERR_NO_PROTOCOL;
545 break;
546 }
547
548 if((*ppCBObj == 0) && (err == OCSD_OK))
549 err = OCSD_ERR_MEM;
550
551 return err;
552 }
553
ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle,DecodeTree ** ppDT)554 static ocsd_err_t ocsd_check_and_add_mem_acc_mapper(const dcd_tree_handle_t handle, DecodeTree **ppDT)
555 {
556 *ppDT = 0;
557 if(handle == C_API_INVALID_TREE_HANDLE)
558 return OCSD_ERR_INVALID_PARAM_VAL;
559 *ppDT = static_cast<DecodeTree *>(handle);
560 if(!(*ppDT)->hasMemAccMapper())
561 return (*ppDT)->createMemAccMapper();
562 return OCSD_OK;
563 }
564
565 /*******************************************************************************/
566 /* C API Helper objects */
567 /*******************************************************************************/
568
569 /****************** Generic trace element output callback function ************/
GenTraceElemCBObj(FnTraceElemIn pCBFn,const void * p_context)570 GenTraceElemCBObj::GenTraceElemCBObj(FnTraceElemIn pCBFn, const void *p_context) :
571 m_c_api_cb_fn(pCBFn),
572 m_p_cb_context(p_context)
573 {
574 }
575
TraceElemIn(const ocsd_trc_index_t index_sop,const uint8_t trc_chan_id,const OcsdTraceElement & elem)576 ocsd_datapath_resp_t GenTraceElemCBObj::TraceElemIn(const ocsd_trc_index_t index_sop,
577 const uint8_t trc_chan_id,
578 const OcsdTraceElement &elem)
579 {
580 return m_c_api_cb_fn(m_p_cb_context, index_sop, trc_chan_id, &elem);
581 }
582
583 /* End of File ocsd_c_api.cpp */
584