MMSPool.cpp
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:3k
源码类别:

P2P编程

开发平台:

Visual C++

  1. /*
  2.  *  Openmysee
  3.  *
  4.  *  This program is free software; you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation; either version 2 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  This program is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with this program; if not, write to the Free Software
  16.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  *
  18.  */
  19. #include "stdafx.h"
  20. #include "mmspool.h"
  21. BOOL CMMSPool::AddNewMMS(string strChannel, string strMMSAddr)
  22. {
  23. HRESULT hr;
  24.     CMMSGraph *pMMS = new CMMSGraph(strChannel, strMMSAddr, &hr) ; 
  25.      
  26. if(FAILED(hr))
  27. {
  28. if(pMMS)
  29. delete pMMS;
  30. return FALSE;
  31. }
  32. EnterCriticalSection(&m_csList);
  33. m_listGraph.push_back(pMMS);
  34. LeaveCriticalSection(&m_csList);
  35. return TRUE;
  36. }
  37. BOOL CMMSPool::RemoveMMS(string strChannel)
  38. {
  39. EnterCriticalSection(&m_csList);
  40. BOOL bFinded = FALSE;
  41. list<CMMSGraph*>::iterator it = m_listGraph.begin();
  42. for(; it != m_listGraph.end(); it++) 
  43. {
  44. CMMSGraph* temp = *it;
  45. if(temp->GetChannelName() == strChannel) 
  46. {
  47. bFinded = TRUE;
  48. m_listGraph.erase(it);
  49. delete temp;
  50. break;
  51. }
  52. }
  53. LeaveCriticalSection(&m_csList);
  54. if(bFinded)
  55. return TRUE;
  56. else
  57. return FALSE;
  58. }
  59. BOOL CMMSPool::RunMMS(string strChannel)
  60. {
  61. EnterCriticalSection(&m_csList);
  62. if(SUCCEEDED(GetMMSByChannel(strChannel)->Run()))
  63. {
  64. LeaveCriticalSection(&m_csList);
  65. return TRUE;
  66. }
  67. else
  68. {
  69. LeaveCriticalSection(&m_csList);
  70. return FALSE;
  71. }
  72. LeaveCriticalSection(&m_csList);
  73. }
  74. BOOL CMMSPool::StopMMS(string strChannel)
  75. {
  76. EnterCriticalSection(&m_csList);
  77. if(NULL ==GetMMSByChannel(strChannel))
  78. return FALSE;
  79. if(SUCCEEDED(GetMMSByChannel(strChannel)->Stop()))
  80. {
  81. LeaveCriticalSection(&m_csList);
  82. return TRUE;
  83. }
  84. else
  85. {
  86. LeaveCriticalSection(&m_csList);
  87. return FALSE;
  88. }
  89. LeaveCriticalSection(&m_csList);
  90. }
  91. BOOL CMMSPool::PauseMMS(string strChannel)
  92. {
  93. EnterCriticalSection(&m_csList);
  94.      
  95. if(NULL ==GetMMSByChannel(strChannel))
  96.      return FALSE ;
  97. if(SUCCEEDED(GetMMSByChannel(strChannel)->Pause()))
  98. {
  99. LeaveCriticalSection(&m_csList);
  100. return TRUE;
  101. }
  102. else
  103. {
  104. LeaveCriticalSection(&m_csList);
  105. return FALSE;
  106. }
  107. LeaveCriticalSection(&m_csList);
  108. }
  109. MMSGRAPHINFO* CMMSPool::GetMMSGraphInfo(string strChannel)
  110. {
  111. MMSGRAPHINFO* pMMSInfo = NULL;
  112. EnterCriticalSection(&m_csList);
  113. CMMSGraph *pMMSGB = GetMMSByChannel(strChannel);
  114. if(pMMSGB)
  115. pMMSInfo = pMMSGB->GetMMSGraphInfo();
  116. LeaveCriticalSection(&m_csList);
  117. return pMMSInfo;
  118. }
  119. CMMSGraph* CMMSPool::GetMMSByChannel(string strChannel)
  120. {
  121. list<CMMSGraph*>::iterator it = m_listGraph.begin();
  122. for(; it != m_listGraph.end(); it++) 
  123. {
  124. CMMSGraph* temp = *it;
  125. if(temp->GetChannelName() == strChannel) 
  126. return temp;
  127. }
  128. return NULL;
  129. }
  130. void CMMSPool::RemoveAllMMS()
  131. {
  132. EnterCriticalSection(&m_csList);
  133. list<CMMSGraph*>::iterator it;
  134. while(m_listGraph.size() > 0) 
  135. {
  136. it = m_listGraph.begin();
  137. CMMSGraph* temp = *it;
  138. m_listGraph.erase(it);
  139. delete temp;
  140. }
  141. m_listGraph.clear();
  142. LeaveCriticalSection(&m_csList);
  143. }