src/core/callback.cc
author Pavel Boyko <boyko@iitp.ru>
Tue, 14 Jul 2009 16:05:23 +0400
changeset 5581 d74aff108ddc
parent 4206 279c3dbe7572
child 6468 b0f9d1408e41
permissions -rw-r--r--
AodvProtocol in progress, doesn't work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
#include "callback.h"
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
namespace ns3 {
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
CallbackValue::CallbackValue ()
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
  : m_value ()
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
{}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
CallbackValue::CallbackValue (const CallbackBase &base)
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
  : m_value (base)
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
{}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
CallbackValue::~CallbackValue ()
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
{}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
void 
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
CallbackValue::Set (CallbackBase base)
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
{
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
  m_value = base;
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
Ptr<AttributeValue> 
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
CallbackValue::Copy (void) const
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
{
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
  return Create<CallbackValue> (m_value);
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
std::string 
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
CallbackValue::SerializeToString (Ptr<const AttributeChecker> checker) const
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
{
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
  std::ostringstream oss;
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
  oss << PeekPointer (m_value.GetImpl ());
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
  return oss.str ();
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
bool 
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
CallbackValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
{
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
  return false;
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
}
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
ATTRIBUTE_CHECKER_IMPLEMENT (Callback);
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
4205
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    38
#if (__GNUC__ >= 3)
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    39
4206
279c3dbe7572 Missing include of stdlib.h for free() in callback.cc
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4205
diff changeset
    40
#include <stdlib.h>
4205
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    41
#include <cxxabi.h>
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    42
#include "log.h"
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    43
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    44
std::string
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    45
CallbackBase::Demangle(const std::string& mangled)
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    46
{
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    47
    int status;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    48
    char* demangled = abi::__cxa_demangle(mangled.c_str(),
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    49
                                          NULL, NULL, &status);
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    50
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    51
    std::string ret;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    52
    if (status == 0) {
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    53
        NS_ASSERT(demangled);
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    54
        ret = demangled;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    55
    }
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    56
    else if (status == -1) {
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    57
        NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occured.");
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    58
        ret = mangled;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    59
    }
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    60
    else if (status == -2) {
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    61
        NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI mangling rules.");
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    62
        ret = mangled;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    63
    }
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    64
    else if (status == -3) {
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    65
        NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid.");
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    66
        ret = mangled;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    67
    }
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    68
    else {
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    69
        NS_LOG_UNCOND("Callback demangling failed: status " << status);
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    70
        ret = mangled;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    71
    }
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    72
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    73
    if (demangled) {
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    74
        free(demangled);
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    75
    }
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    76
    return ret;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    77
}
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    78
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    79
#else
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    80
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    81
std::string
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    82
CallbackBase::Demangle(const std::string& mangled)
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    83
{
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    84
    return mangled;
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    85
}
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    86
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    87
#endif
751691462d36 Print demangled callback signatures if they mismatch. bug #507
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 3763
diff changeset
    88
3763
e46e361a4262 give attribute power to Callback.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
} // namespace ns3