blob: 5106344a606416bc122c95db2894e88a5d339b66 [file] [log] [blame]
Alexandre Lision67916dd2014-01-24 13:33:04 -05001/* $Id$ */
2/*
3 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJSUA2_PRESENCE_HPP__
20#define __PJSUA2_PRESENCE_HPP__
21
22/**
23 * @file pjsua2/presence.hpp
24 * @brief PJSUA2 Presence Operations
25 */
26#include <pjsua2/persistent.hpp>
27#include <pjsua2/siptypes.hpp>
28
29/** PJSUA2 API is inside pj namespace */
30namespace pj
31{
32
33/**
34 * @defgroup PJSUA2_PRES Presence
35 * @ingroup PJSUA2_Ref
36 * @{
37 */
38
39using std::string;
40using std::vector;
41
42
43/**
44 * This describes presence status.
45 */
46struct PresenceStatus
47{
48 /**
49 * Buddy's online status.
50 */
51 pjsua_buddy_status status;
52
53 /**
54 * Text to describe buddy's online status.
55 */
56 string statusText;
57
58 /**
59 * Activity type.
60 */
61 pjrpid_activity activity;
62
63 /**
64 * Optional text describing the person/element.
65 */
66 string note;
67
68 /**
69 * Optional RPID ID string.
70 */
71 string rpidId;
72
73public:
74 /**
75 * Constructor.
76 */
77 PresenceStatus();
78};
79
80
81/**
82 * This structure describes buddy configuration when adding a buddy to
83 * the buddy list with Buddy::create().
84 */
85struct BuddyConfig : public PersistentObject
86{
87 /**
88 * Buddy URL or name address.
89 */
90 string uri;
91
92 /**
93 * Specify whether presence subscription should start immediately.
94 */
95 bool subscribe;
96
97public:
98 /**
99 * Read this object from a container node.
100 *
101 * @param node Container to read values from.
102 */
103 virtual void readObject(const ContainerNode &node) throw(Error);
104
105 /**
106 * Write this object to a container node.
107 *
108 * @param node Container to write values to.
109 */
110 virtual void writeObject(ContainerNode &node) const throw(Error);
111};
112
113
114/**
115 * This structure describes buddy info, which can be retrieved by via
116 * Buddy::getInfo().
117 */
118struct BuddyInfo
119{
120 /**
121 * The full URI of the buddy, as specified in the configuration.
122 */
123 string uri;
124
125 /**
126 * Buddy's Contact, only available when presence subscription has
127 * been established to the buddy.
128 */
129 string contact;
130
131 /**
132 * Flag to indicate that we should monitor the presence information for
133 * this buddy (normally yes, unless explicitly disabled).
134 */
135 bool presMonitorEnabled;
136
137 /**
138 * If \a presMonitorEnabled is true, this specifies the last state of
139 * the presence subscription. If presence subscription session is currently
140 * active, the value will be PJSIP_EVSUB_STATE_ACTIVE. If presence
141 * subscription request has been rejected, the value will be
142 * PJSIP_EVSUB_STATE_TERMINATED, and the termination reason will be
143 * specified in \a subTermReason.
144 */
145 pjsip_evsub_state subState;
146
147 /**
148 * String representation of subscription state.
149 */
150 string subStateName;
151
152 /**
153 * Specifies the last presence subscription termination code. This would
154 * return the last status of the SUBSCRIBE request. If the subscription
155 * is terminated with NOTIFY by the server, this value will be set to
156 * 200, and subscription termination reason will be given in the
157 * \a subTermReason field.
158 */
159 pjsip_status_code subTermCode;
160
161 /**
162 * Specifies the last presence subscription termination reason. If
163 * presence subscription is currently active, the value will be empty.
164 */
165 string subTermReason;
166
167 /**
168 * Presence status.
169 */
170 PresenceStatus presStatus;
171
172public:
173 /** Import from pjsip structure */
174 void fromPj(const pjsua_buddy_info &pbi);
175};
176
177
178/**
179 * Buddy.
180 */
181class Buddy
182{
183public:
184 /**
185 * Constructor.
186 */
187 Buddy();
188
189 /**
190 * Destructor. Note that if the Buddy instance is deleted, it will also
191 * delete the corresponding buddy in the PJSUA-LIB.
192 */
193 virtual ~Buddy();
194
195 /**
196 * Create buddy and register the buddy to PJSUA-LIB.
197 *
198 * @param acc The account for this buddy.
199 * @param cfg The buddy config.
200 */
201 void create(Account &acc, const BuddyConfig &cfg) throw(Error);
202
203 /**
204 * Check if this buddy is valid.
205 *
206 * @return True if it is.
207 */
208 bool isValid() const;
209
210 /**
211 * Get detailed buddy info.
212 *
213 * @return Buddy info.
214 */
215 BuddyInfo getInfo() const throw(Error);
216
217 /**
218 * Enable/disable buddy's presence monitoring. Once buddy's presence is
219 * subscribed, application will be informed about buddy's presence status
220 * changed via \a onBuddyState() callback.
221 *
222 * @param subscribe Specify true to activate presence
223 * subscription.
224 */
225 void subscribePresence(bool subscribe) throw(Error);
226
227 /**
228 * Update the presence information for the buddy. Although the library
229 * periodically refreshes the presence subscription for all buddies,
230 * some application may want to refresh the buddy's presence subscription
231 * immediately, and in this case it can use this function to accomplish
232 * this.
233 *
234 * Note that the buddy's presence subscription will only be initiated
235 * if presence monitoring is enabled for the buddy. See
236 * subscribePresence() for more info. Also if presence subscription for
237 * the buddy is already active, this function will not do anything.
238 *
239 * Once the presence subscription is activated successfully for the buddy,
240 * application will be notified about the buddy's presence status in the
241 * \a onBuddyState() callback.
242 */
243 void updatePresence(void) throw(Error);
244
245 /**
246 * Send instant messaging outside dialog, using this buddy's specified
247 * account for route set and authentication.
248 *
249 * @param prm Sending instant message parameter.
250 */
251 void sendInstantMessage(const SendInstantMessageParam &prm) throw(Error);
252
253 /**
254 * Send typing indication outside dialog.
255 *
256 * @param prm Sending instant message parameter.
257 */
258 void sendTypingIndication(const SendTypingIndicationParam &prm)
259 throw(Error);
260
261public:
262 /*
263 * Callbacks
264 */
265
266 /**
267 * Notify application when the buddy state has changed.
268 * Application may then query the buddy info to get the details.
269 */
270 virtual void onBuddyState()
271 {}
272
273private:
274 /**
275 * Buddy ID.
276 */
277 pjsua_buddy_id id;
278
279 /**
280 * Account.
281 */
282 Account *acc;
283};
284
285
286/** Array of buddies */
287typedef std::vector<Buddy*> BuddyVector;
288
289
290/**
291 * @} // PJSUA2_PRES
292 */
293
294} // namespace pj
295
296#endif /* __PJSUA2_PRESENCE_HPP__ */