diff --git a/src/Event.cc b/src/Event.cc index 1a91b1aaa0..d5f23bc16b 100644 --- a/src/Event.cc +++ b/src/Event.cc @@ -4,7 +4,6 @@ #include "zeek/Desc.h" #include "zeek/Trigger.h" -#include "zeek/Val.h" #include "zeek/iosource/Manager.h" #include "zeek/plugin/Manager.h" @@ -16,7 +15,8 @@ namespace zeek { Event::Event(const EventHandlerPtr& arg_handler, zeek::Args arg_args, util::detail::SourceID arg_src, analyzer::ID arg_aid, Obj* arg_obj, double arg_ts) - : handler(arg_handler), + : ref_cnt(1), + handler(arg_handler), args(std::move(arg_args)), src(arg_src), aid(arg_aid), @@ -27,20 +27,6 @@ Event::Event(const EventHandlerPtr& arg_handler, zeek::Args arg_args, util::deta Ref(obj); } -void Event::Describe(ODesc* d) const { - if ( d->IsReadable() ) - d->AddSP("event"); - - bool s = d->IsShort(); - d->SetShort(s); - - if ( ! d->IsBinary() ) - d->Add("("); - describe_vals(args, d); - if ( ! d->IsBinary() ) - d->Add("("); -} - void Event::Dispatch(bool no_remote) { if ( src == util::detail::SOURCE_BROKER ) no_remote = true; diff --git a/src/Event.h b/src/Event.h index 3aac8c3876..de071b3e16 100644 --- a/src/Event.h +++ b/src/Event.h @@ -17,8 +17,9 @@ extern double network_time; } // namespace run_state class EventMgr; +class Event; -class Event final : public Obj { +class Event final { public: Event(const EventHandlerPtr& handler, zeek::Args args, util::detail::SourceID src = util::detail::SOURCE_LOCAL, analyzer::ID aid = 0, Obj* obj = nullptr, double ts = run_state::network_time); @@ -32,15 +33,16 @@ public: const zeek::Args& Args() const { return args; } double Time() const { return ts; } - void Describe(ODesc* d) const override; - private: friend class EventMgr; + friend void inline Ref(Event*); + friend inline void Unref(Event*); // This method is protected to make sure that everybody goes through // EventMgr::Dispatch(). void Dispatch(bool no_remote = false); + int ref_cnt; EventHandlerPtr handler; zeek::Args args; util::detail::SourceID src; @@ -50,6 +52,13 @@ private: Event* next_event; }; +inline void Unref(Event* e) { + if ( e && --e->ref_cnt <= 0 ) + delete e; +} + +inline void Ref(Event* e) { ++(e->ref_cnt); } + class EventMgr final : public iosource::IOSource { public: ~EventMgr() override;