[Lldb-commits] [lldb] r125080 - in /lldb/trunk: include/lldb/Core/Broadcaster.h source/Core/Broadcaster.cpp

Jim Ingham jingham at apple.com
Mon Feb 7 21:16:50 PST 2011


Author: jingham
Date: Mon Feb  7 23:16:50 2011
New Revision: 125080

URL: http://llvm.org/viewvc/llvm-project?rev=125080&view=rev
Log:
Change the Hijacking interposer to a stack of interposers.

Modified:
    lldb/trunk/include/lldb/Core/Broadcaster.h
    lldb/trunk/source/Core/Broadcaster.cpp

Modified: lldb/trunk/include/lldb/Core/Broadcaster.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Broadcaster.h?rev=125080&r1=125079&r2=125080&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Broadcaster.h (original)
+++ lldb/trunk/include/lldb/Core/Broadcaster.h Mon Feb  7 23:16:50 2011
@@ -195,9 +195,6 @@
     bool
     RemoveListener (Listener* listener, uint32_t event_mask = UINT32_MAX);
     
-protected:
-
-    
     //------------------------------------------------------------------
     /// Provides a simple mechanism to temporarily redirect events from 
     /// broadcaster.  When you call this function passing in a listener and
@@ -225,8 +222,8 @@
     bool
     IsHijackedForEvent (uint32_t event_mask)
     {
-        if (m_hijacking_listener)
-            return (event_mask & m_hijacking_mask) != 0;
+        if (m_hijacking_listeners.size() > 0)
+            return (event_mask & m_hijacking_masks.back()) != 0;
         return false;
     }
 
@@ -237,6 +234,9 @@
     void
     RestoreBroadcaster ();
 
+protected:
+
+    
     void
     PrivateBroadcastEvent (lldb::EventSP &event_sp, bool unique);
 
@@ -251,8 +251,9 @@
     event_names_map m_event_names;  ///< Optionally define event names for readability and logging for each event bit
     collection m_listeners;     ///< A list of Listener / event_mask pairs that are listening to this broadcaster.
     Mutex m_listeners_mutex;    ///< A mutex that protects \a m_listeners.
-    Listener *m_hijacking_listener;         // A simple mechanism to intercept events in lieu of a real Listener collection stack.
-    uint32_t m_hijacking_mask;
+    std::vector<Listener *> m_hijacking_listeners;  // A simple mechanism to intercept events from a broadcaster 
+    std::vector<uint32_t> m_hijacking_masks;        // At some point we may want to have a stack or Listener
+                                                    // collections, but for now this is just for private hijacking.
     
 private:
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Core/Broadcaster.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Broadcaster.cpp?rev=125080&r1=125079&r2=125080&view=diff
==============================================================================
--- lldb/trunk/source/Core/Broadcaster.cpp (original)
+++ lldb/trunk/source/Core/Broadcaster.cpp Mon Feb  7 23:16:50 2011
@@ -25,8 +25,8 @@
     m_broadcaster_name (name),
     m_listeners (),
     m_listeners_mutex (Mutex::eMutexTypeRecursive),
-    m_hijacking_listener(NULL),
-    m_hijacking_mask(UINT32_MAX)
+    m_hijacking_listeners(),
+    m_hijacking_masks()
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
     if (log)
@@ -153,7 +153,7 @@
 {
     Mutex::Locker locker (m_listeners_mutex);
     
-    if (m_hijacking_listener != NULL && event_type & m_hijacking_mask)
+    if (m_hijacking_listeners.size() > 0 && event_type & m_hijacking_masks.back())
         return true;
         
     if (m_listeners.empty())
@@ -224,19 +224,22 @@
                      m_broadcaster_name.AsCString(""),
                      event_description.GetData(),
                      unique,
-                     m_hijacking_listener);
+                     m_hijacking_listeners.back());
     }
 
-    if (m_hijacking_listener != NULL && m_hijacking_mask & event_type)
+    if (m_hijacking_listeners.size() > 0 && m_hijacking_masks.back() & event_type)
     {
+        Listener *hijacking_listener = m_hijacking_listeners.back();
         // FIXME: REMOVE THIS EXTRA LOGGING
         LogSP log_process(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS));
         if (log_process)
-            log_process->Printf ("Hijacking event delivery for Broadcaster(\"%s\").", m_broadcaster_name.AsCString(""));
+            log_process->Printf ("Hijacking event delivery for Broadcaster(\"%s\") to Listener(\"%s\").", 
+                                 m_broadcaster_name.AsCString(""),
+                                 hijacking_listener->GetName());
             
-        if (unique && m_hijacking_listener->PeekAtNextEventForBroadcasterWithType (this, event_type))
+        if (unique && hijacking_listener->PeekAtNextEventForBroadcasterWithType (this, event_type))
             return;
-        m_hijacking_listener->AddEvent (event_sp);
+        hijacking_listener->AddEvent (event_sp);
     }
     else
     {
@@ -276,13 +279,9 @@
 Broadcaster::HijackBroadcaster (Listener *listener, uint32_t event_mask)
 {
     Mutex::Locker event_types_locker(m_listeners_mutex);
-    assert (m_hijacking_listener == NULL);
     
-    if (m_hijacking_listener != NULL)
-        return false;
-    
-    m_hijacking_listener = listener;
-    m_hijacking_mask = event_mask;
+    m_hijacking_listeners.push_back(listener);
+    m_hijacking_masks.push_back(event_mask);
     return true;
 }
 
@@ -290,7 +289,7 @@
 Broadcaster::RestoreBroadcaster ()
 {
     Mutex::Locker event_types_locker(m_listeners_mutex);
-    m_hijacking_listener = NULL;
-    m_hijacking_mask = 0;
+    m_hijacking_listeners.pop_back();
+    m_hijacking_masks.pop_back();
 }
 





More information about the lldb-commits mailing list