2 * \file ocsd_gen_elem_list.cpp
3 * \brief OpenCSD : List of Generic trace elements for output.
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
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.
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.
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.
36 #include "common/ocsd_gen_elem_list.h"
38 OcsdGenElemList::OcsdGenElemList()
50 OcsdGenElemList::~OcsdGenElemList()
52 for(int i = 0; i<m_elemArraySize; i++)
54 delete m_pElemArray[i].pElem;
56 delete [] m_pElemArray;
60 void OcsdGenElemList::reset()
67 OcsdTraceElement *OcsdGenElemList::getNextElem(const ocsd_trc_index_t trc_pkt_idx)
69 OcsdTraceElement *pElem = 0;
70 if(getNumElem() == m_elemArraySize) // all in use
76 int idx = getAdjustedIdx(m_firstElemIdx + m_numUsed - 1);
77 pElem = m_pElemArray[idx].pElem;
78 m_pElemArray[idx].trc_pkt_idx = trc_pkt_idx;
83 const ocsd_gen_trc_elem_t OcsdGenElemList::getElemType(const int entryN) const
85 ocsd_gen_trc_elem_t elem_type = OCSD_GEN_TRC_ELEM_UNKNOWN;
86 if(entryN < getNumElem())
88 int idx = getAdjustedIdx(m_firstElemIdx + entryN);
89 elem_type = m_pElemArray[idx].pElem->getType();
94 ocsd_datapath_resp_t OcsdGenElemList::sendElements()
96 ocsd_datapath_resp_t resp = OCSD_RESP_CONT;
98 if((m_elemArraySize == 0) || (m_sendIf == 0))
99 return OCSD_RESP_FATAL_NOT_INIT;
101 if(!m_sendIf->hasAttachedAndEnabled())
102 return OCSD_RESP_FATAL_NOT_INIT;
104 while(elemToSend() && OCSD_DATA_RESP_IS_CONT(resp))
106 resp = m_sendIf->first()->TraceElemIn(m_pElemArray[m_firstElemIdx].trc_pkt_idx, m_CSID, *(m_pElemArray[m_firstElemIdx].pElem));
108 if(m_firstElemIdx >= m_elemArraySize)
115 // this function will enlarge the array, and create extra element objects.
116 // existing objects will be moved to the front of the array
117 // called if all elements are in use. (sets indexes accordingly)
118 void OcsdGenElemList::growArray()
120 elemPtr_t *p_new_array = 0;
123 if(m_elemArraySize == 0)
124 // starting from scratch...
127 increment = m_elemArraySize / 2; // grow by 50%
130 p_new_array = new (std::nothrow) elemPtr_t[m_elemArraySize+increment];
134 // fill the last increment elements with new objects
135 for(int i=0; i < increment; i++)
137 p_new_array[m_elemArraySize+i].pElem = new (std::nothrow) OcsdTraceElement();
140 // copy the existing objects from the old array to the start of the new one
141 // and adjust the indices.
142 if(m_elemArraySize > 0)
144 int inIdx = m_firstElemIdx;
145 for(int i = 0; i < m_elemArraySize; i++)
147 p_new_array[i].pElem = m_pElemArray[inIdx].pElem;
148 p_new_array[i].trc_pkt_idx = m_pElemArray[inIdx].trc_pkt_idx;
150 if(inIdx >= m_elemArraySize)
155 // delete the old pointer array.
156 delete [] m_pElemArray;
157 m_elemArraySize += increment;
162 // update the internal array pointers to the new array
163 if(m_firstElemIdx >= 0)
165 m_pElemArray = p_new_array;
168 /* End of File ocsd_gen_elem_list.cpp */