OpenCSD - CoreSight Trace Decode Library
1.8.3
Toggle main menu visibility
Loading...
Searching...
No Matches
include
common
comp_attach_pt_t.h
Go to the documentation of this file.
1
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_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
45
46
#include "
comp_attach_notifier_i.h
"
47
60
template
<
class
T>
61
class
componentAttachPt
{
62
public
:
63
componentAttachPt
();
64
virtual
~componentAttachPt
();
65
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
122
void
set_notifier
(
IComponentAttachNotifier
*notifier);
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
;
146
bool
m_hasAttached
;
147
IComponentAttachNotifier
*
m_notifier
;
148
T *
m_comp
;
149
};
150
151
152
153
template
<
class
T>
componentAttachPt<T>::componentAttachPt
()
154
{
155
m_comp
= 0;
156
m_notifier
= 0;
157
m_enabled
=
true
;
158
m_hasAttached
=
false
;
159
}
160
161
template
<
class
T>
componentAttachPt<T>::~componentAttachPt
()
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)
170
return
OCSD_ERR_ATTACH_TOO_MANY
;
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)
191
return
OCSD_ERR_ATTACH_COMP_NOT_FOUND
;
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
220
template
<
class
T>
void
componentAttachPt<T>::set_notifier
(
IComponentAttachNotifier
*notifier)
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
237
238
#endif
// ARM_COMP_ATTACH_PT_T_H_INCLUDED
239
240
/* End of File comp_attach_pt_t.h */
IComponentAttachNotifier
Definition
comp_attach_notifier_i.h:46
componentAttachPt::m_notifier
IComponentAttachNotifier * m_notifier
Definition
comp_attach_pt_t.h:147
componentAttachPt::m_hasAttached
bool m_hasAttached
Definition
comp_attach_pt_t.h:146
componentAttachPt::hasAttachedAndEnabled
const bool hasAttachedAndEnabled() const
Definition
comp_attach_pt_t.h:142
componentAttachPt::m_enabled
bool m_enabled
Definition
comp_attach_pt_t.h:145
componentAttachPt::m_comp
T * m_comp
Definition
comp_attach_pt_t.h:148
componentAttachPt::hasAttached
const bool hasAttached() const
Definition
comp_attach_pt_t.h:134
comp_attach_notifier_i.h
OpenCSD : Component attach point notifier interface.
componentAttachPt::replace_first
virtual ocsd_err_t replace_first(T *component)
Definition
comp_attach_pt_t.h:177
componentAttachPt::componentAttachPt
componentAttachPt()
Definition
comp_attach_pt_t.h:153
componentAttachPt::num_attached
virtual int num_attached()
Definition
comp_attach_pt_t.h:208
componentAttachPt::next
virtual T * next()
Definition
comp_attach_pt_t.h:203
componentAttachPt::~componentAttachPt
virtual ~componentAttachPt()
Definition
comp_attach_pt_t.h:161
componentAttachPt::attach
virtual ocsd_err_t attach(T *component)
Definition
comp_attach_pt_t.h:167
componentAttachPt::set_notifier
void set_notifier(IComponentAttachNotifier *notifier)
Definition
comp_attach_pt_t.h:220
componentAttachPt::set_enabled
void set_enabled(const bool enable)
Definition
comp_attach_pt_t.h:230
componentAttachPt::detach
virtual ocsd_err_t detach(T *component)
Definition
comp_attach_pt_t.h:188
componentAttachPt::first
virtual T * first()
Definition
comp_attach_pt_t.h:198
componentAttachPt::enabled
const bool enabled() const
Definition
comp_attach_pt_t.h:225
componentAttachPt::detach_all
virtual void detach_all()
Definition
comp_attach_pt_t.h:213
ocsd_err_t
enum _ocsd_err_t ocsd_err_t
OCSD_ERR_ATTACH_TOO_MANY
@ OCSD_ERR_ATTACH_TOO_MANY
Definition
ocsd_if_types.h:91
OCSD_OK
@ OCSD_OK
Definition
ocsd_if_types.h:80
OCSD_ERR_ATTACH_COMP_NOT_FOUND
@ OCSD_ERR_ATTACH_COMP_NOT_FOUND
Definition
ocsd_if_types.h:93
ocsd_if_types.h
OpenCSD : Standard Types used in the library interfaces.
Generated on
for OpenCSD - CoreSight Trace Decode Library by
1.17.0