event from c++ to script works (at last...)

This commit is contained in:
Bernhard Amann 2011-10-19 16:35:34 -07:00
parent f8be3519c7
commit 9c8b0dec3b
8 changed files with 33 additions and 16 deletions

View file

@ -0,0 +1 @@
@load ./main

View file

@ -0,0 +1,11 @@
module Input;
export {
type Event: record {
name: string;
columns: any;
};
}
@load base/input.bif

View file

@ -1509,4 +1509,5 @@ const parse_udp_tunnels = F &redef;
# BiFs and script-land defined types. # BiFs and script-land defined types.
@load base/frameworks/logging @load base/frameworks/logging
@load base/input.bif @load base/frameworks/input

View file

@ -35,11 +35,11 @@ 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, string eventName, RecordVal* eventDescription) InputReader* InputMgr::CreateReader(EnumVal* reader, string source, RecordVal* event)
{ {
InputReaderDefinition* ir = input_readers; InputReaderDefinition* ir = input_readers;
RecordType* rtype = eventDescription->Type()->AsRecordType(); RecordType* rtype = InputReaderDefinition->Type()->AsRecordType();
if ( ! same_type(rtype, BifType::Record::Input::Event, 0) ) if ( ! same_type(rtype, BifType::Record::Input::Event, 0) )
{ {
reporter->Error("eventDescription argument not of right type"); reporter->Error("eventDescription argument not of right type");
@ -49,7 +49,6 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, string source, string event
while ( true ) { while ( true ) {
if ( ir->type == BifEnum::Input::READER_DEFAULT ) if ( ir->type == BifEnum::Input::READER_DEFAULT )
{ {
DBG_LOG(DBG_LOGGING, "unknown reader when creating reader");
reporter->Error("unknown reader when creating reader"); reporter->Error("unknown reader when creating reader");
return 0; return 0;
} }
@ -89,6 +88,8 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, string source, string event
InputReader* reader_obj = (*ir->factory)(); InputReader* reader_obj = (*ir->factory)();
assert(reader_obj); assert(reader_obj);
reader_obj->Init(source, eventName);
return reader_obj; return reader_obj;
} }

View file

@ -16,7 +16,7 @@ class InputMgr {
public: public:
InputMgr(); InputMgr();
InputReader* CreateReader(EnumVal* reader, string source, string eventName, RecordVal* eventDescription); InputReader* CreateReader(EnumVal* reader, string source, RecordVal* event);
protected: protected:
friend class InputReader; friend class InputReader;

View file

@ -1,7 +1,7 @@
#include "InputReader.h" #include "InputReader.h"
#include "EventRegistry.h" // #include "EventRegistry.h"
#include "Event.h" // #include "Event.h"
InputReader::InputReader() InputReader::InputReader()
{ {
@ -19,13 +19,16 @@ void InputReader::Error(const char *msg)
} }
bool InputReader::Init(string source, string eventName) { bool InputReader::Init(string source, string eventName) {
EventHandler* handler = event_registry->Lookup(eventName.c_str()); //EventHandler* handler = event_registry->Lookup(eventName.c_str());
if ( handler == 0 ) { //if ( handler == 0 ) {
reporter->Error("Event %s not found", eventName.c_str()); // reporter->Error("Event %s not found", eventName.c_str());
return false; // return false;
} //}
mgr.Dispatch(new Event(handler, 0)); //val_list* vl = new val_list;
//vl->append(new Val(12, TYPE_COUNT));
//mgr.Dispatch(new Event(handler, vl));
return true; return true;
} }

View file

@ -475,7 +475,7 @@ void LogMgr::RemoveDisabledWriters(Stream* stream)
stream->writers.erase(*j); stream->writers.erase(*j);
} }
bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval) bool LogMgr::(EnumVal* id, RecordVal* sval)
{ {
RecordType* rtype = sval->Type()->AsRecordType(); RecordType* rtype = sval->Type()->AsRecordType();

View file

@ -9,9 +9,9 @@ module Input;
type Event: record; type Event: record;
function Input::__create_reader%(reader: Input::Reader, source: string, eventName: string, eventDescription: Input::Event%) : bool function Input::__create_reader%(reader: Input::Reader, source: string, eventDescription: Input::Event%) : bool
%{ %{
InputReader *the_reader = input_mgr->CreateReader(reader->AsEnumVal(), source->AsString()->CheckString(), eventName->AsString()->CheckString(), eventDescription->AsRecordVal()); InputReader *the_reader = input_mgr->CreateReader(reader->AsEnumVal(), source->AsString()->CheckString(), eventDescription->AsRecordVal());
return new Val( the_reader != 0, TYPE_BOOL ); return new Val( the_reader != 0, TYPE_BOOL );
%} %}