mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00

There's now an notifier::Modifiable interface class that class supposed to signal modifications are to be derived from. This takes the place of the former MutableValue class and also unifies how Val and IDs signal modifications.
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
#include "Val.h"
|
|
#include "StateAccess.h"
|
|
#include "Event.h"
|
|
#include "NetVar.h"
|
|
#include "DebugLogger.h"
|
|
|
|
notifier::Registry notifier::registry;
|
|
|
|
notifier::Registry::~Registry()
|
|
{
|
|
for ( auto i : registrations )
|
|
Unregister(i.first);
|
|
}
|
|
|
|
void notifier::Registry::Register(Modifiable* m, notifier::Notifier* notifier)
|
|
{
|
|
DBG_LOG(DBG_NOTIFIERS, "registering modifiable %p for notifier %s",
|
|
m, notifier->Name());
|
|
|
|
registrations.insert({m, notifier});
|
|
++m->notifiers;
|
|
}
|
|
|
|
void notifier::Registry::Unregister(Modifiable* m, notifier::Notifier* notifier)
|
|
{
|
|
DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from notifier %s",
|
|
m, notifier->Name());
|
|
|
|
auto x = registrations.equal_range(m);
|
|
for ( auto i = x.first; i != x.second; i++ )
|
|
{
|
|
if ( i->second == notifier )
|
|
{
|
|
registrations.erase(i);
|
|
--i->first->notifiers;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void notifier::Registry::Unregister(Modifiable* m)
|
|
{
|
|
auto x = registrations.equal_range(m);
|
|
for ( auto i = x.first; i != x.second; i++ )
|
|
Unregister(m, i->second);
|
|
}
|
|
|
|
void notifier::Registry::Modified(Modifiable* m)
|
|
{
|
|
DBG_LOG(DBG_NOTIFIERS, "modification to modifiable %p", m);
|
|
|
|
auto x = registrations.equal_range(m);
|
|
for ( auto i = x.first; i != x.second; i++ )
|
|
i->second->Modified(m);
|
|
}
|
|
|
|
const char* notifier::Notifier::Name() const
|
|
{
|
|
return fmt("%p", this);
|
|
}
|
|
|