LCOV - code coverage report
Current view: top level - slideshow/source/inc - eventqueue.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 4 0.0 %
Date: 2012-08-25 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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                 :            : #ifndef INCLUDED_SLIDESHOW_EVENTQUEUE_HXX
      21                 :            : #define INCLUDED_SLIDESHOW_EVENTQUEUE_HXX
      22                 :            : 
      23                 :            : #include <canvas/elapsedtime.hxx>
      24                 :            : #include <osl/mutex.hxx>
      25                 :            : 
      26                 :            : #include "event.hxx"
      27                 :            : 
      28                 :            : #include <boost/noncopyable.hpp>
      29                 :            : #include <functional>
      30                 :            : #include <queue>
      31                 :            : #include <vector>
      32                 :            : 
      33                 :            : 
      34                 :            : /* Definition of ActivitiesQueue class */
      35                 :            : 
      36                 :            : namespace slideshow
      37                 :            : {
      38                 :            :     namespace internal
      39                 :            :     {
      40                 :            :         /** This class handles events in a presentation. Events are
      41                 :            :             time instants where e.g. effects start.
      42                 :            :          */
      43                 :            :         class EventQueue : private ::boost::noncopyable
      44                 :            :         {
      45                 :            :         public:
      46                 :            :             EventQueue(
      47                 :            :                 ::boost::shared_ptr< ::canvas::tools::ElapsedTime >
      48                 :            :                 const & pPresTimer );
      49                 :            : 
      50                 :            :             ~EventQueue();
      51                 :            : 
      52                 :            :             /** Add the given event to the queue. The event is fired
      53                 :            :                 at, or shortly after, its Event::getActivationTime instant.
      54                 :            :              */
      55                 :            :             bool addEvent( const EventSharedPtr& event );
      56                 :            : 
      57                 :            :             /** Add the given event to the queue. The event is fired
      58                 :            :                 at, or shortly after, its Event::getActivationTime instant.
      59                 :            :                 The difference to addEvent() is that events added during
      60                 :            :                 process() are postponed to next process().
      61                 :            :              */
      62                 :            :             bool addEventForNextRound( const EventSharedPtr& event );
      63                 :            : 
      64                 :            :             /** Another way to control the order of asynchronous event
      65                 :            :                 exeqution.  Use this method to schedule events that are to
      66                 :            :                 be executed after all regular events that have no delay,
      67                 :            :                 even when they schedule new regular events without delay.
      68                 :            :             */
      69                 :            :             bool addEventWhenQueueIsEmpty (const EventSharedPtr& rpEvent);
      70                 :            : 
      71                 :            :             /** Process the event queue.
      72                 :            : 
      73                 :            :                 This method executes all events whose timeout has
      74                 :            :                 expired when calling this method (i.e. all events
      75                 :            :                 whose scheduled time is less or equal the current
      76                 :            :                 time).
      77                 :            : 
      78                 :            :                 Check for the next available event's timeout via
      79                 :            :                 nextTimeout(), or whether the queue is empty
      80                 :            :                 altogether via isEmpty().
      81                 :            :              */
      82                 :            :             void process();
      83                 :            : 
      84                 :            :             /** Query state of the queue
      85                 :            : 
      86                 :            :                 @return false, if queue is empty, true otherwise
      87                 :            :              */
      88                 :            :             bool isEmpty() const;
      89                 :            : 
      90                 :            :             /** Query timeout for the topmost event in the queue.
      91                 :            : 
      92                 :            :                 @return Timeout in seconds, until the next event is
      93                 :            :                 ready. The time returned here is relative to the pres
      94                 :            :                 timer (i.e. the timer specified at the EventQueue
      95                 :            :                 constructor). When the queue is empty (i.e. isEmpty()
      96                 :            :                 returns true), the returned value is the highest
      97                 :            :                 representable double value
      98                 :            :                 (::std::numeric_limits<double>::max()). If the topmost
      99                 :            :                 event in the queue is already pending, the timeout
     100                 :            :                 returned here will actually be negative.
     101                 :            :             */
     102                 :            :             double nextTimeout() const;
     103                 :            : 
     104                 :            :             /** Remove all pending events from the queue.
     105                 :            :              */
     106                 :            :             void clear();
     107                 :            : 
     108                 :            :             /** Forces an empty queue, firing all events immediately
     109                 :            :                 without minding any times.
     110                 :            :                 @attention do only call from event loop, this calls process_()!
     111                 :            :              */
     112                 :            :             void forceEmpty();
     113                 :            : 
     114                 :            :             /** Gets the queue's timer object.
     115                 :            :              */
     116                 :            :             ::boost::shared_ptr< ::canvas::tools::ElapsedTime > const &
     117                 :          0 :             getTimer() const { return mpTimer; }
     118                 :            : 
     119                 :            :         private:
     120                 :            :             mutable ::osl::Mutex      maMutex;
     121                 :            : 
     122                 :          0 :             struct EventEntry : public ::std::unary_function<EventEntry, bool>
     123                 :            :             {
     124                 :            :                 EventSharedPtr  pEvent;
     125                 :            :                 double          nTime;
     126                 :            : 
     127                 :            :                 bool operator<( const EventEntry& ) const; // to leverage priority_queue's default compare
     128                 :            : 
     129                 :          0 :                 EventEntry( EventSharedPtr const& p, double t )
     130                 :          0 :                     : pEvent(p), nTime(t) {}
     131                 :            :             };
     132                 :            : 
     133                 :            :             typedef ::std::priority_queue< EventEntry > ImplQueueType;
     134                 :            :             ImplQueueType                   maEvents;
     135                 :            :             typedef ::std::vector<EventEntry> EventEntryVector;
     136                 :            :             EventEntryVector                maNextEvents;
     137                 :            :             ImplQueueType                   maNextNextEvents;
     138                 :            :             void process_( bool bFireAllEvents );
     139                 :            : 
     140                 :            :             // perform timing of events via relative time
     141                 :            :             // measurements. The world time starts, when the
     142                 :            :             // EventQueue object is created
     143                 :            :             ::boost::shared_ptr< ::canvas::tools::ElapsedTime > mpTimer;
     144                 :            :         };
     145                 :            : 
     146                 :            :     }
     147                 :            : }
     148                 :            : #endif /* INCLUDED_SLIDESHOW_EVENTQUEUE_HXX */
     149                 :            : 
     150                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10