cladvsnk.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:8k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: cladvsnk.cpp,v 1.3.24.1 2004/07/09 01:54:47 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. // include
  50. #include "hxtypes.h"
  51. #include "hxcom.h"
  52. #include "hxcore.h"
  53. #include "hxclsnk.h"
  54. // pxcomlib
  55. #include "cladvsnk.h"
  56. PXClientAdviseSink::PXClientAdviseSink()
  57. {
  58.     m_lRefCount = 0;
  59.     m_pPlayer   = NULL;
  60.     m_pResponse = NULL;
  61. }
  62. PXClientAdviseSink::~PXClientAdviseSink()
  63. {
  64.     Close();
  65. }
  66. STDMETHODIMP PXClientAdviseSink::QueryInterface(REFIID riid, void** ppvObj)
  67. {
  68.     HX_RESULT retVal = HXR_OK;
  69.     if (ppvObj)
  70.     {
  71.         if (IsEqualIID(riid, IID_IUnknown))
  72.         {
  73.             AddRef();
  74.             *ppvObj = (IUnknown*) (IHXClientAdviseSink*) this;
  75.         }
  76.         else if (IsEqualIID(riid, IID_IHXClientAdviseSink))
  77.         {
  78.             AddRef();
  79.             *ppvObj = (IHXClientAdviseSink*) this;
  80.         }
  81.         else
  82.         {
  83.             retVal = HXR_NOINTERFACE;
  84.         }
  85.     }
  86.     else
  87.     {
  88.         retVal = HXR_INVALID_PARAMETER;
  89.     }
  90.     return retVal;
  91. }
  92. STDMETHODIMP_(ULONG32) PXClientAdviseSink::AddRef()
  93. {
  94.     return InterlockedIncrement(&m_lRefCount);
  95. }
  96. STDMETHODIMP_(ULONG32) PXClientAdviseSink::Release()
  97. {
  98.     if (InterlockedDecrement(&m_lRefCount) > 0)
  99.     {
  100.         return m_lRefCount;
  101.     }
  102.     delete this;
  103.     return 0;
  104. }
  105. STDMETHODIMP PXClientAdviseSink::Init(IHXPlayer*                 pPlayer,
  106.                                       PXClientAdviseSinkResponse* pResponse)
  107. {
  108.     HX_RESULT retVal = HXR_OK;
  109.     if (pPlayer && pResponse)
  110.     {
  111.         // Save the IHXPlayer
  112.         HX_RELEASE(m_pPlayer);
  113.         m_pPlayer = pPlayer;
  114.         m_pPlayer->AddRef();
  115.         // Save the response interface
  116.         if (m_pResponse)
  117.         {
  118.             m_pResponse->Release();
  119.             m_pResponse = NULL;
  120.         }
  121.         m_pResponse = pResponse;
  122.         m_pResponse->AddRef();
  123.         // Add ourselves as a client advise sink
  124.         if (m_pPlayer)
  125.         {
  126.             // Get our own IHXClientAdviseSink interface
  127.             IHXClientAdviseSink* pSink = NULL;
  128.             QueryInterface(IID_IHXClientAdviseSink, (void**) &pSink);
  129.             if (pSink)
  130.             {
  131.                 retVal = m_pPlayer->AddAdviseSink(pSink);
  132.             }
  133.             HX_RELEASE(pSink);
  134.         }
  135.     }
  136.     else
  137.     {
  138.         retVal = HXR_FAIL;
  139.     }
  140.     return retVal;
  141. }
  142. STDMETHODIMP PXClientAdviseSink::Close()
  143. {
  144.     HX_RESULT retVal = HXR_OK;
  145.     // Remove ourselves as an advise sink
  146.     if (m_pPlayer)
  147.     {
  148.         // Get our own IHXClientAdviseSink interface
  149.         IHXClientAdviseSink* pSink = NULL;
  150.         QueryInterface(IID_IHXClientAdviseSink, (void**) &pSink);
  151.         if (pSink)
  152.         {
  153.             retVal = m_pPlayer->RemoveAdviseSink(pSink);
  154.         }
  155.         HX_RELEASE(pSink);
  156.     }
  157.     // Release our refs on the player and the response interfaces
  158.     HX_RELEASE(m_pPlayer);
  159.     if (m_pResponse)
  160.     {
  161.         m_pResponse->Release();
  162.         m_pResponse = NULL;
  163.     }
  164.     return retVal;
  165. }
  166. STDMETHODIMP PXClientAdviseSink::OnPosLength(UINT32 ulPosition, UINT32 ulLength)
  167. {
  168.     HX_RESULT retVal = HXR_FAIL;
  169.     if (m_pResponse)
  170.     {
  171.         retVal = m_pResponse->CASOnPosLength(ulPosition, ulLength);
  172.     }
  173.     return retVal;
  174. }
  175. STDMETHODIMP PXClientAdviseSink::OnPresentationOpened()
  176. {
  177.     HX_RESULT retVal = HXR_FAIL;
  178.     if (m_pResponse)
  179.     {
  180.         retVal = m_pResponse->CASOnPresentationOpened();
  181.     }
  182.     return retVal;
  183. }
  184. STDMETHODIMP PXClientAdviseSink::OnPresentationClosed()
  185. {
  186.     HX_RESULT retVal = HXR_FAIL;
  187.     if (m_pResponse)
  188.     {
  189.         retVal = m_pResponse->CASOnPresentationClosed();
  190.     }
  191.     return retVal;
  192. }
  193. STDMETHODIMP PXClientAdviseSink::OnStatisticsChanged()
  194. {
  195.     HX_RESULT retVal = HXR_FAIL;
  196.     if (m_pResponse)
  197.     {
  198.         retVal = m_pResponse->CASOnStatisticsChanged();
  199.     }
  200.     return retVal;
  201. }
  202. STDMETHODIMP PXClientAdviseSink::OnPreSeek(ULONG32 ulOldTime, ULONG32 ulNewTime)
  203. {
  204.     HX_RESULT retVal = HXR_FAIL;
  205.     if (m_pResponse)
  206.     {
  207.         retVal = m_pResponse->CASOnPreSeek(ulOldTime, ulNewTime);
  208.     }
  209.     return retVal;
  210. }
  211. STDMETHODIMP PXClientAdviseSink::OnPostSeek(ULONG32 ulOldTime, ULONG32 ulNewTime)
  212. {
  213.     HX_RESULT retVal = HXR_FAIL;
  214.     if (m_pResponse)
  215.     {
  216.         retVal = m_pResponse->CASOnPostSeek(ulOldTime, ulNewTime);
  217.     }
  218.     return retVal;
  219. }
  220. STDMETHODIMP PXClientAdviseSink::OnStop()
  221. {
  222.     HX_RESULT retVal = HXR_FAIL;
  223.     if (m_pResponse)
  224.     {
  225.         retVal = m_pResponse->CASOnStop();
  226.     }
  227.     return retVal;
  228. }
  229. STDMETHODIMP PXClientAdviseSink::OnPause(ULONG32 ulTime)
  230. {
  231.     HX_RESULT retVal = HXR_FAIL;
  232.     if (m_pResponse)
  233.     {
  234.         retVal = m_pResponse->CASOnPause(ulTime);
  235.     }
  236.     return retVal;
  237. }
  238. STDMETHODIMP PXClientAdviseSink::OnBegin(ULONG32 ulTime)
  239. {
  240.     HX_RESULT retVal = HXR_FAIL;
  241.     if (m_pResponse)
  242.     {
  243.         retVal = m_pResponse->CASOnBegin(ulTime);
  244.     }
  245.     return retVal;
  246. }
  247. STDMETHODIMP PXClientAdviseSink::OnBuffering(ULONG32 ulFlags, UINT16 unPercentComplete)
  248. {
  249.     HX_RESULT retVal = HXR_FAIL;
  250.     if (m_pResponse)
  251.     {
  252.         retVal = m_pResponse->CASOnBuffering(ulFlags, unPercentComplete);
  253.     }
  254.     return retVal;
  255. }
  256. STDMETHODIMP PXClientAdviseSink::OnContacting(const char* pHostName)
  257. {
  258.     HX_RESULT retVal = HXR_FAIL;
  259.     if (m_pResponse)
  260.     {
  261.         retVal = m_pResponse->CASOnContacting(pHostName);
  262.     }
  263.     return retVal;
  264. }