cid#1640468 Dereference after null check
[LibreOffice.git] / forms / source / component / EventThread.hxx
blobdf7b33ee134f35c67fbe13dbc2364283a52d6267
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 #pragma once
22 #include <sal/config.h>
24 #include <memory>
25 #include <mutex>
26 #include <vector>
28 #include <com/sun/star/lang/XEventListener.hpp>
29 #include <com/sun/star/lang/EventObject.hpp>
30 #include <com/sun/star/awt/XControl.hpp>
31 #include <osl/thread.hxx>
32 #include <osl/conditn.hxx>
33 #include <cppuhelper/component.hxx>
34 #include <comphelper/uno3.hxx>
35 #include <rtl/ref.hxx>
38 using namespace comphelper;
41 namespace frm
45 typedef ::osl::Thread OComponentEventThread_TBASE;
46 class OComponentEventThread
47 :public OComponentEventThread_TBASE
48 ,public css::lang::XEventListener
49 ,public ::cppu::OWeakObject
51 typedef std::vector<std::unique_ptr<css::lang::EventObject>> ThreadEvents;
52 typedef std::vector< css::uno::Reference< css::uno::XAdapter> > ThreadObjects;
54 std::mutex m_aMutex;
55 ::osl::Condition m_aCond; // Queue filled?
56 ThreadEvents m_aEvents; // EventQueue
57 ThreadObjects m_aControls; // Control for Submit
58 std::vector<bool> m_aFlags; // Flags for Submit/Reset
60 rtl::Reference<::cppu::OComponentHelper> m_xComp; // Implementation of the Control
62 protected:
64 // XThread
65 virtual void SAL_CALL run() override;
67 virtual void SAL_CALL onTerminated() override;
69 // Edit an Event:
70 // The mutex is not locked, but pCompImpl stays valid in any case.
71 // pEvt can be a derived type, namely the one that cloneEvent returns.
72 // rControl is only set, if a Control has been passed in addEvent.
73 // Because the Control is only held as a WeakRef, it can disappear in the meantime.
74 virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
75 const css::lang::EventObject* _pEvt,
76 const css::uno::Reference< css::awt::XControl>& _rControl,
77 bool _bFlag) = 0;
79 public:
81 // UNO binding
82 DECLARE_UNO3_DEFAULTS(OComponentEventThread, OWeakObject)
83 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override;
85 explicit OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
86 virtual ~OComponentEventThread() override;
88 void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt );
89 void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt, const css::uno::Reference< css::awt::XControl>& rControl,
90 bool bFlag = false );
92 // css::lang::XEventListener
93 virtual void SAL_CALL disposing(const css::lang::EventObject& _rSource ) override;
95 // Resolve ambiguity: both OWeakObject and osl::Thread have these memory operators
96 using osl::Thread::operator new;
97 using osl::Thread::operator delete;
99 private:
100 void impl_clearEventQueue();
104 } // namespace frm
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */