@@ -41,6 +41,9 @@ void CListenerManager::RegisterListener(PyObject* pCallable)
4141 // Is the callable already in the vector?
4242 if ( !IsRegistered (oCallable) )
4343 {
44+ if (!GetCount ())
45+ Initialize ();
46+
4447 m_vecCallables.AddToTail (oCallable);
4548 }
4649 else {
@@ -64,6 +67,9 @@ void CListenerManager::UnregisterListener(PyObject* pCallable)
6467 }
6568 else {
6669 m_vecCallables.Remove (index);
70+
71+ if (!GetCount ())
72+ Finalize ();
6773 }
6874}
6975
@@ -73,11 +79,10 @@ void CListenerManager::UnregisterListener(PyObject* pCallable)
7379// -----------------------------------------------------------------------------
7480void CListenerManager::Notify (tuple args, dict kwargs)
7581{
76- static object callback_caller = eval (" lambda func, args, kwargs: func(*args, **kwargs)" );
7782 for (int i = 0 ; i < m_vecCallables.Count (); i++)
7883 {
7984 BEGIN_BOOST_PY ()
80- callback_caller ( m_vecCallables[i], args, kwargs);
85+ m_vecCallables[i](* args, ** kwargs);
8186 END_BOOST_PY_NORET ()
8287 }
8388}
@@ -92,6 +97,28 @@ int CListenerManager::GetCount()
9297}
9398
9499
100+ // -----------------------------------------------------------------------------
101+ // Called when the first callback is being registered.
102+ // -----------------------------------------------------------------------------
103+ void CListenerManager::Initialize ()
104+ {
105+ override initialize = get_override (" initialize" );
106+ if (!initialize.is_none ())
107+ initialize ();
108+ }
109+
110+
111+ // -----------------------------------------------------------------------------
112+ // Called when the last callback is being unregistered.
113+ // -----------------------------------------------------------------------------
114+ void CListenerManager::Finalize ()
115+ {
116+ override finalize = get_override (" finalize" );
117+ if (!finalize.is_none ())
118+ finalize ();
119+ }
120+
121+
95122// -----------------------------------------------------------------------------
96123// Return whether or not the given callback is registered.
97124// -----------------------------------------------------------------------------
0 commit comments