mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Move notifier code to zeek::notifier::detail namespace
This commit is contained in:
parent
1262109e5a
commit
cba1bc18a5
7 changed files with 43 additions and 28 deletions
2
src/ID.h
2
src/ID.h
|
@ -45,7 +45,7 @@ enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL };
|
|||
class ID;
|
||||
using IDPtr = zeek::IntrusivePtr<ID>;
|
||||
|
||||
class ID final : public Obj, public notifier::Modifiable {
|
||||
class ID final : public Obj, public zeek::notifier::detail::Modifiable {
|
||||
public:
|
||||
static inline const IDPtr nil;
|
||||
|
||||
|
|
|
@ -5,25 +5,28 @@
|
|||
|
||||
#include <set>
|
||||
|
||||
notifier::Registry notifier::registry;
|
||||
zeek::notifier::detail::Registry zeek::notifier::detail::registry;
|
||||
zeek::notifier::detail::Registry& notifier::registry = zeek::notifier::detail::registry;
|
||||
|
||||
notifier::Receiver::Receiver()
|
||||
namespace zeek::notifier::detail {
|
||||
|
||||
Receiver::Receiver()
|
||||
{
|
||||
DBG_LOG(zeek::DBG_NOTIFIERS, "creating receiver %p", this);
|
||||
}
|
||||
|
||||
notifier::Receiver::~Receiver()
|
||||
Receiver::~Receiver()
|
||||
{
|
||||
DBG_LOG(zeek::DBG_NOTIFIERS, "deleting receiver %p", this);
|
||||
}
|
||||
|
||||
notifier::Registry::~Registry()
|
||||
Registry::~Registry()
|
||||
{
|
||||
while ( registrations.begin() != registrations.end() )
|
||||
Unregister(registrations.begin()->first);
|
||||
}
|
||||
|
||||
void notifier::Registry::Register(Modifiable* m, notifier::Receiver* r)
|
||||
void Registry::Register(Modifiable* m, Receiver* r)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_NOTIFIERS, "registering object %p for receiver %p", m, r);
|
||||
|
||||
|
@ -31,7 +34,7 @@ void notifier::Registry::Register(Modifiable* m, notifier::Receiver* r)
|
|||
++m->num_receivers;
|
||||
}
|
||||
|
||||
void notifier::Registry::Unregister(Modifiable* m, notifier::Receiver* r)
|
||||
void Registry::Unregister(Modifiable* m, Receiver* r)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_NOTIFIERS, "unregistering object %p from receiver %p", m, r);
|
||||
|
||||
|
@ -47,7 +50,7 @@ void notifier::Registry::Unregister(Modifiable* m, notifier::Receiver* r)
|
|||
}
|
||||
}
|
||||
|
||||
void notifier::Registry::Unregister(Modifiable* m)
|
||||
void Registry::Unregister(Modifiable* m)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_NOTIFIERS, "unregistering object %p from all notifiers", m);
|
||||
|
||||
|
@ -58,7 +61,7 @@ void notifier::Registry::Unregister(Modifiable* m)
|
|||
registrations.erase(x.first, x.second);
|
||||
}
|
||||
|
||||
void notifier::Registry::Modified(Modifiable* m)
|
||||
void Registry::Modified(Modifiable* m)
|
||||
{
|
||||
DBG_LOG(zeek::DBG_NOTIFIERS, "object %p has been modified", m);
|
||||
|
||||
|
@ -67,7 +70,7 @@ void notifier::Registry::Modified(Modifiable* m)
|
|||
i->second->Modified(m);
|
||||
}
|
||||
|
||||
void notifier::Registry::Terminate()
|
||||
void Registry::Terminate()
|
||||
{
|
||||
std::set<Receiver*> receivers;
|
||||
|
||||
|
@ -78,8 +81,10 @@ void notifier::Registry::Terminate()
|
|||
r->Terminate();
|
||||
}
|
||||
|
||||
notifier::Modifiable::~Modifiable()
|
||||
Modifiable::~Modifiable()
|
||||
{
|
||||
if ( num_receivers )
|
||||
registry.Unregister(this);
|
||||
}
|
||||
|
||||
} // namespace zeek::notifier::detail
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
|
||||
namespace notifier {
|
||||
namespace zeek::notifier::detail {
|
||||
|
||||
class Modifiable;
|
||||
|
||||
|
@ -118,4 +118,14 @@ protected:
|
|||
uint64_t num_receivers = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace zeek::notifier::detail
|
||||
|
||||
namespace notifier {
|
||||
|
||||
using Receiver [[deprecated("Remove in v4.1. Use zeek::notifier::detail::Receiver.")]] = zeek::notifier::detail::Receiver;
|
||||
using Registry [[deprecated("Remove in v4.1. Use zeek::notifier::detail::Registry.")]] = zeek::notifier::detail::Registry;
|
||||
using Modifiable [[deprecated("Remove in v4.1. Use zeek::notifier::detail::Modifiable.")]] = zeek::notifier::detail::Modifiable;
|
||||
|
||||
extern zeek::notifier::detail::Registry& registry [[deprecated("Remove from v4.1. Use zeek::notifier::detail::registry.")]];
|
||||
|
||||
} // namespace notifier
|
||||
|
|
|
@ -388,7 +388,7 @@ void Trigger::Timeout()
|
|||
void Trigger::Register(zeek::detail::ID* id)
|
||||
{
|
||||
assert(! disabled);
|
||||
notifier::registry.Register(id, this);
|
||||
zeek::notifier::detail::registry.Register(id, this);
|
||||
|
||||
Ref(id);
|
||||
objs.push_back({id, id});
|
||||
|
@ -400,7 +400,7 @@ void Trigger::Register(Val* val)
|
|||
return;
|
||||
|
||||
assert(! disabled);
|
||||
notifier::registry.Register(val->Modifiable(), this);
|
||||
zeek::notifier::detail::registry.Register(val->Modifiable(), this);
|
||||
|
||||
Ref(val);
|
||||
objs.emplace_back(val, val->Modifiable());
|
||||
|
@ -412,7 +412,7 @@ void Trigger::UnregisterAll()
|
|||
|
||||
for ( const auto& o : objs )
|
||||
{
|
||||
notifier::registry.Unregister(o.second, this);
|
||||
zeek::notifier::detail::registry.Unregister(o.second, this);
|
||||
Unref(o.first);
|
||||
}
|
||||
|
||||
|
@ -478,7 +478,7 @@ void Trigger::Describe(ODesc* d) const
|
|||
d->Add("<trigger>");
|
||||
}
|
||||
|
||||
void Trigger::Modified(notifier::Modifiable* m)
|
||||
void Trigger::Modified(zeek::notifier::detail::Modifiable* m)
|
||||
{
|
||||
trigger_mgr->Queue(this);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace zeek::detail::trigger {
|
|||
class TriggerTimer;
|
||||
class TriggerTraversalCallback;
|
||||
|
||||
class Trigger final : public Obj, public notifier::Receiver {
|
||||
class Trigger final : public Obj, public zeek::notifier::detail::Receiver {
|
||||
public:
|
||||
// Don't access Trigger objects; they take care of themselves after
|
||||
// instantiation. Note that if the condition is already true, the
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
|
||||
// Overidden from Notifier. We queue the trigger and evaluate it
|
||||
// later to avoid race conditions.
|
||||
void Modified(notifier::Modifiable* m) override;
|
||||
void Modified(zeek::notifier::detail::Modifiable* m) override;
|
||||
|
||||
// Overridden from notifer::Receiver. If we're still waiting
|
||||
// on an ID/Val to be modified at termination time, we can't hope
|
||||
|
@ -109,7 +109,7 @@ private:
|
|||
bool delayed; // true if a function call is currently being delayed
|
||||
bool disabled;
|
||||
|
||||
std::vector<std::pair<Obj *, notifier::Modifiable*>> objs;
|
||||
std::vector<std::pair<Obj *, zeek::notifier::detail::Modifiable*>> objs;
|
||||
|
||||
using ValCache = std::map<const zeek::detail::CallExpr*, Val*>;
|
||||
ValCache cache;
|
||||
|
|
14
src/Val.h
14
src/Val.h
|
@ -341,7 +341,7 @@ public:
|
|||
|
||||
// To be overridden by mutable derived class to enable change
|
||||
// notification.
|
||||
virtual notifier::Modifiable* Modifiable() { return nullptr; }
|
||||
virtual zeek::notifier::detail::Modifiable* Modifiable() { return nullptr; }
|
||||
|
||||
#ifdef DEBUG
|
||||
// For debugging, we keep a reference to the global ID to which a
|
||||
|
@ -771,7 +771,7 @@ protected:
|
|||
TableVal* table;
|
||||
};
|
||||
|
||||
class TableVal final : public Val, public notifier::Modifiable {
|
||||
class TableVal final : public Val, public zeek::notifier::detail::Modifiable {
|
||||
public:
|
||||
explicit TableVal(zeek::TableTypePtr t, zeek::detail::AttributesPtr attrs = nullptr);
|
||||
|
||||
|
@ -1012,7 +1012,7 @@ public:
|
|||
[[deprecated("Remove in v4.1. Use MakeHashKey().")]]
|
||||
zeek::detail::HashKey* ComputeHash(const Val* index) const;
|
||||
|
||||
notifier::Modifiable* Modifiable() override { return this; }
|
||||
zeek::notifier::detail::Modifiable* Modifiable() override { return this; }
|
||||
|
||||
// Retrieves and saves all table state (key-value pairs) for
|
||||
// tables whose index type depends on the given zeek::RecordType.
|
||||
|
@ -1102,7 +1102,7 @@ protected:
|
|||
static ParseTimeTableStates parse_time_table_states;
|
||||
};
|
||||
|
||||
class RecordVal final : public Val, public notifier::Modifiable {
|
||||
class RecordVal final : public Val, public zeek::notifier::detail::Modifiable {
|
||||
public:
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit RecordVal(zeek::RecordType* t, bool init_fields = true);
|
||||
|
@ -1255,7 +1255,7 @@ public:
|
|||
unsigned int MemoryAllocation() const override;
|
||||
void DescribeReST(ODesc* d) const override;
|
||||
|
||||
notifier::Modifiable* Modifiable() override { return this; }
|
||||
zeek::notifier::detail::Modifiable* Modifiable() override { return this; }
|
||||
|
||||
// Extend the underlying arrays of record instances created during
|
||||
// parsing to match the number of fields in the record type (they may
|
||||
|
@ -1292,7 +1292,7 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
class VectorVal final : public Val, public notifier::Modifiable {
|
||||
class VectorVal final : public Val, public zeek::notifier::detail::Modifiable {
|
||||
public:
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit VectorVal(zeek::VectorType* t);
|
||||
|
@ -1372,7 +1372,7 @@ public:
|
|||
// Won't shrink size.
|
||||
unsigned int ResizeAtLeast(unsigned int new_num_elements);
|
||||
|
||||
notifier::Modifiable* Modifiable() override { return this; }
|
||||
zeek::notifier::detail::Modifiable* Modifiable() override { return this; }
|
||||
|
||||
/**
|
||||
* Inserts an element at the given position in the vector. All elements
|
||||
|
|
|
@ -307,7 +307,7 @@ void terminate_bro()
|
|||
|
||||
zeek::event_mgr.Drain();
|
||||
|
||||
notifier::registry.Terminate();
|
||||
zeek::notifier::detail::registry.Terminate();
|
||||
zeek::log_mgr->Terminate();
|
||||
zeek::input_mgr->Terminate();
|
||||
zeek::thread_mgr->Terminate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue