27 #ifndef OPAL_IM_PRES_ENT_H
28 #define OPAL_IM_PRES_ENT_H
35 #include <ptlib/pfactory.h>
36 #include <ptlib/safecoll.h>
37 #include <ptclib/url.h>
38 #include <ptclib/guid.h>
41 #include <ptclib/vcard.h>
50 class OpalPresentityCommand;
68 class OpalPresenceInfo :
public PObject
70 PCLASSINFO_WITH_CLONE(OpalPresenceInfo, PObject);
75 P_DECLARE_STREAMABLE_ENUM_EX(State,StateCount,
86 PStringSet m_activities;
94 PStringSet m_capabilities;
99 OpalPresenceInfo(State state = Unchanged);
100 OpalPresenceInfo(
const PString & str);
102 static PString AsString(State state);
103 static State FromString(
const PString & str);
104 PString AsString()
const;
106 Comparison Compare(
const PObject & other)
const;
109 ostream &
operator<<(ostream & strm, OpalPresenceInfo::State state);
113 class OpalSetLocalPresenceCommand;
114 class OpalSubscribeToPresenceCommand;
115 class OpalAuthorisationRequestCommand;
116 class OpalSendMessageToCommand;
127 class OpalPresentity :
public PSafeObject
129 PCLASSINFO(OpalPresentity, PSafeObject);
136 OpalPresentity(
const OpalPresentity & other);
143 static OpalPresentity * Create(
146 const PString & scheme = PString::Empty()
165 virtual bool IsOpen()
const {
return m_open; }
169 virtual bool Close();
174 PStringOptions & GetAttributes() {
return m_attributes; }
178 virtual PStringArray GetAttributeNames()
const = 0;
181 virtual PStringArray GetAttributeTypes()
const = 0;
183 static const PCaselessString & AuthNameKey();
184 static const PCaselessString & AuthPasswordKey();
185 static const PCaselessString & TimeToLiveKey();
191 const PURL & GetAOR()
const {
return m_aor; }
204 virtual bool SubscribeToPresence(
205 const PURL & presentity,
206 bool subscribe =
true,
207 const PString & note = PString::Empty()
218 virtual bool UnsubscribeFromPresence(
219 const PURL & presentity
224 AuthorisationPermitted,
226 AuthorisationDeniedPolitely,
227 AuthorisationConfirming,
242 virtual bool SetPresenceAuthorisation(
243 const PURL & presentity,
244 Authorisation authorisation
254 bool SetLocalPresence(
255 const OpalPresenceInfo & info
259 bool SetLocalPresence(
260 OpalPresenceInfo::State state,
261 const PString & note = PString::Empty()
266 bool GetLocalPresence(
267 OpalPresenceInfo & info
271 bool GetLocalPresence(
272 OpalPresenceInfo::State & state,
281 template <
class cls> __inline cls * CreateCommand();
294 virtual bool SendCommand(
295 OpalPresentityCommand * cmd
301 struct AuthorisationRequest
314 virtual void OnAuthorisationRequest(
315 const AuthorisationRequest & request
318 typedef PNotifierTemplate<AuthorisationRequest> AuthorisationRequestNotifier;
319 #define PDECLARE_AuthorisationRequestNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalPresentity, cls, fn, OpalPresentity::AuthorisationRequest)
320 #define PDECLARE_ASYNC_AuthorisationRequestNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalPresentity, cls, fn, OpalPresentity::AuthorisationRequest)
321 #define PCREATE_AuthorisationRequestNotifier(fn) PCREATE_NOTIFIER2(fn, OpalPresentity::AuthorisationRequest)
324 void SetAuthorisationRequestNotifier(
325 const AuthorisationRequestNotifier & notifier
336 virtual void OnPresenceChange(
337 const OpalPresenceInfo & info
340 typedef PNotifierTemplate< PAutoPtr<OpalPresenceInfo> > PresenceChangeNotifier;
341 #define PDECLARE_PresenceChangeNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalPresentity, cls, fn, PAutoPtr<OpalPresenceInfo>)
342 #define PDECLARE_ASYNC_PresenceChangeNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalPresentity, cls, fn, PAutoPtr<OpalPresenceInfo>)
343 #define PCREATE_PresenceChangeNotifier(fn) PCREATE_NOTIFIER2(fn, PAutoPtr<OpalPresenceInfo>)
346 void SetPresenceChangeNotifier(
347 const PresenceChangeNotifier & notifier
359 const PURL & presentity = PString::Empty(),
360 const PString & displayName = PString::Empty()
361 ) : m_presentity(presentity)
362 , m_displayName(displayName)
366 PString m_displayName;
389 PString m_contentType;
393 typedef std::list<BuddyInfo> BuddyList;
396 BuddyStatus_GenericFailure = -1,
398 BuddyStatus_SpecifiedBuddyNotFound,
399 BuddyStatus_ListFeatureNotImplemented,
400 BuddyStatus_ListTemporarilyUnavailable,
401 BuddyStatus_ListMayBeIncomplete,
402 BuddyStatus_BadBuddySpecification,
403 BuddyStatus_ListSubscribeFailed,
404 BuddyStatus_AccountNotLoggedIn
409 virtual BuddyStatus GetBuddyListEx(
412 virtual bool GetBuddyList(
415 {
return GetBuddyListEx(buddies) == BuddyStatus_OK; }
419 virtual BuddyStatus SetBuddyListEx(
420 const BuddyList & buddies
422 virtual bool SetBuddyList(
423 const BuddyList & buddies
425 {
return SetBuddyListEx(buddies) == BuddyStatus_OK; }
430 virtual BuddyStatus DeleteBuddyListEx();
431 virtual bool DeleteBuddyList() {
return DeleteBuddyListEx() == BuddyStatus_OK; }
437 virtual BuddyStatus GetBuddyEx(
440 virtual bool GetBuddy(
443 {
return GetBuddyEx(buddy) == BuddyStatus_OK; }
447 virtual BuddyStatus SetBuddyEx(
448 const BuddyInfo & buddy
450 virtual bool SetBuddy(
451 const BuddyInfo & buddy
453 {
return SetBuddyEx(buddy) == BuddyStatus_OK; }
457 virtual BuddyStatus DeleteBuddyEx(
458 const PURL & presentity
460 virtual bool DeleteBuddy(
461 const PURL & presentity
463 {
return DeleteBuddyEx(presentity) == BuddyStatus_OK; }
470 virtual BuddyStatus SubscribeBuddyListEx(
471 PINDEX & successfulCount,
472 bool subscribe =
true
474 virtual bool SubscribeBuddyList(
475 bool subscribe =
true
477 { PINDEX successfulCount;
return SubscribeBuddyListEx(successfulCount, subscribe) == BuddyStatus_OK; }
484 virtual BuddyStatus UnsubscribeBuddyListEx();
485 virtual bool UnsubscribeBuddyList()
486 {
return UnsubscribeBuddyListEx() == BuddyStatus_OK; }
493 virtual bool SendMessageTo(
503 virtual void OnReceivedMessage(
507 typedef PNotifierTemplate<OpalIM> ReceivedMessageNotifier;
508 #define PDECLARE_ReceivedMessageNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalPresentity, cls, fn, OpalIM)
509 #define PDECLARE_ASYNC_ReceivedMessageNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalPresentity, cls, fn, OpalIM)
510 #define PCREATE_ReceivedMessageNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIM)
513 void SetReceivedMessageNotifier(
514 const ReceivedMessageNotifier & notifier
517 void Internal_SendMessageToCommand(
const OpalSendMessageToCommand & cmd);
519 #endif // OPAL_HAS_IM
529 OpalManager & GetManager()
const {
return *m_manager; }
533 PGloballyUniqueID m_guid;
535 PStringOptions m_attributes;
537 AuthorisationRequestNotifier m_onAuthorisationRequestNotifier;
538 PresenceChangeNotifier m_onPresenceChangeNotifier;
540 ReceivedMessageNotifier m_onReceivedMessageNotifier;
541 #endif // OPAL_HAS_IM
544 PDECLARE_MUTEX(m_notificationMutex);
545 bool m_temporarilyUnavailable;
546 OpalPresenceInfo m_localInfo;
555 class OpalPresentityWithCommandThread :
public OpalPresentity
557 PCLASSINFO(OpalPresentityWithCommandThread, OpalPresentity);
563 OpalPresentityWithCommandThread();
564 OpalPresentityWithCommandThread(
const OpalPresentityWithCommandThread & other);
570 ~OpalPresentityWithCommandThread();
577 virtual bool Close();
590 virtual bool SendCommand(
591 OpalPresentityCommand * cmd
598 OpalPresentity & m_owner;
599 OpalPresentityCommand * m_command;
600 WorkItem(OpalPresentityWithCommandThread & owner, OpalPresentityCommand * command);
605 PQueuedThreadPool<WorkItem> m_threadPool;
612 class OpalPresentityCommand {
614 OpalPresentityCommand(
bool responseNeeded =
false)
615 : m_responseNeeded(responseNeeded)
617 virtual ~OpalPresentityCommand() { }
622 virtual void Process(
623 OpalPresentity & presentity
626 static OpalPresentityCommand * Create(OpalPresentity & presentity,
const char * cmdName);
627 static PDefaultPFactoryKey MakeKey(
const char * className,
const char * cmdName);
629 typedef uint32_t CmdSeqType;
630 CmdSeqType m_sequence;
631 bool m_responseNeeded;
637 #define OPAL_PRESENTITY_COMMAND(command, entity, func) \
638 class entity##_##command : public command \
640 public: virtual void Process(OpalPresentity & presentity) { dynamic_cast<entity &>(presentity).func(*this); } \
642 PFACTORY_CREATE(PFactory<OpalPresentityCommand>, entity##_##command, OpalPresentityCommand::MakeKey(typeid(entity).name(), typeid(command).name()))
647 class OpalSubscribeToPresenceCommand :
public OpalPresentityCommand {
649 OpalSubscribeToPresenceCommand(
bool subscribe =
true) : m_subscribe(subscribe) { }
662 class OpalAuthorisationRequestCommand :
public OpalPresentityCommand {
664 OpalAuthorisationRequestCommand() : m_authorisation(OpalPresentity::AuthorisationPermitted) { }
666 OpalPresentity::Authorisation m_authorisation;
676 class OpalSetLocalPresenceCommand :
public OpalPresentityCommand,
public OpalPresenceInfo {
678 OpalSetLocalPresenceCommand(State state = NoPresence) : OpalPresenceInfo(state) { }
685 class OpalSendMessageToCommand :
public OpalPresentityCommand
688 OpalSendMessageToCommand() { }
692 #endif // OPAL_HAS_IM
698 #if OPAL_SIP_PRESENCE
702 template <
class cls> __inline cls * OpalPresentity::CreateCommand()
704 return dynamic_cast<cls *
>(OpalPresentityCommand::Create(*
this,
typeid(cls).name()));
708 #endif // OPAL_HAS_PRESENCE
711 #endif // OPAL_IM_PRES_ENT_H
Definition: manager.h:150
PFACTORY_LOAD(OpalPluginCodecManager)
ostream & operator<<(ostream &strm, OpalSilenceDetector::Mode mode)