LCOV - code coverage report
Current view: top level - src - Event.h (source / functions) Hit Total Coverage
Test: app.info Lines: 24 28 85.7 %
Date: 2010-12-13 Functions: 11 13 84.6 %
Branches: 5 6 83.3 %

           Branch data     Line data    Source code
       1                 :            : // $Id: Event.h 6219 2008-10-01 05:39:07Z vern $
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #ifndef event_h
       6                 :            : #define event_h
       7                 :            : 
       8                 :            : #include "EventRegistry.h"
       9                 :            : #include "Serializer.h"
      10                 :            : #include "AnalyzerTags.h"
      11                 :            : 
      12                 :            : class EventMgr;
      13                 :            : 
      14                 :            : class Event : public BroObj {
      15                 :            : public:
      16                 :            :         Event(EventHandlerPtr handler, val_list* args,
      17                 :            :                 SourceID src = SOURCE_LOCAL, AnalyzerID aid = 0,
      18                 :            :                 TimerMgr* mgr = 0, BroObj* obj = 0);
      19                 :            :         ~Event();
      20                 :            : 
      21                 :      15929 :         void SetNext(Event* n)          { next_event = n; }
      22                 :      22964 :         Event* NextEvent() const        { return next_event; }
      23                 :            : 
      24                 :      23244 :         SourceID Source() const         { return src; }
      25                 :      22964 :         AnalyzerID Analyzer() const     { return aid; }
      26                 :      22964 :         TimerMgr* Mgr() const           { return mgr; }
      27                 :            : 
      28                 :            :         void Describe(ODesc* d) const;
      29                 :            : 
      30                 :            : protected:
      31                 :            :         friend class EventMgr;
      32                 :            : 
      33                 :            :         // This method is protected to make sure that everybody goes through
      34                 :            :         // EventMgr::Dispatch().
      35                 :      23244 :         void Dispatch(bool no_remote = false)
      36                 :            :                 {
      37         [ -  + ]:      23244 :                 if ( event_serializer )
      38                 :            :                         {
      39                 :          0 :                         SerialInfo info(event_serializer);
      40                 :          0 :                         event_serializer->Serialize(&info, handler->Name(), args);
      41                 :            :                         }
      42                 :            : 
      43                 :      23244 :                 handler->Call(args, no_remote);
      44         [ +  + ]:      23244 :                 if ( obj )
      45                 :            :                         // obj->EventDone();
      46                 :      16749 :                         Unref(obj);
      47                 :      23244 :                 }
      48                 :            : 
      49                 :            :         EventHandlerPtr handler;
      50                 :            :         val_list* args;
      51                 :            :         SourceID src;
      52                 :            :         AnalyzerID aid;
      53                 :            :         TimerMgr* mgr;
      54                 :            :         BroObj* obj;
      55                 :            :         Event* next_event;
      56                 :            : };
      57                 :            : 
      58                 :            : extern int num_events_queued;
      59                 :            : extern int num_events_dispatched;
      60                 :            : 
      61                 :            : class EventMgr : public BroObj {
      62                 :            : public:
      63                 :            :         EventMgr();
      64                 :            :         ~EventMgr();
      65                 :            : 
      66                 :            :         void QueueEvent(EventHandlerPtr h, val_list* vl,
      67                 :            :                         SourceID src = SOURCE_LOCAL, AnalyzerID aid = 0,
      68                 :      23558 :                         TimerMgr* mgr = 0, BroObj* obj = 0)
      69                 :            :                 {
      70         [ +  + ]:      23558 :                 if ( h )
      71                 :      22964 :                         QueueEvent(new Event(h, vl, src, aid, mgr, obj));
      72                 :            :                 else
      73                 :        594 :                         delete_vals(vl);
      74                 :      23558 :                 }
      75                 :            : 
      76                 :            :         void Dispatch();
      77                 :            : 
      78                 :        280 :         void Dispatch(Event* event, bool no_remote = false)
      79                 :            :                 {
      80                 :        280 :                 current_src = event->Source();
      81                 :        280 :                 event->Dispatch(no_remote);
      82                 :        280 :                 Unref(event);
      83                 :        280 :                 }
      84                 :            : 
      85                 :            :         void Drain();
      86                 :          0 :         bool IsDraining() const { return draining; }
      87                 :            : 
      88                 :      42701 :         int HasEvents() const   { return head != 0; }
      89                 :            : 
      90                 :            :         // Returns the source ID of last raised event.
      91                 :       5894 :         SourceID CurrentSource() const  { return current_src; }
      92                 :            : 
      93                 :            :         // Returns the ID of the analyzer which raised the last event, or 0 if
      94                 :            :         // non-analyzer event.
      95                 :          0 :         AnalyzerID CurrentAnalyzer() const      { return current_aid; }
      96                 :            : 
      97                 :            :         // Returns the timer mgr associated with the last raised event.
      98                 :       1705 :         TimerMgr* CurrentTimerMgr() const       { return current_mgr; }
      99                 :            : 
     100                 :            :         int Size() const
     101                 :            :                 { return num_events_queued - num_events_dispatched; }
     102                 :            : 
     103                 :            :         // Returns a peer record describing the local Bro.
     104                 :            :         RecordVal* GetLocalPeerVal();
     105                 :            : 
     106                 :            :         void Describe(ODesc* d) const;
     107                 :            : 
     108                 :            : protected:
     109                 :            :         void QueueEvent(Event* event);
     110                 :            : 
     111                 :            :         Event* head;
     112                 :            :         Event* tail;
     113                 :            :         SourceID current_src;
     114                 :            :         AnalyzerID current_aid;
     115                 :            :         TimerMgr* current_mgr;
     116                 :            :         RecordVal* src_val;
     117                 :            :         bool draining;
     118                 :            : };
     119                 :            : 
     120                 :            : extern EventMgr mgr;
     121                 :            : 
     122                 :            : #endif

Generated by: LCOV version 1.8