A Discrete-Event Network Simulator
API
callback.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005,2006 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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #include "callback.h"
21 
22 #include "log.h"
23 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("Callback");
34 
36  : m_value()
37 {
38  NS_LOG_FUNCTION(this);
39 }
40 
42  : m_value(base)
43 {
44 }
45 
47 {
48  NS_LOG_FUNCTION(this);
49 }
50 
51 void
53 {
54  NS_LOG_FUNCTION(&base);
55 
56  m_value = base;
57 }
58 
61 {
62  NS_LOG_FUNCTION(this);
63  return Create<CallbackValue>(m_value);
64 }
65 
66 std::string
68 {
69  NS_LOG_FUNCTION(this << checker);
70  std::ostringstream oss;
71  oss << PeekPointer(m_value.GetImpl());
72  return oss.str();
73 }
74 
75 bool
77 {
78  NS_LOG_FUNCTION(this << value << checker);
79  return false;
80 }
81 
83 
84 } // namespace ns3
85 
86 #if (__GNUC__ >= 3)
87 
88 #include <cstdlib>
89 #include <cxxabi.h>
90 
91 namespace ns3
92 {
93 
94 std::string
95 CallbackImplBase::Demangle(const std::string& mangled)
96 {
97  NS_LOG_FUNCTION(mangled);
98 
99  int status;
100  char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &status);
101 
102  std::string ret;
103  if (status == 0)
104  {
105  NS_ASSERT(demangled);
106  ret = demangled;
107  }
108  else if (status == -1)
109  {
110  NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occurred.");
111  ret = mangled;
112  }
113  else if (status == -2)
114  {
115  NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI "
116  "mangling rules.");
117  ret = mangled;
118  }
119  else if (status == -3)
120  {
121  NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid.");
122  ret = mangled;
123  }
124  else
125  {
126  NS_LOG_UNCOND("Callback demangling failed: status " << status);
127  ret = mangled;
128  }
129 
130  if (demangled)
131  {
132  std::free(demangled);
133  }
134  return ret;
135 }
136 
137 } // namespace ns3
138 
139 #else
140 
141 std::string
142 ns3::CallbackImplBase::Demangle(const std::string& mangled)
143 {
144  NS_LOG_FUNCTION(this << mangled);
145  return mangled;
146 }
147 
148 #endif
Declaration of the various callback functions.
Base class for Callback class.
Definition: callback.h:360
Ptr< CallbackImplBase > GetImpl() const
Definition: callback.h:368
Callback template class.
Definition: callback.h:438
static std::string Demangle(const std::string &mangled)
Definition: callback.cc:142
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Deserialize from string (not implemented)
Definition: callback.cc:76
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Serialize to string.
Definition: callback.cc:67
void Set(CallbackBase base)
Definition: callback.cc:52
CallbackValue()
Constructor.
Definition: callback.cc:35
CallbackBase m_value
Definition: callback.h:841
Ptr< AttributeValue > Copy() const override
Definition: callback.cc:60
~CallbackValue() override
Destructor.
Definition: callback.cc:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define ATTRIBUTE_CHECKER_IMPLEMENT(type)
Define the MaketypeChecker function for class type.
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:449