Deprecate EventHandler::FType(), replace with GetType()

This commit is contained in:
Jon Siwek 2020-05-15 18:37:48 -07:00
parent 6aa1d0468d
commit 938ad35a43
5 changed files with 19 additions and 12 deletions

View file

@ -15,7 +15,6 @@ EventHandler::EventHandler(std::string arg_name)
name = std::move(arg_name); name = std::move(arg_name);
used = false; used = false;
local = nullptr; local = nullptr;
type = nullptr;
error_handler = false; error_handler = false;
enabled = true; enabled = true;
generate_always = false; generate_always = false;
@ -33,8 +32,10 @@ EventHandler::operator bool() const
|| ! auto_publish.empty()); || ! auto_publish.empty());
} }
FuncType* EventHandler::FType(bool check_export) const IntrusivePtr<FuncType>& EventHandler::GetType(bool check_export)
{ {
static IntrusivePtr<FuncType> nil;
if ( type ) if ( type )
return type; return type;
@ -42,12 +43,12 @@ FuncType* EventHandler::FType(bool check_export)
check_export); check_export);
if ( ! id ) if ( ! id )
return nullptr; return nil;
if ( id->GetType()->Tag() != TYPE_FUNC ) if ( id->GetType()->Tag() != TYPE_FUNC )
return nullptr; return nil;
type = id->GetType()->AsFuncType(); type = id->GetType<FuncType>();
return type; 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. // new_event() is the one event we don't want to report.
return; return;
RecordType* args = FType()->Args(); RecordType* args = GetType()->Args();
static auto call_argument_vector = zeek::id::find_type<VectorType>("call_argument_vector"); static auto call_argument_vector = zeek::id::find_type<VectorType>("call_argument_vector");
auto vargs = make_intrusive<VectorVal>(call_argument_vector); auto vargs = make_intrusive<VectorVal>(call_argument_vector);

View file

@ -4,12 +4,12 @@
#include "BroList.h" #include "BroList.h"
#include "ZeekArgs.h" #include "ZeekArgs.h"
#include "Type.h"
#include <unordered_set> #include <unordered_set>
#include <string> #include <string>
class Func; class Func;
class FuncType;
class EventHandler { class EventHandler {
public: public:
@ -18,7 +18,12 @@ public:
const char* Name() { return name.data(); } const char* Name() { return name.data(); }
Func* LocalHandler() { return local; } Func* LocalHandler() { return local; }
FuncType* FType(bool check_export = true);
const IntrusivePtr<FuncType>& 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); void SetLocalHandler(Func* f);
@ -57,7 +62,7 @@ private:
std::string name; std::string name;
Func* local; Func* local;
FuncType* type; IntrusivePtr<FuncType> type;
bool used; // this handler is indeed used somewhere bool used; // this handler is indeed used somewhere
bool enabled; bool enabled;
bool error_handler; // this handler reports error messages. bool error_handler; // this handler reports error messages.

View file

@ -4313,7 +4313,8 @@ EventExpr::EventExpr(const char* arg_name, IntrusivePtr<ListExpr> arg_args)
return; return;
} }
FuncType* func_type = h->FType(); const auto& func_type = h->GetType();
if ( ! func_type ) if ( ! func_type )
{ {
Error("not an event"); Error("not an event");

View file

@ -977,7 +977,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev)
return; 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() ) if ( arg_types.size() != args.size() )
{ {

View file

@ -1810,7 +1810,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu
name.c_str(), num_vals); name.c_str(), num_vals);
#endif #endif
RecordType *type = handler->FType()->Args(); RecordType* type = handler->GetType()->Args();
int num_event_vals = type->NumFields(); int num_event_vals = type->NumFields();
if ( num_vals != num_event_vals ) if ( num_vals != num_event_vals )
{ {