1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #if !defined INCLUDED_COMPHELPER_ACCESSIBLEEVENTBUFFER_HXX
25 #define INCLUDED_COMPHELPER_ACCESSIBLEEVENTBUFFER_HXX
26 
27 #include "com/sun/star/uno/Reference.hxx"
28 #include "com/sun/star/uno/Sequence.hxx"
29 
30 #include <vector>
31 
32 namespace com { namespace sun { namespace star { namespace uno {
33     class XInterface;
34 } } } }
35 namespace com { namespace sun { namespace star {
36     namespace accessibility { struct AccessibleEventObject; }
37 } } }
38 
39 namespace comphelper {
40 
41 /**
42    A buffer for AccessibleEventObjects about to be sent to
43    XAccessibleEventListeners.
44 
45    This buffer records pairs of AccessibleEventObjects and sequences of
46    XAccessibleEventListeners.  At a time when it is safe to do so (e.g., when
47    no critical mutexes are held), all events can be notified at once.
48 
49    This class is not thread-safe in itself, but it is thread-compatible (i.e.,
50    all multi-threaded uses of instances of this class have to ensure proper
51    mutual exclusion).
52  */
53 class AccessibleEventBuffer
54 {
55 public:
56     /**
57        Create an initially empty buffer.
58 
59        Internally uses ::std::vector and thus may throw exceptions thrown by
60        operations on ::std::vector, especially ::std::bad_alloc.
61      */
62     AccessibleEventBuffer();
63 
64     /**
65        Create a buffer with a copy of another buffer.
66 
67        The events from the other buffer are copied, not shared.
68 
69        Internally uses ::std::vector and thus may throw exceptions thrown by
70        operations on ::std::vector, especially ::std::bad_alloc.
71      */
72     AccessibleEventBuffer(AccessibleEventBuffer const & rOther);
73 
74     /**
75        Destroy the buffer.
76 
77        If the buffer contains any events that have not yet been sent, those
78        events are lost.
79 
80        Does not throw any exceptions.
81      */
82     ~AccessibleEventBuffer();
83 
84     /**
85        Copy another buffer into this buffer.
86 
87        If this buffer contained any events that had not yet been sent, those
88        events are lost.  The events from the other buffer are copied, not
89        shared.
90 
91        Internally uses ::std::vector and thus may throw exceptions thrown by
92        operations on ::std::vector, especially ::std::bad_alloc.
93      */
94     AccessibleEventBuffer operator =(AccessibleEventBuffer const & rOther);
95 
96     /**
97        Add an event to the buffer.
98 
99        Internally uses ::std::vector and thus may throw exceptions thrown by
100        operations on ::std::vector, especially ::std::bad_alloc.
101      */
102     void addEvent(
103         ::com::sun::star::accessibility::AccessibleEventObject const &
104         rEvent,
105         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
106         ::com::sun::star::uno::XInterface > > const & rListeners);
107 
108     /**
109        Sends all the events accumulated in the buffer.
110 
111        If sending any of the events to a specific XAccessibleListener fails with
112        a RuntimeException, that exception is ignored and the method carries on
113        with the rest of the notifications.
114 
115        After sending all events, the buffer is cleared.
116      */
117     void sendEvents() const;
118 
119 private:
120     struct Entry;
121 
122     typedef ::std::vector< Entry > Entries;
123 
124     Entries m_aEntries;
125 };
126 
127 }
128 
129 #endif // INCLUDED_COMPHELPER_ACCESSIBLEEVENTBUFFER_HXX
130