Line data Source code
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 : #ifndef _FRM_EVENT_THREAD_HXX_
21 : #define _FRM_EVENT_THREAD_HXX_
22 :
23 : #include <com/sun/star/lang/XEventListener.hpp>
24 : #include <com/sun/star/lang/EventObject.hpp>
25 : #include <com/sun/star/lang/XComponent.hpp>
26 : #include <com/sun/star/awt/XControl.hpp>
27 : #include <osl/thread.hxx>
28 :
29 :
30 : #include <osl/conditn.hxx>
31 : #include <cppuhelper/component.hxx>
32 : #include <comphelper/stl_types.hxx>
33 : #include <comphelper/uno3.hxx>
34 : using namespace comphelper;
35 :
36 : //.........................................................................
37 : namespace frm
38 : {
39 : //.........................................................................
40 :
41 : // ***************************************************************************************************
42 : // ***************************************************************************************************
43 :
44 : typedef ::osl::Thread OComponentEventThread_TBASE;
45 : class OComponentEventThread
46 : :public OComponentEventThread_TBASE
47 : ,public ::com::sun::star::lang::XEventListener
48 : ,public ::cppu::OWeakObject
49 : {
50 : DECLARE_STL_VECTOR(::com::sun::star::lang::EventObject*, ThreadEvents);
51 : DECLARE_STL_VECTOR(::com::sun::star::uno::Reference< ::com::sun::star::uno::XAdapter> , ThreadObjects);
52 : DECLARE_STL_VECTOR(sal_Bool, ThreadBools);
53 :
54 : ::osl::Mutex m_aMutex;
55 : ::osl::Condition m_aCond; // Queue filled?
56 : ThreadEvents m_aEvents; // EventQueue
57 : ThreadObjects m_aControls; // Control for Submit
58 : ThreadBools m_aFlags; // Flags for Submit/Reset
59 :
60 : ::cppu::OComponentHelper* m_pCompImpl; // Implementation of the Control
61 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent> m_xComp; // ::com::sun::star::lang::XComponent of the Control
62 :
63 : protected:
64 :
65 : // XThread
66 : virtual void SAL_CALL run();
67 :
68 : virtual void SAL_CALL kill();
69 : virtual void SAL_CALL onTerminated();
70 :
71 : // The following method is called to duplicate the Event while respecting it's type.
72 : virtual ::com::sun::star::lang::EventObject* cloneEvent(const ::com::sun::star::lang::EventObject* _pEvt) const = 0;
73 :
74 : // Edit an Event:
75 : // The mutex is not locked, but pCompImpl stays valid in any case.
76 : // pEvt can be a derrived type, namely the one that cloneEvent returns.
77 : // rControl is only set, if a Control has been passed in addEvent.
78 : // Because the Control is only held as a WeakRef, it can disappear in the meantime.
79 : virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
80 : const ::com::sun::star::lang::EventObject* _pEvt,
81 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& _rControl,
82 : sal_Bool _bFlag) = 0;
83 :
84 : public:
85 :
86 : // UNO Anbindung
87 0 : DECLARE_UNO3_DEFAULTS(OComponentEventThread, OWeakObject);
88 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
89 :
90 : OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
91 : virtual ~OComponentEventThread();
92 :
93 : void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, sal_Bool bFlag = sal_False );
94 : void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& rControl,
95 : sal_Bool bFlag = sal_False );
96 :
97 : // ::com::sun::star::lang::XEventListener
98 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
99 :
100 : /* resolve ambiguity : both OWeakObject and OObject have these memory operators */
101 0 : void * SAL_CALL operator new( size_t size ) throw() { return osl::Thread::operator new(size); }
102 0 : void SAL_CALL operator delete( void * p ) throw() { osl::Thread::operator delete(p); }
103 :
104 : private:
105 : void implStarted( );
106 : void implTerminated( );
107 :
108 : void impl_clearEventQueue();
109 : };
110 :
111 : //.........................................................................
112 : } // namespace frm
113 : //.........................................................................
114 :
115 : #endif // _FRM_EVENT_THREAD_HXX_
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|