build fix
[LibreOffice.git] / slideshow / source / engine / activitiesqueue.cxx
blobdab919003daae55cf42889939e726ffabc795d46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
29 #include <algorithm>
30 #include <memory>
33 using namespace ::com::sun::star;
35 namespace slideshow
37 namespace internal
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
51 try
53 for( const auto& pActivity : maCurrentActivitiesWaiting )
54 pActivity->dispose();
55 for( const auto& pActivity : maCurrentActivitiesReinsert )
56 pActivity->dispose();
58 catch (uno::Exception &)
60 OSL_FAIL( OUStringToOString(
61 comphelper::anyToString(
62 cppu::getCaughtException() ),
63 RTL_TEXTENCODING_UTF8 ).getStr() );
67 bool ActivitiesQueue::addActivity( const ActivitySharedPtr& pActivity )
69 OSL_ENSURE( pActivity, "ActivitiesQueue::addActivity: activity ptr NULL" );
71 if( !pActivity )
72 return false;
74 // add entry to waiting list
75 maCurrentActivitiesWaiting.push_back( pActivity );
77 return true;
80 void ActivitiesQueue::process()
82 SAL_INFO("slideshow.verbose", "ActivitiesQueue: outer loop heartbeat" );
84 // accumulate time lag for all activities, and lag time
85 // base if necessary:
86 ActivityQueue::const_iterator iPos(
87 maCurrentActivitiesWaiting.begin() );
88 const ActivityQueue::const_iterator iEnd(
89 maCurrentActivitiesWaiting.end() );
90 double fLag = 0.0;
91 for ( ; iPos != iEnd; ++iPos )
92 fLag = std::max<double>( fLag, (*iPos)->calcTimeLag() );
93 if (fLag > 0.0)
95 mpTimer->adjustTimer( -fLag );
98 // process list of activities
99 while( !maCurrentActivitiesWaiting.empty() )
101 // process topmost activity
102 ActivitySharedPtr pActivity( maCurrentActivitiesWaiting.front() );
103 maCurrentActivitiesWaiting.pop_front();
105 bool bReinsert( false );
109 // fire up activity
110 bReinsert = pActivity->perform();
112 catch( uno::RuntimeException& )
114 throw;
116 catch( uno::Exception& )
118 // catch anything here, we don't want
119 // to leave this scope under _any_
120 // circumstance. Although, do _not_
121 // reinsert an activity that threw
122 // once.
124 // NOTE: we explicitly don't catch(...) here,
125 // since this will also capture segmentation
126 // violations and the like. In such a case, we
127 // still better let our clients now...
128 OSL_FAIL( OUStringToOString(
129 comphelper::anyToString( cppu::getCaughtException() ),
130 RTL_TEXTENCODING_UTF8 ).getStr() );
132 catch( SlideShowException& )
134 // catch anything here, we don't want
135 // to leave this scope under _any_
136 // circumstance. Although, do _not_
137 // reinsert an activity that threw
138 // once.
140 // NOTE: we explicitly don't catch(...) here,
141 // since this will also capture segmentation
142 // violations and the like. In such a case, we
143 // still better let our clients now...
144 OSL_TRACE( "::presentation::internal::ActivitiesQueue: Activity threw a SlideShowException, removing from ring" );
147 if( bReinsert )
148 maCurrentActivitiesReinsert.push_back( pActivity );
149 else
150 maDequeuedActivities.push_back( pActivity );
152 SAL_INFO("slideshow.verbose", "ActivitiesQueue: inner loop heartbeat" );
155 if( !maCurrentActivitiesReinsert.empty() )
157 // reinsert all processed, but not finished
158 // activities back to waiting queue. With swap(),
159 // we kill two birds with one stone: we reuse the
160 // list nodes, and we clear the
161 // maCurrentActivitiesReinsert list
162 maCurrentActivitiesWaiting.swap( maCurrentActivitiesReinsert );
166 void ActivitiesQueue::processDequeued()
168 // notify all dequeued activities from last round
169 for( const auto& pActivity : maDequeuedActivities )
170 pActivity->dequeued();
171 maDequeuedActivities.clear();
174 bool ActivitiesQueue::isEmpty() const
176 return maCurrentActivitiesWaiting.empty() && maCurrentActivitiesReinsert.empty();
179 void ActivitiesQueue::clear()
181 // dequeue all entries:
182 for( const auto& pActivity : maCurrentActivitiesWaiting )
183 pActivity->dequeued();
184 ActivityQueue().swap( maCurrentActivitiesWaiting );
186 for( const auto& pActivity : maCurrentActivitiesReinsert )
187 pActivity->dequeued();
188 ActivityQueue().swap( maCurrentActivitiesReinsert );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */