src/core/callback.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 4205 751691462d36
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
mathieu@3763
     1
#include "callback.h"
mathieu@3763
     2
mathieu@3763
     3
namespace ns3 {
mathieu@3763
     4
mathieu@3763
     5
CallbackValue::CallbackValue ()
mathieu@3763
     6
  : m_value ()
mathieu@3763
     7
{}
mathieu@3763
     8
CallbackValue::CallbackValue (const CallbackBase &base)
mathieu@3763
     9
  : m_value (base)
mathieu@3763
    10
{}
mathieu@3763
    11
CallbackValue::~CallbackValue ()
mathieu@3763
    12
{}
mathieu@3763
    13
void 
mathieu@3763
    14
CallbackValue::Set (CallbackBase base)
mathieu@3763
    15
{
mathieu@3763
    16
  m_value = base;
mathieu@3763
    17
}
mathieu@3763
    18
Ptr<AttributeValue> 
mathieu@3763
    19
CallbackValue::Copy (void) const
mathieu@3763
    20
{
mathieu@3763
    21
  return Create<CallbackValue> (m_value);
mathieu@3763
    22
}
mathieu@3763
    23
std::string 
mathieu@3763
    24
CallbackValue::SerializeToString (Ptr<const AttributeChecker> checker) const
mathieu@3763
    25
{
mathieu@3763
    26
  std::ostringstream oss;
mathieu@3763
    27
  oss << PeekPointer (m_value.GetImpl ());
mathieu@3763
    28
  return oss.str ();
mathieu@3763
    29
}
mathieu@3763
    30
bool 
mathieu@3763
    31
CallbackValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
mathieu@3763
    32
{
mathieu@3763
    33
  return false;
mathieu@3763
    34
}
mathieu@3763
    35
mathieu@3763
    36
ATTRIBUTE_CHECKER_IMPLEMENT (Callback);
mathieu@3763
    37
timo@4205
    38
#if (__GNUC__ >= 3)
timo@4205
    39
timo@4206
    40
#include <stdlib.h>
timo@4205
    41
#include <cxxabi.h>
timo@4205
    42
#include "log.h"
timo@4205
    43
timo@4205
    44
std::string
timo@4205
    45
CallbackBase::Demangle(const std::string& mangled)
timo@4205
    46
{
timo@4205
    47
    int status;
timo@4205
    48
    char* demangled = abi::__cxa_demangle(mangled.c_str(),
timo@4205
    49
                                          NULL, NULL, &status);
timo@4205
    50
timo@4205
    51
    std::string ret;
timo@4205
    52
    if (status == 0) {
timo@4205
    53
        NS_ASSERT(demangled);
timo@4205
    54
        ret = demangled;
timo@4205
    55
    }
timo@4205
    56
    else if (status == -1) {
timo@4205
    57
        NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occured.");
timo@4205
    58
        ret = mangled;
timo@4205
    59
    }
timo@4205
    60
    else if (status == -2) {
timo@4205
    61
        NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
timo@4205
    62
        ret = mangled;
timo@4205
    63
    }
timo@4205
    64
    else if (status == -3) {
timo@4205
    65
        NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid.");
timo@4205
    66
        ret = mangled;
timo@4205
    67
    }
timo@4205
    68
    else {
timo@4205
    69
        NS_LOG_UNCOND("Callback demangling failed: status " << status);
timo@4205
    70
        ret = mangled;
timo@4205
    71
    }
timo@4205
    72
timo@4205
    73
    if (demangled) {
timo@4205
    74
        free(demangled);
timo@4205
    75
    }
timo@4205
    76
    return ret;
timo@4205
    77
}
timo@4205
    78
timo@4205
    79
#else
timo@4205
    80
timo@4205
    81
std::string
timo@4205
    82
CallbackBase::Demangle(const std::string& mangled)
timo@4205
    83
{
timo@4205
    84
    return mangled;
timo@4205
    85
}
timo@4205
    86
timo@4205
    87
#endif
timo@4205
    88
mathieu@3763
    89
} // namespace ns3