3
* Ekiga -- A VoIP and Video-Conferencing application
4
* Copyright (C) 2000-2007 Damien Sandras
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.
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.
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.
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
38
#ifndef __PRESENCE_CORE_H__
39
#define __PRESENCE_CORE_H__
43
#include "account-core.h"
47
class PersonalDetails;
50
* @defgroup presence Presence
55
class PresentityDecorator
61
virtual ~PresentityDecorator () {}
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.
68
virtual bool populate_menu (Presentity& /*presentity*/,
69
const std::string /*uri*/,
70
MenuBuilder &/*builder*/) = 0;
79
virtual ~PresenceFetcher () {}
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.
86
virtual void fetch (const std::string /*uri*/) = 0;
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
92
* @param The uri for which to stop fetching presence information.
94
virtual void unfetch (const std::string /*uri*/) = 0;
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).
100
sigc::signal<void, std::string, std::string> presence_received;
101
sigc::signal<void, std::string, std::string> status_received;
104
class PresencePublisher
108
virtual ~PresencePublisher () {}
110
virtual void publish (const PersonalDetails& details) = 0;
113
/** Core object for the presence support.
115
* The presence core has several goals:
116
* - one of them is of course to list presentities, and know what happens to
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
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".
134
* FIXME : couldn't a chain of responsibility be used there instead of a
135
* special registering magic?
144
PresenceCore (ServiceCore& core);
150
/*** Service Implementation ***/
152
/** Returns the name of the service.
153
* @return The service name.
155
const std::string get_name () const
156
{ return "presence-core"; }
158
/** Returns the description of the service.
159
* @return The service description.
161
const std::string get_description () const
162
{ return "\tPresence managing object"; }
164
/*** API to list presentities ***/
167
/** Adds a cluster to the PresenceCore service.
168
* @param The cluster to be added.
170
void add_cluster (Cluster &cluster);
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)
177
void visit_clusters (sigc::slot<bool, Cluster &> visitor);
179
/** This signal is emitted when an Ekiga::Cluster has been added
180
* to the PresenceCore Service.
182
sigc::signal<void, Cluster &> cluster_added;
184
/** Those signals are forwarding the heap_added, heap_updated
185
* and heap_removed from the given Cluster.
188
sigc::signal<void, Cluster &, Heap &> heap_added;
189
sigc::signal<void, Cluster &, Heap &> heap_updated;
190
sigc::signal<void, Cluster &, Heap &> heap_removed;
192
/** Those signals are forwarding the presentity_added, presentity_updated
193
* and presentity_removed from the given Heap of the given Cluster.
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;
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,
208
void on_presentity_updated (Heap &heap,
209
Presentity &presentity,
211
void on_presentity_removed (Heap &heap,
212
Presentity &presentity,
215
/*** API to act on presentities ***/
218
/** Adds a decorator to the pool of presentity decorators.
219
* @param The presentity decorator.
221
void add_presentity_decorator (PresentityDecorator &decorator);
223
/** Removes a decorator from the pool of presentity decorators.
224
* @param The presentity decorator.
226
void remove_presentity_decorator (PresentityDecorator& decorator);
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.
232
bool populate_presentity_menu (Presentity& presentity,
233
const std::string uri,
234
MenuBuilder &builder);
238
std::list<PresentityDecorator*> presentity_decorators;
240
/*** API to help presentities get presence ***/
243
/** Adds a fetcher to the pool of presentce fetchers.
244
* @param The presence fetcher.
246
void add_presence_fetcher (PresenceFetcher &fetcher);
248
/** Removes a fetcher from the pool of presentce fetchers.
249
* @param The presence fetcher.
251
void remove_presence_fetcher (PresenceFetcher &fetcher);
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.
257
void fetch_presence (const std::string uri);
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.
263
void unfetch_presence (const std::string uri);
265
/** Those signals are emitted whenever information has been received
266
* about an uri ; the information is a pair of strings (uri, information).
268
sigc::signal<void, std::string, std::string> presence_received;
269
sigc::signal<void, std::string, std::string> status_received;
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);
280
uri_info (): count(0), presence("unknown"), status("")
284
std::string presence;
288
std::map<std::string, uri_info> uri_infos;
290
/* help publishing presence */
293
void add_presence_publisher (PresencePublisher &publisher);
294
void remove_presence_publisher (PresencePublisher& publisher);
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,
304
Ekiga::PersonalDetails *details);
306
/*** API to control which uri are supported by runtime ***/
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
313
bool is_supported_uri (const std::string uri) const;
315
/** Adds an uri tester to the PresenceCore
318
void add_supported_uri (sigc::slot<bool,std::string> tester);
322
std::set<sigc::slot<bool, std::string> > uri_testers;
327
/** Create the menu of the actions available in the PresenceCore.
328
* @param A MenuBuilder object to populate.
330
bool populate_menu (MenuBuilder &builder);
332
/** This chain allows the PresenceCore to present forms to the user
334
ChainOfResponsibility<FormRequest*> questions;