2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBBroadcaster.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/Broadcaster.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/lldb-forward-rtti.h"
|
|
|
|
|
2010-06-09 15:37:52 +08:00
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
|
|
|
#include "lldb/API/SBListener.h"
|
|
|
|
#include "lldb/API/SBEvent.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
SBBroadcaster::SBBroadcaster () :
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_sp (),
|
|
|
|
m_opaque_ptr (NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBroadcaster::SBBroadcaster (const char *name) :
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_sp (new Broadcaster (name)),
|
|
|
|
m_opaque_ptr (NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr = m_opaque_sp.get();
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-10-31 11:01:06 +08:00
|
|
|
log->Printf ("SBBroadcaster::SBBroadcaster (name=\"%s\") => SBBroadcaster(%p)",
|
2010-11-06 07:17:00 +08:00
|
|
|
name, m_opaque_ptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBBroadcaster::SBBroadcaster (lldb_private::Broadcaster *broadcaster, bool owns) :
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_sp (owns ? broadcaster : NULL),
|
|
|
|
m_opaque_ptr (broadcaster)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-11-06 07:17:00 +08:00
|
|
|
log->Printf ("SBBroadcaster::SBBroadcaster (broadcaster=%p, bool owns=%i) => SBBroadcaster(%p)",
|
|
|
|
broadcaster, owns, m_opaque_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
SBBroadcaster::SBBroadcaster (const SBBroadcaster &rhs) :
|
|
|
|
m_opaque_sp (rhs.m_opaque_sp),
|
|
|
|
m_opaque_ptr (rhs.m_opaque_ptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBBroadcaster &
|
|
|
|
SBBroadcaster::operator = (const SBBroadcaster &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
|
|
|
m_opaque_ptr = rhs.m_opaque_ptr;
|
|
|
|
}
|
|
|
|
return *this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBBroadcaster::~SBBroadcaster()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
reset (NULL, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBroadcaster::BroadcastEventByType (uint32_t event_type, bool unique)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-11-06 07:17:00 +08:00
|
|
|
log->Printf ("SBBroadcaster(%p)::BroadcastEventByType (event_type=0x%8.8x, unique=%i)", m_opaque_ptr, event_type, unique);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
if (m_opaque_ptr == NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (unique)
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr->BroadcastEventIfUnique (event_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr->BroadcastEvent (event_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBroadcaster::BroadcastEvent (const SBEvent &event, bool unique)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-29 12:59:35 +08:00
|
|
|
|
|
|
|
if (log)
|
2010-11-06 07:17:00 +08:00
|
|
|
log->Printf ("SBBroadcaster(%p)::BroadcastEventByType (SBEvent(%p), unique=%i)", m_opaque_ptr, event.get(), unique);
|
2010-10-29 12:59:35 +08:00
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
if (m_opaque_ptr == NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
EventSP event_sp = event.GetSP ();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (unique)
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr->BroadcastEventIfUnique (event_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-11-06 07:17:00 +08:00
|
|
|
m_opaque_ptr->BroadcastEvent (event_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBBroadcaster::AddInitialEventsToListener (const SBListener &listener, uint32_t requested_events)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-29 12:59:35 +08:00
|
|
|
if (log)
|
2010-11-06 07:17:00 +08:00
|
|
|
log->Printf ("SBBroadcaster(%p)::AddInitialEventsToListener (SBListener(%p), event_mask=0x%8.8x)", m_opaque_ptr, listener.get(), requested_events);
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
m_opaque_ptr->AddInitialEventsToListener (listener.get(), requested_events);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBBroadcaster::AddListener (const SBListener &listener, uint32_t event_mask)
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->AddListener (listener.get(), event_mask);
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2010-10-31 11:01:06 +08:00
|
|
|
SBBroadcaster::GetName () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->GetBroadcasterName().GetCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBroadcaster::EventTypeHasListeners (uint32_t event_type)
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->EventTypeHasListeners (event_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBroadcaster::RemoveListener (const SBListener &listener, uint32_t event_mask)
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->RemoveListener (listener.get(), event_mask);
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Broadcaster *
|
2010-06-23 09:19:29 +08:00
|
|
|
SBBroadcaster::get () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
return m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-23 09:19:29 +08:00
|
|
|
SBBroadcaster::reset (Broadcaster *broadcaster, bool owns)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
if (owns)
|
|
|
|
m_opaque_sp.reset (broadcaster);
|
|
|
|
else
|
|
|
|
m_opaque_sp.reset ();
|
|
|
|
m_opaque_ptr = broadcaster;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBroadcaster::IsValid () const
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
return m_opaque_ptr != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBroadcaster::operator == (const SBBroadcaster &rhs) const
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
return m_opaque_ptr == rhs.m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBBroadcaster::operator != (const SBBroadcaster &rhs) const
|
|
|
|
{
|
2010-11-06 07:17:00 +08:00
|
|
|
return m_opaque_ptr != rhs.m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|