A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
24/**
25 * \file
26 * \ingroup callback
27 * ns3::CallbackValue implementation.
28 */
29
30namespace ns3
31{
32
33NS_LOG_COMPONENT_DEFINE("Callback");
34
36 : m_value()
37{
38 NS_LOG_FUNCTION(this);
39}
40
42 : m_value(value)
43{
44}
45
47{
48 NS_LOG_FUNCTION(this);
49}
50
51void
53{
54 NS_LOG_FUNCTION(&value);
55 m_value = value;
56}
57
60{
61 NS_LOG_FUNCTION(this);
62 return m_value;
63}
64
67{
68 NS_LOG_FUNCTION(this);
69 return Create<CallbackValue>(m_value);
70}
71
72std::string
74{
75 NS_LOG_FUNCTION(this << checker);
76 std::ostringstream oss;
77 oss << PeekPointer(m_value.GetImpl());
78 return oss.str();
79}
80
81bool
83{
84 NS_LOG_FUNCTION(this << value << checker);
85 return false;
86}
87
89
90} // namespace ns3
91
92#if (__GNUC__ >= 3)
93
94#include <cstdlib>
95#include <cxxabi.h>
96
97namespace ns3
98{
99
100std::string
101CallbackImplBase::Demangle(const std::string& mangled)
102{
103 NS_LOG_FUNCTION(mangled);
104
105 int status;
106 char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &status);
107
108 std::string ret;
109 if (status == 0)
110 {
111 NS_ASSERT(demangled);
112 ret = demangled;
113 }
114 else if (status == -1)
115 {
116 NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occurred.");
117 ret = mangled;
118 }
119 else if (status == -2)
120 {
121 NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI "
122 "mangling rules.");
123 ret = mangled;
124 }
125 else if (status == -3)
126 {
127 NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid.");
128 ret = mangled;
129 }
130 else
131 {
132 NS_LOG_UNCOND("Callback demangling failed: status " << status);
133 ret = mangled;
134 }
135
136 if (demangled)
137 {
138 std::free(demangled);
139 }
140 return ret;
141}
142
143} // namespace ns3
144
145#else
146
147std::string
148ns3::CallbackImplBase::Demangle(const std::string& mangled)
149{
150 NS_LOG_FUNCTION(this << mangled);
151 return mangled;
152}
153
154#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:148
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Deserialize from string (not implemented)
Definition: callback.cc:82
CallbackBase Get()
Definition: callback.cc:59
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Serialize to string.
Definition: callback.cc:73
void Set(const CallbackBase &value)
Set the value.
Definition: callback.cc:52
CallbackBase m_value
The stored Callback instance.
Definition: callback.h:835
Ptr< AttributeValue > Copy() const override
Definition: callback.cc:66
~CallbackValue() override
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:454