mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
well, it compiles. and perhaps it sends an event. billiant.
This commit is contained in:
parent
0eafeb0369
commit
f8be3519c7
5 changed files with 63 additions and 7 deletions
|
@ -35,10 +35,16 @@ InputMgr::InputMgr()
|
|||
|
||||
|
||||
// create a new input reader object to be used at whomevers leisure lateron.
|
||||
InputReader* InputMgr::CreateReader(EnumVal* reader, string source)
|
||||
InputReader* InputMgr::CreateReader(EnumVal* reader, string source, string eventName, RecordVal* eventDescription)
|
||||
{
|
||||
InputReaderDefinition* ir = input_readers;
|
||||
exit(12);
|
||||
|
||||
RecordType* rtype = eventDescription->Type()->AsRecordType();
|
||||
if ( ! same_type(rtype, BifType::Record::Input::Event, 0) )
|
||||
{
|
||||
reporter->Error("eventDescription argument not of right type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ( true ) {
|
||||
if ( ir->type == BifEnum::Input::READER_DEFAULT )
|
||||
|
@ -87,4 +93,12 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, string source)
|
|||
|
||||
}
|
||||
|
||||
void InputMgr::Error(InputReader* reader, const char* msg)
|
||||
{
|
||||
reporter->Error(fmt("error with input reader for %s: %s",
|
||||
reader->Source().c_str(), msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,12 +10,20 @@
|
|||
#include "EventHandler.h"
|
||||
#include "RemoteSerializer.h"
|
||||
|
||||
class InputReader;
|
||||
|
||||
class InputMgr {
|
||||
public:
|
||||
InputMgr();
|
||||
|
||||
InputReader* CreateReader(EnumVal* reader, string source);
|
||||
InputReader* CreateReader(EnumVal* reader, string source, string eventName, RecordVal* eventDescription);
|
||||
|
||||
protected:
|
||||
friend class InputReader;
|
||||
|
||||
// Reports an error for the given reader.
|
||||
void Error(InputReader* reader, const char* msg);
|
||||
|
||||
};
|
||||
|
||||
extern InputMgr* input_mgr;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
#include "InputReader.h"
|
||||
#include "EventRegistry.h"
|
||||
#include "Event.h"
|
||||
|
||||
InputReader::InputReader()
|
||||
{
|
||||
|
@ -10,3 +12,20 @@ InputReader::~InputReader()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
void InputReader::Error(const char *msg)
|
||||
{
|
||||
input_mgr->Error(this, msg);
|
||||
}
|
||||
|
||||
bool InputReader::Init(string source, string eventName) {
|
||||
EventHandler* handler = event_registry->Lookup(eventName.c_str());
|
||||
|
||||
if ( handler == 0 ) {
|
||||
reporter->Error("Event %s not found", eventName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
mgr.Dispatch(new Event(handler, 0));
|
||||
return true;
|
||||
}
|
|
@ -6,17 +6,30 @@
|
|||
#ifndef INPUTREADER_H
|
||||
#define INPUTREADER_H
|
||||
|
||||
#include "InputMgr.h"
|
||||
#include "BroString.h"
|
||||
|
||||
class InputReader {
|
||||
public:
|
||||
InputReader();
|
||||
virtual ~InputReader();
|
||||
|
||||
bool Init(string source, string eventName);
|
||||
|
||||
protected:
|
||||
// Methods that have to be overwritten by the individual readers
|
||||
|
||||
// Reports an error to the user.
|
||||
void Error(const char *msg);
|
||||
|
||||
// The following methods return the information as passed to Init().
|
||||
const string Source() const { return source; }
|
||||
|
||||
private:
|
||||
friend class InputMgr;
|
||||
|
||||
string source;
|
||||
|
||||
// When an error occurs, this method is called to set a flag marking the
|
||||
// writer as disabled.
|
||||
|
||||
|
|
|
@ -7,9 +7,11 @@ module Input;
|
|||
#include "NetVar.h"
|
||||
%%}
|
||||
|
||||
function Input::__create_reader%(reader: Input::Reader, source: string%) : bool
|
||||
type Event: record;
|
||||
|
||||
function Input::__create_reader%(reader: Input::Reader, source: string, eventName: string, eventDescription: Input::Event%) : bool
|
||||
%{
|
||||
InputReader *the_reader = input_mgr->CreateReader(reader->AsEnumVal(), source->AsString()->CheckString());
|
||||
InputReader *the_reader = input_mgr->CreateReader(reader->AsEnumVal(), source->AsString()->CheckString(), eventName->AsString()->CheckString(), eventDescription->AsRecordVal());
|
||||
return new Val( the_reader != 0, TYPE_BOOL );
|
||||
%}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue