sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / source / app / salusereventlist.cxx
blobc677ff56a411cd00eac66287d53bee7c05bbc226
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 .
20 #include <salusereventlist.hxx>
21 #include <salwtype.hxx>
23 #include <algorithm>
24 #include <cstdlib>
25 #include <exception>
26 #include <typeinfo>
28 #include <com/sun/star/uno/Exception.hpp>
29 #include <tools/debug.hxx>
30 #include <comphelper/diagnose_ex.hxx>
31 #include <sal/log.hxx>
32 #include <sal/types.h>
33 #include <svdata.hxx>
35 SalUserEventList::SalUserEventList()
36 : m_bAllUserEventProcessedSignaled( true )
37 , m_aProcessingThread(0)
41 SalUserEventList::~SalUserEventList() COVERITY_NOEXCEPT_FALSE
45 void SalUserEventList::insertFrame( SalFrame* pFrame )
47 auto aPair = m_aFrames.insert( pFrame );
48 assert( aPair.second ); (void) aPair;
51 void SalUserEventList::eraseFrame( SalFrame* pFrame )
53 auto it = m_aFrames.find( pFrame );
54 assert( it != m_aFrames.end() );
55 if ( it != m_aFrames.end() )
56 m_aFrames.erase( it );
59 bool SalUserEventList::DispatchUserEvents( bool bHandleAllCurrentEvents )
61 bool bWasEvent = false;
62 oslThreadIdentifier aCurId = osl::Thread::getCurrentIdentifier();
64 DBG_TESTSOLARMUTEX();
65 std::unique_lock aResettableListGuard(m_aUserEventsMutex);
67 if (!m_aUserEvents.empty())
69 if (bHandleAllCurrentEvents)
71 if (m_aProcessingUserEvents.empty())
72 m_aProcessingUserEvents.swap(m_aUserEvents);
73 else
74 m_aProcessingUserEvents.splice(m_aProcessingUserEvents.end(), m_aUserEvents);
76 else if (m_aProcessingUserEvents.empty())
78 m_aProcessingUserEvents.push_back( m_aUserEvents.front() );
79 m_aUserEvents.pop_front();
83 if (HasUserEvents_NoLock())
85 bWasEvent = true;
86 m_aProcessingThread = aCurId;
88 SalUserEvent aEvent( nullptr, nullptr, SalEvent::NONE );
89 do {
90 if (m_aProcessingUserEvents.empty() || aCurId != m_aProcessingThread)
91 break;
92 aEvent = m_aProcessingUserEvents.front();
93 m_aProcessingUserEvents.pop_front();
95 // remember to reset the guard before break or continue the loop
96 aResettableListGuard.unlock();
98 if ( !isFrameAlive( aEvent.m_pFrame ) )
100 if ( aEvent.m_nEvent == SalEvent::UserEvent )
101 delete static_cast< ImplSVEvent* >( aEvent.m_pData );
102 aResettableListGuard.lock();
103 continue;
107 * Current policy is that scheduler tasks aren't allowed to throw an exception.
108 * Because otherwise the exception is caught somewhere totally unrelated.
109 * TODO Ideally we could capture a proper backtrace and feed this into breakpad,
110 * which is do-able, but requires writing some assembly.
111 * See also Scheduler::CallbackTaskScheduling
113 #ifdef IOS
114 ProcessEvent( aEvent );
115 #else
116 // the noexcept here means that (a) we abort and (b) debuggers will
117 // likely trigger at the throw site instead of here, making the debugging
118 // experience better when something goes wrong.
119 auto process = [&aEvent, this] () noexcept { ProcessEvent(aEvent); };
120 process();
121 #endif
122 aResettableListGuard.lock();
123 if (!bHandleAllCurrentEvents)
124 break;
126 while( true );
129 if ( !m_bAllUserEventProcessedSignaled && !HasUserEvents_NoLock() )
131 m_bAllUserEventProcessedSignaled = true;
132 TriggerAllUserEventsProcessed();
135 return bWasEvent;
138 void SalUserEventList::RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
140 SalUserEvent aEvent( pFrame, pData, nEvent );
142 std::unique_lock aGuard( m_aUserEventsMutex );
143 auto it = std::find( m_aUserEvents.begin(), m_aUserEvents.end(), aEvent );
144 if ( it != m_aUserEvents.end() )
146 m_aUserEvents.erase( it );
148 else
150 it = std::find( m_aProcessingUserEvents.begin(), m_aProcessingUserEvents.end(), aEvent );
151 if ( it != m_aProcessingUserEvents.end() )
153 m_aProcessingUserEvents.erase( it );
157 if ( !m_bAllUserEventProcessedSignaled && !HasUserEvents_NoLock() )
159 m_bAllUserEventProcessedSignaled = true;
160 TriggerAllUserEventsProcessed();
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */