Skip to content

Commit

Permalink
Added demangle function to AutoNetServer
Browse files Browse the repository at this point in the history
  • Loading branch information
gtremper committed Aug 5, 2014
1 parent a340c9d commit c9a06ed
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/autonet/AutoNetServer.cpp
Expand Up @@ -7,6 +7,26 @@
#include <iostream>
#include FUTURE_HEADER

//
// Demangle type names on mac and linux.
// Just returns type_info.name() on windows
//
#if __GNUG__
#include <cxxabi.h>
static std::string demangle(const std::type_info& ti) {
int status;
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(ti.name(), nullptr, nullptr, &status),
std::free
};
return std::string(status == 0 ? res.get() : ti.name());
}
#else
static std::string demangle(const std::type_info& ti) {
return std::string(ti.name());
}
#endif

using std::placeholders::_1;
using std::placeholders::_2;
using json11::Json;
Expand All @@ -16,16 +36,19 @@ AutoNetServer::AutoNetServer():
m_Server(std::make_shared<server>()),
m_Port(8000)
{
// Register handlers and configure websocketpp
// Configure websocketpp
m_Server->init_asio();
m_Server->set_access_channels(websocketpp::log::alevel::none);

// Register handlers
m_Server->set_open_handler(std::bind(&AutoNetServer::OnOpen, this, ::_1));
m_Server->set_close_handler(std::bind(&AutoNetServer::OnClose, this, ::_1));
m_Server->set_message_handler(std::bind(&AutoNetServer::OnMessage, this, ::_1, ::_2));

// Generate list of all types from type registry
for (auto type = g_pFirstTypeEntry; type; type = type->pFlink)
if (type->CanInject())
m_AllTypes[type->ti.name()] = [type]{ type->Inject(); };
m_AllTypes[demangle(type->ti)] = [type]{ type->Inject(); };

// Generate list of all events from event registry
for (auto event = g_pFirstEventEntry; event; event = event->pFlink)
Expand Down Expand Up @@ -111,7 +134,7 @@ void AutoNetServer::NewContext(CoreContext& newCtxt){

*this += [this, ctxt] {
Json::object context {
{"name", ctxt->GetSigilType().name()}
{"name", demangle(ctxt->GetSigilType())}
};

if (ctxt->GetParentContext()){
Expand All @@ -138,12 +161,12 @@ void AutoNetServer::NewObject(CoreContext& ctxt, const AnySharedPointer& object)
std::shared_ptr<Object> objectPtr(*object);

// Add object data
objData["name"] = typeid(*objectPtr).name();
objData["name"] = demangle(typeid(*objectPtr));
{
Json::array slots;
for (auto slot = object->GetSlotInformation().pHead; slot; slot = slot->pFlink) {
slots.push_back(Json::object{
{"name", slot->type.name()},
{"name", demangle(slot->type)},
{"autoRequired", slot->autoRequired},
{"offset", int(slot->slotOffset)}
});
Expand Down Expand Up @@ -178,7 +201,7 @@ void AutoNetServer::NewObject(CoreContext& ctxt, const AnySharedPointer& object)
Json::array listenerTypes;
for (auto& event : m_EventTypes) {
if (event->IsSameAs(objectPtr.get()))
listenerTypes.push_back(event->Type().name());
listenerTypes.push_back(demangle(event->Type()));
}

if (!listenerTypes.empty())
Expand All @@ -194,7 +217,7 @@ void AutoNetServer::NewObject(CoreContext& ctxt, const AnySharedPointer& object)
if (bolt) {
Json::array sigils;
for(auto cur = bolt->GetContextSigils(); *cur; cur++){
sigils.push_back((*cur)->name());
sigils.push_back(demangle(**cur));
}
types["bolt"] = sigils;
}
Expand All @@ -205,7 +228,7 @@ void AutoNetServer::NewObject(CoreContext& ctxt, const AnySharedPointer& object)

void AutoNetServer::EventFired(CoreContext& context, const std::type_info& info){
int contextID = ResolveContextID(&context);
std::string name = info.name();
std::string name = demangle(info);

*this += [this, contextID, name] {
BroadcastMessage("eventFired", contextID, Json::object{{"name", name}});
Expand Down Expand Up @@ -299,7 +322,7 @@ void AutoNetServer::PollThreadUtilization(std::chrono::milliseconds period){

// Broadcast current thread utilization
int contextID = ResolveContextID(thread->GetContext().get());
std::string name = typeid(*thread.get()).name();
std::string name = demangle(typeid(*thread.get()));

std::chrono::duration<double> periodDbl = period;
double kmPercent = 100.0 * (deltaRuntimeKM.count() / periodDbl.count());
Expand Down

0 comments on commit c9a06ed

Please sign in to comment.