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  {
157  T *p = dynamic_cast<T*> (obj);
158  if (p == 0)
159  {
160  return false;
161  }
162  (p->*m_source).ConnectWithoutContext (cb);
163  return true;
164  }
165  virtual bool Connect (ObjectBase *obj, std::string context, const CallbackBase &cb) const
166  {
167  T *p = dynamic_cast<T*> (obj);
168  if (p == 0)
169  {
170  return false;
171  }
172  (p->*m_source).Connect (cb, context);
173  return true;
174  }
175  virtual bool DisconnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const
176  {
177  T *p = dynamic_cast<T*> (obj);
178  if (p == 0)
179  {
180  return false;
181  }
182  (p->*m_source).DisconnectWithoutContext (cb);
183  return true;
184  }
185  virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const
186  {
187  T *p = dynamic_cast<T*> (obj);
188  if (p == 0)
189  {
190  return false;
191  }
192  (p->*m_source).Disconnect (cb, context);
193  return true;
194  }
195  SOURCE T::*m_source;
196  } *accessor = new Accessor ();
197  accessor->m_source = a;
198  return Ptr<const TraceSourceAccessor> (accessor, false);
199 }
200 
201 template <typename T>
203 {
204  return DoMakeTraceSourceAccessor (a);
205 }
206 
207 } // namespace ns3
208 
209 
210 #endif /* TRACE_SOURCE_ACCESSOR_H */
Declaration of the various callback functions.
Base class for Callback class.
Definition: callback.h:1196
Anchor the ns-3 type and attribute system.
Definition: object-base.h:120
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
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.
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:935
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:914
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:901
Ptr< const TraceSourceAccessor > DoMakeTraceSourceAccessor(SOURCE T::*a)
MakeTraceSourceAccessor() implementation.
static Ptr< const TraceSourceAccessor > MakeEmptyTraceSourceAccessor()
Create an empty TraceSourceAccessor.
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.