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 INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
21 : #define INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
22 :
23 : #include <osl/mutex.hxx>
24 : #include <com/sun/star/lang/XComponent.hpp>
25 : #include <cppuhelper/implbase1.hxx>
26 : #include <com/sun/star/form/XLoadable.hpp>
27 :
28 :
29 : namespace bib
30 : {
31 :
32 :
33 : class OComponentAdapterBase;
34 :
35 : class OComponentListener
36 : {
37 : friend class OComponentAdapterBase;
38 :
39 : private:
40 : OComponentAdapterBase* m_pAdapter;
41 : ::osl::Mutex& m_rMutex;
42 : protected:
43 0 : OComponentListener( ::osl::Mutex& _rMutex )
44 : :m_pAdapter( NULL )
45 0 : ,m_rMutex( _rMutex )
46 : {
47 0 : }
48 :
49 : virtual ~OComponentListener();
50 :
51 : protected:
52 : void setAdapter( OComponentAdapterBase* _pAdapter );
53 : };
54 :
55 : class OComponentAdapterBase
56 : {
57 : friend class OComponentListener;
58 :
59 : private:
60 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
61 : m_xComponent;
62 : OComponentListener* m_pListener;
63 : sal_Int32 m_nLockCount;
64 : bool m_bListening : 1;
65 : bool m_bAutoRelease : 1;
66 :
67 : // impl method for dispose - virtual, 'cause you at least need to remove the listener from the broadcaster
68 : virtual void disposing() = 0;
69 :
70 : protected:
71 : // attribute access for derivees
72 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >&
73 0 : getComponent() const { return m_xComponent; }
74 0 : OComponentListener* getListener() { return m_pListener; }
75 :
76 : // to be called by derivees which started listening at the component
77 : virtual void startComponentListening() = 0;
78 :
79 : virtual ~OComponentAdapterBase();
80 :
81 : public:
82 : OComponentAdapterBase(
83 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComp,
84 : bool _bAutoRelease = true
85 : );
86 :
87 : // late construction
88 : // can be called from within you ctor, to have you're object fully initialized at the moment of
89 : // the call (which would not be the case when calling this ctor)
90 : void Init( OComponentListener* _pListener );
91 :
92 : // base for ref-counting, implemented by OComponentAdapter
93 : virtual void SAL_CALL acquire( ) throw () = 0;
94 : virtual void SAL_CALL release( ) throw () = 0;
95 :
96 : // helper
97 : /// get the lock count
98 0 : sal_Int32 locked() const { return m_nLockCount; }
99 :
100 : /// dispose the object - stop listening and such
101 : void dispose();
102 :
103 : protected:
104 : // XEventListener
105 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException, std::exception);
106 : };
107 :
108 0 : class OLoadListener : public OComponentListener
109 : {
110 : friend class OLoadListenerAdapter;
111 :
112 : protected:
113 0 : OLoadListener( ::osl::Mutex& _rMutex ) : OComponentListener( _rMutex ) { }
114 :
115 : // XLoadListener equivalents
116 : virtual void _loaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
117 : virtual void _unloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
118 : virtual void _unloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
119 : virtual void _reloading( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
120 : virtual void _reloaded( const ::com::sun::star::lang::EventObject& aEvent ) = 0;
121 : };
122 :
123 : typedef ::cppu::WeakImplHelper1< ::com::sun::star::form::XLoadListener > OLoadListenerAdapter_Base;
124 0 : class OLoadListenerAdapter
125 : :public OLoadListenerAdapter_Base
126 : ,public OComponentAdapterBase
127 : {
128 : protected:
129 0 : OLoadListener* getLoadListener( ) { return static_cast< OLoadListener* >( getListener() ); }
130 :
131 : protected:
132 : virtual void disposing() SAL_OVERRIDE;
133 : virtual void startComponentListening() SAL_OVERRIDE;
134 :
135 : public:
136 : OLoadListenerAdapter(
137 : const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable,
138 : bool _bAutoRelease = true
139 : );
140 :
141 :
142 : virtual void SAL_CALL acquire( ) throw () SAL_OVERRIDE;
143 : virtual void SAL_CALL release( ) throw () SAL_OVERRIDE;
144 :
145 : protected:
146 : // XEventListener
147 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 :
149 : // XLoadListener
150 : virtual void SAL_CALL loaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 : virtual void SAL_CALL unloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 : virtual void SAL_CALL unloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 : virtual void SAL_CALL reloading( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 : virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 : };
156 :
157 :
158 : } // namespace bib
159 :
160 :
161 : #endif // INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_LOADLISTENERADAPTER_HXX
162 :
163 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|