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