Initial import of svn+ssh:://svn.icir.org/bro/trunk/bro as of r7088

This commit is contained in:
Robin Sommer 2010-09-27 20:42:30 -07:00
commit 61757ac78b
1383 changed files with 380824 additions and 0 deletions

122
src/Event.h Normal file
View file

@ -0,0 +1,122 @@
// $Id: Event.h 6219 2008-10-01 05:39:07Z vern $
//
// See the file "COPYING" in the main distribution directory for copyright.
#ifndef event_h
#define event_h
#include "EventRegistry.h"
#include "Serializer.h"
#include "AnalyzerTags.h"
class EventMgr;
class Event : public BroObj {
public:
Event(EventHandlerPtr handler, val_list* args,
SourceID src = SOURCE_LOCAL, AnalyzerID aid = 0,
TimerMgr* mgr = 0, BroObj* obj = 0);
~Event();
void SetNext(Event* n) { next_event = n; }
Event* NextEvent() const { return next_event; }
SourceID Source() const { return src; }
AnalyzerID Analyzer() const { return aid; }
TimerMgr* Mgr() const { return mgr; }
void Describe(ODesc* d) const;
protected:
friend class EventMgr;
// This method is protected to make sure that everybody goes through
// EventMgr::Dispatch().
void Dispatch(bool no_remote = false)
{
if ( event_serializer )
{
SerialInfo info(event_serializer);
event_serializer->Serialize(&info, handler->Name(), args);
}
handler->Call(args, no_remote);
if ( obj )
// obj->EventDone();
Unref(obj);
}
EventHandlerPtr handler;
val_list* args;
SourceID src;
AnalyzerID aid;
TimerMgr* mgr;
BroObj* obj;
Event* next_event;
};
extern int num_events_queued;
extern int num_events_dispatched;
class EventMgr : public BroObj {
public:
EventMgr();
~EventMgr();
void QueueEvent(EventHandlerPtr h, val_list* vl,
SourceID src = SOURCE_LOCAL, AnalyzerID aid = 0,
TimerMgr* mgr = 0, BroObj* obj = 0)
{
if ( h )
QueueEvent(new Event(h, vl, src, aid, mgr, obj));
else
delete_vals(vl);
}
void Dispatch();
void Dispatch(Event* event, bool no_remote = false)
{
current_src = event->Source();
event->Dispatch(no_remote);
Unref(event);
}
void Drain();
bool IsDraining() const { return draining; }
int HasEvents() const { return head != 0; }
// Returns the source ID of last raised event.
SourceID CurrentSource() const { return current_src; }
// Returns the ID of the analyzer which raised the last event, or 0 if
// non-analyzer event.
AnalyzerID CurrentAnalyzer() const { return current_aid; }
// Returns the timer mgr associated with the last raised event.
TimerMgr* CurrentTimerMgr() const { return current_mgr; }
int Size() const
{ return num_events_queued - num_events_dispatched; }
// Returns a peer record describing the local Bro.
RecordVal* GetLocalPeerVal();
void Describe(ODesc* d) const;
protected:
void QueueEvent(Event* event);
Event* head;
Event* tail;
SourceID current_src;
AnalyzerID current_aid;
TimerMgr* current_mgr;
RecordVal* src_val;
bool draining;
};
extern EventMgr mgr;
#endif