OpenCSD - CoreSight Trace Decode Library  1.3.3
comp_attach_pt_t.h
Go to the documentation of this file.
1 
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_COMP_ATTACH_PT_T_H_INCLUDED
36 #define ARM_COMP_ATTACH_PT_T_H_INCLUDED
37 
38 #include <vector>
39 #include "opencsd/ocsd_if_types.h"
40 
46 #include "comp_attach_notifier_i.h"
47 
60 template <class T>
62 public:
64  virtual ~componentAttachPt();
73  virtual ocsd_err_t attach(T* component);
74 
82  virtual ocsd_err_t detach(T* component);
83 
84 
85  // detach current first if anything attached, connect supplied pointer, remain unattached if pointer 0
86  virtual ocsd_err_t replace_first(T* component);
87 
91  virtual void detach_all();
92 
99  virtual T* first();
100 
107  virtual T* next();
108 
114  virtual int num_attached();
115 
123 
124  /* enable state does not affect attach / detach, but can be used to filter access to interfaces */
125  const bool enabled() const;
126  void set_enabled(const bool enable);
127 
128 
134  const bool hasAttached() const { return m_hasAttached; };
135 
136 
142  const bool hasAttachedAndEnabled() const { return m_hasAttached && m_enabled; };
143 
144 protected:
145  bool m_enabled;
148  T *m_comp;
149 };
150 
151 
152 
154 {
155  m_comp = 0;
156  m_notifier = 0;
157  m_enabled = true;
158  m_hasAttached = false;
159 }
160 
162 {
163  detach_all();
164 }
165 
166 
167 template<class T> ocsd_err_t componentAttachPt<T>::attach(T* component)
168 {
169  if(m_comp != 0)
171  m_comp = component;
172  if(m_notifier) m_notifier->attachNotify(1);
173  m_hasAttached = true;
174  return OCSD_OK;
175 }
176 
177 template<class T> ocsd_err_t componentAttachPt<T>::replace_first(T* component)
178 {
179  if(m_hasAttached)
180  detach(m_comp);
181 
182  if(component == 0)
183  return OCSD_OK;
184 
185  return attach(component);
186 }
187 
188 template<class T> ocsd_err_t componentAttachPt<T>::detach(T* component)
189 {
190  if(m_comp != component)
192  m_comp = 0;
193  m_hasAttached = false;
194  if(m_notifier) m_notifier->attachNotify(0);
195  return OCSD_OK;
196 }
197 
198 template<class T> T* componentAttachPt<T>::first()
199 {
200  return (m_enabled) ? m_comp : 0;
201 }
202 
203 template<class T> T* componentAttachPt<T>::next()
204 {
205  return 0;
206 }
207 
208 template<class T> int componentAttachPt<T>::num_attached()
209 {
210  return ((m_comp != 0) ? 1 : 0);
211 }
212 
213 template<class T> void componentAttachPt<T>::detach_all()
214 {
215  m_comp = 0;
216  m_hasAttached = false;
217  if(m_notifier) m_notifier->attachNotify(0);
218 }
219 
221 {
222  m_notifier = notifier;
223 }
224 
225 template<class T> const bool componentAttachPt<T>::enabled() const
226 {
227  return m_enabled;
228 }
229 
230 template<class T> void componentAttachPt<T>::set_enabled(const bool enable)
231 {
232  m_enabled = enable;
233 }
234 
235 
238 #endif // ARM_COMP_ATTACH_PT_T_H_INCLUDED
239 
240 /* End of File comp_attach_pt_t.h */
Single component interface pointer attachment point.
IComponentAttachNotifier * m_notifier
const bool hasAttachedAndEnabled() const
const bool hasAttached() const
OpenCSD : Component attach point notifier interface.
virtual ocsd_err_t replace_first(T *component)
virtual int num_attached()
virtual T * next()
virtual ~componentAttachPt()
virtual ocsd_err_t attach(T *component)
void set_notifier(IComponentAttachNotifier *notifier)
void set_enabled(const bool enable)
virtual ocsd_err_t detach(T *component)
virtual T * first()
const bool enabled() const
virtual void detach_all()
enum _ocsd_err_t ocsd_err_t
@ OCSD_ERR_ATTACH_TOO_MANY
Definition: ocsd_if_types.h:99
@ OCSD_OK
Definition: ocsd_if_types.h:88
@ OCSD_ERR_ATTACH_COMP_NOT_FOUND
OpenCSD : Standard Types used in the library interfaces.