LCOV - code coverage report
Current view: top level - svx/source/sdr/event - eventhandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 49 67.3 %
Date: 2015-06-13 12:38:46 Functions: 11 16 68.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "eventhandler.hxx"
      21             : 
      22             : // for SOLARIS compiler include of algorithm part of _STL is necessary to
      23             : // get access to basic algos like ::std::find
      24             : #include <algorithm>
      25             : #include <tools/debug.hxx>
      26             : 
      27             : namespace sdr
      28             : {
      29             :     namespace event
      30             :     {
      31           6 :         BaseEvent::BaseEvent(EventHandler& rEventHandler)
      32           6 :         :   mrEventHandler(rEventHandler)
      33             :         {
      34           6 :             mrEventHandler.AddEvent(*this);
      35           6 :         }
      36             : 
      37           6 :         BaseEvent::~BaseEvent()
      38             :         {
      39           6 :             mrEventHandler.RemoveEvent(*this);
      40           6 :         }
      41             :     } // end of namespace mixer
      42             : } // end of namespace sdr
      43             : 
      44             : 
      45             : 
      46             : namespace sdr
      47             : {
      48             :     namespace event
      49             :     {
      50           6 :         void EventHandler::AddEvent(BaseEvent& rBaseEvent)
      51             :         {
      52           6 :             maVector.push_back(&rBaseEvent);
      53           6 :         }
      54             : 
      55           6 :         void EventHandler::RemoveEvent(BaseEvent& rBaseEvent)
      56             :         {
      57           6 :             if(maVector.back() == &rBaseEvent)
      58             :             {
      59             :                 // the one to remove is the last, pop
      60           1 :                 maVector.pop_back();
      61             :             }
      62             :             else
      63             :             {
      64             :                 const BaseEventVector::iterator aFindResult = ::std::find(
      65           5 :                     maVector.begin(), maVector.end(), &rBaseEvent);
      66             :                 DBG_ASSERT(aFindResult != maVector.end(),
      67             :                     "EventHandler::RemoveEvent: Event to be removed not found (!)");
      68           5 :                 maVector.erase(aFindResult);
      69             :             }
      70           6 :         }
      71             : 
      72           0 :         BaseEvent* EventHandler::GetEvent()
      73             :         {
      74           0 :             if(!maVector.empty())
      75             :             {
      76             :                 // get the last event, that one is fastest to be removed
      77           0 :                 return maVector.back();
      78             :             }
      79             :             else
      80             :             {
      81           0 :                 return 0L;
      82             :             }
      83             :         }
      84             : 
      85           1 :         EventHandler::EventHandler()
      86             :         {
      87           1 :         }
      88             : 
      89           2 :         EventHandler::~EventHandler()
      90             :         {
      91           2 :             while(!maVector.empty())
      92             :             {
      93           0 :                 delete GetEvent();
      94             :             }
      95           1 :         }
      96             : 
      97             :         // Trigger and consume the events
      98           0 :         void EventHandler::ExecuteEvents()
      99             :         {
     100             :             for(;;)
     101             :             {
     102           0 :                 BaseEvent* pEvent = GetEvent();
     103           0 :                 if(pEvent == NULL)
     104           0 :                     break;
     105           0 :                 pEvent->ExecuteEvent();
     106           0 :                 delete pEvent;
     107           0 :             }
     108           0 :         }
     109             : 
     110             :         // for control
     111           5 :         bool EventHandler::IsEmpty() const
     112             :         {
     113           5 :             return (0L == maVector.size());
     114             :         }
     115             :     } // end of namespace mixer
     116             : } // end of namespace sdr
     117             : 
     118             : 
     119             : 
     120             : namespace sdr
     121             : {
     122             :     namespace event
     123             :     {
     124           1 :         TimerEventHandler::TimerEventHandler(SchedulerPriority ePriority)
     125             :         {
     126           1 :             SetPriority(ePriority);
     127           1 :             Stop();
     128           1 :         }
     129             : 
     130           3 :         TimerEventHandler::~TimerEventHandler()
     131             :         {
     132           1 :             Stop();
     133           2 :         }
     134             : 
     135             :         // The timer when it is triggered; from class Timer
     136           0 :         void TimerEventHandler::Invoke()
     137             :         {
     138           0 :             ExecuteEvents();
     139           0 :         }
     140             : 
     141             :         // reset the timer
     142           3 :         void TimerEventHandler::Restart()
     143             :         {
     144           3 :             Start();
     145           3 :         }
     146             :     } // end of namespace mixer
     147             : } // end of namespace sdr
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11