chxpckts.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:18k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #ifndef _HXPCKTS_H_
  36. #include "hxcppflags.h"
  37. #ifndef HX_CPP_BASIC_TEMPLATES
  38. #include "old_hxpckts.h"
  39. #else
  40. #define _HXPCKTS_H_
  41. #include "assocvector.h"
  42. #include "hxtypes.h"
  43. #include "hlxclib/string.h"
  44. #include "hxmap.h"
  45. #include "ihxpckts.h"
  46. #include "hxbuffer.h" /* For all the places that just include this */
  47. struct HXPacketInfo
  48. {
  49.     UINT8   lost;
  50.     UINT8   ASMFlags;
  51.     UINT16  ASMRuleNumber;
  52.     UINT16  streamNum;
  53.     UINT32  time;
  54. };
  55. /****************************************************************************
  56.  * 
  57.  *        Class:
  58.  *
  59.  *                CHXPacket
  60.  *
  61.  *        Purpose:
  62.  *
  63.  *                PN implementation of a basic packet.
  64.  *
  65.  */
  66. class CHXPacket : public IHXRTPPacket
  67. {
  68. protected:
  69.     LONG32                m_lRefCount;
  70.     IHXBuffer*                m_pBuffer;
  71.     ULONG32                m_ulTime;
  72.     UINT16                m_uStreamNumber;        
  73.     UINT8                m_unASMFlags;
  74.     UINT16                m_unASMRuleNumber;
  75.     BOOL                m_bIsLost;
  76.     
  77.     ~CHXPacket()
  78.     {
  79.         if (m_pBuffer)
  80.         {
  81.             m_pBuffer->Release();
  82.         }
  83.     };
  84.     
  85.     inline HX_RESULT _Get(
  86.         IHXBuffer*& pBuffer, 
  87.         ULONG32 &ulTime,
  88.         UINT16 &uStreamNumber,
  89.         UINT8 &unASMFlags,
  90.         UINT16 &unASMRuleNumber);
  91.     inline HX_RESULT _Set(
  92.            IHXBuffer* pBuffer, 
  93.            ULONG32 ulTime,
  94.            UINT16 uStreamNumber,
  95.            UINT8 unASMFlags,
  96.            UINT16 unASMRuleNumber);
  97. public:
  98.     CHXPacket()
  99.         : m_lRefCount(0)
  100.         , m_pBuffer(NULL)
  101.         , m_ulTime(0)
  102.         , m_uStreamNumber(0)
  103.         , m_unASMFlags(0)
  104.         , m_unASMRuleNumber(0)
  105.         , m_bIsLost(FALSE)
  106.     {
  107.         ;
  108.     }
  109.     /*
  110.      *        IUnknown methods
  111.      */
  112.     STDMETHOD(QueryInterface)        (THIS_
  113.                                 REFIID riid,
  114.                                 void** ppvObj);
  115.     STDMETHOD_(ULONG32,AddRef)        (THIS);
  116.     STDMETHOD_(ULONG32,Release)        (THIS);
  117.     /*
  118.      *        IHXPacket methods
  119.      */
  120.     STDMETHOD(Get)  (THIS_
  121.                     REF(IHXBuffer*)        pBuffer, 
  122.                     REF(ULONG32)                ulTime,
  123.                     REF(UINT16)                uStreamNumber,
  124.                     REF(UINT8)                unASMFlags,
  125.                     REF(UINT16)                unASMRuleNumber);
  126.     STDMETHOD_(IHXBuffer*,GetBuffer)                (THIS);
  127.     STDMETHOD_(ULONG32,GetTime)                        (THIS);
  128.     STDMETHOD_(UINT16,GetStreamNumber)                (THIS);
  129.     STDMETHOD_(UINT8,GetASMFlags)                (THIS);
  130.     STDMETHOD_(UINT16,GetASMRuleNumber)                (THIS);
  131.     STDMETHOD_(BOOL,IsLost)                        (THIS);
  132.     STDMETHOD(SetAsLost)                        (THIS);
  133.     STDMETHOD(Set)                                (THIS_
  134.                                                 IHXBuffer*                pBuffer, 
  135.                                                 ULONG32                        ulTime,
  136.                                                 UINT16                        uStreamNumber,
  137.                                                 UINT8                        unASMFlags,
  138.                                                 UINT16                        unASMRuleNumber);
  139.     /*
  140.      *        IHXPacket methods
  141.      */
  142.    STDMETHOD(GetRTP)                                (THIS_
  143.                                                 REF(IHXBuffer*)        pBuffer, 
  144.                                                 REF(ULONG32)                ulTime,
  145.                                                 REF(ULONG32)                ulRTPTime,
  146.                                                 REF(UINT16)                uStreamNumber,
  147.                                                 REF(UINT8)                unASMFlags,
  148.                                                 REF(UINT16)                unASMRuleNumber);
  149.    STDMETHOD_(ULONG32,GetRTPTime)                (THIS);
  150.    STDMETHOD(SetRTP)                                (THIS_
  151.                                                 IHXBuffer*                pBuffer, 
  152.                                                 ULONG32                        ulTime,
  153.                                                 ULONG32                        ulRTPTime,
  154.                                                 UINT16                        uStreamNumber,
  155.                                                 UINT8                        unASMFlags,
  156.                                                 UINT16                        unASMRuleNumber);
  157.    // serialization method
  158.    static void        Pack        (IHXPacket* pPacket, char* pData, UINT32& ulSize);
  159.    static void        UnPack        (IHXPacket*& pPacket, char* pData, UINT32 ulSize);
  160. };
  161. /****************************************************************************
  162.  * 
  163.  *        Class:
  164.  *
  165.  *                CHXRTPPacket
  166.  *
  167.  *        Purpose:
  168.  *
  169.  *                PN implementation of a RTP packet.
  170.  *
  171.  */
  172. class CHXRTPPacket : public CHXPacket
  173. {
  174. protected:
  175.     ULONG32                        m_ulRTPTime;
  176.     ~CHXRTPPacket()
  177.     {
  178.         ;
  179.     }
  180. public:
  181.     CHXRTPPacket()
  182.         : m_ulRTPTime(0)
  183.     {
  184.         ;
  185.     }
  186.     /*
  187.      *        IUnknown methods - override
  188.      */
  189.     STDMETHOD(QueryInterface)        (THIS_
  190.                                 REFIID riid,
  191.                                 void** ppvObj);
  192.     STDMETHOD_(ULONG32,Release)        (THIS);
  193.     /*
  194.      *        IHXPacket methods - override
  195.      */
  196.     STDMETHOD(Set)                                (THIS_
  197.                                                 IHXBuffer*                pBuffer, 
  198.                                                 ULONG32                        ulTime,
  199.                                                 UINT16                        uStreamNumber,
  200.                                                 UINT8                        unASMFlags,
  201.                                                 UINT16                        unASMRuleNumber);
  202.     /*
  203.      *        IHXRTPPacket methods - override
  204.      */
  205.     STDMETHOD(GetRTP)                                (THIS_
  206.                                                 REF(IHXBuffer*)        pBuffer, 
  207.                                                 REF(ULONG32)                ulTime,
  208.                                                 REF(ULONG32)                ulRTPTime,
  209.                                                 REF(UINT16)                uStreamNumber,
  210.                                                 REF(UINT8)                unASMFlags,
  211.                                                 REF(UINT16)                unASMRuleNumber);
  212.     STDMETHOD_(ULONG32,GetRTPTime)                (THIS);
  213.     STDMETHOD(SetRTP)                                (THIS_
  214.                                                 IHXBuffer*                pBuffer, 
  215.                                                 ULONG32                        ulTime,
  216.                                                 ULONG32                        ulRTPTime,
  217.                                                 UINT16                        uStreamNumber,
  218.                                                 UINT8                        unASMFlags,
  219.                                                 UINT16                        unASMRuleNumber);
  220. };
  221. class _CStoreName
  222. {
  223. public:
  224.     _CStoreName();
  225.     virtual ~_CStoreName();
  226.     const CHXString& GetName() const;
  227.     void SetName(const char* szName);
  228. private:
  229.     CHXString m_strName;
  230. };
  231. class _CStoreNameUINT32Pair : public _CStoreName
  232. {
  233. public:
  234.     _CStoreNameUINT32Pair();
  235.     ~_CStoreNameUINT32Pair();
  236.     UINT32 GetValue();
  237.     void SetValue(UINT32 ulValue);
  238. private:
  239.     UINT32 m_ulValue;
  240. };
  241. class _CStoreNameBufferPair : public _CStoreName
  242. {
  243. public:
  244.     _CStoreNameBufferPair();
  245.     ~_CStoreNameBufferPair();
  246.     IHXBuffer* GetValue();
  247.     void SetValue(IHXBuffer* pbufValue);
  248. private:
  249.     IHXBuffer* m_pbufValue;
  250. };
  251. /****************************************************************************
  252.  * 
  253.  *        Class:
  254.  *
  255.  *                CHXHeader
  256.  *
  257.  *        Purpose:
  258.  *
  259.  *                PN implementation of a basic header.
  260.  *
  261.  */
  262. class CHXHeader : public IHXValues
  263. {
  264. private:
  265.     INT32                        m_lRefCount;
  266.     struct CValue
  267.     {
  268.         UINT32 m_lVal;
  269.         BOOL m_lValValid;
  270.         IHXBuffer* m_pIBuffer;
  271.         IHXBuffer* m_pIString;
  272.         const char* m_Key;
  273.         CValue() : m_lValValid(FALSE), m_pIBuffer(NULL), 
  274.             m_pIString(NULL), m_Key(NULL)
  275.         {
  276.         }
  277.         CValue(CValue const& rhs)
  278.         :   m_lVal(rhs.m_lVal), 
  279.             m_lValValid(rhs.m_lValValid), 
  280.             m_pIBuffer(rhs.m_pIBuffer),
  281.             m_pIString(rhs.m_pIString), 
  282.             m_Key(rhs.m_Key)
  283.         {
  284.             if (m_pIBuffer) m_pIBuffer->AddRef();
  285.             if (m_pIString) m_pIString->AddRef();
  286.         }
  287.         CValue& operator= (CValue const&);
  288.         ~CValue();
  289.         HX_RESULT Get(IHXBuffer* CValue::*pMem, IHXBuffer*& value) const
  290.         {
  291.             if (!(this->*pMem)) return HXR_FAIL;
  292.             value = this->*pMem;
  293.             value->AddRef ();
  294.             return HXR_OK;
  295.         }
  296.         
  297.         HX_RESULT Get(UINT32 CValue::*pMem, UINT32& value) const
  298.         {
  299.             HX_ASSERT(pMem == &CValue::m_lVal);
  300.             if (!m_lValValid) return HXR_FAIL;
  301.             value = m_lVal;
  302.             return HXR_OK;
  303.         }
  304.         
  305.         void Set(IHXBuffer* CValue::*pMem, IHXBuffer* value)
  306.         {
  307.             HX_ASSERT(value);
  308.             HX_RELEASE (this->*pMem);
  309.             this->*pMem = value;
  310.             value->AddRef();
  311.         }
  312.         
  313.         void Set(UINT32 CValue::*pMem, UINT32 value)
  314.         {
  315.                 m_lVal = value;
  316.                 m_lValValid = TRUE;
  317.         }
  318.         
  319.         void Swap(CValue& rhs)
  320.         {
  321.             std::swap(m_lVal, rhs.m_lVal);
  322.             std::swap(m_lValValid, rhs.m_lValValid);
  323.             std::swap(m_pIBuffer, rhs.m_pIBuffer);
  324.             std::swap(m_pIString, rhs.m_pIString);
  325.             std::swap(m_Key, rhs.m_Key);
  326.         }
  327.     };
  328.     struct MyCompare : public std::binary_function<const char*, const char*, bool>
  329.     {
  330.         char m_PreserveCase;
  331.         
  332.         explicit MyCompare(char PreserveCase) : m_PreserveCase(PreserveCase) 
  333.         {
  334.         }
  335.         bool operator()(const char* p1, const char* p2) const;
  336.     };
  337.     
  338.     typedef Loki::AssocVector<const char*, CValue, MyCompare> Map;
  339.     //typedef std::map<std::string, CValue/*, MyCompare*/> Map;
  340.     Map m_Map;
  341.     template <typename TVal>
  342.     HX_RESULT GetProperty(
  343.         const char* pPropertyName,
  344.         TVal CValue::*pMem,
  345.         TVal& value)
  346.     {
  347.         HX_ASSERT(pPropertyName);
  348.         //HX_ASSERT(pMem);
  349.         Map::const_iterator i = m_Map.find(pPropertyName);
  350.         return (i == m_Map.end()) ? HXR_FAIL : i->second.Get(pMem, value);
  351.     }
  352.     
  353.     template <typename TVal>
  354.     HX_RESULT SetProperty(
  355.             const char* pPropertyName,
  356.             TVal CValue::*pMem,
  357.             TVal value)
  358.     {
  359.         HX_ASSERT(pPropertyName);
  360.         Map::iterator i = m_Map.find(pPropertyName);
  361.         CValue* pVal; // uninitialized
  362.         if (i == m_Map.end())
  363.         {
  364.             char* pTmp = new char[strlen(pPropertyName)+1];
  365.             strcpy(pTmp, pPropertyName); /* Flawfinder: ignore */
  366.     pVal = &m_Map[pTmp];
  367.             pVal->m_Key = pTmp;
  368.         }
  369.         else
  370.         {
  371.             pVal = &i->second;
  372.         }
  373.         pVal->Set(pMem, value);
  374.         
  375.         return HXR_OK;
  376.     }
  377.     
  378.     template <typename TVal>
  379.     HX_RESULT GetNextProperty(
  380.             const char*& pPropertyName,
  381.             TVal CValue::*pMem,
  382.             TVal& value,
  383.             Map::const_iterator& iter)
  384.     {
  385.             for (; iter != m_Map.end(); ++iter)
  386.             {
  387.                     if (SUCCEEDED(iter->second.Get(pMem, value)))
  388.                     {
  389.                             pPropertyName = iter->second.m_Key;
  390.                             return HXR_OK;
  391.                     }
  392.             }
  393.             return HXR_FAIL;
  394.     }
  395.         Map::const_iterator 
  396.                 m_ULONG32Position,
  397.                 m_BufferPosition,
  398.                 m_CStringPosition;
  399.         ~CHXHeader();
  400.         PRIVATE_DESTRUCTORS_ARE_NOT_A_CRIME
  401. protected:
  402. #if 0
  403. // function to encode CString property escape sequences
  404.         IHXBuffer*                encodeCString(IHXBuffer* pBuffer);
  405. // function to encode buffer property int MIME Base64
  406.         IHXBuffer*                encodeBuffer(IHXBuffer* pBuffer);
  407. #endif
  408. public:
  409.         CHXHeader()
  410.                 : m_lRefCount(0)
  411.                 , m_Map(MyCompare(FALSE)) // case-insensitive by default
  412.         {
  413.                 m_ULONG32Position = m_BufferPosition = m_CStringPosition = m_Map.end();
  414.         }
  415.     /*
  416.      *        IUnknown methods
  417.      */
  418.     STDMETHOD(QueryInterface)                (THIS_
  419.                                         REFIID riid,
  420.                                         void** ppvObj);
  421.     STDMETHOD_(ULONG32,AddRef)                (THIS);
  422.     STDMETHOD_(ULONG32,Release)                (THIS);
  423.     /*
  424.      *        IHXValues methods
  425.      */
  426.     STDMETHOD(SetPropertyULONG32)        (THIS_
  427.                                         const char*         pPropertyName,
  428.                                         ULONG32                 uPropertyValue);
  429.     STDMETHOD(GetPropertyULONG32)        (THIS_
  430.                                         const char*         pPropertyName,
  431.                                         REF(ULONG32)         uPropertyValue);
  432.     STDMETHOD(GetFirstPropertyULONG32)        (THIS_
  433.                                         REF(const char*) pPropertyName,
  434.                                         REF(ULONG32)         uPropertyValue);
  435.     STDMETHOD(GetNextPropertyULONG32)        (THIS_
  436.                                         REF(const char*) pPropertyName,
  437.                                         REF(ULONG32)         uPropertyValue);
  438.     STDMETHOD(SetPropertyBuffer)        (THIS_
  439.                                         const char*         pPropertyName,
  440.                                         IHXBuffer*         pPropertyValue);
  441.     STDMETHOD(GetPropertyBuffer)        (THIS_
  442.                                         const char*         pPropertyName,
  443.                                         REF(IHXBuffer*) pPropertyValue);
  444. #if 0
  445.     STDMETHOD(GetEncodedPropertyBuffer)        (THIS_
  446.                                         const char*         pPropertyName,
  447.                                         REF(IHXBuffer*) pPropertyValue);
  448. #endif
  449.     STDMETHOD(GetFirstPropertyBuffer)        (THIS_
  450.                                         REF(const char*) pPropertyName,
  451.                                         REF(IHXBuffer*) pPropertyValue);
  452.     STDMETHOD(GetNextPropertyBuffer)        (THIS_
  453.                                         REF(const char*) pPropertyName,
  454.                                         REF(IHXBuffer*) pPropertyValue);
  455.     STDMETHOD(SetPropertyCString)        (THIS_
  456.                                         const char*         pPropertyName,
  457.                                         IHXBuffer*         pPropertyValue);
  458.     STDMETHOD(GetPropertyCString)        (THIS_
  459.                                         const char*         pPropertyName,
  460.                                         REF(IHXBuffer*) pPropertyValue);
  461. #if 0
  462.     STDMETHOD(GetEncodedPropertyCString)(THIS_
  463.                                         const char*         pPropertyName,
  464.                                         REF(IHXBuffer*) pPropertyValue);
  465. #endif
  466.     STDMETHOD(GetFirstPropertyCString)        (THIS_
  467.                                         REF(const char*) pPropertyName,
  468.                                         REF(IHXBuffer*) pPropertyValue);
  469.     STDMETHOD(GetNextPropertyCString)        (THIS_
  470.                                         REF(const char*) pPropertyName,
  471.                                         REF(IHXBuffer*) pPropertyValue);
  472.     void PreserveCase(BOOL bPreserve);
  473. public:
  474.     static void mergeHeaders
  475.     (
  476.         IHXValues* pIHXValuesDestHeaders, 
  477.         IHXValues* pIHXValuesSourceHeaders
  478.     );
  479. };
  480. #endif
  481. #endif /* _HXPCKTS_H_ */