31 #ifndef OPAL_IM_PRES_ENT_H
32 #define OPAL_IM_PRES_ENT_H
39 #include <ptlib/pfactory.h>
40 #include <ptlib/safecoll.h>
41 #include <ptclib/url.h>
42 #include <ptclib/guid.h>
45 #include <ptclib/vcard.h>
54 class OpalPresentityCommand;
72 class OpalPresenceInfo :
public PObject
74 PCLASSINFO_WITH_CLONE(OpalPresenceInfo, PObject);
79 P_DECLARE_STREAMABLE_ENUM_EX(State,StateCount,
90 PStringSet m_activities;
98 PStringSet m_capabilities;
103 OpalPresenceInfo(State state = Unchanged);
104 OpalPresenceInfo(
const PString & str);
106 static PString AsString(State state);
107 static State FromString(
const PString & str);
108 PString AsString()
const;
110 Comparison Compare(
const PObject & other)
const;
113 ostream &
operator<<(ostream & strm, OpalPresenceInfo::State state);
117 class OpalSetLocalPresenceCommand;
118 class OpalSubscribeToPresenceCommand;
119 class OpalAuthorisationRequestCommand;
120 class OpalSendMessageToCommand;
131 class OpalPresentity :
public PSafeObject
133 PCLASSINFO(OpalPresentity, PSafeObject);
140 OpalPresentity(
const OpalPresentity & other);
147 static OpalPresentity * Create(
150 const PString & scheme = PString::Empty()
169 virtual bool IsOpen()
const {
return m_open; }
173 virtual bool Close();
179 PStringOptions & GetAttributes() {
return m_attributes; }
182 virtual PStringArray GetAttributeNames()
const = 0;
185 virtual PStringArray GetAttributeTypes()
const = 0;
187 static const PCaselessString & AuthNameKey();
188 static const PCaselessString & AuthPasswordKey();
189 static const PCaselessString & TimeToLiveKey();
195 const PURL & GetAOR()
const {
return m_aor; }
208 virtual bool SubscribeToPresence(
209 const PURL & presentity,
210 bool subscribe =
true,
211 const PString & note = PString::Empty()
222 virtual bool UnsubscribeFromPresence(
223 const PURL & presentity
228 AuthorisationPermitted,
230 AuthorisationDeniedPolitely,
231 AuthorisationConfirming,
246 virtual bool SetPresenceAuthorisation(
247 const PURL & presentity,
248 Authorisation authorisation
258 bool SetLocalPresence(
259 const OpalPresenceInfo & info
263 bool SetLocalPresence(
264 OpalPresenceInfo::State state,
265 const PString & note = PString::Empty()
270 bool GetLocalPresence(
271 OpalPresenceInfo & info
275 bool GetLocalPresence(
276 OpalPresenceInfo::State & state,
286 __inline cls * CreateCommand()
288 return dynamic_cast<cls *
>(InternalCreateCommand(
typeid(cls).name()));
302 virtual bool SendCommand(
303 OpalPresentityCommand * cmd
309 struct AuthorisationRequest
322 virtual void OnAuthorisationRequest(
323 const AuthorisationRequest & request
326 typedef PNotifierTemplate<AuthorisationRequest> AuthorisationRequestNotifier;
327 #define PDECLARE_AuthorisationRequestNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalPresentity, cls, fn, OpalPresentity::AuthorisationRequest)
328 #define PDECLARE_ASYNC_AuthorisationRequestNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalPresentity, cls, fn, OpalPresentity::AuthorisationRequest)
329 #define PCREATE_AuthorisationRequestNotifier(fn) PCREATE_NOTIFIER2(fn, OpalPresentity::AuthorisationRequest)
332 void SetAuthorisationRequestNotifier(
333 const AuthorisationRequestNotifier & notifier
344 virtual void OnPresenceChange(
345 const OpalPresenceInfo & info
348 typedef PNotifierTemplate< std::auto_ptr<OpalPresenceInfo> > PresenceChangeNotifier;
349 #define PDECLARE_PresenceChangeNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalPresentity, cls, fn, std::auto_ptr<OpalPresenceInfo>)
350 #define PDECLARE_ASYNC_PresenceChangeNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalPresentity, cls, fn, std::auto_ptr<OpalPresenceInfo>)
351 #define PCREATE_PresenceChangeNotifier(fn) PCREATE_NOTIFIER2(fn, std::auto_ptr<OpalPresenceInfo>)
354 void SetPresenceChangeNotifier(
355 const PresenceChangeNotifier & notifier
367 const PURL & presentity = PString::Empty(),
368 const PString & displayName = PString::Empty()
369 ) : m_presentity(presentity)
370 , m_displayName(displayName)
374 PString m_displayName;
397 PString m_contentType;
401 typedef std::list<BuddyInfo> BuddyList;
404 BuddyStatus_GenericFailure = -1,
406 BuddyStatus_SpecifiedBuddyNotFound,
407 BuddyStatus_ListFeatureNotImplemented,
408 BuddyStatus_ListTemporarilyUnavailable,
409 BuddyStatus_ListMayBeIncomplete,
410 BuddyStatus_BadBuddySpecification,
411 BuddyStatus_ListSubscribeFailed,
412 BuddyStatus_AccountNotLoggedIn
417 virtual BuddyStatus GetBuddyListEx(
420 virtual bool GetBuddyList(
423 {
return GetBuddyListEx(buddies) == BuddyStatus_OK; }
427 virtual BuddyStatus SetBuddyListEx(
428 const BuddyList & buddies
430 virtual bool SetBuddyList(
431 const BuddyList & buddies
433 {
return SetBuddyListEx(buddies) == BuddyStatus_OK; }
438 virtual BuddyStatus DeleteBuddyListEx();
439 virtual bool DeleteBuddyList() {
return DeleteBuddyListEx() == BuddyStatus_OK; }
445 virtual BuddyStatus GetBuddyEx(
448 virtual bool GetBuddy(
451 {
return GetBuddyEx(buddy) == BuddyStatus_OK; }
455 virtual BuddyStatus SetBuddyEx(
456 const BuddyInfo & buddy
458 virtual bool SetBuddy(
459 const BuddyInfo & buddy
461 {
return SetBuddyEx(buddy) == BuddyStatus_OK; }
465 virtual BuddyStatus DeleteBuddyEx(
466 const PURL & presentity
468 virtual bool DeleteBuddy(
469 const PURL & presentity
471 {
return DeleteBuddyEx(presentity) == BuddyStatus_OK; }
478 virtual BuddyStatus SubscribeBuddyListEx(
479 PINDEX & successfulCount,
480 bool subscribe =
true
482 virtual bool SubscribeBuddyList(
483 bool subscribe =
true
485 { PINDEX successfulCount;
return SubscribeBuddyListEx(successfulCount, subscribe) == BuddyStatus_OK; }
492 virtual BuddyStatus UnsubscribeBuddyListEx();
493 virtual bool UnsubscribeBuddyList()
494 {
return UnsubscribeBuddyListEx() == BuddyStatus_OK; }
501 virtual bool SendMessageTo(
511 virtual void OnReceivedMessage(
515 typedef PNotifierTemplate<OpalIM> ReceivedMessageNotifier;
516 #define PDECLARE_ReceivedMessageNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalPresentity, cls, fn, OpalIM)
517 #define PDECLARE_ASYNC_ReceivedMessageNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalPresentity, cls, fn, OpalIM)
518 #define PCREATE_ReceivedMessageNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIM)
521 void SetReceivedMessageNotifier(
522 const ReceivedMessageNotifier & notifier
525 void Internal_SendMessageToCommand(
const OpalSendMessageToCommand & cmd);
527 #endif // OPAL_HAS_IM
537 OpalManager & GetManager()
const {
return *m_manager; }
540 OpalPresentityCommand * InternalCreateCommand(
const char * cmdName);
543 PGloballyUniqueID m_guid;
545 PStringOptions m_attributes;
547 AuthorisationRequestNotifier m_onAuthorisationRequestNotifier;
548 PresenceChangeNotifier m_onPresenceChangeNotifier;
550 ReceivedMessageNotifier m_onReceivedMessageNotifier;
551 #endif // OPAL_HAS_IM
553 PAtomicBoolean m_open;
554 PMutex m_notificationMutex;
555 bool m_temporarilyUnavailable;
556 OpalPresenceInfo m_localInfo;
565 class OpalPresentityWithCommandThread :
public OpalPresentity
567 PCLASSINFO(OpalPresentityWithCommandThread, OpalPresentity);
573 OpalPresentityWithCommandThread();
574 OpalPresentityWithCommandThread(
const OpalPresentityWithCommandThread & other);
580 ~OpalPresentityWithCommandThread();
596 virtual bool SendCommand(
597 OpalPresentityCommand * cmd
614 bool startQueue =
true
627 bool startQueue =
true
635 typedef std::queue<OpalPresentityCommand *> CommandQueue;
636 CommandQueue m_commandQueue;
637 PMutex m_commandQueueMutex;
638 PAtomicInteger m_commandSequence;
639 PSyncPoint m_commandQueueSync;
641 bool m_threadRunning;
650 class OpalPresentityCommand {
652 OpalPresentityCommand(
bool responseNeeded =
false)
653 : m_responseNeeded(responseNeeded)
655 virtual ~OpalPresentityCommand() { }
660 virtual void Process(
661 OpalPresentity & presentity
664 typedef PAtomicInteger::IntegerType CmdSeqType;
665 CmdSeqType m_sequence;
666 bool m_responseNeeded;
672 #define OPAL_DEFINE_COMMAND(command, entity, func) \
673 class entity##_##command : public command \
675 public: virtual void Process(OpalPresentity & presentity) { dynamic_cast<entity &>(presentity).func(*this); } \
677 PFACTORY_CREATE(PFactory<OpalPresentityCommand>, entity##_##command, PDefaultPFactoryKey(entity::Class())+typeid(command).name())
682 class OpalSubscribeToPresenceCommand :
public OpalPresentityCommand {
684 OpalSubscribeToPresenceCommand(
bool subscribe =
true) : m_subscribe(subscribe) { }
697 class OpalAuthorisationRequestCommand :
public OpalPresentityCommand {
699 OpalAuthorisationRequestCommand() : m_authorisation(OpalPresentity::AuthorisationPermitted) { }
701 OpalPresentity::Authorisation m_authorisation;
711 class OpalSetLocalPresenceCommand :
public OpalPresentityCommand,
public OpalPresenceInfo {
713 OpalSetLocalPresenceCommand(State state = NoPresence) : OpalPresenceInfo(state) { }
720 class OpalSendMessageToCommand :
public OpalPresentityCommand
723 OpalSendMessageToCommand() { }
727 #endif // OPAL_HAS_IM
733 #if OPAL_SIP_PRESENCE
738 #endif // OPAL_HAS_PRESENCE
741 #endif // OPAL_IM_PRES_ENT_H