LCOV - code coverage report
Current view: top level - src - Event.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 69 94 73.4 %
Date: 2010-12-13 Functions: 11 19 57.9 %
Branches: 19 56 33.9 %

           Branch data     Line data    Source code
       1                 :            : // $Id: Event.cc 6219 2008-10-01 05:39:07Z vern $
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #include "config.h"
       6                 :            : 
       7                 :            : #include "Event.h"
       8                 :            : #include "Func.h"
       9                 :            : #include "NetVar.h"
      10                 :            : #include "Trigger.h"
      11                 :            : 
      12                 :          6 : EventMgr mgr;
      13                 :            : 
      14                 :            : int num_events_queued = 0;
      15                 :            : int num_events_dispatched = 0;
      16                 :            : 
      17                 :            : Event::Event(EventHandlerPtr arg_handler, val_list* arg_args,
      18                 :            :                 SourceID arg_src, AnalyzerID arg_aid, TimerMgr* arg_mgr,
      19                 :      23244 :                 BroObj* arg_obj)
      20                 :            :         {
      21                 :      23244 :         handler = arg_handler;
      22                 :      23244 :         args = arg_args;
      23                 :      23244 :         src = arg_src;
      24 [ +  + ][ #  # ]:      23244 :         mgr = arg_mgr ? arg_mgr : timer_mgr; // default is global
      25                 :      23244 :         aid = arg_aid;
      26                 :      23244 :         obj = arg_obj;
      27                 :            : 
      28 [ +  + ][ #  # ]:      23244 :         if ( obj )
      29                 :      16749 :                 Ref(obj);
      30                 :            : 
      31                 :      23244 :         next_event = 0;
      32                 :      23244 :         }
      33                 :            : 
      34                 :      23244 : Event::~Event()
      35                 :            :         {
      36                 :            :         // We don't Unref() the individual arguments by using delete_vals()
      37                 :            :         // here, because Func::Call already did that.
      38 [ +  - ][ #  # ]:      23244 :         delete args;
                 [ #  # ]
      39 [ +  - ][ #  # ]:      23244 :         }
                 [ #  # ]
      40                 :            : 
      41                 :          0 : void Event::Describe(ODesc* d) const
      42                 :            :         {
      43         [ #  # ]:          0 :         if ( d->IsReadable() )
      44                 :          0 :                 d->AddSP("event");
      45                 :            : 
      46                 :          0 :         int s = d->IsShort();
      47                 :          0 :         d->SetShort();
      48                 :            : //      handler->Describe(d);
      49                 :          0 :         d->SetShort(s);
      50                 :            : 
      51         [ #  # ]:          0 :         if ( ! d->IsBinary() )
      52                 :          0 :                 d->Add("(");
      53                 :          0 :         describe_vals(args, d);
      54         [ #  # ]:          0 :         if ( ! d->IsBinary() )
      55                 :          0 :                 d->Add("(");
      56                 :          0 :         }
      57                 :            : 
      58                 :          3 : EventMgr::EventMgr()
      59                 :            :         {
      60                 :          3 :         head = tail = 0;
      61                 :          3 :         current_src = SOURCE_LOCAL;
      62                 :          3 :         current_mgr = timer_mgr;
      63                 :          3 :         current_aid = 0;
      64                 :          3 :         src_val = 0;
      65                 :          3 :         draining = 0;
      66                 :          3 :         }
      67                 :            : 
      68                 :          3 : EventMgr::~EventMgr()
      69                 :            :         {
      70 [ #  # ][ -  + ]:          3 :         while ( head )
                 [ #  # ]
      71                 :            :                 {
      72                 :          0 :                 Event* n = head->NextEvent();
      73                 :          0 :                 Unref(head);
      74                 :          0 :                 head = n;
      75                 :            :                 }
      76                 :            : 
      77                 :          3 :         Unref(src_val);
      78 [ #  # ][ -  + ]:          3 :         }
                 [ #  # ]
      79                 :            : 
      80                 :      22964 : void EventMgr::QueueEvent(Event* event)
      81                 :            :         {
      82         [ +  + ]:      22964 :         if ( ! head )
      83                 :       7035 :                 head = tail = event;
      84                 :            :         else
      85                 :            :                 {
      86                 :      15929 :                 tail->SetNext(event);
      87                 :      15929 :                 tail = event;
      88                 :            :                 }
      89                 :            : 
      90                 :      22964 :         ++num_events_queued;
      91                 :      22964 :         }
      92                 :            : 
      93                 :      22964 : void EventMgr::Dispatch()
      94                 :            :         {
      95         [ -  + ]:      22964 :         if ( ! head )
      96                 :          0 :                 internal_error("EventMgr underflow");
      97                 :            : 
      98                 :      22964 :         Event* current = head;
      99                 :            : 
     100                 :      22964 :         head = head->NextEvent();
     101         [ +  + ]:      22964 :         if ( ! head )
     102                 :       7035 :                 tail = head;
     103                 :            : 
     104                 :      22964 :         current_src = current->Source();
     105                 :      22964 :         current_mgr = current->Mgr();
     106                 :      22964 :         current_aid = current->Analyzer();
     107                 :      22964 :         current->Dispatch();
     108                 :      22964 :         Unref(current);
     109                 :            : 
     110                 :      22964 :         ++num_events_dispatched;
     111                 :      22964 :         }
     112                 :            : 
     113                 :      42701 : void EventMgr::Drain()
     114                 :            :         {
     115                 :      42701 :         SegmentProfiler(segment_logger, "draining-events");
     116                 :            : 
     117                 :      42701 :         draining = true;
     118         [ +  + ]:      65665 :         while ( head )
     119                 :      22964 :                 Dispatch();
     120                 :            : 
     121                 :            :         // Note: we might eventually need a general way to specify things to
     122                 :            :         // do after draining events.
     123                 :            :         extern void flush_rewriter_packet();
     124                 :      42701 :         flush_rewriter_packet();
     125                 :            : 
     126                 :      42701 :         draining = false;
     127                 :            : 
     128                 :            :         // We evaluate Triggers here. While this is somewhat unrelated to event
     129                 :            :         // processing, we ensure that it's done at a regular basis by checking
     130                 :            :         // them here.
     131                 :      42701 :         Trigger::EvaluatePending();
     132                 :      42701 :         }
     133                 :            : 
     134                 :          0 : void EventMgr::Describe(ODesc* d) const
     135                 :            :         {
     136                 :          0 :         int n = 0;
     137                 :            :         Event* e;
     138         [ #  # ]:          0 :         for ( e = head; e; e = e->NextEvent() )
     139                 :          0 :                 ++n;
     140                 :            : 
     141                 :          0 :         d->AddCount(n);
     142                 :            : 
     143         [ #  # ]:          0 :         for ( e = head; e; e = e->NextEvent() )
     144                 :            :                 {
     145                 :          0 :                 e->Describe(d);
     146                 :          0 :                 d->NL();
     147                 :            :                 }
     148                 :          0 :         }
     149                 :            : 
     150                 :       1752 : RecordVal* EventMgr::GetLocalPeerVal()
     151                 :            :         {
     152         [ +  + ]:       1752 :         if ( ! src_val )
     153                 :            :                 {
     154                 :          1 :                 src_val = new RecordVal(peer);
     155                 :          1 :                 src_val->Assign(0, new Val(0, TYPE_COUNT));
     156                 :          1 :                 src_val->Assign(1, new AddrVal("127.0.0.1"));
     157                 :          1 :                 src_val->Assign(2, new PortVal(0));
     158                 :          1 :                 src_val->Assign(3, new Val(true, TYPE_BOOL));
     159                 :            : 
     160                 :          1 :                 Ref(peer_description);
     161                 :          1 :                 src_val->Assign(4, peer_description);
     162                 :          1 :                 src_val->Assign(5, 0);       // class (optional).
     163                 :            :                 }
     164                 :            : 
     165                 :       1752 :         return src_val;
     166 [ +  - ][ +  - ]:          6 :         }

Generated by: LCOV version 1.8