xref: /freebsd/contrib/opencsd/decoder/include/common/ocsd_dcd_tree_elem.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /*!
2  * \file       ocsd_dcd_tree_elem.h
3  * \brief      OpenCSD : Decode tree element.
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 #ifndef ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
36 #define ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
37 
38 #include "common/ocsd_dcd_mngr_i.h"
39 #include "common/trc_component.h"
40 
41 /** @addtogroup dcd_tree
42 @{*/
43 
44 /*!  @struct _decoder_elements
45  *   @brief Decode tree element base structure.
46  *
47  *  Element describes the protocol supported for this element and
48  *  contains pointers to the decoder manager interface and component handle.
49  */
50 typedef struct _decoder_elements
51 {
52     std::string dcd_name;       //!< Registered name of the decoder
53     TraceComponent *dcd_handle; //!< handle to the decoder object
54     IDecoderMngr *dcd_mngr;     //!< pointer to the decoder manager interface for the decodcer
55     ocsd_trace_protocol_t protocol;//!< protocol type
56     bool created;  /**< decode tree created this element (destroy it on tree destruction) */
57 } decoder_element;
58 
59 /*!
60  *  @class DecodeTreeElement
61  *  @brief Decode tree element
62  *
63  *  Decoder tree elements are references to individual decoders in the tree.
64  *  These allow iteration of all decoders in the tree to perform common operations.
65  *
66  * The DecodeTree contains a list of elements.
67  */
68 class DecodeTreeElement : protected decoder_element
69 {
70 public:
71     DecodeTreeElement();
72     ~DecodeTreeElement() {};
73 
74     void SetDecoderElement(const std::string &name, IDecoderMngr *dcdMngr, TraceComponent *pHandle, bool bCreated);
75     void DestroyElem();
76 
77     const std::string &getDecoderTypeName()  { return dcd_name; };
78     IDecoderMngr *getDecoderMngr() { return dcd_mngr; };
79     ocsd_trace_protocol_t getProtocol() const { return protocol; };
80     TraceComponent *getDecoderHandle() { return dcd_handle; };
81 };
82 
83 inline DecodeTreeElement::DecodeTreeElement()
84 {
85     dcd_name = "unknown";
86     dcd_mngr = 0;
87     dcd_handle = 0;
88     protocol = OCSD_PROTOCOL_END;
89     created = false;
90 }
91 
92 inline void DecodeTreeElement::SetDecoderElement(const std::string &name, IDecoderMngr *dcdMngr, TraceComponent *pHandle, bool bCreated)
93 {
94     dcd_name = name;
95     dcd_mngr = dcdMngr;
96     dcd_handle = pHandle;
97     protocol = OCSD_PROTOCOL_UNKNOWN;
98     if(dcd_mngr)
99         protocol = dcd_mngr->getProtocolType();
100     created = bCreated;
101 }
102 
103 inline void DecodeTreeElement::DestroyElem()
104 {
105     if(created && (dcd_mngr != 0) && (dcd_handle != 0))
106         dcd_mngr->destroyDecoder(dcd_handle);
107 }
108 
109 /** @}*/
110 #endif // ARM_OCSD_DCD_TREE_ELEM_H_INCLUDED
111 
112 /* End of File ocsd_dcd_tree_elem.h */
113