00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OPAL_IM_IM_H
00032 #define OPAL_IM_IM_H
00033
00034 #include <ptlib.h>
00035 #include <opal/buildopts.h>
00036
00037 #if OPAL_HAS_IM
00038
00039 #include <ptclib/url.h>
00040 #include <opal//transports.h>
00041
00042
00043 class OpalCall;
00044 class OpalMediaFormat;
00045 class OpalIMEndPoint;
00046
00047
00049
00050 #if OPAL_HAS_SIPIM
00051 #define OPAL_SIPIM "SIP-IM"
00052 #define OpalSIPIM GetOpalSIPIM()
00053 extern const OpalMediaFormat & GetOpalSIPIM();
00054 #endif
00055
00056 #if OPAL_HAS_RFC4103
00057 #define OPAL_T140 "T.140"
00058 #define OpalT140 GetOpalT140()
00059 extern const OpalMediaFormat & GetOpalT140();
00060 #endif
00061
00062 #if OPAL_HAS_MSRP
00063 #define OPAL_MSRP "MSRP"
00064 #define OpalMSRP GetOpalMSRP()
00065 extern const OpalMediaFormat & GetOpalMSRP();
00066 #endif
00067
00068 #define OPAL_IM_MEDIA_TYPE_PREFIX "im-"
00069
00070
00072
00079 class OpalIM : public PObject
00080 {
00081 PCLASSINFO_WITH_CLONE(OpalIM, PObject);
00082 public:
00083 OpalIM();
00084
00085 PString m_conversationId;
00086
00087 PURL m_to;
00088 OpalTransportAddress m_toAddr;
00089 PURL m_from;
00090 OpalTransportAddress m_fromAddr;
00091 PString m_fromName;
00092 PStringToString m_bodies;
00093
00094 PAtomicInteger::IntegerType m_messageId;
00097 static PAtomicInteger::IntegerType GetNextMessageId();
00098 };
00099
00100
00102
00109 class OpalIMContext : public PSafeObject
00110 {
00111 PCLASSINFO(OpalIMContext, PSafeObject);
00112
00115 protected:
00117 OpalIMContext();
00118
00119 public:
00121 ~OpalIMContext();
00122
00125 struct ConversationInfo
00126 {
00127 ConversationInfo(
00128 const PString & id,
00129 bool opening,
00130 bool byRemote,
00131 const PSafePtr<OpalIMContext> & context
00132 ) : m_conversationId(id)
00133 , m_opening(opening)
00134 , m_byRemote(byRemote)
00135 , m_context(context)
00136 { }
00137
00138 PString m_conversationId;
00139 bool m_opening;
00140 bool m_byRemote;
00141 PSafePtr<OpalIMContext> m_context;
00142 };
00143
00147 virtual bool Open(
00148 bool byRemote
00149 );
00150
00154 virtual void Close();
00156
00157
00165 P_DECLARE_STREAMABLE_ENUM(MessageDisposition,
00166 DispositionPending,
00167 DispositionAccepted,
00168 DeliveryOK,
00169 DisplayConfirmed,
00170 ProcessedNotification,
00171 StorageNotification,
00172
00174 DispositionErrors,
00175 GenericError,
00176 UnacceptableContent,
00177 InvalidContent,
00178 DestinationUnknown,
00179 DestinationUnavailable,
00180 TransmissionTimeout,
00181 TransportFailure,
00182 ConversationClosed,
00183 UnsupportedFeature,
00184 DeliveryFailed
00185 );
00186
00197 virtual MessageDisposition Send(
00198 OpalIM * message
00199 );
00200
00203 struct DispositionInfo {
00204 PString m_conversationId;
00205 PAtomicInteger::IntegerType m_messageId;
00206 MessageDisposition m_disposition;
00207 };
00208
00212 virtual void OnMessageDisposition(
00213 const DispositionInfo & info
00214 );
00215
00217 typedef PNotifierTemplate<DispositionInfo> MessageDispositionNotifier;
00218
00220 #define PDECLARE_MessageDispositionNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::DispositionInfo)
00221
00223 #define PDECLARE_ASYNC_MessageDispositionNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::DispositionInfo)
00224
00226 #define PCREATE_MessageDispositionNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::DispositionInfo)
00227
00229 void SetMessageDispositionNotifier(
00230 const MessageDispositionNotifier & notifier
00231 );
00233
00234
00242 virtual MessageDisposition OnMessageReceived(
00243 const OpalIM & message
00244 );
00245
00247 typedef PNotifierTemplate<OpalIM> MessageReceivedNotifier;
00248
00250 #define PDECLARE_MessageReceivedNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIM)
00251
00253 #define PDECLARE_ASYNC_MessageReceivedNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIM)
00254
00256 #define PCREATE_MessageReceivedNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIM)
00257
00259 void SetMessageReceivedNotifier(
00260 const MessageReceivedNotifier & notifier
00261 );
00263
00264
00267 static const PCaselessString & CompositionIndicationActive();
00268 static const PCaselessString & CompositionIndicationIdle();
00269
00272 struct CompositionInfo
00273 {
00274 PString m_conversationId;
00275 PString m_state;
00276 PString m_contentType;
00277
00278 CompositionInfo(
00279 const PString & id,
00280 const PString & state,
00281 const PString & contentType = PString::Empty()
00282 ) : m_conversationId(id)
00283 , m_state(state)
00284 , m_contentType(contentType)
00285 { }
00286 };
00287
00292 virtual bool SendCompositionIndication(
00293 const CompositionInfo & info
00294 );
00295
00299 virtual void OnCompositionIndication(
00300 const CompositionInfo & info
00301 );
00302
00304 typedef PNotifierTemplate<CompositionInfo> CompositionIndicationNotifier;
00305
00307 #define PDECLARE_CompositionIndicationNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::CompositionInfo)
00308
00310 #define PDECLARE_ASYNC_CompositionIndicationNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::CompositionInfo)
00311
00313 #define PCREATE_CompositionIndicationNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::CompositionInfo)
00314
00316 void SetCompositionIndicationNotifier(
00317 const CompositionIndicationNotifier & notifier
00318 );
00320
00321
00324
00325 virtual bool CheckContentType(
00326 const PString & contentType
00327 ) const;
00328
00330 virtual PStringArray GetContentTypes() const;
00331
00333 static PString CreateKey(const PURL & from, const PURL & to);
00335
00336
00339
00340 const PString & GetID() const { return m_conversationId; }
00341
00343 const PString & GetKey() const { return m_key; }
00344
00346 const PURL & GetRemoteURL() const { return m_remoteURL; }
00347
00349 const PString & GetRemoteName() const { return m_remoteName; }
00350
00352 const PURL & GetLocalURL() const { return m_localURL; }
00353
00355 const PString & GetLocalName() const { return m_localName; }
00356
00358 void SetLocalName(const PString & name) { m_localName = name; }
00359
00361 PStringOptions & GetAttributes() { return m_attributes; }
00362 const PStringOptions & GetAttributes() const { return m_attributes; }
00364
00365 protected:
00366 void ResetLastUsed();
00367
00368 virtual MessageDisposition InternalSend();
00369 virtual MessageDisposition InternalSendOutsideCall(OpalIM & message);
00370 virtual MessageDisposition InternalSendInsideCall(OpalIM & message);
00371 virtual void InternalOnMessageSent(const DispositionInfo & info);
00372
00373 OpalIMEndPoint * m_endpoint;
00374 PStringOptions m_attributes;
00375
00376 PSafePtr<OpalCall> m_call;
00377 bool m_weStartedCall;
00378
00379 PMutex m_notificationMutex;
00380 MessageDispositionNotifier m_messageDispositionNotifier;
00381 MessageReceivedNotifier m_messageReceivedNotifier;
00382 CompositionIndicationNotifier m_compositionIndicationNotifier;
00383
00384 PMutex m_outgoingMessagesMutex;
00385 OpalIM * m_currentOutgoingMessage;
00386 PQueue<OpalIM> m_outgoingMessages;
00387
00388 PMutex m_lastUsedMutex;
00389 PTime m_lastUsed;
00390
00391 PString m_conversationId;
00392 PURL m_localURL;
00393 PString m_localName;
00394 PURL m_remoteURL;
00395 PString m_remoteName;
00396 PString m_key;
00397
00398 friend class OpalIMEndPoint;
00399 friend class OpalIMConnection;
00400 };
00401
00402
00403 #endif // OPAL_HAS_IM
00404
00405 #endif // OPAL_IM_IM_H