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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: plsnkctl.cpp,v 1.3.20.1 2004/07/09 02:05:58 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 "hxcom.h"
  50. #include "hxtypes.h"
  51. #include "hxpsink.h"
  52. #include "hxslist.h"
  53. #include "plsnkctl.h"
  54. #include "hxheap.h"
  55. #ifdef _DEBUG
  56. #undef HX_THIS_FILE
  57. static const char HX_THIS_FILE[] = __FILE__;
  58. #endif
  59. /************************************************************************
  60.  *
  61.  * CHXPlayerSinkControl 
  62.  *
  63.  */
  64. CHXPlayerSinkControl::CHXPlayerSinkControl()
  65.     : m_lRefCount(0)
  66.     , m_pSinkList(NULL)
  67.     , m_pSinksToBeRemoved(NULL)
  68.     , m_bInPlayerClosed(FALSE)
  69. {
  70. }
  71. CHXPlayerSinkControl::~CHXPlayerSinkControl()
  72. {
  73.     Terminate();
  74. }
  75. void CHXPlayerSinkControl::Terminate()
  76. {
  77.     m_bInPlayerClosed = TRUE;
  78.     if (m_pSinkList)
  79.     {
  80. CHXSimpleList::Iterator lIterator = m_pSinkList->Begin();
  81.     
  82. for (; lIterator != m_pSinkList->End(); ++lIterator)
  83. {
  84.     IHXPlayerCreationSink* pPlayerSink = (IHXPlayerCreationSink*) (*lIterator);
  85.     pPlayerSink->Release();
  86. }
  87. m_pSinkList->RemoveAll();
  88. HX_DELETE(m_pSinkList);
  89.     }
  90.  
  91.     if (m_pSinksToBeRemoved)
  92.     {
  93.         m_pSinksToBeRemoved->RemoveAll();
  94.     }
  95.     HX_DELETE(m_pSinksToBeRemoved);
  96.     m_bInPlayerClosed = FALSE;
  97. }
  98. STDMETHODIMP
  99. CHXPlayerSinkControl::AddSink(IHXPlayerCreationSink* pPlayerSink)
  100. {
  101.     if (pPlayerSink)
  102.     {
  103. if (!m_pSinkList)
  104. {
  105.     m_pSinkList = new CHXSimpleList;
  106.     if (!m_pSinkList)
  107.     {
  108. return HXR_OUTOFMEMORY;
  109.     }
  110. }
  111.      m_pSinkList->AddTail(pPlayerSink);
  112.      pPlayerSink->AddRef();
  113.     
  114.     }
  115.     return HXR_OK;
  116. }
  117. STDMETHODIMP
  118. CHXPlayerSinkControl::RemoveSink(IHXPlayerCreationSink* pPlayerSink)
  119. {
  120.     if (m_pSinkList)
  121.     {
  122. LISTPOSITION pos = m_pSinkList->Find(pPlayerSink);
  123. if (pos)
  124. {
  125.     if (!m_bInPlayerClosed)
  126.     {
  127. m_pSinkList->RemoveAt(pos);     
  128. pPlayerSink->Release();
  129.     }
  130.     else
  131.     {
  132. if (!m_pSinksToBeRemoved)
  133. {
  134.     m_pSinksToBeRemoved = new CHXSimpleList;
  135.     if (!m_pSinksToBeRemoved)
  136.     {
  137. return HXR_OUTOFMEMORY;
  138.     }
  139. }
  140. /* Add to the list for later removal */
  141. m_pSinksToBeRemoved->AddTail(pPlayerSink);
  142.     }
  143.     return HXR_OK;
  144. }
  145.     }
  146.     return HXR_FAIL;
  147. }
  148. STDMETHODIMP 
  149. CHXPlayerSinkControl::QueryInterface(REFIID riid, void** ppvObj)
  150. {
  151.     QInterfaceList qiList[] =
  152.         {
  153.             { GET_IIDHANDLE(IID_IHXPlayerSinkControl), (IHXPlayerSinkControl*)this },
  154.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPlayerSinkControl*)this },
  155.         };
  156.     
  157.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);        
  158. }
  159. STDMETHODIMP_ (ULONG32) 
  160. CHXPlayerSinkControl::AddRef()
  161. {
  162.     return InterlockedIncrement(&m_lRefCount);
  163. }
  164. STDMETHODIMP_ (ULONG32) 
  165. CHXPlayerSinkControl::Release()
  166. {
  167.     if (InterlockedDecrement(&m_lRefCount) > 0)
  168.     {
  169. return m_lRefCount;
  170.     }
  171.     delete this;
  172.     return 0;
  173. }
  174. void
  175. CHXPlayerSinkControl::PlayerCreated (IHXPlayer* pPlayer)
  176. {
  177.     if (m_pSinkList)
  178.     {
  179. CHXSimpleList::Iterator lIterator = m_pSinkList->Begin();
  180.     
  181. for (; lIterator != m_pSinkList->End(); ++lIterator)
  182. {
  183.     IHXPlayerCreationSink* pPlayerSink = (IHXPlayerCreationSink*) (*lIterator);
  184.     pPlayerSink->PlayerCreated(pPlayer);
  185. }
  186.     }
  187. }
  188. void
  189. CHXPlayerSinkControl::PlayerClosed (IHXPlayer* pPlayer)
  190. {
  191.     if (m_pSinkList)
  192.     {
  193. m_bInPlayerClosed = TRUE;
  194. CHXSimpleList::Iterator lIterator = m_pSinkList->Begin();
  195.     
  196. for (; lIterator != m_pSinkList->End(); ++lIterator)
  197. {
  198.     IHXPlayerCreationSink* pPlayerSink = (IHXPlayerCreationSink*) (*lIterator);
  199.     pPlayerSink->PlayerClosed(pPlayer);
  200. }
  201. m_bInPlayerClosed = FALSE;
  202. if (m_pSinksToBeRemoved && m_pSinksToBeRemoved->GetCount() > 0)
  203. {
  204.     lIterator = m_pSinksToBeRemoved->Begin();
  205.     for (; lIterator != m_pSinksToBeRemoved->End(); ++lIterator)
  206.     {
  207. IHXPlayerCreationSink* pPlayerSink = 
  208.     (IHXPlayerCreationSink*) (*lIterator);
  209. RemoveSink(pPlayerSink);
  210.     }
  211.     m_pSinksToBeRemoved->RemoveAll();
  212. }
  213.     }
  214. }