mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 07:38:19 +00:00
Change EventHandler to store IntrusivePtr<Func>
Also deprecates the LocalHandler() and SetLocalHandler() methods, replaced with GetFunc() and SetFunc().
This commit is contained in:
parent
3b6f60a810
commit
fbc7725278
4 changed files with 20 additions and 27 deletions
|
@ -14,17 +14,11 @@ EventHandler::EventHandler(std::string arg_name)
|
||||||
{
|
{
|
||||||
name = std::move(arg_name);
|
name = std::move(arg_name);
|
||||||
used = false;
|
used = false;
|
||||||
local = nullptr;
|
|
||||||
error_handler = false;
|
error_handler = false;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
generate_always = false;
|
generate_always = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler::~EventHandler()
|
|
||||||
{
|
|
||||||
Unref(local);
|
|
||||||
}
|
|
||||||
|
|
||||||
EventHandler::operator bool() const
|
EventHandler::operator bool() const
|
||||||
{
|
{
|
||||||
return enabled && ((local && local->HasBodies())
|
return enabled && ((local && local->HasBodies())
|
||||||
|
@ -52,15 +46,6 @@ const IntrusivePtr<FuncType>& EventHandler::GetType(bool check_export)
|
||||||
return type;
|
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)
|
void EventHandler::Call(const zeek::Args& vl, bool no_remote)
|
||||||
{
|
{
|
||||||
#ifdef PROFILE_BRO_FUNCTIONS
|
#ifdef PROFILE_BRO_FUNCTIONS
|
||||||
|
|
|
@ -5,19 +5,22 @@
|
||||||
#include "BroList.h"
|
#include "BroList.h"
|
||||||
#include "ZeekArgs.h"
|
#include "ZeekArgs.h"
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
#include "Func.h"
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Func;
|
|
||||||
|
|
||||||
class EventHandler {
|
class EventHandler {
|
||||||
public:
|
public:
|
||||||
explicit EventHandler(std::string name);
|
explicit EventHandler(std::string name);
|
||||||
~EventHandler();
|
|
||||||
|
|
||||||
const char* Name() { return name.data(); }
|
const char* Name() { return name.data(); }
|
||||||
Func* LocalHandler() { return local; }
|
|
||||||
|
const IntrusivePtr<Func>& GetFunc()
|
||||||
|
{ return local; }
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Use GetFunc().")]]
|
||||||
|
Func* LocalHandler() { return local.get(); }
|
||||||
|
|
||||||
const IntrusivePtr<FuncType>& GetType(bool check_export = true);
|
const IntrusivePtr<FuncType>& GetType(bool check_export = true);
|
||||||
|
|
||||||
|
@ -25,7 +28,12 @@ public:
|
||||||
FuncType* FType(bool check_export = true)
|
FuncType* FType(bool check_export = true)
|
||||||
{ return GetType().get(); }
|
{ return GetType().get(); }
|
||||||
|
|
||||||
void SetLocalHandler(Func* f);
|
void SetFunc(IntrusivePtr<Func> f)
|
||||||
|
{ local = std::move(f); }
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Use SetFunc().")]]
|
||||||
|
void SetLocalHandler(Func* f)
|
||||||
|
{ SetFunc({NewRef{}, f}); }
|
||||||
|
|
||||||
void AutoPublish(std::string topic)
|
void AutoPublish(std::string topic)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +69,7 @@ private:
|
||||||
void NewEvent(const zeek::Args& vl); // Raise new_event() meta event.
|
void NewEvent(const zeek::Args& vl); // Raise new_event() meta event.
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
Func* local;
|
IntrusivePtr<Func> local;
|
||||||
IntrusivePtr<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;
|
||||||
|
|
|
@ -47,7 +47,7 @@ EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern)
|
||||||
for ( const auto& entry : handlers )
|
for ( const auto& entry : handlers )
|
||||||
{
|
{
|
||||||
EventHandler* v = entry.second.get();
|
EventHandler* v = entry.second.get();
|
||||||
if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) )
|
if ( v->GetFunc() && pattern->MatchExactly(v->Name()) )
|
||||||
names.push_back(entry.first);
|
names.push_back(entry.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ EventRegistry::string_list EventRegistry::UnusedHandlers()
|
||||||
for ( const auto& entry : handlers )
|
for ( const auto& entry : handlers )
|
||||||
{
|
{
|
||||||
EventHandler* v = entry.second.get();
|
EventHandler* v = entry.second.get();
|
||||||
if ( v->LocalHandler() && ! v->Used() )
|
if ( v->GetFunc() && ! v->Used() )
|
||||||
names.push_back(entry.first);
|
names.push_back(entry.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ EventRegistry::string_list EventRegistry::UsedHandlers()
|
||||||
for ( const auto& entry : handlers )
|
for ( const auto& entry : handlers )
|
||||||
{
|
{
|
||||||
EventHandler* v = entry.second.get();
|
EventHandler* v = entry.second.get();
|
||||||
if ( v->LocalHandler() && v->Used() )
|
if ( v->GetFunc() && v->Used() )
|
||||||
names.push_back(entry.first);
|
names.push_back(entry.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ void EventRegistry::PrintDebug()
|
||||||
{
|
{
|
||||||
EventHandler* v = entry.second.get();
|
EventHandler* v = entry.second.get();
|
||||||
fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(),
|
fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(),
|
||||||
v->LocalHandler()? "local" : "no",
|
v->GetFunc() ? "local" : "no",
|
||||||
*v ? "active" : "not active"
|
*v ? "active" : "not active"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,14 +164,14 @@ void ID::SetVal(IntrusivePtr<Val> v, bool arg_weak_ref)
|
||||||
if ( ! handler )
|
if ( ! handler )
|
||||||
{
|
{
|
||||||
handler = new EventHandler(name);
|
handler = new EventHandler(name);
|
||||||
handler->SetLocalHandler(val->AsFunc());
|
handler->SetFunc(val->AsFuncPtr());
|
||||||
event_registry->Register(handler);
|
event_registry->Register(handler);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise, internally defined events cannot
|
// Otherwise, internally defined events cannot
|
||||||
// have local handler.
|
// have local handler.
|
||||||
handler->SetLocalHandler(val->AsFunc());
|
handler->SetFunc(val->AsFuncPtr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue