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 
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 
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 
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         pPrinter = new (std::nothrow) PacketPrinter<EtmV4ITrcPacket>(CSID);
61         break;
62     case OCSD_PROTOCOL_ETMV3:
63         pPrinter = new (std::nothrow) PacketPrinter<EtmV3TrcPacket>(CSID);
64         break;
65     case OCSD_PROTOCOL_PTM:
66         pPrinter = new (std::nothrow) PacketPrinter<PtmTrcPacket>(CSID);
67         break;
68     case OCSD_PROTOCOL_STM:
69         pPrinter = new (std::nothrow) PacketPrinter<StmTrcPacket>(CSID);
70         break;
71     default:
72         break;
73     }
74     SavePrinter(printer_list, pPrinter, pMsgLogger);
75     return pPrinter;
76 }
77 
78 const int PktPrinterFact::numPrinters(std::vector<ItemPrinter *> &printer_list)
79 {
80     return printer_list.size();
81 }
82 
83 void PktPrinterFact::SavePrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter, ocsdMsgLogger *pMsgLogger)
84 {
85     if (pPrinter)
86     {
87         pPrinter->setMessageLogger(pMsgLogger);
88         printer_list.push_back((ItemPrinter *)pPrinter);
89     }
90 }
91 
92 void PktPrinterFact::destroyAllPrinters(std::vector<ItemPrinter *> &printer_list)
93 {
94     std::vector<ItemPrinter *>::iterator it;
95     it = printer_list.begin();
96     while (it != printer_list.end())
97     {
98         delete *it;
99         it++;
100     }
101     printer_list.clear();
102 }
103 
104 void PktPrinterFact::destroyPrinter(std::vector<ItemPrinter *> &printer_list, ItemPrinter *pPrinter)
105 {
106     std::vector<ItemPrinter *>::iterator it;
107     it = printer_list.begin();
108     while (it != printer_list.end())
109     {
110         if (*it == pPrinter)
111         {
112             printer_list.erase(it);
113             delete pPrinter;
114             return;
115         }
116         else
117             it++;
118     }
119 }
120 
121 
122 
123 /* end of file  trc_print_fact.cpp */
124