LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / component / EventThread.hxx
blob20aff73113dbd6d0623188157444004bd4d94558
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 <vector>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <com/sun/star/lang/EventObject.hpp>
29 #include <com/sun/star/awt/XControl.hpp>
30 #include <osl/thread.hxx>
31 #include <osl/conditn.hxx>
32 #include <cppuhelper/component.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <rtl/ref.hxx>
37 using namespace comphelper;
40 namespace frm
44 typedef ::osl::Thread OComponentEventThread_TBASE;
45 class OComponentEventThread
46 :public OComponentEventThread_TBASE
47 ,public css::lang::XEventListener
48 ,public ::cppu::OWeakObject
50 typedef std::vector<std::unique_ptr<css::lang::EventObject>> ThreadEvents;
51 typedef std::vector< css::uno::Reference< css::uno::XAdapter> > ThreadObjects;
53 ::osl::Mutex m_aMutex;
54 ::osl::Condition m_aCond; // Queue filled?
55 ThreadEvents m_aEvents; // EventQueue
56 ThreadObjects m_aControls; // Control for Submit
57 std::vector<bool> m_aFlags; // Flags for Submit/Reset
59 rtl::Reference<::cppu::OComponentHelper> m_xComp; // Implementation of the Control
61 protected:
63 // XThread
64 virtual void SAL_CALL run() override;
66 virtual void SAL_CALL onTerminated() override;
68 // Edit an Event:
69 // The mutex is not locked, but pCompImpl stays valid in any case.
70 // pEvt can be a derived type, namely the one that cloneEvent returns.
71 // rControl is only set, if a Control has been passed in addEvent.
72 // Because the Control is only held as a WeakRef, it can disappear in the meantime.
73 virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
74 const css::lang::EventObject* _pEvt,
75 const css::uno::Reference< css::awt::XControl>& _rControl,
76 bool _bFlag) = 0;
78 public:
80 // UNO binding
81 DECLARE_UNO3_DEFAULTS(OComponentEventThread, OWeakObject)
82 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override;
84 explicit OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
85 virtual ~OComponentEventThread() override;
87 void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt );
88 void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt, const css::uno::Reference< css::awt::XControl>& rControl,
89 bool bFlag = false );
91 // css::lang::XEventListener
92 virtual void SAL_CALL disposing(const css::lang::EventObject& _rSource ) override;
94 // Resolve ambiguity: both OWeakObject and osl::Thread have these memory operators
95 using osl::Thread::operator new;
96 using osl::Thread::operator delete;
98 private:
99 void impl_clearEventQueue();
103 } // namespace frm
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */