1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <comphelper/anytostring.hxx>
22 #include <cppuhelper/exc_hlp.hxx>
23 #include <osl/diagnose.h>
25 #include <slideshowexceptions.hxx>
26 #include <activity.hxx>
27 #include <activitiesqueue.hxx>
33 using namespace ::com::sun::star
;
39 ActivitiesQueue::ActivitiesQueue(
40 const std::shared_ptr
< ::canvas::tools::ElapsedTime
>& pPresTimer
) :
41 mpTimer( pPresTimer
),
42 maCurrentActivitiesWaiting(),
43 maCurrentActivitiesReinsert(),
44 maDequeuedActivities()
48 ActivitiesQueue::~ActivitiesQueue()
50 // dispose all queue entries
53 for( const auto& pActivity
: maCurrentActivitiesWaiting
)
55 for( const auto& pActivity
: maCurrentActivitiesReinsert
)
58 catch (const uno::Exception
& e
)
60 SAL_WARN("slideshow", e
);
64 bool ActivitiesQueue::addActivity( const ActivitySharedPtr
& pActivity
)
66 OSL_ENSURE( pActivity
, "ActivitiesQueue::addActivity: activity ptr NULL" );
71 // add entry to waiting list
72 maCurrentActivitiesWaiting
.push_back( pActivity
);
77 void ActivitiesQueue::process()
79 SAL_INFO("slideshow.verbose", "ActivitiesQueue: outer loop heartbeat" );
81 // accumulate time lag for all activities, and lag time
83 ActivityQueue::const_iterator
iPos(
84 maCurrentActivitiesWaiting
.begin() );
85 const ActivityQueue::const_iterator
iEnd(
86 maCurrentActivitiesWaiting
.end() );
88 for ( ; iPos
!= iEnd
; ++iPos
)
89 fLag
= std::max
<double>( fLag
, (*iPos
)->calcTimeLag() );
92 mpTimer
->adjustTimer( -fLag
);
95 // process list of activities
96 while( !maCurrentActivitiesWaiting
.empty() )
98 // process topmost activity
99 ActivitySharedPtr
pActivity( maCurrentActivitiesWaiting
.front() );
100 maCurrentActivitiesWaiting
.pop_front();
102 bool bReinsert( false );
107 bReinsert
= pActivity
->perform();
109 catch( uno::RuntimeException
& )
113 catch( uno::Exception
& )
115 // catch anything here, we don't want
116 // to leave this scope under _any_
117 // circumstance. Although, do _not_
118 // reinsert an activity that threw
121 // NOTE: we explicitly don't catch(...) here,
122 // since this will also capture segmentation
123 // violations and the like. In such a case, we
124 // still better let our clients now...
125 SAL_WARN( "slideshow", comphelper::anyToString( cppu::getCaughtException() ) );
127 catch( SlideShowException
& )
129 // catch anything here, we don't want
130 // to leave this scope under _any_
131 // circumstance. Although, do _not_
132 // reinsert an activity that threw
135 // NOTE: we explicitly don't catch(...) here,
136 // since this will also capture segmentation
137 // violations and the like. In such a case, we
138 // still better let our clients now...
139 SAL_WARN("slideshow", "::presentation::internal::ActivitiesQueue: Activity threw a SlideShowException, removing from ring" );
143 maCurrentActivitiesReinsert
.push_back( pActivity
);
145 maDequeuedActivities
.push_back( pActivity
);
147 SAL_INFO("slideshow.verbose", "ActivitiesQueue: inner loop heartbeat" );
150 if( !maCurrentActivitiesReinsert
.empty() )
152 // reinsert all processed, but not finished
153 // activities back to waiting queue. With swap(),
154 // we kill two birds with one stone: we reuse the
155 // list nodes, and we clear the
156 // maCurrentActivitiesReinsert list
157 maCurrentActivitiesWaiting
.swap( maCurrentActivitiesReinsert
);
161 void ActivitiesQueue::processDequeued()
163 // notify all dequeued activities from last round
164 for( const auto& pActivity
: maDequeuedActivities
)
165 pActivity
->dequeued();
166 maDequeuedActivities
.clear();
169 bool ActivitiesQueue::isEmpty() const
171 return maCurrentActivitiesWaiting
.empty() && maCurrentActivitiesReinsert
.empty();
174 void ActivitiesQueue::clear()
176 // dequeue all entries:
177 for( const auto& pActivity
: maCurrentActivitiesWaiting
)
178 pActivity
->dequeued();
179 ActivityQueue().swap( maCurrentActivitiesWaiting
);
181 for( const auto& pActivity
: maCurrentActivitiesReinsert
)
182 pActivity
->dequeued();
183 ActivityQueue().swap( maCurrentActivitiesReinsert
);
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */