mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Move enabled/disabled functionality from analyzers into Component
base class API.
The different analyzers types all had their own methods for enabling/disabling their availability. This change abstracts that into a new API inside their base class (`plugin::Component`) so that they can be toggled in a unified way. In principle, other types of components could/should use this as well now, so that, e.g., an input reader's availability could be toggled at runtime. The code doesn't make that broader change for now because it would requires a series of changes wherever these other component types are being used. However, that means that one now could try toggling some other component through the new API without that having any effect. To catch that, there's a runtime check in place that turns any such attempt into an internal error.
This commit is contained in:
parent
d7e30d9ee2
commit
ac1a7508ee
8 changed files with 50 additions and 55 deletions
|
@ -18,11 +18,11 @@ void Component::Initialize() {
|
|||
}
|
||||
|
||||
void Component::SetEnabled(bool arg_enabled) {
|
||||
enabled = arg_enabled;
|
||||
plugin::Component::SetEnabled(arg_enabled);
|
||||
|
||||
// If we already have instantiated an analyzer, update its state.
|
||||
if ( auto analyzer = packet_mgr->GetAnalyzer(Tag().AsVal().get()) )
|
||||
analyzer->SetEnabled(enabled);
|
||||
if ( auto analyzer = packet_mgr->Lookup(Tag().AsVal().get()) )
|
||||
analyzer->SetEnabled(arg_enabled);
|
||||
}
|
||||
|
||||
void Component::DoDescribe(ODesc* d) const {
|
||||
|
@ -32,5 +32,5 @@ void Component::DoDescribe(ODesc* d) const {
|
|||
d->Add(", ");
|
||||
}
|
||||
|
||||
d->Add(enabled ? "enabled" : "disabled");
|
||||
d->Add(Enabled() ? "enabled" : "disabled");
|
||||
}
|
||||
|
|
|
@ -34,19 +34,7 @@ public:
|
|||
*/
|
||||
factory_callback Factory() const { return factory; }
|
||||
|
||||
/**
|
||||
* Returns true if the analyzer is currently enabled and hence
|
||||
* available for use.
|
||||
*/
|
||||
bool Enabled() const { return enabled; }
|
||||
|
||||
/**
|
||||
* Enables or disables this analyzer.
|
||||
*
|
||||
* @param arg_enabled True to enabled, false to disable.
|
||||
*
|
||||
*/
|
||||
void SetEnabled(bool arg_enabled);
|
||||
void SetEnabled(bool arg_enabled) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -56,7 +44,6 @@ protected:
|
|||
|
||||
private:
|
||||
factory_callback factory; // The analyzer's factory callback.
|
||||
bool enabled = true; // True if the analyzer is enabled.
|
||||
};
|
||||
|
||||
} // namespace zeek::packet_analysis
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue