tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / slideshow / source / engine / activitiesqueue.cxx
blobd03ea8ba25f27f798163a35ce734158b495a038c
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/diagnose_ex.hxx>
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>
31 #include <utility>
34 using namespace ::com::sun::star;
36 namespace slideshow::internal
38 ActivitiesQueue::ActivitiesQueue(
39 std::shared_ptr< ::canvas::tools::ElapsedTime > pPresTimer ) :
40 mpTimer(std::move( pPresTimer )),
41 maCurrentActivitiesWaiting(),
42 maCurrentActivitiesReinsert(),
43 maDequeuedActivities()
47 ActivitiesQueue::~ActivitiesQueue()
49 // dispose all queue entries
50 try
52 for( const auto& pActivity : maCurrentActivitiesWaiting )
53 pActivity->dispose();
54 for( const auto& pActivity : maCurrentTailActivitiesWaiting )
55 pActivity->dispose();
56 for( const auto& pActivity : maCurrentActivitiesReinsert )
57 pActivity->dispose();
59 catch (const uno::Exception&)
61 TOOLS_WARN_EXCEPTION("slideshow", "");
65 bool ActivitiesQueue::addActivity( const ActivitySharedPtr& pActivity )
67 OSL_ENSURE( pActivity, "ActivitiesQueue::addActivity: activity ptr NULL" );
69 if( !pActivity )
70 return false;
72 // add entry to waiting list
73 maCurrentActivitiesWaiting.push_back( pActivity );
75 return true;
78 bool ActivitiesQueue::addTailActivity(const ActivitySharedPtr &pActivity)
80 OSL_ENSURE( pActivity, "ActivitiesQueue::addTailActivity: activity ptr NULL" );
82 if( !pActivity )
83 return false;
85 // Activities that should be processed last are kept in a different
86 // ActivityQueue, and later appended to the end of the maCurrentActivitiesWaiting
87 // on the beginning of ActivitiesQueue::process()
88 maCurrentTailActivitiesWaiting.push_back( pActivity );
90 return true;
93 void ActivitiesQueue::process()
95 SAL_INFO("slideshow.verbose", "ActivitiesQueue: outer loop heartbeat" );
97 // If there are activities to be processed last append them to the end of the ActivitiesQueue
98 maCurrentActivitiesWaiting.insert( maCurrentActivitiesWaiting.end(),
99 maCurrentTailActivitiesWaiting.begin(),
100 maCurrentTailActivitiesWaiting.end() );
101 maCurrentTailActivitiesWaiting.clear();
103 // accumulate time lag for all activities, and lag time
104 // base if necessary:
105 double fLag = 0.0;
106 for ( const auto& rxActivity : maCurrentActivitiesWaiting )
107 fLag = std::max<double>( fLag, rxActivity->calcTimeLag() );
108 if (fLag > 0.0)
110 mpTimer->adjustTimer( -fLag );
113 // process list of activities
114 while( !maCurrentActivitiesWaiting.empty() )
116 // process topmost activity
117 ActivitySharedPtr pActivity( maCurrentActivitiesWaiting.front() );
118 maCurrentActivitiesWaiting.pop_front();
120 bool bReinsert( false );
124 // fire up activity
125 bReinsert = pActivity->perform();
127 catch( uno::RuntimeException& )
129 throw;
131 catch( uno::Exception& )
133 // catch anything here, we don't want
134 // to leave this scope under _any_
135 // circumstance. Although, do _not_
136 // reinsert an activity that threw
137 // once.
139 // NOTE: we explicitly don't catch(...) here,
140 // since this will also capture segmentation
141 // violations and the like. In such a case, we
142 // still better let our clients now...
143 TOOLS_WARN_EXCEPTION( "slideshow", "" );
145 catch( SlideShowException& )
147 // catch anything here, we don't want
148 // to leave this scope under _any_
149 // circumstance. Although, do _not_
150 // reinsert an activity that threw
151 // once.
153 // NOTE: we explicitly don't catch(...) here,
154 // since this will also capture segmentation
155 // violations and the like. In such a case, we
156 // still better let our clients now...
157 SAL_WARN("slideshow", "::presentation::internal::ActivitiesQueue: Activity threw a SlideShowException, removing from ring" );
160 if( bReinsert )
161 maCurrentActivitiesReinsert.push_back( pActivity );
162 else
163 maDequeuedActivities.push_back( pActivity );
165 SAL_INFO("slideshow.verbose", "ActivitiesQueue: inner loop heartbeat" );
168 if( !maCurrentActivitiesReinsert.empty() )
170 // reinsert all processed, but not finished
171 // activities back to waiting queue. With swap(),
172 // we kill two birds with one stone: we reuse the
173 // list nodes, and we clear the
174 // maCurrentActivitiesReinsert list
175 maCurrentActivitiesWaiting.swap( maCurrentActivitiesReinsert );
179 void ActivitiesQueue::processDequeued()
181 // notify all dequeued activities from last round
182 for( const auto& pActivity : maDequeuedActivities )
183 pActivity->dequeued();
184 maDequeuedActivities.clear();
187 bool ActivitiesQueue::isEmpty() const
189 return maCurrentActivitiesWaiting.empty() && maCurrentActivitiesReinsert.empty();
192 void ActivitiesQueue::clear()
194 // dequeue all entries:
195 for( const auto& pActivity : maCurrentActivitiesWaiting )
196 pActivity->dequeued();
197 ActivityQueue().swap( maCurrentActivitiesWaiting );
199 for( const auto& pActivity : maCurrentActivitiesReinsert )
200 pActivity->dequeued();
201 ActivityQueue().swap( maCurrentActivitiesReinsert );
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */