File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
src/core/modules/listeners Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,11 @@ void CListenerManager::RegisterListener(PyObject* pCallable)
41
41
// Is the callable already in the vector?
42
42
if ( !m_vecCallables.HasElement (oCallable) )
43
43
{
44
- // Add the callable to the vector
45
44
m_vecCallables.AddToTail (oCallable);
46
45
}
46
+ else {
47
+ BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Callback already registered." )
48
+ }
47
49
}
48
50
49
51
@@ -55,8 +57,14 @@ void CListenerManager::UnregisterListener(PyObject* pCallable)
55
57
// Get the object instance of the callable
56
58
object oCallable = object (handle<>(borrowed (pCallable)));
57
59
58
- // Remove the callback from the ServerCommandManager instance
59
- m_vecCallables.FindAndRemove (oCallable);
60
+ int index = m_vecCallables.Find (oCallable);
61
+
62
+ if (index == -1 ) {
63
+ BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Callback not registered." )
64
+ }
65
+ else {
66
+ m_vecCallables.Remove (index );
67
+ }
60
68
}
61
69
62
70
@@ -98,3 +106,8 @@ object CListenerManager::__getitem__(unsigned int index)
98
106
99
107
return m_vecCallables[index ];
100
108
}
109
+
110
+ void CListenerManager::clear ()
111
+ {
112
+ m_vecCallables.RemoveAll ();
113
+ }
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ class CListenerManager
68
68
int GetCount ();
69
69
bool IsRegistered (object oCallback);
70
70
object __getitem__ (unsigned int index);
71
+ void clear ();
71
72
72
73
public:
73
74
CUtlVector<object> m_vecCallables;
Original file line number Diff line number Diff line change @@ -111,6 +111,11 @@ void export_listener_managers(scope _listeners)
111
111
&CListenerManager::__getitem__,
112
112
" Return the callback at the given index."
113
113
)
114
+
115
+ .def (" clear" ,
116
+ &CListenerManager::clear,
117
+ " Remove all registered callbacks."
118
+ )
114
119
;
115
120
116
121
_listeners.attr (" on_client_active_listener_manager" ) = object (ptr (GetOnClientActiveListenerManager ()));
You can’t perform that action at this time.
0 commit comments