Debian Codegraph @

Xpjproject/pjsip/include/pjsua2/presence.hpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #ifndef __PJSUA2_PRESENCE_HPP__
19 #define __PJSUA2_PRESENCE_HPP__
20
21 /**
22 * @file pjsua2/presence.hpp
23 * @brief PJSUA2 Presence Operations
24 */
25 #include <pjsua2/persistent.hpp>
26 #include <pjsua2/siptypes.hpp>
27
28 /** PJSUA2 API is inside pj namespace */
29 namespace pj
30 {
31
32 /**
33 * @defgroup PJSUA2_PRES Presence
34 * @ingroup PJSUA2_Ref
35 * @{
36 */
37
38 using std::string;
39 using std::vector;
40
41
42 /**
43 * This describes presence status.
44 */
45 struct PresenceStatus
46 {
47 /**
48 * Buddy's online status.
49 */
50 pjsua_buddy_status status;
51
52 /**
53 * Text to describe buddy's online status.
54 */
55 string statusText;
56
57 /**
58 * Activity type.
59 */
60 pjrpid_activity activity;
61
62 /**
63 * Optional text describing the person/element.
64 */
65 string note;
66
67 /**
68 * Optional RPID ID string.
69 */
70 string rpidId;
71
72 public:
73 /**
74 * Constructor.
75 */
76 PresenceStatus();
77 };
78
79
80 /**
81 * This structure describes buddy configuration when adding a buddy to
82 * the buddy list with Buddy::create().
83 */
84 struct BuddyConfig : public PersistentObject
85 {
86 /**
87 * Buddy URL or name address.
88 */
89 string uri;
90
91 /**
92 * Specify whether presence subscription should start immediately.
93 */
94 bool subscribe;
95
96 /**
97 * Specify whether we should immediately subscribe to the buddy's
98 * dialog event, such as for Busy Lamp Field (BLF) feature.
99 * Note that only one subscription (presence or dialog event)
100 * can be active at any time.
101 */
102 bool subscribe_dlg_event;
103
104 public:
105 /**
106 * Read this object from a container node.
107 *
108 * @param node Container to read values from.
109 */
110 virtual void readObject(const ContainerNode &node) PJSUA2_THROW(Error);
111
112 /**
113 * Write this object to a container node.
114 *
115 * @param node Container to write values to.
116 */
117 virtual void writeObject(ContainerNode &node) const PJSUA2_THROW(Error);
118 };
119
120
121 /**
122 * This structure describes buddy info, which can be retrieved by via
123 * Buddy::getInfo().
124 */
125 struct BuddyInfo
126 {
127 /**
128 * The full URI of the buddy, as specified in the configuration.
129 */
130 string uri;
131
132 /**
133 * Buddy's Contact, only available when presence subscription has
134 * been established to the buddy.
135 */
136 string contact;
137
138 /**
139 * The account ID associated with this buddy. If not associated
140 * with any account, the value will be PJSUA_INVALID_ID.
141 */
142 pjsua_acc_id accId;
143
144 /**
145 * Flag to indicate that we should monitor the presence information for
146 * this buddy (normally yes, unless explicitly disabled).
147 */
148 bool presMonitorEnabled;
149
150 /**
151 * If \a presMonitorEnabled is true, this specifies the last state of
152 * the presence subscription. If presence subscription session is currently
153 * active, the value will be PJSIP_EVSUB_STATE_ACTIVE. If presence
154 * subscription request has been rejected, the value will be
155 * PJSIP_EVSUB_STATE_TERMINATED, and the termination reason will be
156 * specified in \a subTermReason.
157 */
158 pjsip_evsub_state subState;
159
160 /**
161 * String representation of subscription state.
162 */
163 string subStateName;
164
165 /**
166 * Specifies the last presence subscription termination code. This would
167 * return the last status of the SUBSCRIBE request. If the subscription
168 * is terminated with NOTIFY by the server, this value will be set to
169 * 200, and subscription termination reason will be given in the
170 * \a subTermReason field.
171 */
172 pjsip_status_code subTermCode;
173
174 /**
175 * Specifies the last presence subscription termination reason. If
176 * presence subscription is currently active, the value will be empty.
177 */
178 string subTermReason;
179
180 /**
181 * Presence status.
182 */
183 PresenceStatus presStatus;
184
185 public:
186 /**
187 * Default constructor
188 */
189 BuddyInfo()
190 : accId(PJSUA_INVALID_ID),
191 presMonitorEnabled(true),
192 subState(PJSIP_EVSUB_STATE_UNKNOWN),
193 subTermCode(PJSIP_SC_NULL)
194 {}
195
196
197 /** Import from pjsip structure */
198 void fromPj(const pjsua_buddy_info &pbi);
199 };
200
201
202 /**
203 * This structure contains parameters for Buddy::onBuddyEvSubState() callback.
204 */
205 struct OnBuddyEvSubStateParam
206 {
207 /**
208 * * The event which triggers state change event.
209 */
210 SipEvent e;
211 };
212
213
214 /**
215 * Buddy. This is a lite wrapper class for PJSUA-LIB buddy, i.e: this class
216 * only maintains one data member, PJSUA-LIB buddy ID, and the methods are
217 * simply proxies for PJSUA-LIB buddy operations.
218 *
219 * Application can use create() to register a buddy to PJSUA-LIB, and
220 * the destructor of the original instance (i.e: the instance that calls
221 * create()) will unregister and delete the buddy from PJSUA-LIB. Application
222 * must delete all Buddy instances belong to an account before shutting down
223 * the account (via Account::shutdown()).
224 *
225 * The library will not keep a list of Buddy instances, so any Buddy (or
226 * descendant) instances instantiated by application must be maintained
227 * and destroyed by the application itself. Any PJSUA2 APIs that return Buddy
228 * instance(s) such as Account::enumBuddies2() or Account::findBuddy2() will
229 * just return generated copy. All Buddy methods should work normally on this
230 * generated copy instance.
231 */
232 class Buddy
233 {
234 public:
235 /**
236 * Constructor.
237 */
238 Buddy();
239
240 /**
241 * Destructor. Note that if the Buddy original instance (i.e: the instance
242 * that calls Buddy::create()) is destroyed, it will also delete the
243 * corresponding buddy in the PJSUA-LIB. While the destructor of
244 * a generated copy (i.e: Buddy instance returned by PJSUA2 APIs such as
245 * Account::enumBuddies2() or Account::findBuddy2()) will do nothing.
246 */
247 virtual ~Buddy();
248
249 /**
250 * Create buddy and register the buddy to PJSUA-LIB.
251 *
252 * Note that application should maintain the Buddy original instance, i.e:
253 * the instance that calls this create() method as it is only the original
254 * instance destructor that will delete the underlying Buddy in PJSUA-LIB.
255 *
256 * IMPORTANT: Application must make sure that the Account instance remains
257 * valid for the entire lifetime of the Buddy object.
258 *
259 * @param acc The account for this buddy.
260 * @param cfg The buddy config.
261 */
262 void create(Account &acc, const BuddyConfig &cfg) PJSUA2_THROW(Error);
263
264 /**
265 * Check if this buddy is valid.
266 *
267 * @return True if it is.
268 */
269 bool isValid() const;
270
271 /**
272 * Get PJSUA-LIB buddy ID or index associated with this buddy.
273 *
274 * @return Integer greater than or equal to zero.
275 */
276 int getId() const;
277
278 /**
279 * Get detailed buddy info.
280 *
281 * @return Buddy info.
282 */
283 BuddyInfo getInfo() const PJSUA2_THROW(Error);
284
285 /**
286 * Enable/disable buddy's presence monitoring. Once buddy's presence is
287 * subscribed, application will be informed about buddy's presence status
288 * changed via \a onBuddyState() callback.
289 *
290 * @param subscribe Specify true to activate presence
291 * subscription.
292 */
293 void subscribePresence(bool subscribe) PJSUA2_THROW(Error);
294
295 /**
296 * Update the presence information for the buddy. Although the library
297 * periodically refreshes the presence subscription for all buddies,
298 * some application may want to refresh the buddy's presence subscription
299 * immediately, and in this case it can use this function to accomplish
300 * this.
301 *
302 * Note that the buddy's presence subscription will only be initiated
303 * if presence monitoring is enabled for the buddy. See
304 * subscribePresence() for more info. Also if presence subscription for
305 * the buddy is already active, this function will not do anything.
306 *
307 * Once the presence subscription is activated successfully for the buddy,
308 * application will be notified about the buddy's presence status in the
309 * \a onBuddyState() callback.
310 */
311 void updatePresence(void) PJSUA2_THROW(Error);
312
313 /**
314 * Enable/disable buddy's dialog event monitoring. Once buddy's dialog event
315 * is subscribed, application will be informed about buddy's dialog info
316 * status change via \a onBuddyDlgEventState() callback.
317 *
318 * Note that only one subscription (presence or dialog event) can be active
319 * at any time.
320 *
321 * @param subscribe Specify non-zero to activate dialog event subscription
322 * to the specified buddy.
323 *
324 * @return PJ_SUCCESS on success, or the appropriate error code.
325 */
326 void subscribeDlgEvent(bool subscribe) PJSUA2_THROW(Error);
327
328 /**
329 * Update the dialog event information for the buddy. Although the library
330 * periodically refreshes the dialog event subscription for all buddies, some
331 * application may want to refresh the buddy's dialog event subscription
332 * immediately, and in this case it can use this function to accomplish
333 * this.
334 *
335 * Note that the buddy's dialog event subscription will only be initiated
336 * if dialog event monitoring is enabled for the buddy. See
337 * subscribeDlgEvent() for more info. Also if dialog event
338 * subscription for the buddy is already active, this function will not do
339 * anything.
340 *
341 * Once the dialog event subscription is activated successfully for the buddy,
342 * application will be notified about the buddy's dialog info status in the
343 * onBuddyDlgEventState() callback.
344 */
345 void updateDlgEvent(void) PJSUA2_THROW(Error);
346
347 /**
348 * Send instant messaging outside dialog, using this buddy's specified
349 * account for route set and authentication.
350 *
351 * @param prm Sending instant message parameter.
352 */
353 void sendInstantMessage(const SendInstantMessageParam &prm)
354 PJSUA2_THROW(Error);
355
356 /**
357 * Send typing indication outside dialog.
358 *
359 * @param prm Sending instant message parameter.
360 */
361 void sendTypingIndication(const SendTypingIndicationParam &prm)
362 PJSUA2_THROW(Error);
363
364 public:
365 /*
366 * Callbacks
367 */
368
369 /**
370 * Notify application when the buddy state has changed.
371 * Application may then query the buddy info to get the details.
372 */
373 virtual void onBuddyState()
374 {}
375 /**
376 * Notify application when the buddy dialog state has changed.
377 * Application may then query the buddy into to get the details.
378 */
379 virtual void onBuddyDlgEventState()
380 {}
381
382 /**
383 * Notify application when the state of client subscription session
384 * associated with a buddy has changed. Application may use this
385 * callback to retrieve more detailed information about the state
386 * changed event.
387 *
388 * @param prm Callback parameter.
389 */
390 virtual void onBuddyEvSubState(OnBuddyEvSubStateParam &prm)
391 { PJ_UNUSED_ARG(prm); }
392 /**
393 * Notify application when the state of client subscription session
394 * associated with a buddy dialog state has changed. Application
395 * may use this callback to retrieve more detailed information about the
396 * state changed event.
397 */
398 virtual void onBuddyEvSubDlgEventState(OnBuddyEvSubStateParam &prm)
399 { PJ_UNUSED_ARG(prm); }
400 private:
401 /**
402 * Buddy ID.
403 */
404 pjsua_buddy_id id;
405
406 private:
407 friend class Endpoint;
408 friend class Account;
409
410 /* Internal constructor/methods used by Endpoint and Account */
411 Buddy(pjsua_buddy_id buddy_id);
412 Buddy *getOriginalInstance();
413 };
414
415
416 /**
417 * Warning: deprecated, use BuddyVector2 instead.
418 *
419 * Array of buddies.
420 */
421 typedef std::vector<Buddy*> BuddyVector;
422
423 /** Array of buddies */
424 typedef std::vector<Buddy> BuddyVector2;
425
426
427 /**
428 * @} // PJSUA2_PRES
429 */
430
431 } // namespace pj
432
433 #endif /* __PJSUA2_PRESENCE_HPP__ */