Bump version to 6.4-15
[LibreOffice.git] / slideshow / source / engine / activitiesqueue.cxx
blob3181e92175ff0ea3cf5c3bb8c84711e1e8a3e02e
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 <tools/diagnose_ex.h>
22 #include <osl/diagnose.h>
23 #include <sal/log.hxx>
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 (const uno::Exception&)
60 TOOLS_WARN_EXCEPTION("slideshow", "");
64 bool ActivitiesQueue::addActivity( const ActivitySharedPtr& pActivity )
66 OSL_ENSURE( pActivity, "ActivitiesQueue::addActivity: activity ptr NULL" );
68 if( !pActivity )
69 return false;
71 // add entry to waiting list
72 maCurrentActivitiesWaiting.push_back( pActivity );
74 return true;
77 void ActivitiesQueue::process()
79 SAL_INFO("slideshow.verbose", "ActivitiesQueue: outer loop heartbeat" );
81 // accumulate time lag for all activities, and lag time
82 // base if necessary:
83 double fLag = 0.0;
84 for ( const auto& rxActivity : maCurrentActivitiesWaiting )
85 fLag = std::max<double>( fLag, rxActivity->calcTimeLag() );
86 if (fLag > 0.0)
88 mpTimer->adjustTimer( -fLag );
91 // process list of activities
92 while( !maCurrentActivitiesWaiting.empty() )
94 // process topmost activity
95 ActivitySharedPtr pActivity( maCurrentActivitiesWaiting.front() );
96 maCurrentActivitiesWaiting.pop_front();
98 bool bReinsert( false );
102 // fire up activity
103 bReinsert = pActivity->perform();
105 catch( uno::RuntimeException& )
107 throw;
109 catch( uno::Exception& )
111 // catch anything here, we don't want
112 // to leave this scope under _any_
113 // circumstance. Although, do _not_
114 // reinsert an activity that threw
115 // once.
117 // NOTE: we explicitly don't catch(...) here,
118 // since this will also capture segmentation
119 // violations and the like. In such a case, we
120 // still better let our clients now...
121 TOOLS_WARN_EXCEPTION( "slideshow", "" );
123 catch( SlideShowException& )
125 // catch anything here, we don't want
126 // to leave this scope under _any_
127 // circumstance. Although, do _not_
128 // reinsert an activity that threw
129 // once.
131 // NOTE: we explicitly don't catch(...) here,
132 // since this will also capture segmentation
133 // violations and the like. In such a case, we
134 // still better let our clients now...
135 SAL_WARN("slideshow", "::presentation::internal::ActivitiesQueue: Activity threw a SlideShowException, removing from ring" );
138 if( bReinsert )
139 maCurrentActivitiesReinsert.push_back( pActivity );
140 else
141 maDequeuedActivities.push_back( pActivity );
143 SAL_INFO("slideshow.verbose", "ActivitiesQueue: inner loop heartbeat" );
146 if( !maCurrentActivitiesReinsert.empty() )
148 // reinsert all processed, but not finished
149 // activities back to waiting queue. With swap(),
150 // we kill two birds with one stone: we reuse the
151 // list nodes, and we clear the
152 // maCurrentActivitiesReinsert list
153 maCurrentActivitiesWaiting.swap( maCurrentActivitiesReinsert );
157 void ActivitiesQueue::processDequeued()
159 // notify all dequeued activities from last round
160 for( const auto& pActivity : maDequeuedActivities )
161 pActivity->dequeued();
162 maDequeuedActivities.clear();
165 bool ActivitiesQueue::isEmpty() const
167 return maCurrentActivitiesWaiting.empty() && maCurrentActivitiesReinsert.empty();
170 void ActivitiesQueue::clear()
172 // dequeue all entries:
173 for( const auto& pActivity : maCurrentActivitiesWaiting )
174 pActivity->dequeued();
175 ActivityQueue().swap( maCurrentActivitiesWaiting );
177 for( const auto& pActivity : maCurrentActivitiesReinsert )
178 pActivity->dequeued();
179 ActivityQueue().swap( maCurrentActivitiesReinsert );
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */