~ubuntu-branches/ubuntu/vivid/ekiga/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/engine/framework/lister.h

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2011-07-17 00:24:50 UTC
  • mfrom: (5.1.5 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110717002450-ytg3wsrc1ptd3153
Tags: 3.3.1-1
* New upstream release.
 - Required libpt-dev 2.10 and libopal-dev 3.10
* Fix debian/watch to catch new version
* Remove libnotify0.7.patch - included upstream
* Add libboost-dev and libboost-signals-dev to Build-Depends
* debian/rules: Don't install *.la files for new internal shared libs
* Fix Vcs URIs to point to correct desktop/experimental/ekiga tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*
3
 
 * Ekiga -- A VoIP and Video-Conferencing application
4
 
 * Copyright (C) 2000-2007 Damien Sandras
5
 
 
6
 
 * This program is free software; you can  redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or (at
9
 
 * your option) any later version. This program is distributed in the hope
10
 
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
11
 
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 
 * See the GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License along
15
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
16
 
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17
 
 *
18
 
 * Ekiga is licensed under the GPL license and as a special exception, you
19
 
 * have permission to link or otherwise combine this program with the
20
 
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
21
 
 * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
22
 
 * programs, as long as you do follow the requirements of the GNU GPL for all
23
 
 * the rest of the software thus combined.
24
 
 */
25
 
 
26
 
 
27
 
/*
28
 
 *                         lister.h  -  description
29
 
 *                         ------------------------------------------
30
 
 *   begin                : written in 2007 by Julien Puydt
31
 
 *   copyright            : (c) 2007 by Julien Puydt
32
 
 *   description          : declaration of an object able to list others
33
 
 *
34
 
 */
35
 
 
36
 
#ifndef __LISTER_H__
37
 
#define __LISTER_H__
38
 
 
39
 
#include <sigc++/sigc++.h>
40
 
 
41
 
#include "ptr_array.h"
42
 
#include "ptr_array_iterator.h"
43
 
#include "ptr_array_const_iterator.h"
44
 
 
45
 
namespace Ekiga
46
 
{
47
 
  /** Ekiga::Lister
48
 
   *
49
 
   * This class is there to help write a dynamic object lister, that is an
50
 
   * object which will own objects which will emit "updated"
51
 
   * and "removed" signals.
52
 
   *
53
 
   * You can remove an object from an Ekiga::Lister in two ways:
54
 
   *  - either by calling the remove_object method,
55
 
   *  - or by emission of the object's removed signal.
56
 
   *
57
 
   * Notice that this class won't take care of removing the object from a
58
 
   * backend -- only from the Ekiga::Lister.
59
 
   * If you want the object *deleted* from the real backend, then you
60
 
   * probably should have an organization like:
61
 
   *  - the object has a 'deleted' signal;
62
 
   *  - the lister child-class listens to this signal;
63
 
   *  - when the signal is received, then do a remove_object followed by
64
 
   *    calling the appropriate api function to delete the object in your
65
 
   *    backend.
66
 
   */
67
 
  template<typename ObjectType>
68
 
  class Lister
69
 
  {
70
 
 
71
 
  public:
72
 
 
73
 
    typedef Ekiga::ptr_array<ObjectType> container_type;
74
 
    typedef typename Ekiga::ptr_array_iterator<ObjectType> iterator;
75
 
    typedef typename Ekiga::ptr_array_const_iterator<ObjectType> const_iterator;
76
 
 
77
 
 
78
 
    /** The constructor.
79
 
     */
80
 
    Lister ();
81
 
 
82
 
 
83
 
    /** The destructor.
84
 
     */
85
 
    ~Lister ();
86
 
 
87
 
 
88
 
    /** Allows listing all objects
89
 
     * @param The callback (the return value means "go on" and allows
90
 
     *  stopping the visit)
91
 
     */
92
 
    void visit_objects (sigc::slot<bool, ObjectType &> visitor);
93
 
 
94
 
    /** Returns a const iterator to the first object of the collection.
95
 
     */
96
 
    const_iterator begin () const;
97
 
 
98
 
 
99
 
    /** Returns an iterator to the first object of the collection.
100
 
     */
101
 
    iterator begin ();
102
 
 
103
 
 
104
 
    /** Returns a const iterator to the first object of the collection.
105
 
     */
106
 
    const_iterator end () const;
107
 
 
108
 
 
109
 
    /** Returns an iterator to the last object of the collection.
110
 
     */
111
 
    iterator end ();
112
 
 
113
 
    /** Adds an object to the Ekiga::Lister.
114
 
     * @param: The object to be added.
115
 
     * @return: The Ekiga::Lister 'object_added' signal is emitted when
116
 
     *          the object has been added. The
117
 
     *          Ekiga::Lister 'object_updated' signal will be emitted
118
 
     *          when the object has been updated and the
119
 
     *          Ekiga::Lister 'object_removed' signal will be emitted when
120
 
     *          the object has been removed from the Ekiga::Lister.
121
 
     */
122
 
    void add_object (ObjectType &object);
123
 
 
124
 
 
125
 
    /** Removes an object from the Ekiga::Lister.
126
 
     * @param: The object to be removed.
127
 
     * @return: The Ekiga::Lister 'object_removed' signal is emitted when
128
 
     * the object has been removed.
129
 
     */
130
 
    void remove_object (ObjectType &object);
131
 
 
132
 
 
133
 
    /** Signals emitted by this object
134
 
     *
135
 
     */
136
 
    sigc::signal<void, ObjectType &> object_added;
137
 
    sigc::signal<void, ObjectType &> object_removed;
138
 
    sigc::signal<void, ObjectType &> object_updated;
139
 
 
140
 
  private:
141
 
 
142
 
    /** Disconnects the signals for the object, emits the 'object_removed'
143
 
     * signal on the Ekiga::Lister and takes care of the release of that
144
 
     * object.
145
 
     * @param: The object to remove.
146
 
     */
147
 
    void common_removal_steps (ObjectType &object);
148
 
 
149
 
 
150
 
    /** This callback is triggered when the 'updated' signal is emitted on
151
 
     * an object.
152
 
     * Emits the Ekiga::Lister 'object_updated' signal for that object.
153
 
     * @param: The updated object.
154
 
     */
155
 
    void on_object_updated (ObjectType *object);
156
 
 
157
 
 
158
 
    /** This callback is triggered when the 'removed' signal is emitted on
159
 
     * an object.
160
 
     * Emits the Ekiga::Lister 'object_removed' signal for that object and
161
 
     * takes care of the deletion of the object.
162
 
     * @param: The removed object.
163
 
     */
164
 
    void on_object_removed (ObjectType *object);
165
 
 
166
 
    /** Object store.
167
 
     */
168
 
    container_type objects;
169
 
 
170
 
    /** Are we shutting done, hence not reacting to our objects saying goodbye?
171
 
     */
172
 
    bool shutting_down;
173
 
  };
174
 
};
175
 
 
176
 
 
177
 
/* here begins the code from the template functions */
178
 
 
179
 
template<typename ObjectType>
180
 
Ekiga::Lister<ObjectType>::Lister (): shutting_down(false)
181
 
{
182
 
}
183
 
 
184
 
 
185
 
template<typename ObjectType>
186
 
Ekiga::Lister<ObjectType>::~Lister ()
187
 
{
188
 
  shutting_down = true;
189
 
 
190
 
  for (unsigned int ii = 0;
191
 
       ii < objects.size ();
192
 
       ii++) {
193
 
 
194
 
    ObjectType *obj = objects[ii];
195
 
    obj->removed.emit ();
196
 
  }
197
 
}
198
 
 
199
 
 
200
 
template<typename ObjectType>
201
 
void
202
 
Ekiga::Lister<ObjectType>::visit_objects (sigc::slot<bool, ObjectType &> visitor)
203
 
{
204
 
  bool go_on = true;
205
 
  for (unsigned int ii = 0;
206
 
       ii < objects.size () && go_on; ii++)
207
 
    go_on = visitor (*objects[ii]);
208
 
}
209
 
 
210
 
 
211
 
template<typename ObjectType>
212
 
typename Ekiga::Lister<ObjectType>::const_iterator
213
 
Ekiga::Lister<ObjectType>::begin () const
214
 
{
215
 
  return const_iterator (objects);
216
 
}
217
 
 
218
 
 
219
 
template<typename ObjectType>
220
 
typename Ekiga::Lister<ObjectType>::iterator
221
 
Ekiga::Lister<ObjectType>::begin ()
222
 
{
223
 
  return iterator (objects);
224
 
}
225
 
 
226
 
 
227
 
template<typename ObjectType>
228
 
typename Ekiga::Lister<ObjectType>::const_iterator
229
 
Ekiga::Lister<ObjectType>::end () const
230
 
{
231
 
  return const_iterator (objects, objects.size ());
232
 
}
233
 
 
234
 
 
235
 
template<typename ObjectType>
236
 
typename Ekiga::Lister<ObjectType>::iterator
237
 
Ekiga::Lister<ObjectType>::end ()
238
 
{
239
 
  return iterator (objects, objects.size ());
240
 
}
241
 
 
242
 
 
243
 
template<typename ObjectType>
244
 
void
245
 
Ekiga::Lister<ObjectType>::add_object (ObjectType &object)
246
 
{
247
 
  object.removed.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_removed), &object));
248
 
  object.updated.connect (sigc::bind (sigc::mem_fun (this, &Lister::on_object_updated), &object));
249
 
  objects.add (&object);
250
 
  object_added.emit (object);
251
 
}
252
 
 
253
 
 
254
 
template<typename ObjectType>
255
 
void
256
 
Ekiga::Lister<ObjectType>::remove_object (ObjectType &object)
257
 
{
258
 
  common_removal_steps (object);
259
 
}
260
 
 
261
 
template<typename ObjectType>
262
 
void
263
 
Ekiga::Lister<ObjectType>::common_removal_steps (ObjectType &object)
264
 
{
265
 
  object_removed.emit (object);
266
 
  objects.remove (&object);
267
 
}
268
 
 
269
 
 
270
 
template<typename ObjectType>
271
 
void
272
 
Ekiga::Lister<ObjectType>::on_object_updated (ObjectType *object)
273
 
{
274
 
  object_updated.emit (*object);
275
 
}
276
 
 
277
 
 
278
 
template<typename ObjectType>
279
 
void
280
 
Ekiga::Lister<ObjectType>::on_object_removed (ObjectType *object)
281
 
{
282
 
  if ( !shutting_down)
283
 
    common_removal_steps (*object);
284
 
}
285
 
 
286
 
#endif