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

« back to all changes in this revision

Viewing changes to lib/engine/presence/skel/presence-core.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
 
 *                         presence-core.h  -  description
29
 
 *                         ------------------------------------------
30
 
 *   begin                : written in 2007 by Julien Puydt
31
 
 *   copyright            : (c) 2007 by Julien Puydt
32
 
 *                          (c) 2008 by Damien Sandras
33
 
 *   description          : declaration of the main
34
 
 *                          presentity managing object
35
 
 *
36
 
 */
37
 
 
38
 
#ifndef __PRESENCE_CORE_H__
39
 
#define __PRESENCE_CORE_H__
40
 
 
41
 
#include "services.h"
42
 
#include "cluster.h"
43
 
#include "account-core.h"
44
 
 
45
 
namespace Ekiga
46
 
{
47
 
  class PersonalDetails;
48
 
 
49
 
/**
50
 
 * @defgroup presence Presence
51
 
 * @{
52
 
 */
53
 
 
54
 
 
55
 
  class PresentityDecorator
56
 
  {
57
 
  public:
58
 
 
59
 
    /** The destructor.
60
 
     */
61
 
    virtual ~PresentityDecorator () {}
62
 
 
63
 
    /** Completes the menu for actions available on an uri
64
 
     * @param The presentity for which the action could be made available.
65
 
     * @param The uri for which actions could be made available.
66
 
     * @param A MenuBuilder object to populate.
67
 
     */
68
 
    virtual bool populate_menu (Presentity& /*presentity*/,
69
 
                                const std::string /*uri*/,
70
 
                                MenuBuilder &/*builder*/) = 0;
71
 
  };
72
 
 
73
 
  class PresenceFetcher
74
 
  {
75
 
  public:
76
 
 
77
 
    /** The destructor.
78
 
     */
79
 
    virtual ~PresenceFetcher () {}
80
 
 
81
 
    /** Triggers presence fetching for the given uri
82
 
     * (notice: the PresenceFetcher should count how many times it was
83
 
     * requested presence for an uri, in case several presentities share it)
84
 
     * @param The uri for which to fetch presence information.
85
 
     */
86
 
    virtual void fetch (const std::string /*uri*/) = 0;
87
 
 
88
 
    /** Stops presence fetching for the given uri
89
 
     * (notice that if some other presentity asked for presence information
90
 
     * on the same uri, the fetching should go on until the last of them is
91
 
     * gone)
92
 
     * @param The uri for which to stop fetching presence information.
93
 
     */
94
 
    virtual void unfetch (const std::string /*uri*/) = 0;
95
 
 
96
 
    /** Those signals are emitted whenever this presence fetcher gets
97
 
     * presence information about an uri it was required to handle.
98
 
     * The information is given as a pair of strings (uri, data).
99
 
     */
100
 
    sigc::signal<void, std::string, std::string> presence_received;
101
 
    sigc::signal<void, std::string, std::string> status_received;
102
 
  };
103
 
 
104
 
  class PresencePublisher
105
 
  {
106
 
  public:
107
 
 
108
 
    virtual ~PresencePublisher () {}
109
 
 
110
 
    virtual void publish (const PersonalDetails& details) = 0;
111
 
  };
112
 
 
113
 
  /** Core object for the presence support.
114
 
   *
115
 
   * The presence core has several goals:
116
 
   *  - one of them is of course to list presentities, and know what happens to
117
 
   *    them;
118
 
   *  - another one is that we may want to store presentities somewhere as dead
119
 
   *    data, but still be able to gain presence information and actions on
120
 
   *    them.
121
 
   *
122
 
   * This is achieved by using three types of helpers:
123
 
   *  - the abstract class PresentityDecorator, which allows to enable actions
124
 
   *    on presentities based on uris;
125
 
   * - the abstract class PresenceFetcher, through which it is possible to gain
126
 
   *   presence information: they allow the PresenceCore to declare some
127
 
   *   presence information is needed about an uri, or now unneeded;
128
 
   * - finally, a simple callback-based api allows to add detecters for
129
 
   *   supported uris: this allows for example a Presentity to know if it
130
 
   *   should declare an uri as "foo@bar" or as "prtcl:foo@bar".
131
 
   */
132
 
 
133
 
  /*
134
 
   * FIXME : couldn't a chain of responsibility be used there instead of a
135
 
   *         special registering magic?
136
 
   */
137
 
  class PresenceCore:
138
 
    public Service
139
 
  {
140
 
  public:
141
 
 
142
 
    /** The constructor.
143
 
     */
144
 
    PresenceCore (ServiceCore& core);
145
 
 
146
 
    /** The destructor.
147
 
     */
148
 
    ~PresenceCore ();
149
 
 
150
 
    /*** Service Implementation ***/
151
 
  public:
152
 
    /** Returns the name of the service.
153
 
     * @return The service name.
154
 
     */
155
 
    const std::string get_name () const
156
 
    { return "presence-core"; }
157
 
 
158
 
    /** Returns the description of the service.
159
 
     * @return The service description.
160
 
     */
161
 
    const std::string get_description () const
162
 
    { return "\tPresence managing object"; }
163
 
 
164
 
    /*** API to list presentities ***/
165
 
  public:
166
 
 
167
 
    /** Adds a cluster to the PresenceCore service.
168
 
     * @param The cluster to be added.
169
 
     */
170
 
    void add_cluster (Cluster &cluster);
171
 
 
172
 
    /** Triggers a callback for all Ekiga::Cluster clusters of the
173
 
     * PresenceCore service.
174
 
     * @param The callback (the return value means "go on" and allows
175
 
     *  stopping the visit)
176
 
     */
177
 
    void visit_clusters (sigc::slot<bool, Cluster &> visitor);
178
 
 
179
 
    /** This signal is emitted when an Ekiga::Cluster has been added
180
 
     * to the PresenceCore Service.
181
 
     */
182
 
    sigc::signal<void, Cluster &> cluster_added;
183
 
 
184
 
    /** Those signals are forwarding the heap_added, heap_updated
185
 
     * and heap_removed from the given Cluster.
186
 
     *
187
 
     */
188
 
    sigc::signal<void, Cluster &, Heap &> heap_added;
189
 
    sigc::signal<void, Cluster &, Heap &> heap_updated;
190
 
    sigc::signal<void, Cluster &, Heap &> heap_removed;
191
 
 
192
 
    /** Those signals are forwarding the presentity_added, presentity_updated
193
 
     * and presentity_removed from the given Heap of the given Cluster.
194
 
     */
195
 
    sigc::signal<void, Cluster &, Heap &, Presentity &> presentity_added;
196
 
    sigc::signal<void, Cluster &, Heap &, Presentity &> presentity_updated;
197
 
    sigc::signal<void, Cluster &, Heap &, Presentity &> presentity_removed;
198
 
 
199
 
  private:
200
 
 
201
 
    std::set<Cluster *> clusters;
202
 
    void on_heap_added (Heap &heap, Cluster *cluster);
203
 
    void on_heap_updated (Heap &heap, Cluster *cluster);
204
 
    void on_heap_removed (Heap &heap, Cluster *cluster);
205
 
    void on_presentity_added (Heap &heap,
206
 
                              Presentity &presentity,
207
 
                              Cluster *cluster);
208
 
    void on_presentity_updated (Heap &heap,
209
 
                                Presentity &presentity,
210
 
                                Cluster *cluster);
211
 
    void on_presentity_removed (Heap &heap,
212
 
                                Presentity &presentity,
213
 
                                Cluster *cluster);
214
 
 
215
 
    /*** API to act on presentities ***/
216
 
  public:
217
 
 
218
 
    /** Adds a decorator to the pool of presentity decorators.
219
 
     * @param The presentity decorator.
220
 
     */
221
 
    void add_presentity_decorator (PresentityDecorator &decorator);
222
 
 
223
 
    /** Removes a decorator from the pool of presentity decorators.
224
 
     * @param The presentity decorator.
225
 
     */
226
 
    void remove_presentity_decorator (PresentityDecorator& decorator);
227
 
 
228
 
    /** Populates a menu with the actions available on a given uri.
229
 
     * @param The uri for which the decoration is needed.
230
 
     * @param The builder to populate.
231
 
     */
232
 
    bool populate_presentity_menu (Presentity& presentity,
233
 
                                   const std::string uri,
234
 
                                   MenuBuilder &builder);
235
 
 
236
 
  private:
237
 
 
238
 
    std::list<PresentityDecorator*> presentity_decorators;
239
 
 
240
 
    /*** API to help presentities get presence ***/
241
 
  public:
242
 
 
243
 
    /** Adds a fetcher to the pool of presentce fetchers.
244
 
     * @param The presence fetcher.
245
 
     */
246
 
    void add_presence_fetcher (PresenceFetcher &fetcher);
247
 
 
248
 
    /** Removes a fetcher from the pool of presentce fetchers.
249
 
     * @param The presence fetcher.
250
 
     */
251
 
    void remove_presence_fetcher (PresenceFetcher &fetcher);
252
 
 
253
 
    /** Tells the PresenceCore that someone is interested in presence
254
 
     * information for the given uri.
255
 
     * @param: The uri for which presence is requested.
256
 
     */
257
 
    void fetch_presence (const std::string uri);
258
 
 
259
 
    /** Tells the PresenceCore that someone becomes uninterested in presence
260
 
     * information for the given uri.
261
 
     * @param: The uri for which presence isn't requested anymore.
262
 
     */
263
 
    void unfetch_presence (const std::string uri);
264
 
 
265
 
    /** Those signals are emitted whenever information has been received
266
 
     * about an uri ; the information is a pair of strings (uri, information).
267
 
     */
268
 
    sigc::signal<void, std::string, std::string> presence_received;
269
 
    sigc::signal<void, std::string, std::string> status_received;
270
 
 
271
 
  private:
272
 
 
273
 
    std::list<PresenceFetcher*> presence_fetchers;
274
 
    void on_presence_received (const std::string uri,
275
 
                               const std::string presence);
276
 
    void on_status_received (const std::string uri,
277
 
                             const std::string status);
278
 
    struct uri_info
279
 
    {
280
 
      uri_info (): count(0), presence("unknown"), status("")
281
 
      { }
282
 
 
283
 
      int count;
284
 
      std::string presence;
285
 
      std::string status;
286
 
    };
287
 
 
288
 
    std::map<std::string, uri_info> uri_infos;
289
 
 
290
 
    /* help publishing presence */
291
 
  public:
292
 
 
293
 
    void add_presence_publisher (PresencePublisher &publisher);
294
 
    void remove_presence_publisher (PresencePublisher& publisher);
295
 
 
296
 
  private:
297
 
 
298
 
    std::list<PresencePublisher*> presence_publishers;
299
 
    void publish (const PersonalDetails* details);
300
 
    void on_personal_details_updated (PersonalDetails &details);
301
 
    void on_registration_event (const Ekiga::Account & account,
302
 
                                Ekiga::AccountCore::RegistrationState state,
303
 
                                std::string info,
304
 
                                Ekiga::PersonalDetails *details);
305
 
 
306
 
    /*** API to control which uri are supported by runtime ***/
307
 
  public:
308
 
 
309
 
    /** Decides whether an uri is supported by the PresenceCore
310
 
     * @param The uri to test for support
311
 
     * @return True if the uri is supported
312
 
     */
313
 
    bool is_supported_uri (const std::string uri) const;
314
 
 
315
 
    /** Adds an uri tester to the PresenceCore
316
 
     * @param The tester
317
 
     */
318
 
    void add_supported_uri (sigc::slot<bool,std::string> tester);
319
 
 
320
 
  private:
321
 
 
322
 
    std::set<sigc::slot<bool, std::string> > uri_testers;
323
 
 
324
 
    /*** Misc ***/
325
 
  public:
326
 
 
327
 
    /** Create the menu of the actions available in the PresenceCore.
328
 
     * @param A MenuBuilder object to populate.
329
 
     */
330
 
    bool populate_menu (MenuBuilder &builder);
331
 
 
332
 
    /** This chain allows the PresenceCore to present forms to the user
333
 
     */
334
 
    ChainOfResponsibility<FormRequest*> questions;
335
 
  };
336
 
 
337
 
/**
338
 
 * @}
339
 
 */
340
 
 
341
 
};
342
 
 
343
 
#endif