mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 21:18:20 +00:00

Turns out the finish methods weren't called correctly, caused by a mess up with method names which all sounded too similar and the wrong one ended up being called. I've reworked this by changing the thread/writer/reader interfaces, which actually also simplifies them by getting rid of the requirement for writer backends to call their parent methods (i.e., less opportunity for errors). This commit also includes the following (because I noticed the problem above when working on some of these): - The ASCII log writer now includes "#start <timestamp>" and "#end <timestamp> lines in the each file. The latter supersedes Bernhard's "EOF" patch. This required a number of tests updates. The standard canonifier removes the timestamps, but some tests compare files directly, which doesn't work if they aren't printing out the same timestamps (like the comm tests). - The above required yet another change to the writer API to network_time to methods. - Renamed ASCII logger "header" options to "meta". - Fixes #763 "Escape # when first character in log file line". All btests pass for me on Linux FC15. Will try MacOS next.
94 lines
2 KiB
C++
94 lines
2 KiB
C++
// See the file "COPYING" in the main distribution directory for copyright.
|
|
|
|
#include "Manager.h"
|
|
#include "ReaderFrontend.h"
|
|
#include "ReaderBackend.h"
|
|
|
|
#include "threading/MsgThread.h"
|
|
|
|
namespace input {
|
|
|
|
class InitMessage : public threading::InputMessage<ReaderBackend>
|
|
{
|
|
public:
|
|
InitMessage(ReaderBackend* backend, const ReaderBackend::ReaderInfo& info,
|
|
const int num_fields, const threading::Field* const* fields)
|
|
: threading::InputMessage<ReaderBackend>("Init", backend),
|
|
info(info), num_fields(num_fields), fields(fields) { }
|
|
|
|
virtual bool Process()
|
|
{
|
|
return Object()->Init(info, num_fields, fields);
|
|
}
|
|
|
|
private:
|
|
const ReaderBackend::ReaderInfo info;
|
|
const int num_fields;
|
|
const threading::Field* const* fields;
|
|
};
|
|
|
|
class UpdateMessage : public threading::InputMessage<ReaderBackend>
|
|
{
|
|
public:
|
|
UpdateMessage(ReaderBackend* backend)
|
|
: threading::InputMessage<ReaderBackend>("Update", backend)
|
|
{ }
|
|
|
|
virtual bool Process() { return Object()->Update(); }
|
|
};
|
|
|
|
ReaderFrontend::ReaderFrontend(bro_int_t type)
|
|
{
|
|
disabled = initialized = false;
|
|
ty_name = "<not set>";
|
|
backend = input_mgr->CreateBackend(this, type);
|
|
|
|
assert(backend);
|
|
backend->Start();
|
|
}
|
|
|
|
ReaderFrontend::~ReaderFrontend()
|
|
{
|
|
}
|
|
|
|
void ReaderFrontend::Init(const ReaderBackend::ReaderInfo& arg_info, const int arg_num_fields,
|
|
const threading::Field* const* arg_fields)
|
|
{
|
|
if ( disabled )
|
|
return;
|
|
|
|
if ( initialized )
|
|
reporter->InternalError("reader initialize twice");
|
|
|
|
info = arg_info;
|
|
num_fields = arg_num_fields;
|
|
fields = arg_fields;
|
|
initialized = true;
|
|
|
|
backend->SendIn(new InitMessage(backend, info, num_fields, fields));
|
|
}
|
|
|
|
void ReaderFrontend::Update()
|
|
{
|
|
if ( disabled )
|
|
return;
|
|
|
|
if ( ! initialized )
|
|
{
|
|
reporter->Error("Tried to call update on uninitialized reader");
|
|
return;
|
|
}
|
|
|
|
backend->SendIn(new UpdateMessage(backend));
|
|
}
|
|
|
|
string ReaderFrontend::Name() const
|
|
{
|
|
if ( ! info.source.size() )
|
|
return ty_name;
|
|
|
|
return ty_name + "/" + info.source;
|
|
}
|
|
|
|
}
|
|
|