diff --git a/src/EventHandler.cc b/src/EventHandler.cc index fe3472fbf5..051a7f98d2 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -14,17 +14,11 @@ EventHandler::EventHandler(std::string arg_name) { name = std::move(arg_name); used = false; - local = nullptr; error_handler = false; enabled = true; generate_always = false; } -EventHandler::~EventHandler() - { - Unref(local); - } - EventHandler::operator bool() const { return enabled && ((local && local->HasBodies()) @@ -52,15 +46,6 @@ const IntrusivePtr& EventHandler::GetType(bool check_export) return type; } -void EventHandler::SetLocalHandler(Func* f) - { - if ( local ) - Unref(local); - - Ref(f); - local = f; - } - void EventHandler::Call(const zeek::Args& vl, bool no_remote) { #ifdef PROFILE_BRO_FUNCTIONS diff --git a/src/EventHandler.h b/src/EventHandler.h index 86d6defb4f..ccbd90e44b 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -5,19 +5,22 @@ #include "BroList.h" #include "ZeekArgs.h" #include "Type.h" +#include "Func.h" #include #include -class Func; - class EventHandler { public: explicit EventHandler(std::string name); - ~EventHandler(); const char* Name() { return name.data(); } - Func* LocalHandler() { return local; } + + const IntrusivePtr& GetFunc() + { return local; } + + [[deprecated("Remove in v4.1. Use GetFunc().")]] + Func* LocalHandler() { return local.get(); } const IntrusivePtr& GetType(bool check_export = true); @@ -25,7 +28,12 @@ public: FuncType* FType(bool check_export = true) { return GetType().get(); } - void SetLocalHandler(Func* f); + void SetFunc(IntrusivePtr f) + { local = std::move(f); } + + [[deprecated("Remove in v4.1. Use SetFunc().")]] + void SetLocalHandler(Func* f) + { SetFunc({NewRef{}, f}); } void AutoPublish(std::string topic) { @@ -61,7 +69,7 @@ private: void NewEvent(const zeek::Args& vl); // Raise new_event() meta event. std::string name; - Func* local; + IntrusivePtr local; IntrusivePtr type; bool used; // this handler is indeed used somewhere bool enabled; diff --git a/src/EventRegistry.cc b/src/EventRegistry.cc index ea6f3a0ca2..7cf05a7042 100644 --- a/src/EventRegistry.cc +++ b/src/EventRegistry.cc @@ -47,7 +47,7 @@ EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern) for ( const auto& entry : handlers ) { EventHandler* v = entry.second.get(); - if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) ) + if ( v->GetFunc() && pattern->MatchExactly(v->Name()) ) names.push_back(entry.first); } @@ -61,7 +61,7 @@ EventRegistry::string_list EventRegistry::UnusedHandlers() for ( const auto& entry : handlers ) { EventHandler* v = entry.second.get(); - if ( v->LocalHandler() && ! v->Used() ) + if ( v->GetFunc() && ! v->Used() ) names.push_back(entry.first); } @@ -75,7 +75,7 @@ EventRegistry::string_list EventRegistry::UsedHandlers() for ( const auto& entry : handlers ) { EventHandler* v = entry.second.get(); - if ( v->LocalHandler() && v->Used() ) + if ( v->GetFunc() && v->Used() ) names.push_back(entry.first); } @@ -100,7 +100,7 @@ void EventRegistry::PrintDebug() { EventHandler* v = entry.second.get(); fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(), - v->LocalHandler()? "local" : "no", + v->GetFunc() ? "local" : "no", *v ? "active" : "not active" ); } diff --git a/src/ID.cc b/src/ID.cc index e7b7638a75..95da8e6568 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -164,14 +164,14 @@ void ID::SetVal(IntrusivePtr v, bool arg_weak_ref) if ( ! handler ) { handler = new EventHandler(name); - handler->SetLocalHandler(val->AsFunc()); + handler->SetFunc(val->AsFuncPtr()); event_registry->Register(handler); } else { // Otherwise, internally defined events cannot // have local handler. - handler->SetLocalHandler(val->AsFunc()); + handler->SetFunc(val->AsFuncPtr()); } } }