OPAL  Version 3.14.3
im.h
Go to the documentation of this file.
1 /*
2  * im.h
3  *
4  * Instant Messaging classes
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (c) 2008 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 29863 $
27  * $Author: rjongbloed $
28  * $Date: 2013-06-03 10:41:08 +1000 (Mon, 03 Jun 2013) $
29  */
30 
31 #ifndef OPAL_IM_IM_H
32 #define OPAL_IM_IM_H
33 
34 #include <ptlib.h>
35 #include <opal_config.h>
36 
37 #if OPAL_HAS_IM
38 
39 #include <ptclib/url.h>
40 #include <opal//transports.h>
41 
42 
43 class OpalCall;
44 class OpalMediaFormat;
45 class OpalIMEndPoint;
46 
47 
49 
50 #if OPAL_HAS_SIPIM
51  #define OPAL_SIPIM "SIP-IM"
52  #define OpalSIPIM GetOpalSIPIM()
53  extern const OpalMediaFormat & GetOpalSIPIM();
54 #endif
55 
56 #if OPAL_HAS_RFC4103
57  #define OPAL_T140 "T.140"
58  #define OpalT140 GetOpalT140()
59  extern const OpalMediaFormat & GetOpalT140();
60 #endif
61 
62 #if OPAL_HAS_MSRP
63  #define OPAL_MSRP "MSRP"
64  #define OpalMSRP GetOpalMSRP()
65  extern const OpalMediaFormat & GetOpalMSRP();
66 #endif
67 
68 #define OPAL_IM_MEDIA_TYPE_PREFIX "im-"
69 
70 
72 
79 class OpalIM : public PObject
80 {
81  PCLASSINFO_WITH_CLONE(OpalIM, PObject);
82  public:
83  OpalIM();
84 
85  PString m_conversationId;
86 
87  PURL m_to;
89  PURL m_from;
91  PString m_fromName;
92  PStringToString m_bodies;
93 
94  PAtomicInteger::IntegerType m_messageId;
97  static PAtomicInteger::IntegerType GetNextMessageId();
98 };
99 
100 
102 
109 class OpalIMContext : public PSafeObject
110 {
111  PCLASSINFO(OpalIMContext, PSafeObject);
112 
115  protected:
117  OpalIMContext();
118 
119  public:
121  ~OpalIMContext();
122 
126  {
128  const PString & id,
129  bool opening,
130  bool byRemote,
131  const PSafePtr<OpalIMContext> & context
132  ) : m_conversationId(id)
133  , m_opening(opening)
134  , m_byRemote(byRemote)
135  , m_context(context)
136  { }
137 
139  bool m_opening;
140  bool m_byRemote;
141  PSafePtr<OpalIMContext> m_context;
142  };
143 
147  virtual bool Open(
148  bool byRemote
149  );
150 
154  virtual void Close();
156 
157 
165  P_DECLARE_STREAMABLE_ENUM(MessageDisposition,
166  DispositionPending,
167  DispositionAccepted,
168  DeliveryOK,
169  DisplayConfirmed,
170  ProcessedNotification,
171  StorageNotification,
172 
174  DispositionErrors,
175  GenericError,
176  UnacceptableContent,
177  InvalidContent,
178  DestinationUnknown,
179  DestinationUnavailable,
180  TransmissionTimeout,
181  TransportFailure,
182  ConversationClosed,
183  UnsupportedFeature,
184  DeliveryFailed
185  );
186 
197  virtual MessageDisposition Send(
198  OpalIM * message
199  );
200 
205  PAtomicInteger::IntegerType m_messageId;
206  MessageDisposition m_disposition;
207  };
208 
212  virtual void OnMessageDisposition(
213  const DispositionInfo & info
214  );
215 
217  typedef PNotifierTemplate<DispositionInfo> MessageDispositionNotifier;
218 
220  #define PDECLARE_MessageDispositionNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::DispositionInfo)
221 
223  #define PDECLARE_ASYNC_MessageDispositionNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::DispositionInfo)
224 
226  #define PCREATE_MessageDispositionNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::DispositionInfo)
227 
230  const MessageDispositionNotifier & notifier
231  );
233 
234 
242  virtual MessageDisposition OnMessageReceived(
243  const OpalIM & message
244  );
245 
247  typedef PNotifierTemplate<OpalIM> MessageReceivedNotifier;
248 
250  #define PDECLARE_MessageReceivedNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIM)
251 
253  #define PDECLARE_ASYNC_MessageReceivedNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIM)
254 
256  #define PCREATE_MessageReceivedNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIM)
257 
260  const MessageReceivedNotifier & notifier
261  );
263 
264 
267  static const PCaselessString & CompositionIndicationActive();
268  static const PCaselessString & CompositionIndicationIdle();
269 
273  {
275  PString m_state;
276  PString m_contentType;
277 
279  const PString & id,
280  const PString & state,
281  const PString & contentType = PString::Empty()
282  ) : m_conversationId(id)
283  , m_state(state)
284  , m_contentType(contentType)
285  { }
286  };
287 
292  virtual bool SendCompositionIndication(
293  const CompositionInfo & info
294  );
295 
299  virtual void OnCompositionIndication(
300  const CompositionInfo & info
301  );
302 
304  typedef PNotifierTemplate<CompositionInfo> CompositionIndicationNotifier;
305 
307  #define PDECLARE_CompositionIndicationNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::CompositionInfo)
308 
310  #define PDECLARE_ASYNC_CompositionIndicationNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::CompositionInfo)
311 
313  #define PCREATE_CompositionIndicationNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::CompositionInfo)
314 
317  const CompositionIndicationNotifier & notifier
318  );
320 
321 
324 
325  virtual bool CheckContentType(
326  const PString & contentType
327  ) const;
328 
330  virtual PStringArray GetContentTypes() const;
331 
333  static PString CreateKey(const PURL & from, const PURL & to);
335 
336 
339 
340  const PString & GetID() const { return m_conversationId; }
341 
343  const PString & GetKey() const { return m_key; }
344 
346  const PURL & GetRemoteURL() const { return m_remoteURL; }
347 
349  const PString & GetRemoteName() const { return m_remoteName; }
350 
352  const PURL & GetLocalURL() const { return m_localURL; }
353 
355  const PString & GetLocalName() const { return m_localName; }
356 
358  void SetLocalName(const PString & name) { m_localName = name; }
359 
361  PStringOptions & GetAttributes() { return m_attributes; }
362  const PStringOptions & GetAttributes() const { return m_attributes; }
364 
365  protected:
366  void ResetLastUsed();
367 
368  virtual MessageDisposition InternalSend();
369  virtual MessageDisposition InternalSendOutsideCall(OpalIM & message);
370  virtual MessageDisposition InternalSendInsideCall(OpalIM & message);
371  virtual void InternalOnMessageSent(const DispositionInfo & info);
372 
374  PStringOptions m_attributes;
375 
376  PSafePtr<OpalCall> m_call;
378 
383 
386  PQueue<OpalIM> m_outgoingMessages;
387 
389  PTime m_lastUsed;
390 
393  PString m_localName;
395  PString m_remoteName;
396  PString m_key;
397 
398  friend class OpalIMEndPoint;
399  friend class OpalIMConnection;
400 };
401 
402 
403 #endif // OPAL_HAS_IM
404 
405 #endif // OPAL_IM_IM_H