From 938ad35a43f2719bf40e5dd9609049ed8719682a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 18:37:48 -0700 Subject: [PATCH] Deprecate EventHandler::FType(), replace with GetType() --- src/EventHandler.cc | 13 +++++++------ src/EventHandler.h | 11 ++++++++--- src/Expr.cc | 3 ++- src/broker/Manager.cc | 2 +- src/input/Manager.cc | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 580d48be27..1f6172cbd8 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -15,7 +15,6 @@ EventHandler::EventHandler(std::string arg_name) name = std::move(arg_name); used = false; local = nullptr; - type = nullptr; error_handler = false; enabled = true; generate_always = false; @@ -33,8 +32,10 @@ EventHandler::operator bool() const || ! auto_publish.empty()); } -FuncType* EventHandler::FType(bool check_export) +const IntrusivePtr& EventHandler::GetType(bool check_export) { + static IntrusivePtr nil; + if ( type ) return type; @@ -42,12 +43,12 @@ FuncType* EventHandler::FType(bool check_export) check_export); if ( ! id ) - return nullptr; + return nil; if ( id->GetType()->Tag() != TYPE_FUNC ) - return nullptr; + return nil; - type = id->GetType()->AsFuncType(); + type = id->GetType(); return type; } @@ -126,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) // new_event() is the one event we don't want to report. return; - RecordType* args = FType()->Args(); + RecordType* args = GetType()->Args(); static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); diff --git a/src/EventHandler.h b/src/EventHandler.h index 6844662b22..86d6defb4f 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -4,12 +4,12 @@ #include "BroList.h" #include "ZeekArgs.h" +#include "Type.h" #include #include class Func; -class FuncType; class EventHandler { public: @@ -18,7 +18,12 @@ public: const char* Name() { return name.data(); } Func* LocalHandler() { return local; } - FuncType* FType(bool check_export = true); + + const IntrusivePtr& GetType(bool check_export = true); + + [[deprecated("Remove in v4.1. Use GetType().")]] + FuncType* FType(bool check_export = true) + { return GetType().get(); } void SetLocalHandler(Func* f); @@ -57,7 +62,7 @@ private: std::string name; Func* local; - FuncType* type; + IntrusivePtr type; bool used; // this handler is indeed used somewhere bool enabled; bool error_handler; // this handler reports error messages. diff --git a/src/Expr.cc b/src/Expr.cc index 739a0e8b8b..afd9b7a695 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4313,7 +4313,8 @@ EventExpr::EventExpr(const char* arg_name, IntrusivePtr arg_args) return; } - FuncType* func_type = h->FType(); + const auto& func_type = h->GetType(); + if ( ! func_type ) { Error("not an event"); diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index ab2851e4af..de279a0b4b 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -977,7 +977,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev) return; } - const auto& arg_types = handler->FType(false)->ArgTypes()->Types(); + const auto& arg_types = handler->GetType(false)->ArgTypes()->Types(); if ( arg_types.size() != args.size() ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 9fceb2ee67..efc9c48a36 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1810,7 +1810,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu name.c_str(), num_vals); #endif - RecordType *type = handler->FType()->Args(); + RecordType* type = handler->GetType()->Args(); int num_event_vals = type->NumFields(); if ( num_vals != num_event_vals ) {