• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * \file       trc_print_fact.cpp
3 * \brief      OpenCSD : Trace Packet printer factory.
4 *
5 * \copyright  Copyright (c) 2017, ARM Limited. All Rights Reserved.
6 */
7 
8 
9 /*
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the copyright holder nor the names of its contributors
21 * may be used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 
36 #include "pkt_printers/trc_print_fact.h"
37 
createRawFramePrinter(std::vector<ItemPrinter * > & printer_list,ocsdMsgLogger * pMsgLogger)38 RawFramePrinter * PktPrinterFact::createRawFramePrinter(std::vector<ItemPrinter *> &printer_list, ocsdMsgLogger *pMsgLogger /*= 0*/)
39 {
40     RawFramePrinter *pPrinter = 0;
41     pPrinter = new (std::nothrow)RawFramePrinter();
42     SavePrinter(printer_list, pPrinter, pMsgLogger);
43     return pPrinter;
44 }
45 
createGenElemPrinter(std::vector<ItemPrinter * > & printer_list,ocsdMsgLogger * pMsgLogger)46 TrcGenericElementPrinter *PktPrinterFact::createGenElemPrinter(std::vector<ItemPrinter *> &printer_list, ocsdMsgLogger *pMsgLogger /*= 0*/)
47 {
48     TrcGenericElementPrinter *pPrinter = 0;
49     pPrinter = new (std::nothrow)TrcGenericElementPrinter();
50     SavePrinter(printer_list, pPrinter, pMsgLogger);
51     return pPrinter;
52 }
53 
createProtocolPrinter(std::vector<ItemPrinter * > & printer_list,ocsd_trace_protocol_t protocol,uint8_t CSID,ocsdMsgLogger * pMsgLogger)54 ItemPrinter *PktPrinterFact::createProtocolPrinter(std::vector<ItemPrinter *> &printer_list, ocsd_trace_protocol_t protocol, uint8_t CSID, ocsdMsgLogger *pMsgLogger /*= 0*/)
55 {
56     ItemPrinter *pPrinter = 0;
57     switch (protocol)
58     {
59     case OCSD_PROTOCOL_ETMV4I:
60     case OCSD_PROTOCOL_ETE:
61         pPrinter = new (std::nothrow) PacketPrinter<EtmV4ITrcPacket>(CSID);
62         break;
63     case OCSD_PROTOCOL_ETMV3:
64         pPrinter = new (std::nothrow) PacketPrinter<EtmV3TrcPacket>(CSID);
65         break;
66     case OCSD_PROTOCOL_PTM:
67         pPrinter = new (std::nothrow) PacketPrinter<PtmTrcPacket>(CSID);
68         break;
69     case OCSD_PROTOCOL_STM:
70         pPrinter = new (std::nothrow) PacketPrinter<StmTrcPacket>(CSID);
71         break;
72     default:
73         break;
74     }
75     SavePrinter(printer_list, pPrinter, pMsgLogger);
76     return pPrinter;
77 }
78 
numPrinters(std::vector<ItemPrinter * > & printer_list)79 const int PktPrinterFact::numPrinters(std::vector<ItemPrinter *> &printer_list)
80 {
81     return printer_list.size();
82 }
83 
SavePrinter(std::vector<ItemPrinter * > & printer_list,ItemPrinter * pPrinter,ocsdMsgLogger * pMsgLogger)84 void PktPrinterFact::SavePrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger)
85 {
86     if (pPrinter)
87     {
88         pPrinter->setMessageLogger(pMsgLogger);
89         printer_list.push_back((ItemPrinter *)pPrinter);
90     }
91 }
92 
destroyAllPrinters(std::vector<ItemPrinter * > & printer_list)93 void PktPrinterFact::destroyAllPrinters(std::vector<ItemPrinter *> &printer_list)
94 {
95     std::vector<ItemPrinter *>::iterator it;
96     it = printer_list.begin();
97     while (it != printer_list.end())
98     {
99         delete *it;
100         it++;
101     }
102     printer_list.clear();
103 }
104 
destroyPrinter(std::vector<ItemPrinter * > & printer_list,ItemPrinter * pPrinter)105 void PktPrinterFact::destroyPrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter)
106 {
107     std::vector<ItemPrinter *>::iterator it;
108     it = printer_list.begin();
109     while (it != printer_list.end())
110     {
111         if (*it == pPrinter)
112         {
113             printer_list.erase(it);
114             delete pPrinter;
115             return;
116         }
117         else
118             it++;
119     }
120 }
121 
122 
123 
124 /* end of file  trc_print_fact.cpp */
125