LibreOffice Module toolkit (master) 1
macros.hxx
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#ifndef INCLUDED_TOOLKIT_HELPER_MACROS_HXX
21#define INCLUDED_TOOLKIT_HELPER_MACROS_HXX
22
23#include <sal/log.hxx>
24#include <osl/diagnose.h>
26
27#define IMPL_IMPLEMENTATION_ID( ClassName ) \
28css::uno::Sequence< sal_Int8 > ClassName::getImplementationId() \
29{ \
30 return css::uno::Sequence<sal_Int8>(); \
31}
32
33
34#define DECL_LISTENERMULTIPLEXER_START( ClassName, InterfaceName ) \
35class ClassName final : public ListenerMultiplexerBase<InterfaceName>, public InterfaceName \
36{ \
37public: \
38 ClassName( ::cppu::OWeakObject& rSource ); \
39 css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; \
40 void SAL_CALL acquire() noexcept override; \
41 void SAL_CALL release() noexcept override; \
42 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
43
44
45#define DECL_LISTENERMULTIPLEXER_START_DLLPUB( ClassName, InterfaceName ) \
46class TOOLKIT_DLLPUBLIC ClassName final : public ListenerMultiplexerBase<InterfaceName>, public InterfaceName \
47{ \
48public: \
49 ClassName( ::cppu::OWeakObject& rSource ); \
50 css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; \
51 void SAL_CALL acquire() noexcept override; \
52 void SAL_CALL release() noexcept override; \
53 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
54
55
56#define DECL_LISTENERMULTIPLEXER_END \
57};
58
59
60#define IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ClassName, InterfaceName ) \
61ClassName::ClassName( ::cppu::OWeakObject& rSource ) \
62 : ListenerMultiplexerBase<InterfaceName>(rSource) \
63{ \
64} \
65void SAL_CALL ClassName::acquire() noexcept { ListenerMultiplexerBase::acquire(); } \
66void SAL_CALL ClassName::release() noexcept { ListenerMultiplexerBase::release(); } \
67css::uno::Any ClassName::queryInterface( const css::uno::Type & rType ) \
68{ \
69 css::uno::Any aRet = ::cppu::queryInterface( rType, \
70 (static_cast< css::lang::XEventListener* >(this)), \
71 (static_cast< InterfaceName* >(this)) ); \
72 return (aRet.hasValue() ? aRet : ListenerMultiplexerBase::queryInterface( rType )); \
73} \
74void ClassName::disposing( const css::lang::EventObject& ) \
75{ \
76}
77
78
79#if OSL_DEBUG_LEVEL > 0
80 #define DISPLAY_EXCEPTION( ClassName, MethodName ) \
81 css::uno::Any ex( cppu::getCaughtException() ); \
82 SAL_WARN( "toolkit", #ClassName "::" #MethodName ": caught an exception! " << exceptionToString(ex));
83#else
84 #define DISPLAY_EXCEPTION( ClassName, MethodName )
85#endif
86
87#define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( ClassName, InterfaceName, MethodName, ParamType1 ) \
88{ \
89 ParamType1 aMulti( evt ); \
90 std::unique_lock g(m_aMutex); \
91 ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners); \
92 g.unlock(); \
93 while( aIt.hasMoreElements() ) \
94 { \
95 css::uno::Reference<InterfaceName> xListener(aIt.next()); \
96 try \
97 { \
98 xListener->MethodName( aMulti ); \
99 } \
100 catch(const css::lang::DisposedException& e) \
101 { \
102 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
103 if ( e.Context == xListener || !e.Context.is() ) \
104 { \
105 std::unique_lock g2(m_aMutex); \
106 aIt.remove(g2); \
107 } \
108 } \
109 catch(const css::uno::RuntimeException&) \
110 { \
111 DISPLAY_EXCEPTION( ClassName, MethodName ) \
112 } \
113 } \
114}
115
116#define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType ) \
117{ \
118 EventType aMulti( evt ); \
119 aMulti.Source = &GetContext(); \
120 std::unique_lock g(m_aMutex); \
121 ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners); \
122 g.unlock(); \
123 while( aIt.hasMoreElements() ) \
124 { \
125 css::uno::Reference<InterfaceName> xListener(aIt.next()); \
126 try \
127 { \
128 xListener->MethodName( aMulti ); \
129 } \
130 catch(const css::lang::DisposedException& e) \
131 { \
132 OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
133 if ( e.Context == xListener || !e.Context.is() ) \
134 { \
135 std::unique_lock g2(m_aMutex); \
136 aIt.remove(g2); \
137 } \
138 } \
139 catch(const css::uno::RuntimeException&) \
140 { \
141 DISPLAY_EXCEPTION( ClassName, MethodName ) \
142 } \
143 } \
144}
145
146#define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_EXCEPTION( ClassName, InterfaceName, MethodName, EventType, Exception ) \
147void ClassName::MethodName( const EventType& evt ) \
148IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
149
150#define IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ClassName, InterfaceName, MethodName, EventType ) \
151void ClassName::MethodName( const EventType& evt ) \
152IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodName, EventType )
153
154#define DECLIMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \
155 OUString SAL_CALL getImplementationName( ) override { return "stardiv.Toolkit." #ImplName; } \
156 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override \
157 { \
158 css::uno::Sequence< OUString > aNames = BaseClass::getSupportedServiceNames( ); \
159 aNames.realloc( aNames.getLength() + 1 ); \
160 aNames.getArray()[ aNames.getLength() - 1 ] = ServiceName; \
161 return aNames; \
162 } \
163
164#endif // INCLUDED_TOOLKIT_HELPER_MACROS_HXX
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */