LibreOffice Module slideshow (master) 1
activitiesqueue.cxx
Go to the documentation of this file.
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
22#include <osl/diagnose.h>
23#include <sal/log.hxx>
24
26#include <activity.hxx>
27#include <activitiesqueue.hxx>
28
29#include <algorithm>
30#include <memory>
31#include <utility>
32
33
34using namespace ::com::sun::star;
35
36namespace slideshow::internal
37{
39 std::shared_ptr< ::canvas::tools::ElapsedTime > pPresTimer ) :
40 mpTimer(std::move( pPresTimer )),
41 maCurrentActivitiesWaiting(),
42 maCurrentActivitiesReinsert(),
43 maDequeuedActivities()
44 {
45 }
46
48 {
49 // dispose all queue entries
50 try
51 {
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();
58 }
59 catch (const uno::Exception&)
60 {
61 TOOLS_WARN_EXCEPTION("slideshow", "");
62 }
63 }
64
66 {
67 OSL_ENSURE( pActivity, "ActivitiesQueue::addActivity: activity ptr NULL" );
68
69 if( !pActivity )
70 return false;
71
72 // add entry to waiting list
73 maCurrentActivitiesWaiting.push_back( pActivity );
74
75 return true;
76 }
77
79 {
80 OSL_ENSURE( pActivity, "ActivitiesQueue::addTailActivity: activity ptr NULL" );
81
82 if( !pActivity )
83 return false;
84
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 );
89
90 return true;
91 }
92
94 {
95 SAL_INFO("slideshow.verbose", "ActivitiesQueue: outer loop heartbeat" );
96
97 // If there are activities to be processed last append them to the end of the ActivitiesQueue
102
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)
109 {
110 mpTimer->adjustTimer( -fLag );
111 }
112
113 // process list of activities
114 while( !maCurrentActivitiesWaiting.empty() )
115 {
116 // process topmost activity
118 maCurrentActivitiesWaiting.pop_front();
119
120 bool bReinsert( false );
121
122 try
123 {
124 // fire up activity
125 bReinsert = pActivity->perform();
126 }
127 catch( uno::RuntimeException& )
128 {
129 throw;
130 }
131 catch( uno::Exception& )
132 {
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.
138
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", "" );
144 }
145 catch( SlideShowException& )
146 {
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.
152
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" );
158 }
159
160 if( bReinsert )
161 maCurrentActivitiesReinsert.push_back( pActivity );
162 else
163 maDequeuedActivities.push_back( pActivity );
164
165 SAL_INFO("slideshow.verbose", "ActivitiesQueue: inner loop heartbeat" );
166 }
167
168 if( !maCurrentActivitiesReinsert.empty() )
169 {
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
176 }
177 }
178
180 {
181 // notify all dequeued activities from last round
182 for( const auto& pActivity : maDequeuedActivities )
183 pActivity->dequeued();
184 maDequeuedActivities.clear();
185 }
186
188 {
190 }
191
193 {
194 // dequeue all entries:
195 for( const auto& pActivity : maCurrentActivitiesWaiting )
196 pActivity->dequeued();
198
199 for( const auto& pActivity : maCurrentActivitiesReinsert )
200 pActivity->dequeued();
202 }
203}
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool addActivity(const ActivitySharedPtr &pActivity)
Add the given activity to the queue.
void processDequeued()
Call all dequeued activities' dequeued() method.
ActivitiesQueue(std::shared_ptr< ::canvas::tools::ElapsedTime > pPresTimer)
Create an ActivitiesQueue.
bool isEmpty() const
Query state of the queue.
bool addTailActivity(const ActivitySharedPtr &pActivity)
Add the given activity prioritized last in the queue.
::std::deque< ActivitySharedPtr > ActivityQueue
std::shared_ptr< ::canvas::tools::ElapsedTime > mpTimer
void clear()
Remove all pending activities from the queue.
void process()
Process the activities queue.
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
::std::shared_ptr< Activity > ActivitySharedPtr
Definition: activity.hxx:83