plsnkctl.cpp
Upload User: zhongxx05
Upload Date: 2007-06-06
Package Size: 33641k
Code Size: 6k
Category:

Symbian

Development Platform:

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