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,11 +35,17 @@ InputMgr::InputMgr()
|
||||||
|
|
||||||
|
|
||||||
// create a new input reader object to be used at whomevers leisure lateron.
|
// 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;
|
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 ) {
|
while ( true ) {
|
||||||
if ( ir->type == BifEnum::Input::READER_DEFAULT )
|
if ( ir->type == BifEnum::Input::READER_DEFAULT )
|
||||||
{
|
{
|
||||||
|
@ -86,5 +92,13 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, string source)
|
||||||
return reader_obj;
|
return reader_obj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 "EventHandler.h"
|
||||||
#include "RemoteSerializer.h"
|
#include "RemoteSerializer.h"
|
||||||
|
|
||||||
|
class InputReader;
|
||||||
|
|
||||||
class InputMgr {
|
class InputMgr {
|
||||||
public:
|
public:
|
||||||
InputMgr();
|
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;
|
extern InputMgr* input_mgr;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
|
||||||
#include "InputReader.h"
|
#include "InputReader.h"
|
||||||
|
#include "EventRegistry.h"
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
InputReader::InputReader()
|
InputReader::InputReader()
|
||||||
{
|
{
|
||||||
|
@ -9,4 +11,21 @@ InputReader::InputReader()
|
||||||
InputReader::~InputReader()
|
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,16 +6,29 @@
|
||||||
#ifndef INPUTREADER_H
|
#ifndef INPUTREADER_H
|
||||||
#define INPUTREADER_H
|
#define INPUTREADER_H
|
||||||
|
|
||||||
|
#include "InputMgr.h"
|
||||||
|
#include "BroString.h"
|
||||||
|
|
||||||
class InputReader {
|
class InputReader {
|
||||||
public:
|
public:
|
||||||
InputReader();
|
InputReader();
|
||||||
virtual ~InputReader();
|
virtual ~InputReader();
|
||||||
|
|
||||||
|
bool Init(string source, string eventName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Methods that have to be overwritten by the individual readers
|
// 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:
|
private:
|
||||||
friend class InputMgr;
|
friend class InputMgr;
|
||||||
|
|
||||||
|
string source;
|
||||||
|
|
||||||
// When an error occurs, this method is called to set a flag marking the
|
// When an error occurs, this method is called to set a flag marking the
|
||||||
// writer as disabled.
|
// writer as disabled.
|
||||||
|
|
|
@ -7,9 +7,11 @@ module Input;
|
||||||
#include "NetVar.h"
|
#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 );
|
return new Val( the_reader != 0, TYPE_BOOL );
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue