im_ep.h

Go to the documentation of this file.
00001 /*
00002  * im_ep.h
00003  *
00004  * Endpoint for Instant Messaging
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  *
00008  * Copyright (c) 2008 Post Increment
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open Phone Abstraction Library.
00021  *
00022  * The Initial Developer of the Original Code is Post Increment
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 29850 $
00027  * $Author: rjongbloed $
00028  * $Date: 2013-05-31 02:34:06 -0500 (Fri, 31 May 2013) $
00029  */
00030 
00031 #ifndef OPAL_IM_EP_H
00032 #define OPAL_IM_EP_H
00033 
00034 #include <ptlib.h>
00035 #include <opal/buildopts.h>
00036 
00037 #if OPAL_HAS_IM
00038 
00039 #include <opal/endpoint.h>
00040 
00041 
00044 class OpalIMEndPoint : public OpalEndPoint
00045 {
00046   public:
00047     static const PCaselessString & Prefix();
00048 
00051     OpalIMEndPoint(OpalManager & manager);
00052     ~OpalIMEndPoint();
00054 
00055 
00058     virtual PSafePtr<OpalConnection> MakeConnection(
00059       OpalCall & call,          
00060       const PString & party,    
00061       void * userData = NULL,          
00062       unsigned int options = 0,     
00063       OpalConnection::StringOptions * stringOptions = NULL 
00064     );
00065 
00075     virtual OpalMediaFormatList GetMediaFormats() const;
00076 
00081     virtual PBoolean GarbageCollection();
00082 
00085     virtual void ShutDown();
00087 
00088 
00098     PSafePtr<OpalIMContext> CreateContext(
00099       const PURL & localURL,      
00100       const PURL & remoteURL,     
00101       const char * scheme = NULL  
00102     ) { return InternalCreateContext(localURL, remoteURL, scheme, false, NULL, NULL); }
00103 
00106     PSafePtr<OpalIMContext> CreateContext(
00107       OpalCall & call
00108     );
00109 
00114     void RemoveContext(OpalIMContext * context, bool byRemote);
00115 
00119     PSafePtr<OpalIMContext> FindContextByIdWithLock(
00120       const PString & key,
00121       PSafetyMode mode = PSafeReadWrite
00122     );
00123 
00127     PSafePtr<OpalIMContext> FindContextByNamesWithLock(
00128       const PURL & local, 
00129       const PURL & remote, 
00130       PSafetyMode mode = PSafeReadWrite
00131     );
00132 
00136     PSafePtr<OpalIMContext> FindContextForMessageWithLock(
00137       OpalIM & im,
00138       OpalConnection * conn = NULL
00139     );
00141 
00142 
00149     virtual void OnConversation(
00150       const OpalIMContext::ConversationInfo & info
00151     );
00152 
00154     typedef PNotifierTemplate<OpalIMContext::ConversationInfo> ConversationNotifier;
00155 
00157     #define PDECLARE_ConversationNotifier(cls, fn) PDECLARE_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::ConversationInfo)
00158 
00160     #define PDECLARE_ASYNC_ConversationNotifier(cls, fn) PDECLARE_ASYNC_NOTIFIER2(OpalIMContext, cls, fn, OpalIMContext::ConversationInfo)
00161 
00163     #define PCREATE_ConversationNotifier(fn) PCREATE_NOTIFIER2(fn, OpalIMContext::ConversationInfo)
00164 
00171     void AddNotifier(
00172       const ConversationNotifier & notifier,  
00173       const PString & scheme                  
00174     );
00175 
00178     bool RemoveNotifier(const ConversationNotifier & notifier, const PString & scheme);
00180 
00181 
00182     OpalIMContext::MessageDisposition OnRawMessageReceived(
00183       OpalIM & message,
00184       OpalConnection * connnection,
00185       PString & errorInfo
00186     );
00187 
00188     OpalManager & GetManager() const { return m_manager; }
00189 
00190   protected:
00191     PSafePtr<OpalIMContext> InternalCreateContext(
00192       const PURL & localURL,
00193       const PURL & remoteURL,
00194       const char * scheme,
00195       bool byRemote,
00196       OpalCall * call,
00197       const char * conversationID
00198     );
00199 
00200     OpalManager & m_manager;
00201     typedef PSafeDictionary<PString, OpalIMContext> ContextsByConversationId;
00202     ContextsByConversationId m_contextsByConversationId;
00203 
00204     PMutex m_contextsByNamesMutex;
00205     typedef std::multimap<PString, PString> ContextsByNames;
00206     ContextsByNames m_contextsByNames;
00207 
00208     PMutex m_notifierMutex;
00209     typedef std::multimap<PString, ConversationNotifier> ConversationMap;
00210     ConversationMap m_notifiers;
00211 
00212     PTime m_lastGarbageCollection;
00213     bool m_deleting;
00214 };
00215 
00216 
00221 class OpalIMConnection : public OpalConnection
00222 {
00223     PCLASSINFO(OpalIMConnection, OpalConnection);
00224   public:
00229     OpalIMConnection(
00230       OpalCall & call,              
00231       OpalIMEndPoint & endpoint,    
00232       void * userData,              
00233       unsigned options,             
00234       OpalConnection::StringOptions * stringOptions 
00235     );
00237 
00248     virtual PBoolean IsNetworkConnection() const { return false; }
00249 
00253     virtual PBoolean OnSetUpConnection();
00254 
00266     virtual void OnEstablished();
00267 
00274     virtual void OnReleased();
00276 
00277   protected:
00278     OpalIMContext * m_context;
00279 };
00280 
00281 
00282 #endif // OPAL_HAS_IM
00283 
00284 #endif // OPAL_IM_EP_H

Generated on 21 Jun 2013 for OPAL by  doxygen 1.4.7