OPAL  Version 3.18.8
im_ep.h
Go to the documentation of this file.
1 /*
2  * im_ep.h
3  *
4  * Endpoint for Instant Messaging
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 
27 #ifndef OPAL_IM_EP_H
28 #define OPAL_IM_EP_H
29 
30 #include <ptlib.h>
31 #include <opal_config.h>
32 
33 #if OPAL_HAS_IM
34 
35 #include <opal/endpoint.h>
36 
37 
41 {
42  public:
43  static const PCaselessString & Prefix();
44 
47  OpalIMEndPoint(OpalManager & manager);
50 
51 
54  virtual PSafePtr<OpalConnection> MakeConnection(
55  OpalCall & call,
56  const PString & party,
57  void * userData = NULL,
58  unsigned int options = 0,
59  OpalConnection::StringOptions * stringOptions = NULL
60  );
61 
71  virtual OpalMediaFormatList GetMediaFormats() const;
72 
77  virtual PBoolean GarbageCollection();
78 
81  virtual void ShutDown();
83 
84 
94  PSafePtr<OpalIMContext> CreateContext(
95  const PURL & localURL,
96  const PURL & remoteURL,
97  const char * scheme = NULL
98  ) { return InternalCreateContext(localURL, remoteURL, scheme, false, NULL, NULL); }
99 
102  PSafePtr<OpalIMContext> CreateContext(
103  OpalCall & call
104  );
105 
110  void RemoveContext(OpalIMContext * context, bool byRemote);
111 
115  PSafePtr<OpalIMContext> FindContextByIdWithLock(
116  const PString & key,
117  PSafetyMode mode = PSafeReadWrite
118  );
119 
123  PSafePtr<OpalIMContext> FindContextByNamesWithLock(
124  const PURL & local,
125  const PURL & remote,
126  PSafetyMode mode = PSafeReadWrite
127  );
128 
132  PSafePtr<OpalIMContext> FindContextForMessageWithLock(
133  OpalIM & im,
134  OpalConnection * conn = NULL
135  );
137 
138 
145  virtual void OnConversation(
147  );
148 
150  typedef PNotifierTemplate<OpalIMContext::ConversationInfo> ConversationNotifier;
151 
153  #define PDECLARE_ConversationNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::ConversationInfo)
154 
156  #define PDECLARE_ASYNC_ConversationNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::ConversationInfo)
157 
159  #define PCREATE_ConversationNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::ConversationInfo)
160 
167  void AddNotifier(
168  const ConversationNotifier & notifier,
169  const PString & scheme
170  );
171 
174  bool RemoveNotifier(const ConversationNotifier & notifier, const PString & scheme);
176 
177 
178  OpalIMContext::MessageDisposition OnRawMessageReceived(
179  OpalIM & message,
180  OpalConnection * connnection,
181  PString & errorInfo
182  );
183 
184  OpalManager & GetManager() const { return m_manager; }
185 
186  protected:
187  PSafePtr<OpalIMContext> InternalCreateContext(
188  const PURL & localURL,
189  const PURL & remoteURL,
190  const char * scheme,
191  bool byRemote,
192  OpalCall * call,
193  const char * conversationID
194  );
195 
197  typedef PSafeDictionary<PString, OpalIMContext> ContextsByConversationId;
199 
200  PDECLARE_MUTEX(m_contextsByNamesMutex);
201  typedef std::multimap<PString, PString> ContextsByNames;
203 
204  PDECLARE_MUTEX(m_notifierMutex);
205  typedef std::multimap<PString, ConversationNotifier> ConversationMap;
207 
210 };
211 
212 
218 {
219  PCLASSINFO(OpalIMConnection, OpalConnection);
220  public:
226  OpalCall & call,
227  OpalIMEndPoint & endpoint,
228  void * userData,
229  unsigned options,
230  OpalConnection::StringOptions * stringOptions
231  );
233 
244  virtual PBoolean IsNetworkConnection() const { return false; }
245 
249  virtual PBoolean OnSetUpConnection();
250 
262  virtual void OnEstablished();
263 
270  virtual void OnReleased();
272 
273  protected:
275 };
276 
277 
278 #endif // OPAL_HAS_IM
279 
280 #endif // OPAL_IM_EP_H
OpalManager & m_manager
Definition: im_ep.h:196
virtual PBoolean GarbageCollection()
bool RemoveNotifier(const ConversationNotifier &notifier, const PString &scheme)
Definition: manager.h:150
Definition: endpoint.h:65
void AddNotifier(const ConversationNotifier &notifier, const PString &scheme)
bool m_deleting
Definition: im_ep.h:209
static const PCaselessString & Prefix()
Definition: im_ep.h:40
std::multimap< PString, PString > ContextsByNames
Definition: im_ep.h:201
PSafePtr< OpalIMContext > CreateContext(const PURL &localURL, const PURL &remoteURL, const char *scheme=NULL)
Definition: im_ep.h:94
OpalIMContext * m_context
Definition: im_ep.h:274
PSafeDictionary< PString, OpalIMContext > ContextsByConversationId
Definition: im_ep.h:197
PSafePtr< OpalIMContext > FindContextByIdWithLock(const PString &key, PSafetyMode mode=PSafeReadWrite)
Definition: im.h:75
PTime m_lastGarbageCollection
Definition: im_ep.h:208
OpalIMContext::MessageDisposition OnRawMessageReceived(OpalIM &message, OpalConnection *connnection, PString &errorInfo)
Definition: mediafmt.h:112
Definition: connection.h:530
PSafePtr< OpalIMContext > InternalCreateContext(const PURL &localURL, const PURL &remoteURL, const char *scheme, bool byRemote, OpalCall *call, const char *conversationID)
PNotifierTemplate< OpalIMContext::ConversationInfo > ConversationNotifier
Type for converstaion notifiers.
Definition: im_ep.h:150
Definition: call.h:62
ContextsByNames m_contextsByNames
Definition: im_ep.h:202
void RemoveContext(OpalIMContext *context, bool byRemote)
OpalManager & GetManager() const
Definition: im_ep.h:184
virtual OpalMediaFormatList GetMediaFormats() const
virtual PBoolean IsNetworkConnection() const
Definition: im_ep.h:244
virtual void OnConversation(const OpalIMContext::ConversationInfo &info)
virtual void OnReleased()
PSafePtr< OpalIMContext > FindContextForMessageWithLock(OpalIM &im, OpalConnection *conn=NULL)
PSafePtr< OpalIMContext > FindContextByNamesWithLock(const PURL &local, const PURL &remote, PSafetyMode mode=PSafeReadWrite)
virtual void ShutDown()
std::multimap< PString, ConversationNotifier > ConversationMap
Definition: im_ep.h:205
virtual PBoolean OnSetUpConnection()
ContextsByConversationId m_contextsByConversationId
Definition: im_ep.h:198
Definition: connection.h:415
Definition: im.h:107
virtual void OnEstablished()
Definition: im_ep.h:217
OpalIMEndPoint(OpalManager &manager)
PDECLARE_MUTEX(m_contextsByNamesMutex)
ConversationMap m_notifiers
Definition: im_ep.h:206
virtual PSafePtr< OpalConnection > MakeConnection(OpalCall &call, const PString &party, void *userData=NULL, unsigned int options=0, OpalConnection::StringOptions *stringOptions=NULL)
OpalIMConnection(OpalCall &call, OpalIMEndPoint &endpoint, void *userData, unsigned options, OpalConnection::StringOptions *stringOptions)