mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 02:58:20 +00:00
Unify all of the Tag types into one type
- Remove tag types for each component type (analyzer, etc) - Add deprecated versions of the old types - Remove unnecessary tag element from templates for TaggedComponent and ComponentManager - Enable TaggedComponent to pass an EnumType when initializing Tag objects - Update some tests that are affected by the tag enum values changing order
This commit is contained in:
parent
4f9f46a0c4
commit
331161138a
46 changed files with 352 additions and 955 deletions
|
@ -15,11 +15,9 @@ set(logging_SRCS
|
|||
Manager.cc
|
||||
WriterBackend.cc
|
||||
WriterFrontend.cc
|
||||
Tag.cc
|
||||
)
|
||||
|
||||
bif_target(logging.bif)
|
||||
|
||||
bro_add_subdir_library(logging ${logging_SRCS})
|
||||
add_dependencies(bro_logging generate_outputs)
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace zeek::logging
|
|||
{
|
||||
|
||||
Component::Component(const std::string& name, factory_callback arg_factory)
|
||||
: plugin::Component(plugin::component::WRITER, name)
|
||||
: plugin::Component(plugin::component::WRITER, name), plugin::TaggedComponent(
|
||||
0, log_mgr->GetTagType())
|
||||
{
|
||||
factory = arg_factory;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class WriterBackend;
|
|||
/**
|
||||
* Component description for plugins providing log writers.
|
||||
*/
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent<logging::Tag>
|
||||
class Component : public plugin::Component, public plugin::TaggedComponent
|
||||
{
|
||||
public:
|
||||
using factory_callback = WriterBackend* (*)(WriterFrontend* frontend);
|
||||
|
|
|
@ -132,7 +132,7 @@ Manager::Stream::~Stream()
|
|||
delete *f;
|
||||
}
|
||||
|
||||
Manager::Manager() : plugin::ComponentManager<logging::Tag, logging::Component>("Log", "Writer")
|
||||
Manager::Manager() : plugin::ComponentManager<logging::Component>("Log", "Writer")
|
||||
{
|
||||
rotations_pending = 0;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class RotationTimer;
|
|||
/**
|
||||
* Singleton class for managing log streams.
|
||||
*/
|
||||
class Manager : public plugin::ComponentManager<Tag, Component>
|
||||
class Manager : public plugin::ComponentManager<Component>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/logging/Tag.h"
|
||||
|
||||
#include "zeek/logging/Manager.h"
|
||||
|
||||
namespace zeek::logging
|
||||
{
|
||||
|
||||
const Tag Tag::Error;
|
||||
|
||||
Tag::Tag(type_t type, subtype_t subtype) : zeek::Tag(log_mgr->GetTagType(), type, subtype) { }
|
||||
|
||||
Tag& Tag::operator=(const Tag& other)
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Tag& Tag::operator=(const Tag&& other) noexcept
|
||||
{
|
||||
zeek::Tag::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const EnumValPtr& Tag::AsVal() const
|
||||
{
|
||||
return zeek::Tag::AsVal(log_mgr->GetTagType());
|
||||
}
|
||||
|
||||
Tag::Tag(EnumValPtr val) : zeek::Tag(std::move(val)) { }
|
||||
|
||||
} // namespace zeek::logging
|
|
@ -6,113 +6,9 @@
|
|||
|
||||
#include "zeek/Tag.h"
|
||||
|
||||
namespace zeek
|
||||
namespace zeek::logging
|
||||
{
|
||||
|
||||
class EnumVal;
|
||||
using Tag [[deprecated("Remove in v5.1. Use zeek::Tag.")]] = zeek::Tag;
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
|
||||
template <class T> class TaggedComponent;
|
||||
template <class T, class C> class ComponentManager;
|
||||
|
||||
} // namespace plugin
|
||||
|
||||
namespace logging
|
||||
{
|
||||
|
||||
class Manager;
|
||||
class Component;
|
||||
|
||||
/**
|
||||
* Class to identify a writer type.
|
||||
*
|
||||
* The script-layer analogue is Log::Writer.
|
||||
*/
|
||||
class Tag : public zeek::Tag
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Copy constructor.
|
||||
*/
|
||||
Tag(const Tag& other) : zeek::Tag(other) { }
|
||||
|
||||
/**
|
||||
* Default constructor. This initializes the tag with an error value
|
||||
* that will make \c operator \c bool return false.
|
||||
*/
|
||||
Tag() : zeek::Tag() { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Tag() { }
|
||||
|
||||
/**
|
||||
* Returns false if the tag represents an error value rather than a
|
||||
* legal writer type.
|
||||
*/
|
||||
explicit operator bool() const { return *this != Error; }
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag& other);
|
||||
|
||||
/**
|
||||
* Move assignment operator.
|
||||
*/
|
||||
Tag& operator=(const Tag&& other) noexcept;
|
||||
|
||||
/**
|
||||
* Compares two tags for equality.
|
||||
*/
|
||||
bool operator==(const Tag& other) const { return zeek::Tag::operator==(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for inequality.
|
||||
*/
|
||||
bool operator!=(const Tag& other) const { return zeek::Tag::operator!=(other); }
|
||||
|
||||
/**
|
||||
* Compares two tags for less-than relationship.
|
||||
*/
|
||||
bool operator<(const Tag& other) const { return zeek::Tag::operator<(other); }
|
||||
|
||||
/**
|
||||
* Returns the \c Log::Writer enum that corresponds to this tag.
|
||||
* The returned value does not have its ref-count increased.
|
||||
*
|
||||
* @param etype the script-layer enum type associated with the tag.
|
||||
*/
|
||||
const EnumValPtr& AsVal() const;
|
||||
|
||||
static const Tag Error;
|
||||
|
||||
protected:
|
||||
friend class plugin::ComponentManager<Tag, Component>;
|
||||
friend class plugin::TaggedComponent<Tag>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The main type. Note that the \a logging::Manager
|
||||
* manages the value space internally, so noone else should assign
|
||||
* any main types.
|
||||
*
|
||||
* @param subtype The sub type, which is left to an writer for
|
||||
* interpretation. By default it's set to zero.
|
||||
*/
|
||||
explicit Tag(type_t type, subtype_t subtype = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param val An enum value of script type \c Log::Writer.
|
||||
*/
|
||||
explicit Tag(EnumValPtr val);
|
||||
};
|
||||
|
||||
} // namespace logging
|
||||
} // namespace zeek
|
||||
} // namespace zeek::logging
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue