21#include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
27#include <unordered_map>
36typedef std::pair< AccessibleEventNotifier::TClientId,
37 AccessibleEventObject > ClientEvent;
39typedef ::comphelper::OInterfaceContainerHelper4<XAccessibleEventListener> ListenerContainer;
40typedef std::unordered_map< AccessibleEventNotifier::TClientId, ListenerContainer > ClientMap;
43typedef std::map<AccessibleEventNotifier::TClientId,
44 AccessibleEventNotifier::TClientId> IntervalMap;
54IntervalMap& GetFreeIntervals()
56 static IntervalMap
MAP =
60 map.insert(std::make_pair(
61 std::numeric_limits<AccessibleEventNotifier::TClientId>::max(), 1));
67void releaseId(AccessibleEventNotifier::TClientId
const nId)
69 IntervalMap & rFreeIntervals(GetFreeIntervals());
70 IntervalMap::iterator
const upper(rFreeIntervals.upper_bound(nId));
71 assert(upper != rFreeIntervals.end());
72 assert(nId < upper->second);
73 if (nId + 1 == upper->second)
79 IntervalMap::iterator
const lower(rFreeIntervals.lower_bound(nId));
80 if (lower != rFreeIntervals.end() && lower->first == nId - 1)
83 rFreeIntervals.insert(std::make_pair(nId, lower->second));
84 rFreeIntervals.erase(lower);
88 rFreeIntervals.insert(std::make_pair(nId, nId));
96AccessibleEventNotifier::TClientId generateId()
98 IntervalMap & rFreeIntervals(GetFreeIntervals());
99 assert(!rFreeIntervals.empty());
100 IntervalMap::iterator
const iter(rFreeIntervals.begin());
101 AccessibleEventNotifier::TClientId
const nFirst = iter->first;
102 AccessibleEventNotifier::TClientId
const nFreeId = iter->second;
103 assert(nFreeId <= nFirst);
104 if (nFreeId != nFirst)
110 rFreeIntervals.erase(iter);
113 assert(gaClients.end() == gaClients.find(nFreeId));
133bool implLookupClient(
134 const AccessibleEventNotifier::TClientId nClient,
135 ClientMap::iterator& rPos )
138 ClientMap &rClients = gaClients;
139 rPos = rClients.find( nClient );
140 assert( rClients.end() != rPos &&
141 "AccessibleEventNotifier::implLookupClient: invalid client id "
142 "(did you register your client?)!" );
144 return ( rClients.end() != rPos );
153 std::scoped_lock aGuard( GetLocalMutex() );
159 gaClients.emplace( nNewClientId, ListenerContainer{} );
167 std::scoped_lock aGuard( GetLocalMutex() );
169 ClientMap::iterator aClientPos;
170 if ( !implLookupClient( _nClient, aClientPos ) )
175 gaClients.erase( aClientPos );
180 const TClientId _nClient,
const Reference< XInterface >& _rxEventSource )
182 std::unique_lock aGuard( GetLocalMutex() );
184 ClientMap::iterator aClientPos;
185 if (!implLookupClient(_nClient, aClientPos))
190 ListenerContainer
aListeners(std::move(aClientPos->second));
196 gaClients.erase(aClientPos);
200 EventObject aDisposalEvent;
201 aDisposalEvent.Source = _rxEventSource;
204 aListeners.disposeAndClear( aGuard, aDisposalEvent );
208 const TClientId _nClient,
const Reference< XAccessibleEventListener >& _rxListener )
210 std::unique_lock aGuard( GetLocalMutex() );
212 ClientMap::iterator aClientPos;
213 if ( !implLookupClient( _nClient, aClientPos ) )
217 if ( _rxListener.is() )
218 aClientPos->second.addInterface( aGuard, _rxListener );
220 return aClientPos->second.getLength(aGuard);
224 const TClientId _nClient,
const Reference< XAccessibleEventListener >& _rxListener )
226 std::unique_lock aGuard( GetLocalMutex() );
228 ClientMap::iterator aClientPos;
229 if ( !implLookupClient( _nClient, aClientPos ) )
233 if ( _rxListener.is() )
234 aClientPos->second.removeInterface( aGuard, _rxListener );
236 return aClientPos->second.getLength(aGuard);
241 std::unique_lock aGuard( GetLocalMutex() );
243 ClientMap::iterator aClientPos;
244 if ( !implLookupClient( _nClient, aClientPos ) )
256 aIt.
next()->notifyEvent(_rEvent);
static sal_Int32 addEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
registers a listener for the given client
static void addEvent(const TClientId _nClient, const css::accessibility::AccessibleEventObject &_rEvent)
adds an event, which is to be broadcasted, to the queue
static sal_Int32 removeEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
revokes a listener for the given client
static TClientId registerClient()
registers a client of this class, means a broadcaster of AccessibleEvents
static void revokeClient(const TClientId _nClient)
revokes a broadcaster of AccessibleEvents
static void revokeClientNotifyDisposing(const TClientId _nClient, const css::uno::Reference< css::uno::XInterface > &_rxEventSource)
revokes a client, with additionally notifying a disposing event to all listeners registered for this ...
This is the iterator of an OInterfaceContainerHelper4.
bool hasMoreElements() const
Return true, if there are more elements in the iterator.
css::uno::Reference< ListenerT > const & next()
Return the next element of the iterator.
std::map< OUString, rtl::Reference< Entity > > map
#define MAP(name, prefix, token, type, context)