A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
trace-source-accessor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef TRACE_SOURCE_ACCESSOR_H
20#define TRACE_SOURCE_ACCESSOR_H
21
22#include "callback.h"
23#include "ptr.h"
24#include "simple-ref-count.h"
25
26#include <stdint.h>
27
34namespace ns3
35{
36
37class ObjectBase;
38
47class TraceSourceAccessor : public SimpleRefCount<TraceSourceAccessor>
48{
49 public:
53 virtual ~TraceSourceAccessor();
54
63 virtual bool ConnectWithoutContext(ObjectBase* obj, const CallbackBase& cb) const = 0;
76 virtual bool Connect(ObjectBase* obj, std::string context, const CallbackBase& cb) const = 0;
85 virtual bool DisconnectWithoutContext(ObjectBase* obj, const CallbackBase& cb) const = 0;
98 virtual bool Disconnect(ObjectBase* obj, std::string context, const CallbackBase& cb) const = 0;
99};
100
116template <typename T>
118
128{
129 return Ptr<const TraceSourceAccessor>(nullptr);
130}
131
132} // namespace ns3
133
134/********************************************************************
135 * Implementation of the templates declared above.
136 ********************************************************************/
137
138namespace ns3
139{
140
150template <typename T, typename SOURCE>
151Ptr<const TraceSourceAccessor>
153{
154 struct Accessor : public TraceSourceAccessor
155 {
156 bool ConnectWithoutContext(ObjectBase* obj, const CallbackBase& cb) const override
157 {
158 T* p = dynamic_cast<T*>(obj);
159 if (p == nullptr)
160 {
161 return false;
162 }
163 (p->*m_source).ConnectWithoutContext(cb);
164 return true;
165 }
166
167 bool Connect(ObjectBase* obj, std::string context, const CallbackBase& cb) const override
168 {
169 T* p = dynamic_cast<T*>(obj);
170 if (p == nullptr)
171 {
172 return false;
173 }
174 (p->*m_source).Connect(cb, context);
175 return true;
176 }
177
178 bool DisconnectWithoutContext(ObjectBase* obj, const CallbackBase& cb) const override
179 {
180 T* p = dynamic_cast<T*>(obj);
181 if (p == nullptr)
182 {
183 return false;
184 }
185 (p->*m_source).DisconnectWithoutContext(cb);
186 return true;
187 }
188
189 bool Disconnect(ObjectBase* obj, std::string context, const CallbackBase& cb) const override
190 {
191 T* p = dynamic_cast<T*>(obj);
192 if (p == nullptr)
193 {
194 return false;
195 }
196 (p->*m_source).Disconnect(cb, context);
197 return true;
198 }
199
200 SOURCE T::*m_source;
201 }* accessor = new Accessor();
202
203 accessor->m_source = a;
204 return Ptr<const TraceSourceAccessor>(accessor, false);
205}
206
207template <typename T>
208Ptr<const TraceSourceAccessor>
210{
212}
213
214} // namespace ns3
215
216#endif /* TRACE_SOURCE_ACCESSOR_H */
Declaration of the various callback functions.
Base class for Callback class.
Definition: callback.h:360
Anchor the ns-3 type and attribute system.
Definition: object-base.h:173
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
A template-based reference counting class.
Control access to objects' trace sources.
virtual bool ConnectWithoutContext(ObjectBase *obj, const CallbackBase &cb) const =0
Connect a Callback to a TraceSource (without context.)
virtual bool Connect(ObjectBase *obj, std::string context, const CallbackBase &cb) const =0
Connect a Callback to a TraceSource with a context string.
virtual bool Disconnect(ObjectBase *obj, std::string context, const CallbackBase &cb) const =0
Disconnect a Callback from a TraceSource with a context string.
virtual bool DisconnectWithoutContext(ObjectBase *obj, const CallbackBase &cb) const =0
Disconnect a Callback from a TraceSource (without context).
virtual ~TraceSourceAccessor()
Destructor.
static Ptr< const TraceSourceAccessor > MakeEmptyTraceSourceAccessor()
Create an empty TraceSourceAccessor.
Ptr< const TraceSourceAccessor > DoMakeTraceSourceAccessor(SOURCE T::*a)
MakeTraceSourceAccessor() implementation.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.
ns3::SimpleRefCount declaration and template implementation.