This documentation is not the Latest Release.
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 
118 } // namespace ns3
119 
120 
121 /********************************************************************
122  * Implementation of the templates declared above.
123  ********************************************************************/
124 
125 namespace ns3 {
126 
136 template <typename T, typename SOURCE>
137 Ptr<const TraceSourceAccessor>
139 {
140  struct Accessor : public TraceSourceAccessor
141  {
142  virtual bool ConnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const {
143  T *p = dynamic_cast<T*> (obj);
144  if (p == 0)
145  {
146  return false;
147  }
148  (p->*m_source).ConnectWithoutContext (cb);
149  return true;
150  }
151  virtual bool Connect (ObjectBase *obj, std::string context, const CallbackBase &cb) const {
152  T *p = dynamic_cast<T*> (obj);
153  if (p == 0)
154  {
155  return false;
156  }
157  (p->*m_source).Connect (cb, context);
158  return true;
159  }
160  virtual bool DisconnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const {
161  T *p = dynamic_cast<T*> (obj);
162  if (p == 0)
163  {
164  return false;
165  }
166  (p->*m_source).DisconnectWithoutContext (cb);
167  return true;
168  }
169  virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const {
170  T *p = dynamic_cast<T*> (obj);
171  if (p == 0)
172  {
173  return false;
174  }
175  (p->*m_source).Disconnect (cb, context);
176  return true;
177  }
178  SOURCE T::*m_source;
179  } *accessor = new Accessor ();
180  accessor->m_source = a;
181  return Ptr<const TraceSourceAccessor> (accessor, false);
182 }
183 
184 template <typename T>
186 {
187  return DoMakeTraceSourceAccessor (a);
188 }
189 
190 } // namespace ns3
191 
192 
193 #endif /* TRACE_SOURCE_ACCESSOR_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Smart pointer 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:1092
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:829
Anchor the ns-3 type and attribute system.
Definition: object-base.h:68
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:824
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
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' trace sources.
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:841
A template-based reference counting class.
Reference counting for smart pointers.