LibreOffice Module vcl (master)  1
salusereventlist.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 #include <salusereventlist.hxx>
21 #include <salwtype.hxx>
22 
23 #include <algorithm>
24 #include <cstdlib>
25 #include <exception>
26 #include <typeinfo>
27 
28 #include <com/sun/star/uno/Exception.hpp>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <sal/log.hxx>
32 #include <sal/types.h>
33 #include <svdata.hxx>
34 
36  : m_bAllUserEventProcessedSignaled( true )
37  , m_aProcessingThread(0)
38 {
39 }
40 
41 SalUserEventList::~SalUserEventList() COVERITY_NOEXCEPT_FALSE
42 {
43 }
44 
46 {
47  auto aPair = m_aFrames.insert( pFrame );
48  assert( aPair.second ); (void) aPair;
49 }
50 
52 {
53  auto it = m_aFrames.find( pFrame );
54  assert( it != m_aFrames.end() );
55  if ( it != m_aFrames.end() )
56  m_aFrames.erase( it );
57 }
58 
59 bool SalUserEventList::DispatchUserEvents( bool bHandleAllCurrentEvents )
60 {
61  bool bWasEvent = false;
62  oslThreadIdentifier aCurId = osl::Thread::getCurrentIdentifier();
63 
65  osl::ResettableMutexGuard aResettableListGuard(m_aUserEventsMutex);
66 
67  if (!m_aUserEvents.empty())
68  {
69  if (bHandleAllCurrentEvents)
70  {
71  if (m_aProcessingUserEvents.empty())
73  else
75  }
76  else if (m_aProcessingUserEvents.empty())
77  {
78  m_aProcessingUserEvents.push_back( m_aUserEvents.front() );
79  m_aUserEvents.pop_front();
80  }
81  }
82 
83  if (HasUserEvents())
84  {
85  bWasEvent = true;
86  m_aProcessingThread = aCurId;
87 
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();
94 
95  // remember to reset the guard before break or continue the loop
96  aResettableListGuard.clear();
97 
98  if ( !isFrameAlive( aEvent.m_pFrame ) )
99  {
100  if ( aEvent.m_nEvent == SalEvent::UserEvent )
101  delete static_cast< ImplSVEvent* >( aEvent.m_pData );
102  aResettableListGuard.reset();
103  continue;
104  }
105 
106  try
107  {
108  ProcessEvent( aEvent );
109  }
110  catch (css::uno::Exception&)
111  {
112  TOOLS_WARN_EXCEPTION("vcl", "Uncaught");
113  std::abort();
114  }
115  catch (std::exception& e)
116  {
117  SAL_WARN("vcl", "Uncaught " << typeid(e).name() << " " << e.what());
118  std::abort();
119  }
120  catch (...)
121  {
122  SAL_WARN("vcl", "Uncaught exception during DispatchUserEvents!");
123  std::abort();
124  }
125  aResettableListGuard.reset();
126  if (!bHandleAllCurrentEvents)
127  break;
128  }
129  while( true );
130  }
131 
133  {
136  }
137 
138  return bWasEvent;
139 }
140 
141 void SalUserEventList::RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
142 {
143  SalUserEvent aEvent( pFrame, pData, nEvent );
144 
145  osl::MutexGuard aGuard( m_aUserEventsMutex );
146  auto it = std::find( m_aUserEvents.begin(), m_aUserEvents.end(), aEvent );
147  if ( it != m_aUserEvents.end() )
148  {
149  m_aUserEvents.erase( it );
150  }
151  else
152  {
153  it = std::find( m_aProcessingUserEvents.begin(), m_aProcessingUserEvents.end(), aEvent );
154  if ( it != m_aProcessingUserEvents.end() )
155  {
156  m_aProcessingUserEvents.erase( it );
157  }
158  }
159 
161  {
164  }
165 }
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void insertFrame(SalFrame *pFrame)
std::list< SalUserEvent > m_aProcessingUserEvents
virtual ~SalUserEventList() COVERITY_NOEXCEPT_FALSE
std::list< SalUserEvent > m_aUserEvents
virtual void TriggerAllUserEventsProcessed()
#define TOOLS_WARN_EXCEPTION(area, stream)
osl::Mutex m_aUserEventsMutex
bool DispatchUserEvents(bool bHandleAllCurrentEvents)
virtual void ProcessEvent(SalUserEvent aEvent)=0
bool HasUserEvents() const
void RemoveEvent(SalFrame *pFrame, void *pData, SalEvent nEvent)
SalEvent
Definition: salwtype.hxx:40
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
void eraseFrame(SalFrame *pFrame)
bool isFrameAlive(const SalFrame *pFrame) const
bool m_bAllUserEventProcessedSignaled
const char * name
#define SAL_WARN(area, stream)
#define DBG_TESTSOLARMUTEX()
oslThreadIdentifier m_aProcessingThread
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo