msrp.h

Go to the documentation of this file.
00001 /*
00002  * msrp.h
00003  *
00004  * Support for RFC 4975 Message Session Relay Protocol (MSRP)
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: 22675 $
00027  * $Author: rjongbloed $
00028  * $Date: 2009-05-20 04:23:29 +0000 (Wed, 20 May 2009) $
00029  */
00030 
00031 #ifndef OPAL_IM_MSRP_H
00032 #define OPAL_IM_MSRP_H
00033 
00034 #include <ptlib.h>
00035 #include <opal/buildopts.h>
00036 #include <opal/rtpconn.h>
00037 #include <opal/manager.h>
00038 #include <opal/mediastrm.h>
00039 #include <opal/mediatype.h>
00040 #include <im/im.h>
00041 
00042 #if OPAL_SIP
00043 #include <sip/sdp.h>
00044 #endif
00045 
00046 #if OPAL_HAS_MSRP
00047 
00048 class OpalMSRPMediaType : public OpalIMMediaType 
00049 {
00050   public:
00051     OpalMSRPMediaType();
00052     virtual OpalMediaSession * CreateMediaSession(OpalConnection & conn, unsigned sessionID) const;
00053 
00054 #if OPAL_SIP
00055     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00056 #endif
00057 };
00058 
00060 //
00061 //  Ancestor for all MSRP encoding types
00062 //
00063 
00064 class OpalMSRPEncoding {
00065 };
00066 
00068 //
00069 //
00070 //
00071 
00072 class OpalMSRPManager : public PObject
00073 {
00074   public:
00075     enum {
00076       DefaultPort = 2855
00077     };
00078 
00079     //
00080     //  Create an MSRP manager. This is a singleton class
00081     //
00082     OpalMSRPManager(OpalManager & opal, WORD port = DefaultPort);
00083     ~OpalMSRPManager();
00084 
00085     //
00086     //  Get the local address of the MSRP manager
00087     //
00088     bool GetLocalAddress(OpalTransportAddress & addr);
00089 
00090     //
00091     //  Get the local port for the MSRP manager
00092     //
00093     bool GetLocalPort(WORD & port);
00094 
00095     //
00096     //  Allocate a new MSRP session ID
00097     //
00098     std::string OpenSession();
00099 
00100     //
00101     //  Dellocate an existing MSRP session ID
00102     //
00103     void CloseSession(const std::string & id);
00104 
00105     //
00106     //  return session ID as a path
00107     //
00108     std::string SessionIDToPath(const std::string & id);
00109 
00110     //
00111     //  Main listening thread
00112     //
00113     void ThreadMain();
00114     OpalManager & GetOpalManager() { return opalManager; }
00115 
00116   protected:
00117     OpalManager & opalManager;
00118     WORD listeningPort;
00119     PMutex mutex;
00120     PAtomicInteger lastID;
00121     PTCPSocket listeningSocket;
00122     PThread * listeningThread;
00123     OpalTransportAddress listeningAddress;
00124 
00125     struct SessionInfo {
00126     };
00127 
00128     typedef std::map<std::string, SessionInfo> SessionInfoMap;
00129     SessionInfoMap sessionInfoMap;
00130 
00131     struct ConnectionInfo {
00132       PTCPSocket * socket;
00133     };
00134     typedef std::map<std::string, ConnectionInfo> ConnectionInfoMap;
00135     ConnectionInfoMap connectionInfoMap;
00136 
00137   private:
00138     static OpalMSRPManager * msrp;
00139 };
00140 
00142 
00143 class MSRPSession 
00144 {
00145   public:
00146     MSRPSession(OpalMSRPManager & _manager);
00147     ~MSRPSession();
00148 
00149 #if OPAL_SIP
00150     virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00151 #endif
00152 
00153     OpalMSRPManager & GetManager() { return manager; }
00154 
00155     PString GetURL() const { return url; }
00156 
00157   protected:
00158     OpalMSRPManager & manager;
00159     std::string msrpSessionId;
00160     PString url;
00161 };
00162 
00164 
00167 class OpalMSRPMediaSession : public OpalMediaSession
00168 {
00169   PCLASSINFO(OpalMSRPMediaSession, OpalMediaSession);
00170   public:
00171     OpalMSRPMediaSession(OpalConnection & connection, unsigned sessionId);
00172     OpalMSRPMediaSession(const OpalMSRPMediaSession & _obj);
00173 
00174     virtual void Close();
00175 
00176     virtual PObject * Clone() const { return new OpalMSRPMediaSession(*this); }
00177 
00178     virtual bool IsActive() const { return msrpSession != NULL; }
00179 
00180     virtual bool IsRTP() const { return false; }
00181 
00182     virtual bool HasFailed() const { return false; }
00183 
00184     virtual OpalTransportAddress GetLocalMediaAddress() const;
00185 
00186     virtual void SetRemoteMediaAddress(const OpalTransportAddress &, const OpalMediaFormatList & );
00187 
00188 #if OPAL_SIP
00189     virtual SDPMediaDescription * CreateSDPMediaDescription(
00190       const OpalTransportAddress & localAddress
00191     );
00192 #endif
00193 
00194     virtual OpalMediaStream * CreateMediaStream(
00195       const OpalMediaFormat & mediaFormat, 
00196       unsigned sessionID, 
00197       PBoolean isSource
00198     );
00199 
00200     MSRPSession * msrpSession;
00201 };
00202 
00204 
00205 class OpalMSRPMediaStream : public OpalIMMediaStream
00206 {
00207   public:
00208     OpalMSRPMediaStream(
00209       OpalConnection & conn,
00210       const OpalMediaFormat & mediaFormat, 
00211       unsigned sessionID,                  
00212       bool isSource,                       
00213       OpalMSRPMediaSession & msrpSession
00214 
00215     );
00216 
00217     ~OpalMSRPMediaStream();
00218 
00222     virtual PBoolean ReadData(
00223       BYTE * data,      
00224       PINDEX size,      
00225       PINDEX & length   
00226     );
00227 
00231     virtual PBoolean WriteData(
00232       const BYTE * data,   
00233       PINDEX length,       
00234       PINDEX & written     
00235     );
00236 
00241     virtual PBoolean Close();
00243   protected:
00244     OpalMSRPMediaSession & m_msrpSession;
00245 };
00246 
00247 #endif // OPAL_HAS_MSRP
00248 
00249 #endif // OPAL_IM_MSRP_H
00250 

Generated on Mon Feb 1 00:25:53 2010 for OPAL by  doxygen 1.5.1